diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-10 03:06:44 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-10-10 03:06:44 +0300 |
commit | 308146dc398fd4c13453048105498018459e0985 (patch) | |
tree | d843eb63c1672e4b18c483907e2cd4aa7fca708e /spec/lib/gitlab | |
parent | 4b28d5ae770c6bd332283a3f13ceae06329c409b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/auth/user_access_denied_reason_spec.rb | 8 | ||||
-rw-r--r-- | spec/lib/gitlab/auth_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/position_collection_spec.rb | 77 | ||||
-rw-r--r-- | spec/lib/gitlab/git_access_spec.rb | 13 |
4 files changed, 104 insertions, 0 deletions
diff --git a/spec/lib/gitlab/auth/user_access_denied_reason_spec.rb b/spec/lib/gitlab/auth/user_access_denied_reason_spec.rb index 8ec19c454d8..7045105a2c7 100644 --- a/spec/lib/gitlab/auth/user_access_denied_reason_spec.rb +++ b/spec/lib/gitlab/auth/user_access_denied_reason_spec.rb @@ -33,5 +33,13 @@ describe Gitlab::Auth::UserAccessDeniedReason do it { is_expected.to match /This action cannot be performed by internal users/ } end + + context 'when the user is deactivated' do + before do + user.deactivate! + end + + it { is_expected.to eq "Your account has been deactivated by your administrator. Please log back in from a web browser to reactivate your account at #{Gitlab.config.gitlab.url}" } + end end end diff --git a/spec/lib/gitlab/auth_spec.rb b/spec/lib/gitlab/auth_spec.rb index 3fc45bfc920..dc4b0b5b1b6 100644 --- a/spec/lib/gitlab/auth_spec.rb +++ b/spec/lib/gitlab/auth_spec.rb @@ -520,6 +520,12 @@ describe Gitlab::Auth do end end + it 'finds the user in deactivated state' do + user.deactivate! + + expect( gl_auth.find_with_user_password(username, password) ).to eql user + end + it "does not find user in blocked state" do user.block diff --git a/spec/lib/gitlab/diff/position_collection_spec.rb b/spec/lib/gitlab/diff/position_collection_spec.rb new file mode 100644 index 00000000000..de0e631ab03 --- /dev/null +++ b/spec/lib/gitlab/diff/position_collection_spec.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Diff::PositionCollection do + let(:merge_request) { build(:merge_request) } + + def build_text_position(attrs = {}) + attributes = { + old_path: "files/ruby/popen.rb", + new_path: "files/ruby/popen.rb", + old_line: nil, + new_line: 14, + diff_refs: merge_request.diff_refs + }.merge(attrs) + + Gitlab::Diff::Position.new(attributes) + end + + def build_image_position(attrs = {}) + attributes = { + old_path: "files/images/any_image.png", + new_path: "files/images/any_image.png", + width: 10, + height: 10, + x: 1, + y: 1, + diff_refs: merge_request.diff_refs, + position_type: "image" + }.merge(attrs) + + Gitlab::Diff::Position.new(attributes) + end + + let(:text_position) { build_text_position } + let(:folded_text_position) { build_text_position(old_line: 1, new_line: 1) } + let(:image_position) { build_image_position } + let(:head_sha) { merge_request.diff_head_sha } + + let(:collection) do + described_class.new([text_position, folded_text_position, image_position], head_sha) + end + + describe '#to_a' do + it 'returns all positions' do + expect(collection.to_a).to eq([text_position, folded_text_position, image_position]) + end + end + + describe '#unfoldable' do + it 'returns unfoldable diff positions' do + expect(collection.unfoldable).to eq([folded_text_position]) + end + + context 'when given head_sha does not match with positions head_sha' do + let(:head_sha) { 'unknown' } + + it 'returns no position' do + expect(collection.unfoldable).to be_empty + end + end + end + + describe '#concat' do + let(:new_text_position) { build_text_position(old_line: 1, new_line: 1) } + + it 'returns a Gitlab::Diff::Position' do + expect(collection.concat([new_text_position])).to be_a(described_class) + end + + it 'concatenates the new position to the collection' do + collection.concat([new_text_position]) + + expect(collection.to_a).to eq([text_position, folded_text_position, image_position, new_text_position]) + end + end +end diff --git a/spec/lib/gitlab/git_access_spec.rb b/spec/lib/gitlab/git_access_spec.rb index d584cdbe280..81dc96b538a 100644 --- a/spec/lib/gitlab/git_access_spec.rb +++ b/spec/lib/gitlab/git_access_spec.rb @@ -541,6 +541,13 @@ describe Gitlab::GitAccess do expect { pull_access_check }.to raise_unauthorized('Your account has been blocked.') end + it 'disallows deactivated users to pull' do + project.add_maintainer(user) + user.deactivate! + + expect { pull_access_check }.to raise_unauthorized("Your account has been deactivated by your administrator. Please log back in from a web browser to reactivate your account at #{Gitlab.config.gitlab.url}") + end + context 'when the project repository does not exist' do it 'returns not found' do project.add_guest(user) @@ -925,6 +932,12 @@ describe Gitlab::GitAccess do project.add_developer(user) end + it 'does not allow deactivated users to push' do + user.deactivate! + + expect { push_access_check }.to raise_unauthorized("Your account has been deactivated by your administrator. Please log back in from a web browser to reactivate your account at #{Gitlab.config.gitlab.url}") + end + it 'cleans up the files' do expect(project.repository).to receive(:clean_stale_repository_files).and_call_original expect { push_access_check }.not_to raise_error |