From 4cb5e5011abfe8d50ac3a7ebd0018c563c6d7af4 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 13 Mar 2020 09:09:23 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../admin/integrations_controller_spec.rb | 86 ++++++++++++++++++++++ spec/controllers/profiles/keys_controller_spec.rb | 16 ++++ .../ingress_modsecurity_settings_spec.js | 52 +++++++++---- spec/frontend/clusters/services/mock_data.js | 1 + .../discussion_jump_to_next_button_spec.js.snap | 3 + .../discussion_jump_to_next_button_spec.js | 23 +++++- spec/lib/gitlab/auth/key_status_checker_spec.rb | 68 +++++++++++++++++ spec/models/clusters/applications/ingress_spec.rb | 1 + spec/requests/api/internal/base_spec.rb | 31 ++++---- spec/requests/api/keys_spec.rb | 3 +- 10 files changed, 251 insertions(+), 33 deletions(-) create mode 100644 spec/controllers/admin/integrations_controller_spec.rb create mode 100644 spec/lib/gitlab/auth/key_status_checker_spec.rb (limited to 'spec') diff --git a/spec/controllers/admin/integrations_controller_spec.rb b/spec/controllers/admin/integrations_controller_spec.rb new file mode 100644 index 00000000000..0641f64b0e3 --- /dev/null +++ b/spec/controllers/admin/integrations_controller_spec.rb @@ -0,0 +1,86 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Admin::IntegrationsController do + let(:admin) { create(:admin) } + let!(:project) { create(:project) } + + before do + sign_in(admin) + end + + describe '#edit' do + context 'when instance_level_integrations not enabled' do + it 'returns not_found' do + allow(Feature).to receive(:enabled?).with(:instance_level_integrations) { false } + + get :edit, params: { id: Service.available_services_names.sample } + + expect(response).to have_gitlab_http_status(:not_found) + end + end + + Service.available_services_names.each do |integration_name| + context "#{integration_name}" do + it 'successfully displays the template' do + get :edit, params: { id: integration_name } + + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template(:edit) + end + end + end + end + + describe '#update' do + let(:integration) { create(:jira_service, project: project) } + + before do + put :update, params: { id: integration.class.to_param, service: { url: url } } + end + + context 'valid params' do + let(:url) { 'https://jira.gitlab-example.com' } + + it 'updates the integration' do + expect(response).to have_gitlab_http_status(:found) + expect(integration.reload.url).to eq(url) + end + end + + context 'invalid params' do + let(:url) { 'https://jira.localhost' } + + it 'does not update the integration' do + expect(response).to have_gitlab_http_status(:ok) + expect(response).to render_template(:edit) + expect(integration.reload.url).not_to eq(url) + end + end + end + + describe '#test' do + context 'testable' do + let(:integration) { create(:jira_service, project: project) } + + it 'returns ok' do + allow_any_instance_of(integration.class).to receive(:test) { { success: true } } + + put :test, params: { id: integration.class.to_param } + + expect(response).to have_gitlab_http_status(:ok) + end + end + + context 'not testable' do + let(:integration) { create(:alerts_service, project: project) } + + it 'returns not found' do + put :test, params: { id: integration.class.to_param } + + expect(response).to have_gitlab_http_status(:not_found) + end + end + end +end diff --git a/spec/controllers/profiles/keys_controller_spec.rb b/spec/controllers/profiles/keys_controller_spec.rb index 3bed117deb0..8582ecbb06d 100644 --- a/spec/controllers/profiles/keys_controller_spec.rb +++ b/spec/controllers/profiles/keys_controller_spec.rb @@ -5,6 +5,22 @@ require 'spec_helper' describe Profiles::KeysController do let(:user) { create(:user) } + describe 'POST #create' do + before do + sign_in(user) + end + + it 'creates a new key' do + expires_at = 3.days.from_now + + expect do + post :create, params: { key: build(:key, expires_at: expires_at).attributes } + end.to change { Key.count }.by(1) + + expect(Key.last.expires_at).to be_like_time(expires_at) + end + end + describe "#get_keys" do describe "non existent user" do it "does not generally work" do diff --git a/spec/frontend/clusters/components/ingress_modsecurity_settings_spec.js b/spec/frontend/clusters/components/ingress_modsecurity_settings_spec.js index e7d2b7bf5c5..beb0721260b 100644 --- a/spec/frontend/clusters/components/ingress_modsecurity_settings_spec.js +++ b/spec/frontend/clusters/components/ingress_modsecurity_settings_spec.js @@ -1,8 +1,7 @@ import { shallowMount } from '@vue/test-utils'; import IngressModsecuritySettings from '~/clusters/components/ingress_modsecurity_settings.vue'; -import LoadingButton from '~/vue_shared/components/loading_button.vue'; import { APPLICATION_STATUS, INGRESS } from '~/clusters/constants'; -import { GlAlert } from '@gitlab/ui'; +import { GlAlert, GlToggle } from '@gitlab/ui'; import eventHub from '~/clusters/event_hub'; const { UPDATING } = APPLICATION_STATUS; @@ -27,32 +26,55 @@ describe('IngressModsecuritySettings', () => { }); }; - const findSaveButton = () => wrapper.find(LoadingButton); - const findModSecurityCheckbox = () => wrapper.find('input').element; + const findSaveButton = () => wrapper.find('.btn-success'); + const findCancelButton = () => wrapper.find('[variant="secondary"]'); + const findModSecurityToggle = () => wrapper.find(GlToggle); describe('when ingress is installed', () => { beforeEach(() => { - createComponent({ installed: true }); + createComponent({ installed: true, status: 'installed' }); jest.spyOn(eventHub, '$emit'); }); - it('renders save button', () => { - expect(findSaveButton().exists()).toBe(true); - expect(findModSecurityCheckbox().checked).toBe(false); + it('does not render save and cancel buttons', () => { + expect(findSaveButton().exists()).toBe(false); + expect(findCancelButton().exists()).toBe(false); }); - describe('and the save changes button is clicked', () => { + describe('with toggle changed by the user', () => { beforeEach(() => { - findSaveButton().vm.$emit('click'); + findModSecurityToggle().vm.$emit('change'); + }); + + it('renders both save and cancel buttons', () => { + expect(findSaveButton().exists()).toBe(true); + expect(findCancelButton().exists()).toBe(true); }); - it('triggers save event and pass current modsecurity value', () => - wrapper.vm.$nextTick().then(() => { + describe('and the save changes button is clicked', () => { + beforeEach(() => { + findSaveButton().vm.$emit('click'); + }); + + it('triggers save event and pass current modsecurity value', () => { expect(eventHub.$emit).toHaveBeenCalledWith('updateApplication', { id: INGRESS, params: { modsecurity_enabled: false }, }); - })); + }); + }); + + describe('and the cancel button is clicked', () => { + beforeEach(() => { + findCancelButton().vm.$emit('click'); + }); + + it('triggers reset event and hides both cancel and save changes button', () => { + expect(eventHub.$emit).toHaveBeenCalledWith('resetIngressModSecurityEnabled', INGRESS); + expect(findSaveButton().exists()).toBe(false); + expect(findCancelButton().exists()).toBe(false); + }); + }); }); it('triggers set event to be propagated with the current modsecurity value', () => { @@ -79,7 +101,7 @@ describe('IngressModsecuritySettings', () => { }); it('renders save button with "Saving" label', () => { - expect(findSaveButton().props('label')).toBe('Saving'); + expect(findSaveButton().text()).toBe('Saving'); }); }); @@ -101,7 +123,7 @@ describe('IngressModsecuritySettings', () => { it('does not render the save button', () => { expect(findSaveButton().exists()).toBe(false); - expect(findModSecurityCheckbox().checked).toBe(false); + expect(findModSecurityToggle().props('value')).toBe(false); }); }); }); diff --git a/spec/frontend/clusters/services/mock_data.js b/spec/frontend/clusters/services/mock_data.js index f0bcf5d980f..52d78ea1176 100644 --- a/spec/frontend/clusters/services/mock_data.js +++ b/spec/frontend/clusters/services/mock_data.js @@ -20,6 +20,7 @@ const CLUSTERS_MOCK_DATA = { external_ip: null, external_hostname: null, can_uninstall: false, + modsecurity_enabled: false, }, { name: 'runner', diff --git a/spec/frontend/notes/components/__snapshots__/discussion_jump_to_next_button_spec.js.snap b/spec/frontend/notes/components/__snapshots__/discussion_jump_to_next_button_spec.js.snap index 2f4c114dd3d..b1a718d58b5 100644 --- a/spec/frontend/notes/components/__snapshots__/discussion_jump_to_next_button_spec.js.snap +++ b/spec/frontend/notes/components/__snapshots__/discussion_jump_to_next_button_spec.js.snap @@ -7,6 +7,9 @@ exports[`JumpToNextDiscussionButton matches the snapshot 1`] = ` >