diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-21 15:11:26 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-21 15:11:26 +0300 |
commit | eac99f198f2834788c38108bcee3a2c567fba9e0 (patch) | |
tree | 427b3e304f49b62a207f345d2ebb9ded47ee63d4 /spec | |
parent | 59ffff96dfdb114c112d14cedc5dfd9553cf568b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/repositories/git_http_controller_spec.rb | 4 | ||||
-rw-r--r-- | spec/features/boards/boards_spec.rb | 4 | ||||
-rw-r--r-- | spec/features/boards/new_issue_spec.rb | 50 | ||||
-rw-r--r-- | spec/features/groups/board_spec.rb | 6 | ||||
-rw-r--r-- | spec/frontend/boards/components/board_list_header_spec.js | 105 | ||||
-rw-r--r-- | spec/lib/gitlab/i18n/pluralization_spec.rb | 53 | ||||
-rw-r--r-- | spec/lib/gitlab/i18n_spec.rb | 17 | ||||
-rw-r--r-- | spec/lib/gitlab/instrumentation/redis_base_spec.rb | 12 | ||||
-rw-r--r-- | spec/lib/gitlab/instrumentation/redis_interceptor_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/redis/cache_spec.rb | 17 | ||||
-rw-r--r-- | spec/lib/gitlab/redis/rate_limiting_spec.rb | 17 | ||||
-rw-r--r-- | spec/lib/gitlab/redis/repository_cache_spec.rb | 15 | ||||
-rw-r--r-- | spec/requests/api/draft_notes_spec.rb | 96 | ||||
-rw-r--r-- | spec/requests/git_http_spec.rb | 18 | ||||
-rw-r--r-- | spec/support/shared_examples/controllers/repositories/git_http_controller_shared_examples.rb | 12 |
15 files changed, 291 insertions, 137 deletions
diff --git a/spec/controllers/repositories/git_http_controller_spec.rb b/spec/controllers/repositories/git_http_controller_spec.rb index da62acb1fda..93857435c9d 100644 --- a/spec/controllers/repositories/git_http_controller_spec.rb +++ b/spec/controllers/repositories/git_http_controller_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Repositories::GitHttpController do +RSpec.describe Repositories::GitHttpController, feature_category: :source_code_management do let_it_be(:project) { create(:project, :public, :repository) } let_it_be(:personal_snippet) { create(:personal_snippet, :public, :repository) } let_it_be(:project_snippet) { create(:project_snippet, :public, :repository, project: project) } @@ -14,7 +14,7 @@ RSpec.describe Repositories::GitHttpController do request.headers.merge! auth_env(user.username, user.password, nil) end - context 'when Gitaly is unavailable' do + context 'when Gitaly is unavailable', :use_clean_rails_redis_caching do it 'responds with a 503 message' do expect(Gitlab::GitalyClient).to receive(:call).and_raise(GRPC::Unavailable) diff --git a/spec/features/boards/boards_spec.rb b/spec/features/boards/boards_spec.rb index 87896b60f87..1ea6e079104 100644 --- a/spec/features/boards/boards_spec.rb +++ b/spec/features/boards/boards_spec.rb @@ -591,7 +591,9 @@ RSpec.describe 'Project issue boards', :js, feature_category: :team_planning do def remove_list page.within(find('.board:nth-child(2)')) do - find('button[title="List settings"]').click + dropdown = first("[data-testid='header-list-actions']") + dropdown.click + click_button('Edit list settings') end page.within(find('.js-board-settings-sidebar')) do diff --git a/spec/features/boards/new_issue_spec.rb b/spec/features/boards/new_issue_spec.rb index d597c57ac1c..6753f0ea009 100644 --- a/spec/features/boards/new_issue_spec.rb +++ b/spec/features/boards/new_issue_spec.rb @@ -32,18 +32,23 @@ RSpec.describe 'Issue Boards new issue', :js, feature_category: :team_planning d end it 'displays new issue button' do - expect(first('.board')).to have_button('New issue', count: 1) + dropdown = first("[data-testid='header-list-actions']") + dropdown.click + expect(first('.board')).to have_button('Create new issue', count: 1) end it 'does not display new issue button in closed list' do page.within('.board:nth-child(3)') do - expect(page).not_to have_button('New issue') + expect(page).not_to have_selector("[data-testid='header-list-actions']") + expect(page).not_to have_button('Create new issue') end end it 'shows form when clicking button' do page.within(first('.board')) do - click_button 'New issue' + dropdown = first("[data-testid='header-list-actions']") + dropdown.click + click_button 'Create new issue' expect(page).to have_selector('.board-new-issue-form') end @@ -51,7 +56,9 @@ RSpec.describe 'Issue Boards new issue', :js, feature_category: :team_planning d it 'hides form when clicking cancel' do page.within(first('.board')) do - click_button 'New issue' + dropdown = first("[data-testid='header-list-actions']") + dropdown.click + click_button 'Create new issue' expect(page).to have_selector('.board-new-issue-form') @@ -63,7 +70,9 @@ RSpec.describe 'Issue Boards new issue', :js, feature_category: :team_planning d it 'creates new issue, places it on top of the list, and opens sidebar' do page.within(first('.board')) do - click_button 'New issue' + dropdown = first("[data-testid='header-list-actions']") + dropdown.click + click_button 'Create new issue' end page.within(first('.board-new-issue-form')) do @@ -91,7 +100,9 @@ RSpec.describe 'Issue Boards new issue', :js, feature_category: :team_planning d it 'successfuly loads labels to be added to newly created issue' do page.within(first('.board')) do - click_button 'New issue' + dropdown = first("[data-testid='header-list-actions']") + dropdown.click + click_button 'Create new issue' end page.within(first('.board-new-issue-form')) do @@ -121,7 +132,9 @@ RSpec.describe 'Issue Boards new issue', :js, feature_category: :team_planning d wait_for_all_requests page.within('.board:nth-child(2)') do - click_button('New issue') + dropdown = first("[data-testid='header-list-actions']") + dropdown.click + click_button('Create new issue') page.within(first('.board-new-issue-form')) do find('.form-control').set('new issue') @@ -144,12 +157,14 @@ RSpec.describe 'Issue Boards new issue', :js, feature_category: :team_planning d end it 'does not display new issue button in open list' do - expect(first('.board')).not_to have_button('New issue') + expect(page).not_to have_selector("[data-testid='header-list-actions']") + expect(first('.board')).not_to have_button('Create new issue') end it 'does not display new issue button in label list' do page.within('.board:nth-child(2)') do - expect(page).not_to have_button('New issue') + expect(page).not_to have_selector("[data-testid='header-list-actions']") + expect(page).not_to have_button('Create new issue') end end end @@ -173,7 +188,8 @@ RSpec.describe 'Issue Boards new issue', :js, feature_category: :team_planning d context 'when backlog does not exist' do it 'does not display new issue button in label list' do page.within('.board.is-draggable') do - expect(page).not_to have_button('New issue') + expect(page).not_to have_selector("[data-testid='header-list-actions']") + expect(page).not_to have_button('Create new issue') end end end @@ -182,12 +198,14 @@ RSpec.describe 'Issue Boards new issue', :js, feature_category: :team_planning d let_it_be(:backlog_list) { create(:backlog_list, board: group_board) } it 'does not display new issue button in open list' do - expect(first('.board')).not_to have_button('New issue') + expect(page).not_to have_selector("[data-testid='header-list-actions']") + expect(first('.board')).not_to have_button('Create new issue') end it 'does not display new issue button in label list' do page.within('.board.is-draggable') do - expect(page).not_to have_button('New issue') + expect(page).not_to have_selector("[data-testid='header-list-actions']") + expect(page).not_to have_button('Create new issue') end end end @@ -205,7 +223,9 @@ RSpec.describe 'Issue Boards new issue', :js, feature_category: :team_planning d context 'when backlog does not exist' do it 'display new issue button in label list' do - expect(board_list_header).to have_button('New issue') + dropdown = first("[data-testid='header-list-actions']") + dropdown.click + expect(board_list_header).to have_button('Create new issue') end end @@ -214,7 +234,9 @@ RSpec.describe 'Issue Boards new issue', :js, feature_category: :team_planning d before do page.within(board_list_header) do - click_button 'New issue' + dropdown = first("[data-testid='header-list-actions']") + dropdown.click + click_button 'Create new issue' end project_select_dropdown.click diff --git a/spec/features/groups/board_spec.rb b/spec/features/groups/board_spec.rb index c451a97bed5..8acf3ffe441 100644 --- a/spec/features/groups/board_spec.rb +++ b/spec/features/groups/board_spec.rb @@ -25,8 +25,10 @@ RSpec.describe 'Group Boards', feature_category: :team_planning do it 'adds an issue to the backlog' do page.within(find('.board', match: :first)) do - issue_title = 'New Issue' - click_button 'New issue' + dropdown = first("[data-testid='header-list-actions']") + dropdown.click + issue_title = 'Create new issue' + click_button issue_title wait_for_requests diff --git a/spec/frontend/boards/components/board_list_header_spec.js b/spec/frontend/boards/components/board_list_header_spec.js index 9e65e900440..f8865bb6feb 100644 --- a/spec/frontend/boards/components/board_list_header_spec.js +++ b/spec/frontend/boards/components/board_list_header_spec.js @@ -1,10 +1,9 @@ -import { shallowMount } from '@vue/test-utils'; +import { GlDisclosureDropdown, GlDisclosureDropdownItem } from '@gitlab/ui'; import Vue, { nextTick } from 'vue'; import VueApollo from 'vue-apollo'; import Vuex from 'vuex'; import createMockApollo from 'helpers/mock_apollo_helper'; -import { extendedWrapper } from 'helpers/vue_test_utils_helper'; - +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { boardListQueryResponse, mockLabelList } from 'jest/boards/mock_data'; import BoardListHeader from '~/boards/components/board_list_header.vue'; import { ListType } from '~/boards/constants'; @@ -64,31 +63,33 @@ describe('Board List Header Component', () => { fakeApollo = createMockApollo([[listQuery, listQueryHandler]]); - wrapper = extendedWrapper( - shallowMount(BoardListHeader, { - apolloProvider: fakeApollo, - store, - propsData: { - list: listMock, - }, - provide: { - boardId, - weightFeatureAvailable: false, - currentUserId, - isEpicBoard: false, - disabled: false, - ...injectedProps, - }, - }), - ); + wrapper = shallowMountExtended(BoardListHeader, { + apolloProvider: fakeApollo, + store, + propsData: { + list: listMock, + }, + provide: { + boardId, + weightFeatureAvailable: false, + currentUserId, + isEpicBoard: false, + disabled: false, + ...injectedProps, + }, + stubs: { + GlDisclosureDropdown, + GlDisclosureDropdownItem, + }, + }); }; + const findDropdown = () => wrapper.findComponent(GlDisclosureDropdown); const isCollapsed = () => wrapper.vm.list.collapsed; - - const findAddIssueButton = () => wrapper.findComponent({ ref: 'newIssueBtn' }); const findTitle = () => wrapper.find('.board-title'); const findCaret = () => wrapper.findByTestId('board-title-caret'); - const findSettingsButton = () => wrapper.findComponent({ ref: 'settingsBtn' }); + const findNewIssueButton = () => wrapper.findByTestId('newIssueBtn'); + const findSettingsButton = () => wrapper.findByTestId('settingsBtn'); describe('Add issue button', () => { const hasNoAddButton = [ListType.closed]; @@ -100,59 +101,49 @@ describe('Board List Header Component', () => { ListType.assignee, ]; - it.each(hasNoAddButton)('does not render when List Type is `%s`', (listType) => { + it.each(hasNoAddButton)('does not render dropdown when List Type is `%s`', (listType) => { createComponent({ listType }); - expect(findAddIssueButton().exists()).toBe(false); + expect(findDropdown().exists()).toBe(false); }); it.each(hasAddButton)('does render when List Type is `%s`', (listType) => { createComponent({ listType }); - expect(findAddIssueButton().exists()).toBe(true); + expect(findDropdown().exists()).toBe(true); + expect(findNewIssueButton().exists()).toBe(true); }); - it('has a test for each list type', () => { - createComponent(); - - Object.values(ListType).forEach((value) => { - expect([...hasAddButton, ...hasNoAddButton]).toContain(value); - }); - }); - - it('does not render when logged out', () => { + it('does not render dropdown when logged out', () => { createComponent({ currentUserId: null, }); - expect(findAddIssueButton().exists()).toBe(false); + expect(findDropdown().exists()).toBe(false); }); }); describe('Settings Button', () => { - describe('with disabled=true', () => { - const hasSettings = [ - ListType.assignee, - ListType.milestone, - ListType.iteration, - ListType.label, - ]; - const hasNoSettings = [ListType.backlog, ListType.closed]; - - it.each(hasSettings)('does render for List Type `%s` when disabled=true', (listType) => { - createComponent({ listType, injectedProps: { disabled: true } }); - - expect(findSettingsButton().exists()).toBe(true); - }); + const hasSettings = [ListType.assignee, ListType.milestone, ListType.iteration, ListType.label]; - it.each(hasNoSettings)( - 'does not render for List Type `%s` when disabled=true', - (listType) => { - createComponent({ listType }); + it.each(hasSettings)('does render for List Type `%s`', (listType) => { + createComponent({ listType }); - expect(findSettingsButton().exists()).toBe(false); - }, - ); + expect(findDropdown().exists()).toBe(true); + expect(findSettingsButton().exists()).toBe(true); + }); + + it('does not render dropdown when ListType `closed`', () => { + createComponent({ listType: ListType.closed }); + + expect(findDropdown().exists()).toBe(false); + }); + + it('renders dropdown but not the Settings button when ListType `backlog`', () => { + createComponent({ listType: ListType.backlog }); + + expect(findDropdown().exists()).toBe(true); + expect(findSettingsButton().exists()).toBe(false); }); }); diff --git a/spec/lib/gitlab/i18n/pluralization_spec.rb b/spec/lib/gitlab/i18n/pluralization_spec.rb new file mode 100644 index 00000000000..857562d549c --- /dev/null +++ b/spec/lib/gitlab/i18n/pluralization_spec.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require 'rspec-parameterized' +require 'gettext_i18n_rails' + +RSpec.describe Gitlab::I18n::Pluralization, feature_category: :internationalization do + describe '.call' do + subject(:rule) { described_class.call(1) } + + context 'with available locales' do + around do |example| + Gitlab::I18n.with_locale(locale, &example) + end + + where(:locale) do + Gitlab::I18n.available_locales + end + + with_them do + it 'supports pluralization' do + expect(rule).not_to be_nil + end + end + + context 'with missing rules' do + let(:locale) { "pl_PL" } + + before do + stub_const("#{described_class}::MAP", described_class::MAP.except(locale)) + end + + it 'raises an ArgumentError' do + expect { rule }.to raise_error(ArgumentError, + /Missing pluralization rule for locale "#{locale}"/ + ) + end + end + end + end + + describe '.install_on' do + let(:mod) { Module.new } + + before do + described_class.install_on(mod) + end + + it 'adds pluralisation_rule method' do + expect(mod.pluralisation_rule).to eq(described_class) + end + end +end diff --git a/spec/lib/gitlab/i18n_spec.rb b/spec/lib/gitlab/i18n_spec.rb index b752d89bf0d..ee92831922d 100644 --- a/spec/lib/gitlab/i18n_spec.rb +++ b/spec/lib/gitlab/i18n_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::I18n do +RSpec.describe Gitlab::I18n, feature_category: :internationalization do let(:user) { create(:user, preferred_language: :es) } describe '.selectable_locales' do @@ -47,4 +47,19 @@ RSpec.describe Gitlab::I18n do expect(::I18n.locale).to eq(:en) end end + + describe '.pluralisation_rule' do + context 'when overridden' do + before do + # Internally, FastGettext sets + # Thread.current[:fast_gettext_pluralisation_rule]. + # Our patch patches `FastGettext.pluralisation_rule` instead. + FastGettext.pluralisation_rule = :something + end + + it 'returns custom definition regardless' do + expect(FastGettext.pluralisation_rule).to eq(Gitlab::I18n::Pluralization) + end + end + end end diff --git a/spec/lib/gitlab/instrumentation/redis_base_spec.rb b/spec/lib/gitlab/instrumentation/redis_base_spec.rb index 656e6ffba05..426997f6e86 100644 --- a/spec/lib/gitlab/instrumentation/redis_base_spec.rb +++ b/spec/lib/gitlab/instrumentation/redis_base_spec.rb @@ -210,4 +210,16 @@ RSpec.describe Gitlab::Instrumentation::RedisBase, :request_store do end end end + + describe '.log_exception' do + it 'logs exception with storage details' do + expect(::Gitlab::ErrorTracking).to receive(:log_exception) + .with( + an_instance_of(StandardError), + storage: instrumentation_class_a.storage_key + ) + + instrumentation_class_a.log_exception(StandardError.new) + end + end end diff --git a/spec/lib/gitlab/instrumentation/redis_interceptor_spec.rb b/spec/lib/gitlab/instrumentation/redis_interceptor_spec.rb index 187a6ff1739..63fdad0cab2 100644 --- a/spec/lib/gitlab/instrumentation/redis_interceptor_spec.rb +++ b/spec/lib/gitlab/instrumentation/redis_interceptor_spec.rb @@ -67,6 +67,8 @@ RSpec.describe Gitlab::Instrumentation::RedisInterceptor, :clean_gitlab_redis_sh it 'counts exceptions' do expect(instrumentation_class).to receive(:instance_count_exception) .with(instance_of(Redis::CommandError)).and_call_original + expect(instrumentation_class).to receive(:log_exception) + .with(instance_of(Redis::CommandError)).and_call_original expect(instrumentation_class).to receive(:instance_count_request).and_call_original expect do diff --git a/spec/lib/gitlab/redis/cache_spec.rb b/spec/lib/gitlab/redis/cache_spec.rb index 64615c4d9ad..82ff8a26199 100644 --- a/spec/lib/gitlab/redis/cache_spec.rb +++ b/spec/lib/gitlab/redis/cache_spec.rb @@ -26,22 +26,5 @@ RSpec.describe Gitlab::Redis::Cache do expect(described_class.active_support_config[:expires_in]).to eq(1.day) end - - context 'when encountering an error' do - let(:cache) { ActiveSupport::Cache::RedisCacheStore.new(**described_class.active_support_config) } - - subject { cache.read('x') } - - before do - described_class.with do |redis| - allow(redis).to receive(:get).and_raise(::Redis::CommandError) - end - end - - it 'logs error' do - expect(::Gitlab::ErrorTracking).to receive(:log_exception) - subject - end - end end end diff --git a/spec/lib/gitlab/redis/rate_limiting_spec.rb b/spec/lib/gitlab/redis/rate_limiting_spec.rb index d82228426f0..e79c070df93 100644 --- a/spec/lib/gitlab/redis/rate_limiting_spec.rb +++ b/spec/lib/gitlab/redis/rate_limiting_spec.rb @@ -4,21 +4,4 @@ require 'spec_helper' RSpec.describe Gitlab::Redis::RateLimiting do include_examples "redis_new_instance_shared_examples", 'rate_limiting', Gitlab::Redis::Cache - - describe '.cache_store' do - context 'when encountering an error' do - subject { described_class.cache_store.read('x') } - - before do - described_class.with do |redis| - allow(redis).to receive(:get).and_raise(::Redis::CommandError) - end - end - - it 'logs error' do - expect(::Gitlab::ErrorTracking).to receive(:log_exception) - subject - end - end - end end diff --git a/spec/lib/gitlab/redis/repository_cache_spec.rb b/spec/lib/gitlab/redis/repository_cache_spec.rb index 2c167a6eb62..8cdc4580f9e 100644 --- a/spec/lib/gitlab/redis/repository_cache_spec.rb +++ b/spec/lib/gitlab/redis/repository_cache_spec.rb @@ -17,20 +17,5 @@ RSpec.describe Gitlab::Redis::RepositoryCache, feature_category: :scalability do it 'has a default ttl of 8 hours' do expect(described_class.cache_store.options[:expires_in]).to eq(8.hours) end - - context 'when encountering an error' do - subject { described_class.cache_store.read('x') } - - before do - described_class.with do |redis| - allow(redis).to receive(:get).and_raise(::Redis::CommandError) - end - end - - it 'logs error' do - expect(::Gitlab::ErrorTracking).to receive(:log_exception) - subject - end - end end end diff --git a/spec/requests/api/draft_notes_spec.rb b/spec/requests/api/draft_notes_spec.rb index e8f519e004d..56b0c834010 100644 --- a/spec/requests/api/draft_notes_spec.rb +++ b/spec/requests/api/draft_notes_spec.rb @@ -8,6 +8,11 @@ RSpec.describe API::DraftNotes, feature_category: :code_review_workflow do let_it_be(:project) { create(:project, :public) } let_it_be(:merge_request) { create(:merge_request, source_project: project, target_project: project, author: user) } + let_it_be(:private_project) { create(:project, :private) } + let_it_be(:private_merge_request) do + create(:merge_request, source_project: private_project, target_project: private_project) + end + let_it_be(:merge_request_note) { create(:note, noteable: merge_request, project: project, author: user) } let!(:draft_note_by_current_user) { create(:draft_note, merge_request: merge_request, author: user) } let!(:draft_note_by_random_user) { create(:draft_note, merge_request: merge_request) } @@ -120,6 +125,97 @@ RSpec.describe API::DraftNotes, feature_category: :code_review_workflow do end end + def create_draft_note(params = {}, url = api_stub) + post api("#{url}/draft_notes", user), params: params + end + + describe "Create a new draft note" do + let(:basic_create_params) do + { + note: "Example body string" + } + end + + context "when creating a new draft note" do + context "with required params" do + it "returns 201 Created status" do + create_draft_note(basic_create_params) + + expect(response).to have_gitlab_http_status(:created) + end + + it "creates a new draft note with the submitted params" do + expect { create_draft_note(basic_create_params) }.to change { DraftNote.count }.by(1) + + expect(json_response["note"]).to eq(basic_create_params[:note]) + expect(json_response["merge_request_id"]).to eq(merge_request.id) + expect(json_response["author_id"]).to eq(user.id) + end + end + + context "without required params" do + it "returns 400 Bad Request status" do + create_draft_note({}) + + expect(response).to have_gitlab_http_status(:bad_request) + end + end + + context "when providing a non-existing commit_id" do + it "returns a 400 Bad Request" do + create_draft_note( + basic_create_params.merge( + commit_id: 'bad SHA' + ) + ) + + expect(response).to have_gitlab_http_status(:bad_request) + end + end + + context "when targeting a merge request the user doesn't have access to" do + it "returns a 404 Not Found" do + create_draft_note( + basic_create_params, + "/projects/#{private_project.id}/merge_requests/#{private_merge_request.iid}" + ) + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + context "when attempting to resolve a disscussion" do + context "when providing a non-existant ID" do + it "returns a 400 Bad Request" do + create_draft_note( + basic_create_params.merge( + resolve_discussion: true, + in_reply_to_discussion_id: non_existing_record_id + ) + ) + + expect(response).to have_gitlab_http_status(:bad_request) + end + end + + context "when not providing an ID" do + it "returns a 400 Bad Request" do + create_draft_note(basic_create_params.merge(resolve_discussion: true)) + + expect(response).to have_gitlab_http_status(:bad_request) + end + + it "returns a validation error message" do + create_draft_note(basic_create_params.merge(resolve_discussion: true)) + + expect(response.body) + .to eq("{\"message\":{\"base\":[\"User is not allowed to resolve thread\"]}}") + end + end + end + end + end + describe "Publishing a draft note" do let(:publish_draft_note) do put api( diff --git a/spec/requests/git_http_spec.rb b/spec/requests/git_http_spec.rb index 02b99eba8ce..eaac2a77353 100644 --- a/spec/requests/git_http_spec.rb +++ b/spec/requests/git_http_spec.rb @@ -472,10 +472,11 @@ RSpec.describe 'Git HTTP requests', feature_category: :source_code_management do end context 'when the request is not from gitlab-workhorse' do - it 'raises an exception' do - expect do - get("/#{project.full_path}.git/info/refs?service=git-upload-pack") - end.to raise_error(JWT::DecodeError) + it 'responds with 403 Forbidden' do + get("/#{project.full_path}.git/info/refs?service=git-upload-pack") + + expect(response).to have_gitlab_http_status(:forbidden) + expect(response.body).to eq('Nil JSON web token') end end @@ -1112,10 +1113,11 @@ RSpec.describe 'Git HTTP requests', feature_category: :source_code_management do end context 'when the request is not from gitlab-workhorse' do - it 'raises an exception' do - expect do - get("/#{project.full_path}.git/info/refs?service=git-upload-pack") - end.to raise_error(JWT::DecodeError) + it 'responds with 403 Forbidden' do + get("/#{project.full_path}.git/info/refs?service=git-upload-pack") + + expect(response).to have_gitlab_http_status(:forbidden) + expect(response.body).to eq('Nil JSON web token') end end diff --git a/spec/support/shared_examples/controllers/repositories/git_http_controller_shared_examples.rb b/spec/support/shared_examples/controllers/repositories/git_http_controller_shared_examples.rb index cc28a79b4ca..39c300d547d 100644 --- a/spec/support/shared_examples/controllers/repositories/git_http_controller_shared_examples.rb +++ b/spec/support/shared_examples/controllers/repositories/git_http_controller_shared_examples.rb @@ -87,14 +87,20 @@ RSpec.shared_examples Repositories::GitHttpController do end describe 'POST #git_upload_pack' do - before do + it 'returns 200' do allow(controller).to receive(:verify_workhorse_api!).and_return(true) - end - it 'returns 200' do post :git_upload_pack, params: params expect(response).to have_gitlab_http_status(:ok) end + + context 'when JWT token is not provided' do + it 'returns 403' do + post :git_upload_pack, params: params + + expect(response).to have_gitlab_http_status(:forbidden) + end + end end end |