summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-07 12:07:55 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-07 12:07:55 +0000
commit05f1d5d9813332bdd456cb358517e56168a24224 (patch)
treef9ed7a2692a537b5e1e541318f39d7464fdd8098 /spec
parente440c86979e9c02a09fb6558f59a1fbe29433b51 (diff)
downloadgitlab-ce-05f1d5d9813332bdd456cb358517e56168a24224.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/factories/clusters/applications/helm.rb1
-rw-r--r--spec/fixtures/api/schemas/cluster_status.json1
-rw-r--r--spec/frontend/clusters/components/applications_spec.js8
-rw-r--r--spec/frontend/clusters/services/mock_data.js2
-rw-r--r--spec/frontend/clusters/stores/clusters_store_spec.js1
-rw-r--r--spec/frontend/sentry_error_stack_trace/components/sentry_error_stack_trace_spec.js6
-rw-r--r--spec/lib/gitlab/database_importers/self_monitoring/project/create_service_spec.rb58
-rw-r--r--spec/models/clusters/applications/ingress_spec.rb10
-rw-r--r--spec/services/clusters/applications/create_service_spec.rb27
-rw-r--r--spec/workers/self_monitoring_project_create_worker_spec.rb28
10 files changed, 113 insertions, 29 deletions
diff --git a/spec/factories/clusters/applications/helm.rb b/spec/factories/clusters/applications/helm.rb
index 0e59f8cb9ec..8858675c2b8 100644
--- a/spec/factories/clusters/applications/helm.rb
+++ b/spec/factories/clusters/applications/helm.rb
@@ -71,6 +71,7 @@ FactoryBot.define do
end
factory :clusters_applications_ingress, class: Clusters::Applications::Ingress do
+ modsecurity_enabled { false }
cluster factory: %i(cluster with_installed_helm provided_by_gcp)
end
diff --git a/spec/fixtures/api/schemas/cluster_status.json b/spec/fixtures/api/schemas/cluster_status.json
index f978baa2026..fcb4f2b94cd 100644
--- a/spec/fixtures/api/schemas/cluster_status.json
+++ b/spec/fixtures/api/schemas/cluster_status.json
@@ -38,6 +38,7 @@
"kibana_hostname": { "type": ["string", "null"] },
"email": { "type": ["string", "null"] },
"stack": { "type": ["string", "null"] },
+ "modsecurity_enabled": { "type": ["boolean", "null"] },
"update_available": { "type": ["boolean", "null"] },
"can_uninstall": { "type": "boolean" }
},
diff --git a/spec/frontend/clusters/components/applications_spec.js b/spec/frontend/clusters/components/applications_spec.js
index 2d7958a6b65..e8c5a2bd242 100644
--- a/spec/frontend/clusters/components/applications_spec.js
+++ b/spec/frontend/clusters/components/applications_spec.js
@@ -190,6 +190,7 @@ describe('Applications', () => {
title: 'Ingress',
status: 'installed',
externalHostname: 'localhost.localdomain',
+ modsecurity_enabled: false,
},
helm: { title: 'Helm Tiller' },
cert_manager: { title: 'Cert-Manager' },
@@ -473,7 +474,12 @@ describe('Applications', () => {
vm = mountComponent(Applications, {
applications: {
...APPLICATIONS_MOCK_STATE,
- ingress: { title: 'Ingress', status: 'installed', externalIp: '1.1.1.1' },
+ ingress: {
+ title: 'Ingress',
+ status: 'installed',
+ externalIp: '1.1.1.1',
+ modsecurity_enabled: false,
+ },
elastic_stack: { title: 'Elastic Stack', status: 'installed', kibana_hostname: '' },
},
});
diff --git a/spec/frontend/clusters/services/mock_data.js b/spec/frontend/clusters/services/mock_data.js
index 016f5a259b5..98fa0ec3b07 100644
--- a/spec/frontend/clusters/services/mock_data.js
+++ b/spec/frontend/clusters/services/mock_data.js
@@ -150,7 +150,7 @@ const DEFAULT_APPLICATION_STATE = {
const APPLICATIONS_MOCK_STATE = {
helm: { title: 'Helm Tiller', status: 'installable' },
- ingress: { title: 'Ingress', status: 'installable' },
+ ingress: { title: 'Ingress', status: 'installable', modsecurity_enabled: false },
crossplane: { title: 'Crossplane', status: 'installable', stack: '' },
cert_manager: { title: 'Cert-Manager', status: 'installable' },
runner: { title: 'GitLab Runner' },
diff --git a/spec/frontend/clusters/stores/clusters_store_spec.js b/spec/frontend/clusters/stores/clusters_store_spec.js
index 71d4daceb75..c7ec4ddc464 100644
--- a/spec/frontend/clusters/stores/clusters_store_spec.js
+++ b/spec/frontend/clusters/stores/clusters_store_spec.js
@@ -86,6 +86,7 @@ describe('Clusters Store', () => {
uninstallSuccessful: false,
uninstallFailed: false,
validationError: null,
+ modsecurity_enabled: false,
},
runner: {
title: 'GitLab Runner',
diff --git a/spec/frontend/sentry_error_stack_trace/components/sentry_error_stack_trace_spec.js b/spec/frontend/sentry_error_stack_trace/components/sentry_error_stack_trace_spec.js
index fb50b31a3da..e5f83b6fa49 100644
--- a/spec/frontend/sentry_error_stack_trace/components/sentry_error_stack_trace_spec.js
+++ b/spec/frontend/sentry_error_stack_trace/components/sentry_error_stack_trace_spec.js
@@ -69,15 +69,17 @@ describe('Sentry Error Stack Trace', () => {
});
describe('Stack trace', () => {
- it('should show stacktrace', () => {
+ beforeEach(() => {
store.state.details.loadingStacktrace = false;
+ });
+
+ it('should show stacktrace', () => {
mountComponent({ stubs: {} });
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
expect(wrapper.find(Stacktrace).exists()).toBe(true);
});
it('should not show stacktrace if it does not exist', () => {
- store.state.details.loadingStacktrace = false;
expect(wrapper.find(GlLoadingIcon).exists()).toBe(false);
expect(wrapper.find(Stacktrace).exists()).toBe(false);
});
diff --git a/spec/lib/gitlab/database_importers/self_monitoring/project/create_service_spec.rb b/spec/lib/gitlab/database_importers/self_monitoring/project/create_service_spec.rb
index ee3c99afdf1..082485f5ddd 100644
--- a/spec/lib/gitlab/database_importers/self_monitoring/project/create_service_spec.rb
+++ b/spec/lib/gitlab/database_importers/self_monitoring/project/create_service_spec.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
describe '#execute' do
- let(:result) { subject.execute! }
+ let(:result) { subject.execute }
let(:prometheus_settings) do
{
@@ -18,10 +18,12 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
end
context 'without application_settings' do
- it 'does not fail' do
+ it 'returns error' do
expect(subject).to receive(:log_error).and_call_original
expect(result).to eq(
- status: :success
+ status: :error,
+ message: 'No application_settings found',
+ last_step: :validate_application_settings
)
expect(Project.count).to eq(0)
@@ -36,10 +38,12 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
allow(ApplicationSetting).to receive(:current_without_cache) { application_setting }
end
- it 'does not fail' do
+ it 'returns error' do
expect(subject).to receive(:log_error).and_call_original
expect(result).to eq(
- status: :success
+ status: :error,
+ message: 'No active admin user found',
+ last_step: :validate_admins
)
expect(Project.count).to eq(0)
@@ -47,7 +51,7 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
end
end
- context 'with admin users' do
+ context 'with application settings and admin users' do
let(:project) { result[:project] }
let(:group) { result[:group] }
let(:application_setting) { Gitlab::CurrentSettings.current_application_settings }
@@ -73,6 +77,13 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
it_behaves_like 'has prometheus service', 'http://localhost:9090'
+ it "tracks successful install" do
+ expect(::Gitlab::Tracking).to receive(:event)
+ expect(::Gitlab::Tracking).to receive(:event).with("self_monitoring", "project_created")
+
+ result
+ end
+
it 'creates group' do
expect(result[:status]).to eq(:success)
expect(group).to be_persisted
@@ -132,7 +143,11 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
it 'returns error when saving project ID fails' do
allow(application_setting).to receive(:save) { false }
- expect { result }.to raise_error(StandardError, 'Could not save project ID')
+ expect(result).to eq(
+ status: :error,
+ message: 'Could not save project ID',
+ last_step: :save_project_id
+ )
end
context 'when project already exists' do
@@ -149,9 +164,8 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
application_setting.instance_administration_project_id = existing_project.id
end
- it 'does not fail' do
- expect(subject).to receive(:log_error).and_call_original
- expect(result[:status]).to eq(:success)
+ it 'returns success' do
+ expect(result).to include(status: :success)
expect(Project.count).to eq(1)
expect(Group.count).to eq(1)
@@ -250,7 +264,11 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
it 'returns error' do
expect(subject).to receive(:log_error).and_call_original
- expect { result }.to raise_error(StandardError, 'Could not create project')
+ expect(result).to eq(
+ status: :error,
+ message: 'Could not create project',
+ last_step: :create_project
+ )
end
end
@@ -261,7 +279,11 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
it 'returns error' do
expect(subject).to receive(:log_error).and_call_original
- expect { result }.to raise_error(StandardError, 'Could not add admins as members')
+ expect(result).to eq(
+ status: :error,
+ message: 'Could not add admins as members',
+ last_step: :add_group_members
+ )
end
end
@@ -275,15 +297,13 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
it 'returns error' do
expect(subject).to receive(:log_error).and_call_original
- expect { result }.to raise_error(StandardError, 'Could not save prometheus manual configuration')
+ expect(result).to eq(
+ status: :error,
+ message: 'Could not save prometheus manual configuration',
+ last_step: :add_prometheus_manual_configuration
+ )
end
end
end
-
- it "tracks successful install" do
- expect(Gitlab::Tracking).to receive(:event).with("self_monitoring", "project_created")
-
- result
- end
end
end
diff --git a/spec/models/clusters/applications/ingress_spec.rb b/spec/models/clusters/applications/ingress_spec.rb
index d7ad7867e1a..c1158698601 100644
--- a/spec/models/clusters/applications/ingress_spec.rb
+++ b/spec/models/clusters/applications/ingress_spec.rb
@@ -142,11 +142,11 @@ describe Clusters::Applications::Ingress do
let(:project) { build(:project) }
let(:cluster) { build(:cluster, projects: [project]) }
- context 'when ingress_modsecurity is enabled' do
+ context 'when modsecurity_enabled is enabled' do
before do
- stub_feature_flags(ingress_modsecurity: true)
-
allow(subject).to receive(:cluster).and_return(cluster)
+
+ allow(subject).to receive(:modsecurity_enabled).and_return(true)
end
it 'includes modsecurity module enablement' do
@@ -173,10 +173,8 @@ describe Clusters::Applications::Ingress do
end
end
- context 'when ingress_modsecurity is disabled' do
+ context 'when modsecurity_enabled is disabled' do
before do
- stub_feature_flags(ingress_modsecurity: false)
-
allow(subject).to receive(:cluster).and_return(cluster)
end
diff --git a/spec/services/clusters/applications/create_service_spec.rb b/spec/services/clusters/applications/create_service_spec.rb
index bdacb9ce071..d5ad03a94ac 100644
--- a/spec/services/clusters/applications/create_service_spec.rb
+++ b/spec/services/clusters/applications/create_service_spec.rb
@@ -47,6 +47,33 @@ describe Clusters::Applications::CreateService do
create(:clusters_applications_helm, :installed, cluster: cluster)
end
+ context 'ingress application' do
+ let(:params) do
+ {
+ application: 'ingress',
+ modsecurity_enabled: true
+ }
+ end
+
+ before do
+ expect_any_instance_of(Clusters::Applications::Ingress)
+ .to receive(:make_scheduled!)
+ .and_call_original
+ end
+
+ it 'creates the application' do
+ expect do
+ subject
+
+ cluster.reload
+ end.to change(cluster, :application_ingress)
+ end
+
+ it 'sets modsecurity_enabled' do
+ expect(subject.modsecurity_enabled).to eq(true)
+ end
+ end
+
context 'cert manager application' do
let(:params) do
{
diff --git a/spec/workers/self_monitoring_project_create_worker_spec.rb b/spec/workers/self_monitoring_project_create_worker_spec.rb
new file mode 100644
index 00000000000..75c4f5d49d1
--- /dev/null
+++ b/spec/workers/self_monitoring_project_create_worker_spec.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe SelfMonitoringProjectCreateWorker do
+ describe '#perform' do
+ let(:service_class) { Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService }
+ let(:service) { instance_double(service_class) }
+
+ before do
+ allow(service_class).to receive(:new) { service }
+ end
+
+ it 'runs the SelfMonitoring::Project::CreateService' do
+ expect(service).to receive(:execute)
+
+ subject.perform
+ end
+ end
+
+ describe '.in_progress?', :clean_gitlab_redis_shared_state do
+ it 'returns in_progress when job is enqueued' do
+ jid = described_class.perform_async
+
+ expect(described_class.in_progress?(jid)).to eq(true)
+ end
+ end
+end