summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-13 09:09:23 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-13 09:09:23 +0000
commit4cb5e5011abfe8d50ac3a7ebd0018c563c6d7af4 (patch)
tree82591df15758864325897043f855b4e4dfcb6a56 /spec
parent0301a0cad0063d76b1607358dc6c711ea043fdda (diff)
downloadgitlab-ce-4cb5e5011abfe8d50ac3a7ebd0018c563c6d7af4.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin/integrations_controller_spec.rb86
-rw-r--r--spec/controllers/profiles/keys_controller_spec.rb16
-rw-r--r--spec/frontend/clusters/components/ingress_modsecurity_settings_spec.js52
-rw-r--r--spec/frontend/clusters/services/mock_data.js1
-rw-r--r--spec/frontend/notes/components/__snapshots__/discussion_jump_to_next_button_spec.js.snap3
-rw-r--r--spec/frontend/notes/components/discussion_jump_to_next_button_spec.js23
-rw-r--r--spec/lib/gitlab/auth/key_status_checker_spec.rb68
-rw-r--r--spec/models/clusters/applications/ingress_spec.rb1
-rw-r--r--spec/requests/api/internal/base_spec.rb31
-rw-r--r--spec/requests/api/keys_spec.rb3
10 files changed, 251 insertions, 33 deletions
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`] = `
>
<button
class="btn btn-default discussion-next-btn"
+ data-track-event="click_button"
+ data-track-label="mr_next_unresolved_thread"
+ data-track-property="click_next_unresolved_thread"
title="Jump to next unresolved thread"
>
<icon-stub
diff --git a/spec/frontend/notes/components/discussion_jump_to_next_button_spec.js b/spec/frontend/notes/components/discussion_jump_to_next_button_spec.js
index 2ff9dbc5c19..183966cf435 100644
--- a/spec/frontend/notes/components/discussion_jump_to_next_button_spec.js
+++ b/spec/frontend/notes/components/discussion_jump_to_next_button_spec.js
@@ -1,14 +1,21 @@
import { shallowMount } from '@vue/test-utils';
import JumpToNextDiscussionButton from '~/notes/components/discussion_jump_to_next_button.vue';
+import { mockTracking } from '../../helpers/tracking_helper';
describe('JumpToNextDiscussionButton', () => {
- let wrapper;
const fromDiscussionId = 'abc123';
+ let wrapper;
+ let trackingSpy;
+ let jumpFn;
beforeEach(() => {
+ jumpFn = jest.fn();
wrapper = shallowMount(JumpToNextDiscussionButton, {
propsData: { fromDiscussionId },
});
+ wrapper.setMethods({ jumpToNextRelativeDiscussion: jumpFn });
+
+ trackingSpy = mockTracking('_category_', wrapper.element, jest.spyOn);
});
afterEach(() => {
@@ -20,9 +27,17 @@ describe('JumpToNextDiscussionButton', () => {
});
it('calls jumpToNextRelativeDiscussion when clicked', () => {
- const jumpToNextRelativeDiscussion = jest.fn();
- wrapper.setMethods({ jumpToNextRelativeDiscussion });
wrapper.find({ ref: 'button' }).trigger('click');
- expect(jumpToNextRelativeDiscussion).toHaveBeenCalledWith(fromDiscussionId);
+
+ expect(jumpFn).toHaveBeenCalledWith(fromDiscussionId);
+ });
+
+ it('sends the correct tracking event when clicked', () => {
+ wrapper.find({ ref: 'button' }).trigger('click');
+
+ expect(trackingSpy).toHaveBeenCalledWith('_category_', 'click_button', {
+ label: 'mr_next_unresolved_thread',
+ property: 'click_next_unresolved_thread',
+ });
});
});
diff --git a/spec/lib/gitlab/auth/key_status_checker_spec.rb b/spec/lib/gitlab/auth/key_status_checker_spec.rb
new file mode 100644
index 00000000000..b1a540eae81
--- /dev/null
+++ b/spec/lib/gitlab/auth/key_status_checker_spec.rb
@@ -0,0 +1,68 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::Auth::KeyStatusChecker do
+ let_it_be(:never_expires_key) { build(:personal_key, expires_at: nil) }
+ let_it_be(:expired_key) { build(:personal_key, expires_at: 3.days.ago) }
+ let_it_be(:expiring_soon_key) { build(:personal_key, expires_at: 3.days.from_now) }
+ let_it_be(:expires_in_future_key) { build(:personal_key, expires_at: 14.days.from_now) }
+
+ let(:key_status_checker) { described_class.new(key) }
+
+ describe '#show_console_message?' do
+ subject { key_status_checker.show_console_message? }
+
+ context 'for an expired key' do
+ let(:key) { expired_key }
+
+ it { is_expected.to eq(true) }
+ end
+
+ context 'for a key expiring in the next 7 days' do
+ let(:key) { expiring_soon_key }
+
+ it { is_expected.to eq(true) }
+ end
+
+ context 'for a key expiring after the next 7 days' do
+ let(:key) { expires_in_future_key }
+
+ it { is_expected.to eq(false) }
+ end
+
+ context 'for a key that never expires' do
+ let(:key) { never_expires_key }
+
+ it { is_expected.to eq(false) }
+ end
+ end
+
+ describe '#console_message' do
+ subject { key_status_checker.console_message }
+
+ context 'for an expired key' do
+ let(:key) { expired_key }
+
+ it { is_expected.to eq('INFO: Your SSH key has expired. Please generate a new key.') }
+ end
+
+ context 'for a key expiring in the next 7 days' do
+ let(:key) { expiring_soon_key }
+
+ it { is_expected.to eq('INFO: Your SSH key is expiring soon. Please generate a new key.') }
+ end
+
+ context 'for a key expiring after the next 7 days' do
+ let(:key) { expires_in_future_key }
+
+ it { is_expected.to be_nil }
+ end
+
+ context 'for a key that never expires' do
+ let(:key) { never_expires_key }
+
+ it { is_expected.to be_nil }
+ end
+ end
+end
diff --git a/spec/models/clusters/applications/ingress_spec.rb b/spec/models/clusters/applications/ingress_spec.rb
index 754e26dcec8..b1dd8ede3eb 100644
--- a/spec/models/clusters/applications/ingress_spec.rb
+++ b/spec/models/clusters/applications/ingress_spec.rb
@@ -177,6 +177,7 @@ describe Clusters::Applications::Ingress do
context 'when modsecurity_enabled is disabled' do
before do
allow(subject).to receive(:cluster).and_return(cluster)
+ allow(subject).to receive(:modsecurity_enabled).and_return(false)
end
it 'excludes modsecurity module enablement' do
diff --git a/spec/requests/api/internal/base_spec.rb b/spec/requests/api/internal/base_spec.rb
index 95513776f39..be592ac6a5c 100644
--- a/spec/requests/api/internal/base_spec.rb
+++ b/spec/requests/api/internal/base_spec.rb
@@ -575,30 +575,35 @@ describe API::Internal::Base do
project.add_developer(user)
end
- context "git pull" do
- context "with no console message" do
- it "has the correct payload" do
+ context 'git pull' do
+ context 'with a key that has expired' do
+ let(:key) { create(:key, user: user, expires_at: 2.days.ago) }
+
+ it 'includes the `key expired` message in the response' do
pull(key, project)
expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['gl_console_messages']).to eq([])
+ expect(json_response['gl_console_messages']).to eq(['INFO: Your SSH key has expired. Please generate a new key.'])
end
end
- context "with a console message" do
- let(:console_messages) { ['message for the console'] }
+ context 'with a key that will expire in the next 7 days' do
+ let(:key) { create(:key, user: user, expires_at: 2.days.from_now) }
- it "has the correct payload" do
- expect_next_instance_of(Gitlab::GitAccess) do |access|
- expect(access).to receive(:check_for_console_messages)
- .with('git-upload-pack')
- .and_return(console_messages)
- end
+ it 'includes the `key expiring soon` message in the response' do
+ pull(key, project)
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(json_response['gl_console_messages']).to eq(['INFO: Your SSH key is expiring soon. Please generate a new key.'])
+ end
+ end
+
+ context 'with a key that has no expiry' do
+ it 'does not include any message in the response' do
pull(key, project)
expect(response).to have_gitlab_http_status(:ok)
- expect(json_response['gl_console_messages']).to eq(console_messages)
+ expect(json_response['gl_console_messages']).to eq([])
end
end
end
diff --git a/spec/requests/api/keys_spec.rb b/spec/requests/api/keys_spec.rb
index df0bae603b1..089ee22982c 100644
--- a/spec/requests/api/keys_spec.rb
+++ b/spec/requests/api/keys_spec.rb
@@ -5,7 +5,7 @@ require 'spec_helper'
describe API::Keys do
let(:user) { create(:user) }
let(:admin) { create(:admin) }
- let(:key) { create(:key, user: user) }
+ let(:key) { create(:key, user: user, expires_at: 1.day.from_now) }
let(:email) { create(:email, user: user) }
describe 'GET /keys/:uid' do
@@ -28,6 +28,7 @@ describe API::Keys do
get api("/keys/#{key.id}", admin)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['title']).to eq(key.title)
+ expect(Time.parse(json_response['expires_at'])).to be_like_time(key.expires_at)
expect(json_response['user']['id']).to eq(user.id)
expect(json_response['user']['username']).to eq(user.username)
end