diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-03 18:10:03 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-03 18:10:03 +0000 |
commit | b6847c621ff246e6abceb90545d5a608318762d6 (patch) | |
tree | 460da2a6c2be2e4f5164c2bba1851b66260f850d /spec | |
parent | c08d9c22569d1c9e7c7737e183969593394133d9 (diff) | |
download | gitlab-ce-b6847c621ff246e6abceb90545d5a608318762d6.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
21 files changed, 167 insertions, 58 deletions
diff --git a/spec/controllers/concerns/controller_with_cross_project_access_check_spec.rb b/spec/controllers/concerns/controller_with_cross_project_access_check_spec.rb index 85989ea3e92..3f9d690837b 100644 --- a/spec/controllers/concerns/controller_with_cross_project_access_check_spec.rb +++ b/spec/controllers/concerns/controller_with_cross_project_access_check_spec.rb @@ -14,6 +14,7 @@ describe ControllerWithCrossProjectAccessCheck do context 'When reading cross project is not allowed' do before do allow(Ability).to receive(:allowed).and_call_original + expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original allow(Ability).to receive(:allowed?) .with(user, :read_cross_project, :global) .and_return(false) diff --git a/spec/controllers/graphql_controller_spec.rb b/spec/controllers/graphql_controller_spec.rb index a8e78524910..06a949471a7 100644 --- a/spec/controllers/graphql_controller_spec.rb +++ b/spec/controllers/graphql_controller_spec.rb @@ -46,6 +46,7 @@ describe GraphqlController do # User cannot access API in a couple of cases # * When user is internal(like ghost users) # * When user is blocked + expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original expect(Ability).to receive(:allowed?).with(user, :access_api, :global).and_return(false) post :execute diff --git a/spec/controllers/groups/boards_controller_spec.rb b/spec/controllers/groups/boards_controller_spec.rb index acfa8bc9354..b556af0eedc 100644 --- a/spec/controllers/groups/boards_controller_spec.rb +++ b/spec/controllers/groups/boards_controller_spec.rb @@ -26,6 +26,7 @@ describe Groups::BoardsController do context 'with unauthorized user' do before do + expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true) allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(true) allow(Ability).to receive(:allowed?).with(user, :read_board, group).and_return(false) @@ -70,6 +71,7 @@ describe Groups::BoardsController do context 'with unauthorized user' do before do + expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true) allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(true) allow(Ability).to receive(:allowed?).with(user, :read_board, group).and_return(false) @@ -106,6 +108,7 @@ describe Groups::BoardsController do context 'with unauthorized user' do before do + expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true) allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(true) allow(Ability).to receive(:allowed?).with(user, :read_board, group).and_return(false) @@ -144,6 +147,7 @@ describe Groups::BoardsController do context 'with unauthorized user' do before do + expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original allow(Ability).to receive(:allowed?).with(user, :read_cross_project, :global).and_return(true) allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(true) allow(Ability).to receive(:allowed?).with(user, :read_group, group).and_return(false) diff --git a/spec/controllers/projects/boards_controller_spec.rb b/spec/controllers/projects/boards_controller_spec.rb index ebfdb997974..6634801939b 100644 --- a/spec/controllers/projects/boards_controller_spec.rb +++ b/spec/controllers/projects/boards_controller_spec.rb @@ -32,6 +32,7 @@ describe Projects::BoardsController do context 'with unauthorized user' do before do + expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true) allow(Ability).to receive(:allowed?).with(user, :read_board, project).and_return(false) end @@ -75,6 +76,7 @@ describe Projects::BoardsController do context 'with unauthorized user' do before do + expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true) allow(Ability).to receive(:allowed?).with(user, :read_board, project).and_return(false) end @@ -130,6 +132,7 @@ describe Projects::BoardsController do context 'with unauthorized user' do before do + expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true) allow(Ability).to receive(:allowed?).with(user, :read_board, project).and_return(false) end @@ -167,6 +170,7 @@ describe Projects::BoardsController do context 'with unauthorized user' do before do + expect(Ability).to receive(:allowed?).with(user, :log_in, :global).and_call_original allow(Ability).to receive(:allowed?).with(user, :read_project, project).and_return(true) allow(Ability).to receive(:allowed?).with(user, :read_board, project).and_return(false) end diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index ccaf0dd997b..fb3c163dff1 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -29,6 +29,7 @@ FactoryBot.define do end pipeline factory: :ci_pipeline + project { pipeline.project } trait :degenerated do options { nil } @@ -220,10 +221,6 @@ FactoryBot.define do end end - after(:build) do |build, evaluator| - build.project ||= build.pipeline.project - end - trait :with_deployment do after(:build) do |build, evaluator| ## diff --git a/spec/factories/internal_ids.rb b/spec/factories/internal_ids.rb index bc6ea41ec06..02baaedb996 100644 --- a/spec/factories/internal_ids.rb +++ b/spec/factories/internal_ids.rb @@ -6,4 +6,10 @@ FactoryBot.define do usage { :issues } last_value { project.issues.maximum(:iid) || 0 } end + + trait :has_internal_id do + after(:stub) do |record| + record.iid ||= generate(:iid) + end + end end diff --git a/spec/factories/issues.rb b/spec/factories/issues.rb index 24c12a66599..4d0924a9412 100644 --- a/spec/factories/issues.rb +++ b/spec/factories/issues.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true FactoryBot.define do - factory :issue do + factory :issue, traits: [:has_internal_id] do title { generate(:title) } project author { project.creator } diff --git a/spec/factories/merge_requests.rb b/spec/factories/merge_requests.rb index 08a8ede61b1..abccd775c8a 100644 --- a/spec/factories/merge_requests.rb +++ b/spec/factories/merge_requests.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true FactoryBot.define do - factory :merge_request do + factory :merge_request, traits: [:has_internal_id] do title { generate(:title) } association :source_project, :repository, factory: :project target_project { source_project } diff --git a/spec/factories/milestones.rb b/spec/factories/milestones.rb index 32eee645f6a..151d286cc29 100644 --- a/spec/factories/milestones.rb +++ b/spec/factories/milestones.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true FactoryBot.define do - factory :milestone do + factory :milestone, traits: [:has_internal_id] do title transient do diff --git a/spec/factories/notes.rb b/spec/factories/notes.rb index a15c7625500..fdd1a9a18b2 100644 --- a/spec/factories/notes.rb +++ b/spec/factories/notes.rb @@ -40,7 +40,7 @@ FactoryBot.define do factory :discussion_note_on_personal_snippet, traits: [:on_personal_snippet], class: 'DiscussionNote' - factory :discussion_note_on_snippet, traits: [:on_snippet], class: 'DiscussionNote' + factory :discussion_note_on_project_snippet, traits: [:on_project_snippet], class: 'DiscussionNote' factory :legacy_diff_note_on_commit, traits: [:on_commit, :legacy_diff_note], class: 'LegacyDiffNote' @@ -120,23 +120,19 @@ FactoryBot.define do end trait :on_issue do - noteable { create(:issue, project: project) } - end - - trait :on_snippet do - noteable { create(:snippet, project: project) } + noteable { association(:issue, project: project) } end trait :on_merge_request do - noteable { create(:merge_request, source_project: project) } + noteable { association(:merge_request, source_project: project) } end trait :on_project_snippet do - noteable { create(:project_snippet, project: project) } + noteable { association(:project_snippet, project: project) } end trait :on_personal_snippet do - noteable { create(:personal_snippet) } + noteable { association(:personal_snippet) } project { nil } end diff --git a/spec/factories/sequences.rb b/spec/factories/sequences.rb index 17b54d69372..cdc64a8502e 100644 --- a/spec/factories/sequences.rb +++ b/spec/factories/sequences.rb @@ -11,4 +11,5 @@ FactoryBot.define do sequence(:label_title) { |n| "label#{n}" } sequence(:branch) { |n| "my-branch-#{n}" } sequence(:past_time) { |n| 4.hours.ago + (2 * n).seconds } + sequence(:iid) end diff --git a/spec/frontend/fixtures/snippet.rb b/spec/frontend/fixtures/snippet.rb index e91050cd2c5..d27c2fbe68b 100644 --- a/spec/frontend/fixtures/snippet.rb +++ b/spec/frontend/fixtures/snippet.rb @@ -27,7 +27,7 @@ describe SnippetsController, '(JavaScript fixtures)', type: :controller do end it 'snippets/show.html' do - create(:discussion_note_on_snippet, noteable: snippet, project: project, author: admin, note: '- [ ] Task List Item') + create(:discussion_note_on_project_snippet, noteable: snippet, project: project, author: admin, note: '- [ ] Task List Item') get(:show, params: { id: snippet.to_param }) diff --git a/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap b/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap index f7e15d4a5c4..88710b23bc9 100644 --- a/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap +++ b/spec/frontend/monitoring/components/__snapshots__/dashboard_template_spec.js.snap @@ -96,7 +96,7 @@ exports[`Dashboard template matches the default snapshot 1`] = ` variant="default" > <icon-stub - name="repeat" + name="retry" size="16" /> </gl-deprecated-button-stub> diff --git a/spec/graphql/types/snippet_type_spec.rb b/spec/graphql/types/snippet_type_spec.rb index ba0152ae983..6e580711fda 100644 --- a/spec/graphql/types/snippet_type_spec.rb +++ b/spec/graphql/types/snippet_type_spec.rb @@ -27,25 +27,9 @@ describe GitlabSchema.types['Snippet'] do end end - describe 'Repository URLs' do - let(:query) do - %( - { - snippets { - nodes { - sshUrlToRepo - httpUrlToRepo - } - } - } - ) - end - let(:response) { subject.dig('data', 'snippets', 'nodes')[0] } - - subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } - + shared_examples 'snippets with repositories' do context 'when snippet has repository' do - let!(:snippet) { create(:personal_snippet, :repository, :public, author: user) } + let_it_be(:snippet) { create(:personal_snippet, :repository, :public, author: user) } it 'responds with repository URLs' do expect(response['sshUrlToRepo']).to eq(snippet.ssh_url_to_repo) @@ -60,14 +44,44 @@ describe GitlabSchema.types['Snippet'] do it_behaves_like 'response without repository URLs' end end + end + shared_examples 'snippets without repositories' do context 'when snippet does not have a repository' do - let!(:snippet) { create(:personal_snippet, :public, author: user) } + let_it_be(:snippet) { create(:personal_snippet, :public, author: user) } it_behaves_like 'response without repository URLs' end end + describe 'Repository URLs' do + let(:query) do + %( + { + snippets { + nodes { + sshUrlToRepo + httpUrlToRepo + } + } + } + ) + end + let(:response) { subject.dig('data', 'snippets', 'nodes')[0] } + + subject { GitlabSchema.execute(query, context: { current_user: user }).as_json } + + context 'when RequestStore is disabled' do + it_behaves_like 'snippets with repositories' + it_behaves_like 'snippets without repositories' + end + + context 'when RequestStore is enabled', :request_store do + it_behaves_like 'snippets with repositories' + it_behaves_like 'snippets without repositories' + end + end + describe '#blob' do let(:query_blob) { subject.dig('data', 'snippets', 'edges')[0]['node']['blob'] } let(:query) do diff --git a/spec/helpers/events_helper_spec.rb b/spec/helpers/events_helper_spec.rb index 0109525bcac..ff99f76eb4d 100644 --- a/spec/helpers/events_helper_spec.rb +++ b/spec/helpers/events_helper_spec.rb @@ -181,7 +181,7 @@ describe EventsHelper do end it 'returns a project snippet note url' do - event.target = create(:note, :on_snippet, note: 'keep going') + event.target = create(:note_on_project_snippet, note: 'keep going') expect(subject).to eq("#{project_base_url}/snippets/#{event.note_target.id}#note_#{event.target.id}") end diff --git a/spec/lib/gitlab/danger/changelog_spec.rb b/spec/lib/gitlab/danger/changelog_spec.rb index c61e47f80d9..ba23c3828de 100644 --- a/spec/lib/gitlab/danger/changelog_spec.rb +++ b/spec/lib/gitlab/danger/changelog_spec.rb @@ -28,18 +28,6 @@ describe Gitlab::Danger::Changelog do describe '#needed?' do subject { changelog.needed? } - [ - { docs: nil }, - { none: nil }, - { docs: nil, none: nil } - ].each do |categories| - let(:changes_by_category) { categories } - - it "is falsy when categories don't require a changelog" do - is_expected.to be_falsy - end - end - where(:categories, :labels) do { backend: nil } | %w[backend backstage] { frontend: nil, docs: nil } | ['ci-build'] @@ -50,7 +38,7 @@ describe Gitlab::Danger::Changelog do let(:changes_by_category) { categories } let(:mr_labels) { labels } - it "is falsy when labels require no changelog" do + it "is falsy when categories and labels require no changelog" do is_expected.to be_falsy end end diff --git a/spec/lib/gitlab/gfm/reference_rewriter_spec.rb b/spec/lib/gitlab/gfm/reference_rewriter_spec.rb index a3904f4a97c..084dde1f93f 100644 --- a/spec/lib/gitlab/gfm/reference_rewriter_spec.rb +++ b/spec/lib/gitlab/gfm/reference_rewriter_spec.rb @@ -3,11 +3,11 @@ require 'spec_helper' describe Gitlab::Gfm::ReferenceRewriter do - let(:group) { create(:group) } - let(:old_project) { create(:project, name: 'old-project', group: group) } - let(:new_project) { create(:project, name: 'new-project', group: group) } - let(:user) { create(:user) } + let_it_be(:group) { create(:group) } + let_it_be(:user) { create(:user) } + let(:new_project) { create(:project, name: 'new-project', group: group) } + let(:old_project) { create(:project, name: 'old-project', group: group) } let(:old_project_ref) { old_project.to_reference_base(new_project) } let(:text) { 'some text' } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 291c628bfde..12f83e6d8c6 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -4475,4 +4475,73 @@ describe User, :do_not_mock_admin_mode do end end end + + describe '#active_for_authentication?' do + subject { user.active_for_authentication? } + + let(:user) { create(:user) } + + context 'when user is blocked' do + before do + user.block + end + + it { is_expected.to be false } + end + + context 'when user is a ghost user' do + before do + user.update(ghost: true) + end + + it { is_expected.to be false } + end + + context 'based on user type' do + using RSpec::Parameterized::TableSyntax + + where(:user_type, :expected_result) do + 'human' | true + 'alert_bot' | false + end + + with_them do + before do + user.update(user_type: user_type) + end + + it { is_expected.to be expected_result } + end + end + end + + describe '#inactive_message' do + subject { user.inactive_message } + + let(:user) { create(:user) } + + context 'when user is blocked' do + before do + user.block + end + + it { is_expected.to eq User::BLOCKED_MESSAGE } + end + + context 'when user is an internal user' do + before do + user.update(ghost: true) + end + + it { is_expected.to be User::LOGIN_FORBIDDEN } + end + + context 'when user is locked' do + before do + user.lock_access! + end + + it { is_expected.to be :locked } + end + end end diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb index 4b110874df0..86b3dd4095f 100644 --- a/spec/requests/api/commits_spec.rb +++ b/spec/requests/api/commits_spec.rb @@ -1889,11 +1889,11 @@ describe API::Commits do context 'unsigned commit' do it_behaves_like '404 response' do let(:request) { get api(route, current_user) } - let(:message) { '404 GPG Signature Not Found'} + let(:message) { '404 Signature Not Found'} end end - context 'signed commit' do + context 'gpg signed commit' do let(:commit) { project.repository.commit(GpgHelpers::SIGNED_COMMIT_SHA) } let(:commit_id) { commit.id } @@ -1901,11 +1901,35 @@ describe API::Commits do get api(route, current_user) expect(response).to have_gitlab_http_status(:ok) + expect(json_response['signature_type']).to eq('PGP') expect(json_response['gpg_key_id']).to eq(commit.signature.gpg_key_id) expect(json_response['gpg_key_subkey_id']).to eq(commit.signature.gpg_key_subkey_id) expect(json_response['gpg_key_primary_keyid']).to eq(commit.signature.gpg_key_primary_keyid) expect(json_response['verification_status']).to eq(commit.signature.verification_status) end end + + context 'x509 signed commit' do + let(:commit) { project.repository.commit_by(oid: '189a6c924013fc3fe40d6f1ec1dc20214183bc97') } + let(:commit_id) { commit.id } + + it 'returns correct JSON' do + get api(route, current_user) + + expect(response).to have_gitlab_http_status(:ok) + expect(json_response['signature_type']).to eq('X509') + expect(json_response['verification_status']).to eq(commit.signature.verification_status) + expect(json_response['x509_certificate']['id']).to eq(commit.signature.x509_certificate.id) + expect(json_response['x509_certificate']['subject']).to eq(commit.signature.x509_certificate.subject) + expect(json_response['x509_certificate']['subject_key_identifier']).to eq(commit.signature.x509_certificate.subject_key_identifier) + expect(json_response['x509_certificate']['email']).to eq(commit.signature.x509_certificate.email) + expect(json_response['x509_certificate']['serial_number']).to eq(commit.signature.x509_certificate.serial_number) + expect(json_response['x509_certificate']['certificate_status']).to eq(commit.signature.x509_certificate.certificate_status) + expect(json_response['x509_certificate']['x509_issuer']['id']).to eq(commit.signature.x509_certificate.x509_issuer.id) + expect(json_response['x509_certificate']['x509_issuer']['subject']).to eq(commit.signature.x509_certificate.x509_issuer.subject) + expect(json_response['x509_certificate']['x509_issuer']['subject_key_identifier']).to eq(commit.signature.x509_certificate.x509_issuer.subject_key_identifier) + expect(json_response['x509_certificate']['x509_issuer']['crl_url']).to eq(commit.signature.x509_certificate.x509_issuer.crl_url) + end + end end end diff --git a/spec/requests/api/discussions_spec.rb b/spec/requests/api/discussions_spec.rb index e4dd6dfbeff..cb3efb2cf5f 100644 --- a/spec/requests/api/discussions_spec.rb +++ b/spec/requests/api/discussions_spec.rb @@ -31,7 +31,7 @@ describe API::Discussions do context 'when noteable is a Snippet' do let!(:snippet) { create(:project_snippet, project: project, author: user) } - let!(:snippet_note) { create(:discussion_note_on_snippet, noteable: snippet, project: project, author: user) } + let!(:snippet_note) { create(:discussion_note_on_project_snippet, noteable: snippet, project: project, author: user) } it_behaves_like 'discussions API', 'projects', 'snippets', 'id' do let(:parent) { project } diff --git a/spec/support/helpers/repo_helpers.rb b/spec/support/helpers/repo_helpers.rb index 255a15b1ab0..7741c805b37 100644 --- a/spec/support/helpers/repo_helpers.rb +++ b/spec/support/helpers/repo_helpers.rb @@ -33,6 +33,7 @@ eos def sample_commit OpenStruct.new( id: "570e7b2abdd848b95f2f578043fc23bd6f6fd24d", + sha: "570e7b2abdd848b95f2f578043fc23bd6f6fd24d", parent_id: '6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9', author_full_name: "Dmitriy Zaporozhets", author_email: "dmitriy.zaporozhets@gmail.com", @@ -50,6 +51,7 @@ eos def another_sample_commit OpenStruct.new( id: "e56497bb5f03a90a51293fc6d516788730953899", + sha: "e56497bb5f03a90a51293fc6d516788730953899", parent_id: '4cd80ccab63c82b4bad16faa5193fbd2aa06df40', author_full_name: "Sytse Sijbrandij", author_email: "sytse@gitlab.com", @@ -69,6 +71,7 @@ eos def sample_big_commit OpenStruct.new( id: "913c66a37b4a45b9769037c55c2d238bd0942d2e", + sha: "913c66a37b4a45b9769037c55c2d238bd0942d2e", author_full_name: "Dmitriy Zaporozhets", author_email: "dmitriy.zaporozhets@gmail.com", message: <<eos @@ -81,6 +84,7 @@ eos def sample_image_commit OpenStruct.new( id: "2f63565e7aac07bcdadb654e253078b727143ec4", + sha: "2f63565e7aac07bcdadb654e253078b727143ec4", author_full_name: "Dmitriy Zaporozhets", author_email: "dmitriy.zaporozhets@gmail.com", old_blob_id: '33f3729a45c02fc67d00adb1b8bca394b0e761d9', |