diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-30 00:08:27 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-30 00:08:27 +0300 |
commit | 836ddfc35d1778675b3bd6d51f51972f36a96bbe (patch) | |
tree | bc1c0247c76a2cbdbab94b3884bc040b179f41fe /spec/models | |
parent | 488e1b59feb4314b034636990bcc4e220e61f0ce (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/application_setting_spec.rb | 6 | ||||
-rw-r--r-- | spec/models/ci/pipeline_metadata_spec.rb | 14 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/concerns/integrations/has_web_hook_spec.rb | 28 | ||||
-rw-r--r-- | spec/models/hooks/web_hook_log_spec.rb | 47 | ||||
-rw-r--r-- | spec/models/integrations/buildkite_spec.rb | 4 | ||||
-rw-r--r-- | spec/models/integrations/datadog_spec.rb | 15 | ||||
-rw-r--r-- | spec/models/integrations/drone_ci_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/integrations/jira_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/integrations/packagist_spec.rb | 2 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/project_statistics_spec.rb | 20 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 25 |
13 files changed, 132 insertions, 36 deletions
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index b5f153e7add..db64e8439a5 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -1453,4 +1453,10 @@ RSpec.describe ApplicationSetting do expect(setting.personal_access_token_prefix).to eql('glpat-') end end + + describe '.personal_access_tokens_disabled?' do + it 'is false' do + expect(setting.personal_access_tokens_disabled?).to eq(false) + end + end end diff --git a/spec/models/ci/pipeline_metadata_spec.rb b/spec/models/ci/pipeline_metadata_spec.rb new file mode 100644 index 00000000000..0704cbc8ec1 --- /dev/null +++ b/spec/models/ci/pipeline_metadata_spec.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::PipelineMetadata do + it { is_expected.to belong_to(:project) } + it { is_expected.to belong_to(:pipeline) } + + describe 'validations' do + it { is_expected.to validate_length_of(:title).is_at_least(1).is_at_most(255) } + it { is_expected.to validate_presence_of(:project) } + it { is_expected.to validate_presence_of(:pipeline) } + end +end diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 839e5ed03cc..3fc1883c1e6 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -43,12 +43,14 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do it { is_expected.to have_one(:triggered_by_pipeline) } it { is_expected.to have_one(:source_job) } it { is_expected.to have_one(:pipeline_config) } + it { is_expected.to have_one(:pipeline_metadata) } it { is_expected.to respond_to :git_author_name } it { is_expected.to respond_to :git_author_email } it { is_expected.to respond_to :git_author_full_text } it { is_expected.to respond_to :short_sha } it { is_expected.to delegate_method(:full_path).to(:project).with_prefix } + it { is_expected.to delegate_method(:title).to(:pipeline_metadata).allow_nil } describe 'validations' do it { is_expected.to validate_presence_of(:sha) } diff --git a/spec/models/concerns/integrations/has_web_hook_spec.rb b/spec/models/concerns/integrations/has_web_hook_spec.rb new file mode 100644 index 00000000000..9061cb90f90 --- /dev/null +++ b/spec/models/concerns/integrations/has_web_hook_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Integrations::HasWebHook do + let(:integration_class) do + Class.new(Integration) do + include Integrations::HasWebHook + end + end + + let(:integration) { integration_class.new } + + context 'when hook_url and url_variables are not implemented' do + it { expect { integration.hook_url }.to raise_error(NotImplementedError) } + it { expect { integration.url_variables }.to raise_error(NotImplementedError) } + end + + context 'when integration does not respond to enable_ssl_verification' do + it { expect(integration.hook_ssl_verification).to eq true } + end + + context 'when integration responds to enable_ssl_verification' do + let(:integration) { build(:drone_ci_integration) } + + it { expect(integration.hook_ssl_verification).to eq true } + end +end diff --git a/spec/models/hooks/web_hook_log_spec.rb b/spec/models/hooks/web_hook_log_spec.rb index 8ff8a1c3865..3441dfda7d6 100644 --- a/spec/models/hooks/web_hook_log_spec.rb +++ b/spec/models/hooks/web_hook_log_spec.rb @@ -44,26 +44,49 @@ RSpec.describe WebHookLog do end end - context 'with author email' do + context "with users' emails" do let(:author) { create(:user) } + let(:user) { create(:user) } let(:web_hook_log) { create(:web_hook_log, request_data: data) } let(:data) do { - commit: { - author: { - name: author.name, - email: author.email + user: { + name: user.name, + email: user.email + }, + commits: [ + { + user: { + name: author.name, + email: author.email + } + }, + { + user: { + name: user.name, + email: user.email + } } - } + ] }.deep_stringify_keys end - it "redacts author's email" do - expect(web_hook_log.request_data['commit']).to match a_hash_including( - 'author' => { - 'name' => author.name, - 'email' => _('[REDACTED]') - } + it "redacts users' emails" do + expect(web_hook_log.request_data['user']).to match a_hash_including( + 'name' => user.name, + 'email' => _('[REDACTED]') + ) + expect(web_hook_log.request_data['commits'].pluck('user')).to match_array( + [ + { + 'name' => author.name, + 'email' => _('[REDACTED]') + }, + { + 'name' => user.name, + 'email' => _('[REDACTED]') + } + ] ) end end diff --git a/spec/models/integrations/buildkite_spec.rb b/spec/models/integrations/buildkite_spec.rb index 38ceb5db49c..c720dc6d418 100644 --- a/spec/models/integrations/buildkite_spec.rb +++ b/spec/models/integrations/buildkite_spec.rb @@ -19,7 +19,7 @@ RSpec.describe Integrations::Buildkite, :use_clean_rails_memory_store_caching do end it_behaves_like Integrations::HasWebHook do - let(:hook_url) { 'https://webhook.buildkite.com/deliver/secret-sauce-webhook-token' } + let(:hook_url) { 'https://webhook.buildkite.com/deliver/{webhook_token}' } end describe 'Validations' do @@ -68,7 +68,7 @@ RSpec.describe Integrations::Buildkite, :use_clean_rails_memory_store_caching do describe '#hook_url' do it 'returns the webhook url' do expect(integration.hook_url).to eq( - 'https://webhook.buildkite.com/deliver/secret-sauce-webhook-token' + 'https://webhook.buildkite.com/deliver/{webhook_token}' ) end end diff --git a/spec/models/integrations/datadog_spec.rb b/spec/models/integrations/datadog_spec.rb index 4ac684e8ff0..b7da6a79e44 100644 --- a/spec/models/integrations/datadog_spec.rb +++ b/spec/models/integrations/datadog_spec.rb @@ -19,6 +19,7 @@ RSpec.describe Integrations::Datadog do let(:dd_tags) { '' } let(:expected_hook_url) { default_url + "?dd-api-key=#{api_key}&env=#{dd_env}&service=#{dd_service}" } + let(:hook_url) { default_url + "?dd-api-key={api_key}&env=#{dd_env}&service=#{dd_service}" } let(:instance) do described_class.new( @@ -48,7 +49,7 @@ RSpec.describe Integrations::Datadog do it_behaves_like Integrations::HasWebHook do let(:integration) { instance } - let(:hook_url) { "#{described_class::URL_TEMPLATE % { datadog_domain: dd_site }}?dd-api-key=#{api_key}&env=#{dd_env}&service=#{dd_service}" } + let(:hook_url) { "#{described_class::URL_TEMPLATE % { datadog_domain: dd_site }}?dd-api-key={api_key}&env=#{dd_env}&service=#{dd_service}" } end describe 'validations' do @@ -132,18 +133,18 @@ RSpec.describe Integrations::Datadog do subject { instance.hook_url } context 'with standard site URL' do - it { is_expected.to eq(expected_hook_url) } + it { is_expected.to eq(hook_url) } end context 'with custom URL' do let(:api_url) { 'https://webhook-intake.datad0g.com/api/v2/webhook' } - it { is_expected.to eq(api_url + "?dd-api-key=#{api_key}&env=#{dd_env}&service=#{dd_service}") } + it { is_expected.to eq(api_url + "?dd-api-key={api_key}&env=#{dd_env}&service=#{dd_service}") } context 'blank' do let(:api_url) { '' } - it { is_expected.to eq(expected_hook_url) } + it { is_expected.to eq(hook_url) } end end @@ -152,19 +153,19 @@ RSpec.describe Integrations::Datadog do let(:dd_env) { '' } let(:dd_tags) { '' } - it { is_expected.to eq(default_url + "?dd-api-key=#{api_key}") } + it { is_expected.to eq(default_url + "?dd-api-key={api_key}") } end context 'with custom tags' do let(:dd_tags) { "key:value\nkey2:value, 2" } let(:escaped_tags) { CGI.escape("key:value,\"key2:value, 2\"") } - it { is_expected.to eq(expected_hook_url + "&tags=#{escaped_tags}") } + it { is_expected.to eq(hook_url + "&tags=#{escaped_tags}") } context 'and empty lines' do let(:dd_tags) { "key:value\r\n\n\n\nkey2:value, 2\n" } - it { is_expected.to eq(expected_hook_url + "&tags=#{escaped_tags}") } + it { is_expected.to eq(hook_url + "&tags=#{escaped_tags}") } end end end diff --git a/spec/models/integrations/drone_ci_spec.rb b/spec/models/integrations/drone_ci_spec.rb index 905fee075ad..f3203a6e69d 100644 --- a/spec/models/integrations/drone_ci_spec.rb +++ b/spec/models/integrations/drone_ci_spec.rb @@ -116,7 +116,7 @@ RSpec.describe Integrations::DroneCi, :use_clean_rails_memory_store_caching do include_context :drone_ci_integration let(:integration) { drone } - let(:hook_url) { "#{drone_url}/hook?owner=#{project.namespace.full_path}&name=#{project.path}&access_token=#{token}" } + let(:hook_url) { "#{drone_url}/hook?owner=#{project.namespace.full_path}&name=#{project.path}&access_token={token}" } it 'does not create a hook if project is not present' do integration.project = nil diff --git a/spec/models/integrations/jira_spec.rb b/spec/models/integrations/jira_spec.rb index 4dd6245fc2f..9f928442b28 100644 --- a/spec/models/integrations/jira_spec.rb +++ b/spec/models/integrations/jira_spec.rb @@ -214,6 +214,8 @@ RSpec.describe Integrations::Jira do 'EXT_EXT-1234' | 'EXT_EXT-1234' 'EXT3_EXT-1234' | 'EXT3_EXT-1234' '3EXT_EXT-1234' | '' + 'CVE-2022-123' | '' + 'CVE-123' | 'CVE-123' end with_them do diff --git a/spec/models/integrations/packagist_spec.rb b/spec/models/integrations/packagist_spec.rb index d1976e73e2e..e078debd126 100644 --- a/spec/models/integrations/packagist_spec.rb +++ b/spec/models/integrations/packagist_spec.rb @@ -26,7 +26,7 @@ RSpec.describe Integrations::Packagist do it_behaves_like Integrations::HasWebHook do let(:integration) { described_class.new(packagist_params) } - let(:hook_url) { "#{packagist_server}/api/update-package?username=#{packagist_username}&apiToken=#{packagist_token}" } + let(:hook_url) { "#{packagist_server}/api/update-package?username={username}&apiToken={token}" } end it_behaves_like Integrations::ResetSecretFields do diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index aef665bb585..6c85c66c6eb 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -149,6 +149,7 @@ RSpec.describe Project, factory_default: :keep do it { is_expected.to have_many(:secure_files).class_name('Ci::SecureFile').dependent(:restrict_with_error) } it { is_expected.to have_one(:build_artifacts_size_refresh).class_name('Projects::BuildArtifactsSizeRefresh') } it { is_expected.to have_many(:project_callouts).class_name('Users::ProjectCallout').with_foreign_key(:project_id) } + it { is_expected.to have_many(:pipeline_metadata).class_name('Ci::PipelineMetadata') } # GitLab Pages it { is_expected.to have_many(:pages_domains) } diff --git a/spec/models/project_statistics_spec.rb b/spec/models/project_statistics_spec.rb index 1a3283dfe51..2de7bd3696f 100644 --- a/spec/models/project_statistics_spec.rb +++ b/spec/models/project_statistics_spec.rb @@ -98,7 +98,7 @@ RSpec.describe ProjectStatistics do end describe '#refresh!' do - subject { statistics.refresh! } + subject(:refresh_statistics) { statistics.refresh! } before do allow(statistics).to receive(:update_commit_count) @@ -113,7 +113,7 @@ RSpec.describe ProjectStatistics do context "without arguments" do before do - subject + refresh_statistics end it "sums all counters" do @@ -148,7 +148,7 @@ RSpec.describe ProjectStatistics do expect(project.repository.exists?).to be_falsey expect(project.wiki.repository.exists?).to be_falsey - subject + refresh_statistics expect(statistics).to have_received(:update_commit_count) expect(statistics).to have_received(:update_repository_size) @@ -176,7 +176,7 @@ RSpec.describe ProjectStatistics do end it 'does not crash' do - subject + refresh_statistics expect(statistics).to have_received(:update_commit_count) expect(statistics).to have_received(:update_repository_size) @@ -211,7 +211,7 @@ RSpec.describe ProjectStatistics do expect(Namespaces::ScheduleAggregationWorker) .to receive(:perform_async) - subject + refresh_statistics end end end @@ -240,7 +240,7 @@ RSpec.describe ProjectStatistics do expect(Namespaces::ScheduleAggregationWorker) .not_to receive(:perform_async) - subject + refresh_statistics end end @@ -414,7 +414,7 @@ RSpec.describe ProjectStatistics do end describe '#refresh_storage_size!' do - subject { statistics.refresh_storage_size! } + subject(:refresh_storage_size) { statistics.refresh_storage_size! } it 'recalculates storage size from its components and save it' do statistics.update_columns( @@ -430,7 +430,7 @@ RSpec.describe ProjectStatistics do storage_size: 0 ) - expect { subject }.to change { statistics.reload.storage_size }.from(0).to(28) + expect { refresh_storage_size }.to change { statistics.reload.storage_size }.from(0).to(28) end context 'when nullable columns are nil' do @@ -443,11 +443,11 @@ RSpec.describe ProjectStatistics do end it 'does not raise any error' do - expect { subject }.not_to raise_error + expect { refresh_storage_size }.not_to raise_error end it 'recalculates storage size from its components' do - expect { subject }.to change { statistics.reload.storage_size }.from(0).to(2) + expect { refresh_storage_size }.to change { statistics.reload.storage_size }.from(0).to(2) end end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index cff820eb88a..8d848ad528d 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1882,9 +1882,9 @@ RSpec.describe User do end it 'ensures correct rights and limits for user' do - stub_config_setting(default_can_create_group: true) + stub_application_setting(can_create_group: true) - expect { user.update!(external: false) }.to change { user.can_create_group }.to(true) + expect { user.update!(external: false) }.to change { user.can_create_group }.from(false).to(true) .and change { user.projects_limit }.to(Gitlab::CurrentSettings.default_projects_limit) end end @@ -2604,7 +2604,7 @@ RSpec.describe User do it 'applies defaults to user' do expect(user.projects_limit).to eq(Gitlab.config.gitlab.default_projects_limit) - expect(user.can_create_group).to eq(Gitlab.config.gitlab.default_can_create_group) + expect(user.can_create_group).to eq(Gitlab::CurrentSettings.can_create_group) expect(user.theme_id).to eq(Gitlab.config.gitlab.default_theme) expect(user.external).to be_falsey expect(user.private_profile).to eq(false) @@ -6849,6 +6849,25 @@ RSpec.describe User do end end + describe '#webhook_email' do + let(:user) { build(:user, public_email: nil) } + + context 'when public email is present' do + before do + user.public_email = "hello@hello.com" + end + it 'returns public email' do + expect(user.webhook_email).to eq(user.public_email) + end + end + + context 'when public email is nil' do + it 'returns [REDACTED]' do + expect(user.webhook_email).to eq(_('[REDACTED]')) + end + end + end + describe 'user credit card validation' do context 'when user is initialized' do let(:user) { build(:user) } |