diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-06 18:08:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-06 18:08:08 +0300 |
commit | 526f1e98593d1d5691df5de18862f31dd08c4889 (patch) | |
tree | fdda2ed2752bfb458a67cc522d893ec3298d95dd /spec | |
parent | c1f785fe21ee785618ef3bf0407fee166b6e0ecd (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
19 files changed, 341 insertions, 89 deletions
diff --git a/spec/frontend/pages/shared/wikis/components/wiki_form_spec.js b/spec/frontend/pages/shared/wikis/components/wiki_form_spec.js index fc490bfb774..a5db10d106d 100644 --- a/spec/frontend/pages/shared/wikis/components/wiki_form_spec.js +++ b/spec/frontend/pages/shared/wikis/components/wiki_form_spec.js @@ -1,5 +1,5 @@ import { nextTick } from 'vue'; -import { GlAlert, GlButton } from '@gitlab/ui'; +import { GlAlert, GlButton, GlFormInput, GlFormGroup } from '@gitlab/ui'; import { mount, shallowMount } from '@vue/test-utils'; import axios from 'axios'; import MockAdapter from 'axios-mock-adapter'; @@ -107,6 +107,8 @@ describe('WikiForm', () => { GlAlert, GlButton, LocalStorageSync: stubComponent(LocalStorageSync), + GlFormInput, + GlFormGroup, }, }), ); @@ -132,7 +134,7 @@ describe('WikiForm', () => { `( 'updates the commit message to $message when title is $title and persisted=$persisted', async ({ title, message, persisted }) => { - createWrapper({ persisted }); + createWrapper({ persisted, mountFn: mount }); await findTitle().setValue(title); @@ -141,7 +143,7 @@ describe('WikiForm', () => { ); it('sets the commit message to "Update My page" when the page first loads when persisted', async () => { - createWrapper({ persisted: true }); + createWrapper({ persisted: true, mountFn: mount }); await nextTick(); @@ -161,7 +163,7 @@ describe('WikiForm', () => { ${'asciidoc'} | ${false} | ${'hides'} ${'org'} | ${false} | ${'hides'} `('$action preview in the markdown field when format is $format', async ({ format, enabled }) => { - createWrapper(); + createWrapper({ mountFn: mount }); await setFormat(format); @@ -258,7 +260,7 @@ describe('WikiForm', () => { `( "when title='$title', content='$content', then the button is $buttonState'", async ({ title, content, disabledAttr }) => { - createWrapper(); + createWrapper({ mountFn: mount }); await findTitle().setValue(title); await findContent().setValue(content); @@ -295,7 +297,7 @@ describe('WikiForm', () => { describe('toggle editing mode control', () => { beforeEach(() => { - createWrapper(); + createWrapper({ mountFn: mount }); }); it.each` diff --git a/spec/lib/gitlab/database_importers/instance_administrators/create_group_spec.rb b/spec/lib/gitlab/database_importers/instance_administrators/create_group_spec.rb index 2878d72210e..68c29bad287 100644 --- a/spec/lib/gitlab/database_importers/instance_administrators/create_group_spec.rb +++ b/spec/lib/gitlab/database_importers/instance_administrators/create_group_spec.rb @@ -38,7 +38,11 @@ RSpec.describe Gitlab::DatabaseImporters::InstanceAdministrators::CreateGroup do end end - context 'with application settings and admin users', :do_not_mock_admin_mode_setting do + context( + 'with application settings and admin users', + :do_not_mock_admin_mode_setting, + :do_not_stub_snowplow_by_default + ) do let(:group) { result[:group] } let(:application_setting) { Gitlab::CurrentSettings.current_application_settings } diff --git a/spec/lib/gitlab/error_tracking/processor/sanitizer_processor_spec.rb b/spec/lib/gitlab/error_tracking/processor/sanitizer_processor_spec.rb new file mode 100644 index 00000000000..9673bfc5cd3 --- /dev/null +++ b/spec/lib/gitlab/error_tracking/processor/sanitizer_processor_spec.rb @@ -0,0 +1,114 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::ErrorTracking::Processor::SanitizerProcessor, :sentry do + describe '.call' do + let(:event) { Sentry.get_current_client.event_from_exception(exception) } + let(:result_hash) { described_class.call(event).to_hash } + + before do + data.each do |key, value| + event.send("#{key}=", value) + end + end + + after do + Sentry.get_current_scope.clear + end + + context 'when event attributes contains sensitive information' do + let(:exception) { RuntimeError.new } + let(:data) do + { + contexts: { + jwt: 'abcdef', + controller: 'GraphController#execute' + }, + tags: { + variables: %w[some sensitive information'], + deep_hash: { + sharedSecret: 'secret123' + } + }, + user: { + email: 'a@a.com', + password: 'nobodyknows' + }, + extra: { + issue_url: 'http://gitlab.com/gitlab-org/gitlab-foss/-/issues/1', + my_token: '[FILTERED]', + another_token: '[FILTERED]' + } + } + end + + it 'filters sensitive attributes' do + expect_next_instance_of(ActiveSupport::ParameterFilter) do |instance| + expect(instance).to receive(:filter).exactly(4).times.and_call_original + end + + expect(result_hash).to include( + contexts: { + jwt: '[FILTERED]', + controller: 'GraphController#execute' + }, + tags: { + variables: '[FILTERED]', + deep_hash: { + sharedSecret: '[FILTERED]' + } + }, + user: { + email: 'a@a.com', + password: '[FILTERED]' + }, + extra: { + issue_url: 'http://gitlab.com/gitlab-org/gitlab-foss/-/issues/1', + my_token: '[FILTERED]', + another_token: '[FILTERED]' + } + ) + end + end + + context 'when request contains sensitive information' do + let(:exception) { RuntimeError.new } + let(:data) { {} } + + before do + event.rack_env = { + 'HTTP_AUTHORIZATION' => 'Bearer 123456', + 'HTTP_PRIVATE_TOKEN' => 'abcdef', + 'HTTP_JOB_TOKEN' => 'secret123', + 'HTTP_GITLAB_WORKHORSE_PROXY_START' => 123456, + 'HTTP_COOKIE' => 'yummy_cookie=choco; tasty_cookie=strawberry', + 'QUERY_STRING' => 'token=secret&access_token=secret&job_token=secret&private_token=secret', + 'Content-Type' => 'application/json', + 'rack.input' => StringIO.new('{"name":"new_project", "some_token":"value"}') + } + end + + it 'filters sensitive headers' do + expect(result_hash[:request][:headers]).to include( + 'Authorization' => '[FILTERED]', + 'Private-Token' => '[FILTERED]', + 'Job-Token' => '[FILTERED]', + 'Gitlab-Workhorse-Proxy-Start' => '123456' + ) + end + + it 'filters query string parameters' do + expect(result_hash[:request][:query_string]).not_to include('secret') + end + + it 'removes cookies' do + expect(result_hash[:request][:cookies]).to be_empty + end + + it 'removes data' do + expect(result_hash[:request][:data]).to be_empty + end + end + end +end diff --git a/spec/lib/gitlab/error_tracking_spec.rb b/spec/lib/gitlab/error_tracking_spec.rb index 1ade3a51c55..fd859ae40fb 100644 --- a/spec/lib/gitlab/error_tracking_spec.rb +++ b/spec/lib/gitlab/error_tracking_spec.rb @@ -424,5 +424,25 @@ RSpec.describe Gitlab::ErrorTracking do end end end + + context 'when request contains sensitive information' do + before do + Sentry.get_current_scope.set_rack_env({ + 'HTTP_AUTHORIZATION' => 'Bearer 123456', + 'HTTP_PRIVATE_TOKEN' => 'abcdef', + 'HTTP_JOB_TOKEN' => 'secret123' + }) + end + + it 'filters sensitive data' do + track_exception + + expect(sentry_event.to_hash[:request][:headers]).to include( + 'Authorization' => '[FILTERED]', + 'Private-Token' => '[FILTERED]', + 'Job-Token' => '[FILTERED]' + ) + end + end end end diff --git a/spec/lib/gitlab/pages/cache_control_spec.rb b/spec/lib/gitlab/pages/cache_control_spec.rb new file mode 100644 index 00000000000..6ed823427fb --- /dev/null +++ b/spec/lib/gitlab/pages/cache_control_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Pages::CacheControl do + it 'fails with invalid type' do + expect { described_class.new(type: :unknown, id: nil) } + .to raise_error(ArgumentError, "type must be :namespace or :project") + end + + describe '.for_namespace' do + let(:subject) { described_class.for_namespace(1) } + + it { expect(subject.cache_key).to eq('pages_domain_for_namespace_1') } + + describe '#clear_cache' do + it 'clears the cache' do + expect(Rails.cache) + .to receive(:delete) + .with('pages_domain_for_namespace_1') + + subject.clear_cache + end + end + end + + describe '.for_project' do + let(:subject) { described_class.for_project(1) } + + it { expect(subject.cache_key).to eq('pages_domain_for_project_1') } + + describe '#clear_cache' do + it 'clears the cache' do + expect(Rails.cache) + .to receive(:delete) + .with('pages_domain_for_project_1') + + subject.clear_cache + end + end + end +end diff --git a/spec/lib/gitlab/tracking/destinations/snowplow_spec.rb b/spec/lib/gitlab/tracking/destinations/snowplow_spec.rb index 06cc2d3800c..1d4725cf405 100644 --- a/spec/lib/gitlab/tracking/destinations/snowplow_spec.rb +++ b/spec/lib/gitlab/tracking/destinations/snowplow_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::Tracking::Destinations::Snowplow do +RSpec.describe Gitlab::Tracking::Destinations::Snowplow, :do_not_stub_snowplow_by_default do let(:emitter) { SnowplowTracker::Emitter.new('localhost', buffer_size: 1) } let(:tracker) { SnowplowTracker::Tracker.new(emitter, SnowplowTracker::Subject.new, 'namespace', 'app_id') } diff --git a/spec/lib/gitlab/tracking/incident_management_spec.rb b/spec/lib/gitlab/tracking/incident_management_spec.rb index fbcb9bf3e4c..ef7816aa0db 100644 --- a/spec/lib/gitlab/tracking/incident_management_spec.rb +++ b/spec/lib/gitlab/tracking/incident_management_spec.rb @@ -20,7 +20,7 @@ RSpec.describe Gitlab::Tracking::IncidentManagement do described_class.track_from_params(params) end - context 'known params' do + context 'known params', :do_not_stub_snowplow_by_default do known_params = described_class.tracking_keys known_params.each do |key, values| diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index dcb9890c7cd..afcc3cee913 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -305,18 +305,20 @@ RSpec.describe ApplicationSetting do end end - context 'when snowplow is enabled' do - before do - setting.snowplow_enabled = true - end + describe 'snowplow settings', :do_not_stub_snowplow_by_default do + context 'when snowplow is enabled' do + before do + setting.snowplow_enabled = true + end - it { is_expected.not_to allow_value(nil).for(:snowplow_collector_hostname) } - it { is_expected.to allow_value("snowplow.gitlab.com").for(:snowplow_collector_hostname) } - it { is_expected.not_to allow_value('/example').for(:snowplow_collector_hostname) } - end + it { is_expected.not_to allow_value(nil).for(:snowplow_collector_hostname) } + it { is_expected.to allow_value("snowplow.gitlab.com").for(:snowplow_collector_hostname) } + it { is_expected.not_to allow_value('/example').for(:snowplow_collector_hostname) } + end - context 'when snowplow is not enabled' do - it { is_expected.to allow_value(nil).for(:snowplow_collector_hostname) } + context 'when snowplow is not enabled' do + it { is_expected.to allow_value(nil).for(:snowplow_collector_hostname) } + end end context 'when mailgun_events_enabled is enabled' do diff --git a/spec/models/concerns/cacheable_attributes_spec.rb b/spec/models/concerns/cacheable_attributes_spec.rb index dc80e30216a..0629debda15 100644 --- a/spec/models/concerns/cacheable_attributes_spec.rb +++ b/spec/models/concerns/cacheable_attributes_spec.rb @@ -205,7 +205,12 @@ RSpec.describe CacheableAttributes do end end - it 'uses RequestStore in addition to process memory cache', :request_store, :do_not_mock_admin_mode_setting do + it( + 'uses RequestStore in addition to process memory cache', + :request_store, + :do_not_mock_admin_mode_setting, + :do_not_stub_snowplow_by_default + ) do # Warm up the cache create(:application_setting).cache! diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb index ee21b857fc8..f4304056907 100644 --- a/spec/models/namespace_spec.rb +++ b/spec/models/namespace_spec.rb @@ -1885,15 +1885,29 @@ RSpec.describe Namespace do describe '#pages_virtual_domain' do let(:project) { create(:project, namespace: namespace) } + let(:virtual_domain) { namespace.pages_virtual_domain } - it 'returns the virual domain' do + before do project.mark_pages_as_deployed project.update_pages_deployment!(create(:pages_deployment, project: project)) + end - virtual_domain = namespace.pages_virtual_domain - + it 'returns the virual domain' do expect(virtual_domain).to be_an_instance_of(Pages::VirtualDomain) expect(virtual_domain.lookup_paths).not_to be_empty + expect(virtual_domain.cache_key).to eq("pages_domain_for_namespace_#{namespace.root_ancestor.id}") + end + + context 'when :cache_pages_domain_api is disabled' do + before do + stub_feature_flags(cache_pages_domain_api: false) + end + + it 'returns the virual domain' do + expect(virtual_domain).to be_an_instance_of(Pages::VirtualDomain) + expect(virtual_domain.lookup_paths).not_to be_empty + expect(virtual_domain.cache_key).to be_nil + end end end diff --git a/spec/models/pages/virtual_domain_spec.rb b/spec/models/pages/virtual_domain_spec.rb index 29c14cbeb3e..b5a421295b2 100644 --- a/spec/models/pages/virtual_domain_spec.rb +++ b/spec/models/pages/virtual_domain_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Pages::VirtualDomain do let(:domain) { nil } let(:project) { instance_double(Project) } - subject(:virtual_domain) { described_class.new([project], domain: domain) } + subject(:virtual_domain) { described_class.new(projects: [project], domain: domain) } it 'returns nil if there is no domain provided' do expect(virtual_domain.certificate).to be_nil @@ -35,7 +35,7 @@ RSpec.describe Pages::VirtualDomain do context 'when there is pages domain provided' do let(:domain) { instance_double(PagesDomain) } - subject(:virtual_domain) { described_class.new([project_a, project_b, project_c], domain: domain) } + subject(:virtual_domain) { described_class.new(projects: [project_a, project_b, project_c], domain: domain) } it 'returns collection of projects pages lookup paths sorted by prefix in reverse' do expect(project_a).to receive(:pages_lookup_path).with(domain: domain, trim_prefix: nil).and_return(pages_lookup_path_a) @@ -47,7 +47,7 @@ RSpec.describe Pages::VirtualDomain do end context 'when there is trim_prefix provided' do - subject(:virtual_domain) { described_class.new([project_a, project_b], trim_prefix: 'group/') } + subject(:virtual_domain) { described_class.new(projects: [project_a, project_b], trim_prefix: 'group/') } it 'returns collection of projects pages lookup paths sorted by prefix in reverse' do expect(project_a).to receive(:pages_lookup_path).with(trim_prefix: 'group/', domain: nil).and_return(pages_lookup_path_a) @@ -57,4 +57,19 @@ RSpec.describe Pages::VirtualDomain do end end end + + describe '#cache_key' do + it 'returns the cache key based in the given cache_control' do + cache_control = instance_double(::Gitlab::Pages::CacheControl, cache_key: 'cache_key') + virtual_domain = described_class.new(projects: [instance_double(Project)], cache: cache_control) + + expect(virtual_domain.cache_key).to eq('cache_key') + end + + it 'returns nil when no cache_control is given' do + virtual_domain = described_class.new(projects: [instance_double(Project)]) + + expect(virtual_domain.cache_key).to be_nil + end + end end diff --git a/spec/models/pages_domain_spec.rb b/spec/models/pages_domain_spec.rb index 7fde8d63947..4e463b1194c 100644 --- a/spec/models/pages_domain_spec.rb +++ b/spec/models/pages_domain_spec.rb @@ -544,16 +544,31 @@ RSpec.describe PagesDomain do end end - it 'returns the virual domain when there are pages deployed for the project' do - project.mark_pages_as_deployed - project.update_pages_deployment!(create(:pages_deployment, project: project)) + context 'when there are pages deployed for the project' do + let(:virtual_domain) { pages_domain.pages_virtual_domain } - expect(Pages::VirtualDomain).to receive(:new).with([project], domain: pages_domain).and_call_original + before do + project.mark_pages_as_deployed + project.update_pages_deployment!(create(:pages_deployment, project: project)) + end + + it 'returns the virual domain when there are pages deployed for the project' do + expect(virtual_domain).to be_an_instance_of(Pages::VirtualDomain) + expect(virtual_domain.lookup_paths).not_to be_empty + expect(virtual_domain.cache_key).to eq("pages_domain_for_project_#{project.id}") + end - virtual_domain = pages_domain.pages_virtual_domain + context 'when :cache_pages_domain_api is disabled' do + before do + stub_feature_flags(cache_pages_domain_api: false) + end - expect(virtual_domain).to be_an_instance_of(Pages::VirtualDomain) - expect(virtual_domain.lookup_paths).not_to be_empty + it 'returns the virual domain when there are pages deployed for the project' do + expect(virtual_domain).to be_an_instance_of(Pages::VirtualDomain) + expect(virtual_domain.lookup_paths).not_to be_empty + expect(virtual_domain.cache_key).to be_nil + end + end end end diff --git a/spec/requests/api/settings_spec.rb b/spec/requests/api/settings_spec.rb index cfda06da8f3..d4a8e591622 100644 --- a/spec/requests/api/settings_spec.rb +++ b/spec/requests/api/settings_spec.rb @@ -373,7 +373,7 @@ RSpec.describe API::Settings, 'Settings', :do_not_mock_admin_mode_setting do end end - context "snowplow tracking settings" do + context "snowplow tracking settings", :do_not_stub_snowplow_by_default do let(:settings) do { snowplow_collector_hostname: "snowplow.example.com", diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 06d6a8d9c0f..6f7d3e40901 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -201,10 +201,12 @@ RSpec.configure do |config| config.include SidekiqMiddleware config.include StubActionCableConnection, type: :channel config.include StubSpamServices + config.include SnowplowHelpers config.include RenderedHelpers config.include RSpec::Benchmark::Matchers, type: :benchmark include StubFeatureFlags + include StubSnowplow if ENV['CI'] || ENV['RETRIES'] # This includes the first try, i.e. tests will be run 4 times before failing. @@ -367,6 +369,9 @@ RSpec.configure do |config| stub_application_setting(admin_mode: true) unless example.metadata[:do_not_mock_admin_mode_setting] allow(Gitlab::CurrentSettings).to receive(:current_application_settings?).and_return(false) + + # Ensure that Snowplow is enabled by default unless forced to the opposite + stub_snowplow unless example.metadata[:do_not_stub_snowplow_by_default] end config.around(:example, :quarantine) do |example| diff --git a/spec/support/gitlab_experiment.rb b/spec/support/gitlab_experiment.rb index 823aab0436e..4236091ca6c 100644 --- a/spec/support/gitlab_experiment.rb +++ b/spec/support/gitlab_experiment.rb @@ -2,7 +2,6 @@ # Require the provided spec helper and matchers. require 'gitlab/experiment/rspec' -require_relative 'stub_snowplow' RSpec.configure do |config| config.include StubSnowplow, :experiment diff --git a/spec/support/stub_snowplow.rb b/spec/support/helpers/stub_snowplow.rb index c6e3b40972f..85c605efea3 100644 --- a/spec/support/stub_snowplow.rb +++ b/spec/support/helpers/stub_snowplow.rb @@ -13,7 +13,7 @@ module StubSnowplow .and_return(SnowplowTracker::Emitter.new(host, buffer_size: buffer_size)) # rubocop:enable RSpec/AnyInstanceOf - stub_application_setting(snowplow_enabled: true) + stub_application_setting(snowplow_enabled: true, snowplow_collector_hostname: host) allow(SnowplowTracker::SelfDescribingJson).to receive(:new).and_call_original allow(Gitlab::Tracking).to receive(:event).and_call_original # rubocop:disable RSpec/ExpectGitlabTracking diff --git a/spec/support/shared_examples/csp.rb b/spec/support/shared_examples/csp.rb index 9143d0f4720..91242ae9f37 100644 --- a/spec/support/shared_examples/csp.rb +++ b/spec/support/shared_examples/csp.rb @@ -15,64 +15,66 @@ RSpec.shared_examples 'setting CSP' do |rule_name| end end - context 'when no CSP config' do - include_context 'csp config', nil + context 'csp config and feature toggle', :do_not_stub_snowplow_by_default do + context 'when no CSP config' do + include_context 'csp config', nil - it 'does not add CSP directives' do - is_expected.to be_blank + it 'does not add CSP directives' do + is_expected.to be_blank + end end - end - describe "when a CSP config exists for #{rule_name}" do - include_context 'csp config', rule_name.parameterize.underscore.to_sym + describe "when a CSP config exists for #{rule_name}" do + include_context 'csp config', rule_name.parameterize.underscore.to_sym - context 'when feature is enabled' do - it "appends to #{rule_name}" do - is_expected.to eql("#{rule_name} #{default_csp_values} #{allowlisted_url}") + context 'when feature is enabled' do + it "appends to #{rule_name}" do + is_expected.to eql("#{rule_name} #{default_csp_values} #{allowlisted_url}") + end end - end - context 'when feature is disabled' do - include_context 'disable feature' + context 'when feature is disabled' do + include_context 'disable feature' - it "keeps original #{rule_name}" do - is_expected.to eql("#{rule_name} #{default_csp_values}") + it "keeps original #{rule_name}" do + is_expected.to eql("#{rule_name} #{default_csp_values}") + end end end - end - describe "when a CSP config exists for default-src but not #{rule_name}" do - include_context 'csp config', :default_src + describe "when a CSP config exists for default-src but not #{rule_name}" do + include_context 'csp config', :default_src - context 'when feature is enabled' do - it "uses default-src values in #{rule_name}" do - is_expected.to eql("default-src #{default_csp_values}; #{rule_name} #{default_csp_values} #{allowlisted_url}") + context 'when feature is enabled' do + it "uses default-src values in #{rule_name}" do + is_expected.to eql("default-src #{default_csp_values}; #{rule_name} #{default_csp_values} #{allowlisted_url}") + end end - end - context 'when feature is disabled' do - include_context 'disable feature' + context 'when feature is disabled' do + include_context 'disable feature' - it "does not add #{rule_name}" do - is_expected.to eql("default-src #{default_csp_values}") + it "does not add #{rule_name}" do + is_expected.to eql("default-src #{default_csp_values}") + end end end - end - describe "when a CSP config exists for font-src but not #{rule_name}" do - include_context 'csp config', :font_src + describe "when a CSP config exists for font-src but not #{rule_name}" do + include_context 'csp config', :font_src - context 'when feature is enabled' do - it "uses default-src values in #{rule_name}" do - is_expected.to eql("font-src #{default_csp_values}; #{rule_name} #{allowlisted_url}") + context 'when feature is enabled' do + it "uses default-src values in #{rule_name}" do + is_expected.to eql("font-src #{default_csp_values}; #{rule_name} #{allowlisted_url}") + end end - end - context 'when feature is disabled' do - include_context 'disable feature' + context 'when feature is disabled' do + include_context 'disable feature' - it "does not add #{rule_name}" do - is_expected.to eql("font-src #{default_csp_values}") + it "does not add #{rule_name}" do + is_expected.to eql("font-src #{default_csp_values}") + end end end end diff --git a/spec/support/snowplow.rb b/spec/support/snowplow.rb deleted file mode 100644 index d600bf008b0..00000000000 --- a/spec/support/snowplow.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require_relative 'stub_snowplow' - -RSpec.configure do |config| - config.include SnowplowHelpers, :snowplow - config.include StubSnowplow, :snowplow - - config.before(:each, :snowplow) do - stub_snowplow - end - - config.after(:each, :snowplow) do - Gitlab::Tracking.send(:tracker).send(:tracker).flush - end -end diff --git a/spec/workers/pages/invalidate_domain_cache_worker_spec.rb b/spec/workers/pages/invalidate_domain_cache_worker_spec.rb new file mode 100644 index 00000000000..8fdc7316069 --- /dev/null +++ b/spec/workers/pages/invalidate_domain_cache_worker_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Pages::InvalidateDomainCacheWorker do + let(:event) do + Pages::PageDeployedEvent.new(data: { + project_id: 1, + namespace_id: 2, + root_namespace_id: 3 + }) + end + + subject { consume_event(subscriber: described_class, event: event) } + + it_behaves_like 'subscribes to event' + + it 'enqueues ScheduleAggregationWorker' do + expect_next_instance_of(Gitlab::Pages::CacheControl, type: :project, id: 1) do |cache_control| + expect(cache_control).to receive(:clear_cache) + end + + expect_next_instance_of(Gitlab::Pages::CacheControl, type: :namespace, id: 3) do |cache_control| + expect(cache_control).to receive(:clear_cache) + end + + subject + end +end |