diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-12 00:09:23 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-12 00:09:23 +0300 |
commit | c53e365d68ee800702befb15adfdfac708d5de6f (patch) | |
tree | 023b65376d2929e777be5785ec9c3fdd24263c7e /spec | |
parent | 1bd9d2d9499d0d28e62254a28fcd3d913a8704af (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
3 files changed, 94 insertions, 21 deletions
diff --git a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb index a7dc0b6a060..da8098bfee1 100644 --- a/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/hll_redis_counter_spec.rb @@ -168,6 +168,54 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s end end end + + describe "redis key overrides" do + let(:event_name) { "g_analytics_contribution" } + + before do + allow(File).to receive(:read).and_call_original + allow(File).to receive(:read).with(described_class::KEY_OVERRIDES_PATH).and_return(overrides_file_content) + end + + after do + described_class.clear_memoization(:key_overrides) + end + + context "with an empty file" do + let(:overrides_file_content) { "{}" } + + it "tracks the events using original Redis key" do + expected_key = "{hll_counters}_#{event_name}-2020-23" + expect(Gitlab::Redis::HLL).to receive(:add).with(hash_including(key: expected_key)) + + described_class.track_event(event_name, values: entity1) + end + end + + context "with the file including overrides" do + let(:overrides_file_content) { "#{event_name}1: new_key2\n#{event_name}: new_key" } + + context "when the event is included in overrides file" do + it "tracks the events using overridden Redis key" do + expected_key = "{hll_counters}_new_key-2020-23" + expect(Gitlab::Redis::HLL).to receive(:add).with(hash_including(key: expected_key)) + + described_class.track_event(:g_analytics_contribution, values: entity1) + end + end + + context "when the event is not included in overrides file" do + let(:not_overridden_name) { "g_compliance_dashboard" } + + it "tracks the events using original Redis key" do + expected_key = "{hll_counters}_#{not_overridden_name}-2020-23" + expect(Gitlab::Redis::HLL).to receive(:add).with(hash_including(key: expected_key)) + + described_class.track_event(not_overridden_name, values: entity1) + end + end + end + end end describe '.unique_events' do @@ -236,6 +284,16 @@ RSpec.describe Gitlab::UsageDataCounters::HLLRedisCounter, :clean_gitlab_redis_s end end end + + describe 'key overrides file' do + let(:key_overrides) { YAML.safe_load(File.read(described_class::KEY_OVERRIDES_PATH)) } + + it "has a valid structure", :aggregate_failures do + expect(key_overrides).to be_a(Hash) + + expect(key_overrides.keys + key_overrides.values).to all(be_a(String)) + end + end end describe '.keys_for_aggregation' do diff --git a/spec/models/bulk_imports/failure_spec.rb b/spec/models/bulk_imports/failure_spec.rb index 928f14aaced..bbb5ad52fe1 100644 --- a/spec/models/bulk_imports/failure_spec.rb +++ b/spec/models/bulk_imports/failure_spec.rb @@ -58,4 +58,20 @@ RSpec.describe BulkImports::Failure, type: :model, feature_category: :importers expect(failure.exception_message.size).to eq(255) end end + + describe '#source_title=' do + it 'truncates title to 255 characters' do + failure = described_class.new + failure.source_title = 'A' * 1000 + expect(failure.source_title.size).to eq(255) + end + end + + describe '#source_url=' do + it 'truncates url to 255 characters' do + failure = described_class.new + failure.source_url = 'A' * 1000 + expect(failure.source_url.size).to eq(255) + end + end end diff --git a/spec/support/shared_examples/services/protected_branches_shared_examples.rb b/spec/support/shared_examples/services/protected_branches_shared_examples.rb index 6d4b82730da..980241ad586 100644 --- a/spec/support/shared_examples/services/protected_branches_shared_examples.rb +++ b/spec/support/shared_examples/services/protected_branches_shared_examples.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -RSpec.shared_context 'with scan result policy blocking protected branches' do +RSpec.shared_context 'with scan result policy' do include RepoHelpers let(:policy_path) { Security::OrchestrationPolicyConfiguration::POLICY_PATH } @@ -8,12 +8,10 @@ RSpec.shared_context 'with scan result policy blocking protected branches' do let(:default_branch) { policy_project.default_branch } let(:policy_yaml) do - build(:orchestration_policy_yaml, scan_execution_policy: [], scan_result_policy: [scan_result_policy]) + build(:orchestration_policy_yaml, scan_execution_policy: [], scan_result_policy: scan_result_policies) end - let(:scan_result_policy) do - build(:scan_result_policy, branches: [branch_name], approval_settings: { block_branch_modification: true }) - end + let(:scan_result_policies) { [scan_result_policy] } before do policy_configuration.update_attribute(:security_policy_management_project, policy_project) @@ -24,25 +22,26 @@ RSpec.shared_context 'with scan result policy blocking protected branches' do end end -RSpec.shared_context 'with scan result policy preventing force pushing' do - include RepoHelpers - - let(:policy_path) { Security::OrchestrationPolicyConfiguration::POLICY_PATH } - let(:default_branch) { policy_project.default_branch } - let(:prevent_pushing_and_force_pushing) { true } - - let(:scan_result_policy) do - build(:scan_result_policy, branches: [branch_name], - approval_settings: { prevent_pushing_and_force_pushing: prevent_pushing_and_force_pushing }) +RSpec.shared_context 'with scan result policy blocking protected branches' do + include_context 'with scan result policy' do + let(:scan_result_policy) do + build(:scan_result_policy, branches: [branch_name], approval_settings: { block_branch_modification: true }) + end end +end - let(:policy_yaml) do - build(:orchestration_policy_yaml, scan_result_policy: [scan_result_policy]) - end +RSpec.shared_context 'with scan result policy preventing force pushing' do + include_context 'with scan result policy' do + let(:prevent_pushing_and_force_pushing) { true } - before do - create_file_in_repo(policy_project, default_branch, default_branch, policy_path, policy_yaml) - stub_licensed_features(security_orchestration_policies: true) + let(:scan_result_policy) do + build(:scan_result_policy, branches: [branch_name], + approval_settings: { prevent_pushing_and_force_pushing: prevent_pushing_and_force_pushing }) + end + + let(:policy_yaml) do + build(:orchestration_policy_yaml, scan_result_policy: [scan_result_policy]) + end end after do |