diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-16 15:07:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-16 15:07:11 +0300 |
commit | d87800c3cfa21bde64704542d61a587c5ff4306e (patch) | |
tree | 4921659e458ef0b21a637ba68a2765c93e4f20b7 /spec/lib | |
parent | 8ae36d93f1a63874b584f0488fde88c1fee999c4 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/error_tracking/collector/payload_validator_spec.rb | 45 | ||||
-rw-r--r-- | spec/lib/error_tracking/collector/sentry_auth_parser_spec.rb | 32 | ||||
-rw-r--r-- | spec/lib/error_tracking/collector/sentry_request_parser_spec.rb | 37 | ||||
-rw-r--r-- | spec/lib/gitlab/auth/saml/config_spec.rb | 26 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/config/external/rules_spec.rb | 28 | ||||
-rw-r--r-- | spec/lib/gitlab/git/repository_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client/ref_service_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/spamcheck/client_spec.rb | 4 |
8 files changed, 62 insertions, 120 deletions
diff --git a/spec/lib/error_tracking/collector/payload_validator_spec.rb b/spec/lib/error_tracking/collector/payload_validator_spec.rb deleted file mode 100644 index 96ad66e9b58..00000000000 --- a/spec/lib/error_tracking/collector/payload_validator_spec.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe ErrorTracking::Collector::PayloadValidator do - let(:validator) { described_class.new } - - describe '#valid?' do - RSpec.shared_examples 'valid payload' do - specify do - expect(validator).to be_valid(payload) - end - end - - RSpec.shared_examples 'invalid payload' do - specify do - expect(validator).not_to be_valid(payload) - end - end - - context 'with event fixtures' do - where(:event_fixture) do - Dir.glob(Rails.root.join('spec/fixtures/error_tracking/*event*.json')) - end - - with_them do - let(:payload) { Gitlab::Json.parse(File.read(event_fixture)) } - - it_behaves_like 'valid payload' - end - end - - context 'when empty' do - let(:payload) { '' } - - it_behaves_like 'invalid payload' - end - - context 'when invalid' do - let(:payload) { { 'foo' => 'bar' } } - - it_behaves_like 'invalid payload' - end - end -end diff --git a/spec/lib/error_tracking/collector/sentry_auth_parser_spec.rb b/spec/lib/error_tracking/collector/sentry_auth_parser_spec.rb deleted file mode 100644 index 0e4bba04baa..00000000000 --- a/spec/lib/error_tracking/collector/sentry_auth_parser_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe ErrorTracking::Collector::SentryAuthParser do - describe '.parse' do - let(:headers) { { 'X-Sentry-Auth' => "Sentry sentry_key=glet_1fedb514e17f4b958435093deb02048c" } } - let(:request) { instance_double('ActionDispatch::Request', headers: headers) } - - subject { described_class.parse(request) } - - context 'with empty headers' do - let(:headers) { {} } - - it 'fails with exception' do - expect { subject }.to raise_error(StandardError) - end - end - - context 'with missing sentry_key' do - let(:headers) { { 'X-Sentry-Auth' => "Sentry foo=bar" } } - - it 'returns empty value for public_key' do - expect(subject[:public_key]).to be_nil - end - end - - it 'returns correct value for public_key' do - expect(subject[:public_key]).to eq('glet_1fedb514e17f4b958435093deb02048c') - end - end -end diff --git a/spec/lib/error_tracking/collector/sentry_request_parser_spec.rb b/spec/lib/error_tracking/collector/sentry_request_parser_spec.rb deleted file mode 100644 index e86ee67c129..00000000000 --- a/spec/lib/error_tracking/collector/sentry_request_parser_spec.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe ErrorTracking::Collector::SentryRequestParser do - describe '.parse' do - let_it_be(:raw_event) { fixture_file('error_tracking/event.txt') } - let_it_be(:parsed_event) { Gitlab::Json.parse(fixture_file('error_tracking/parsed_event.json')) } - - let(:body) { raw_event } - let(:headers) { { 'Content-Encoding' => '' } } - let(:request) { instance_double('ActionDispatch::Request', headers: headers, body: StringIO.new(body)) } - - subject { described_class.parse(request) } - - RSpec.shared_examples 'valid parser' do - it 'returns a valid hash' do - parsed_request = subject - - expect(parsed_request[:request_type]).to eq('event') - expect(parsed_request[:event]).to eq(parsed_event) - end - end - - context 'with empty body content' do - let(:body) { '' } - - it 'fails with exception' do - expect { subject }.to raise_error(StandardError) - end - end - - context 'with plain text sentry request' do - it_behaves_like 'valid parser' - end - end -end diff --git a/spec/lib/gitlab/auth/saml/config_spec.rb b/spec/lib/gitlab/auth/saml/config_spec.rb index 12f5da48873..d657622c9f2 100644 --- a/spec/lib/gitlab/auth/saml/config_spec.rb +++ b/spec/lib/gitlab/auth/saml/config_spec.rb @@ -16,4 +16,30 @@ RSpec.describe Gitlab::Auth::Saml::Config do it { is_expected.to eq(true) } end end + + describe '#external_groups' do + let(:config_1) { described_class.new('saml1') } + + let(:config_2) { described_class.new('saml2') } + + before do + saml1_config = ActiveSupport::InheritableOptions.new(name: 'saml1', label: 'saml1', args: { + 'strategy_class' => 'OmniAuth::Strategies::SAML' + }) + + saml2_config = ActiveSupport::InheritableOptions.new(name: 'saml2', + external_groups: ['FreeLancers'], + label: 'saml2', + args: { + 'strategy_class' => 'OmniAuth::Strategies::SAML' + }) + + stub_omniauth_setting(enabled: true, auto_link_saml_user: true, providers: [saml1_config, saml2_config]) + end + + it "lists groups" do + expect(config_1.external_groups).to be_nil + expect(config_2.external_groups).to be_eql(['FreeLancers']) + end + end end diff --git a/spec/lib/gitlab/ci/config/external/rules_spec.rb b/spec/lib/gitlab/ci/config/external/rules_spec.rb index 3cb9dedbefe..1ba5caa1d4b 100644 --- a/spec/lib/gitlab/ci/config/external/rules_spec.rb +++ b/spec/lib/gitlab/ci/config/external/rules_spec.rb @@ -80,6 +80,20 @@ RSpec.describe Gitlab::Ci::Config::External::Rules, feature_category: :pipeline_ end end + context 'with when: always' do + let(:rule_hashes) { [{ if: '$MY_VAR == "hello"', when: 'always' }] } + + it_behaves_like 'when there is a rule with if' + + context 'when FF `ci_support_include_rules_when_never` is disabled' do + before do + stub_feature_flags(ci_support_include_rules_when_never: false) + end + + it_behaves_like 'when there is a rule with if' + end + end + context 'with when: <invalid string>' do let(:rule_hashes) { [{ if: '$MY_VAR == "hello"', when: 'on_success' }] } @@ -111,6 +125,20 @@ RSpec.describe Gitlab::Ci::Config::External::Rules, feature_category: :pipeline_ end end + context 'with when: always' do + let(:rule_hashes) { [{ exists: 'Dockerfile', when: 'always' }] } + + it_behaves_like 'when there is a rule with exists' + + context 'when FF `ci_support_include_rules_when_never` is disabled' do + before do + stub_feature_flags(ci_support_include_rules_when_never: false) + end + + it_behaves_like 'when there is a rule with exists' + end + end + context 'with when: <invalid string>' do let(:rule_hashes) { [{ exists: 'Dockerfile', when: 'on_success' }] } diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb index 23f5c61d335..78a2470b808 100644 --- a/spec/lib/gitlab/git/repository_spec.rb +++ b/spec/lib/gitlab/git/repository_spec.rb @@ -41,8 +41,8 @@ RSpec.describe Gitlab::Git::Repository, feature_category: :source_code_managemen end it 'gets the branch name from GitalyClient' do - expect_any_instance_of(Gitlab::GitalyClient::RefService).to receive(:default_branch_name) - repository.root_ref + expect_any_instance_of(Gitlab::GitalyClient::RefService).to receive(:default_branch_name).with(head_only: true) + repository.root_ref(head_only: true) end it_behaves_like 'wrapping gRPC errors', Gitlab::GitalyClient::RefService, :default_branch_name do diff --git a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb index 89ac0c119bf..fe04ad36e9a 100644 --- a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb @@ -138,9 +138,11 @@ RSpec.describe Gitlab::GitalyClient::RefService, feature_category: :gitaly do expect_any_instance_of(Gitaly::RefService::Stub) .to receive(:find_default_branch_name) .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) - .and_return(double(name: 'foo')) + .and_return(double(name: 'refs/heads/main')) - client.default_branch_name + response = client.default_branch_name + + expect(response).to eq('main') end end diff --git a/spec/lib/gitlab/spamcheck/client_spec.rb b/spec/lib/gitlab/spamcheck/client_spec.rb index 57ce6334c1c..080c2803ddd 100644 --- a/spec/lib/gitlab/spamcheck/client_spec.rb +++ b/spec/lib/gitlab/spamcheck/client_spec.rb @@ -106,8 +106,8 @@ RSpec.describe Gitlab::Spamcheck::Client, feature_category: :instance_resiliency let_it_be(:generic_updated_at) { issue.updated_at } before do - allow(generic_spammable.class).to receive(:name).and_return('GenericSpam') allow(generic_spammable).to receive_messages( + spammable_entity_type: 'generic', spammable_text: 'generic spam', created_at: generic_created_at, updated_at: generic_updated_at, @@ -152,7 +152,7 @@ RSpec.describe Gitlab::Spamcheck::Client, feature_category: :instance_resiliency generic_pb, _ = described_class.new.send(:build_protobuf, spammable: generic_spammable, user: user, context: cxt, extra_features: {}) expect(generic_pb.text).to eq 'generic spam' - expect(generic_pb.type).to eq 'GenericSpam' + expect(generic_pb.type).to eq 'generic' expect(generic_pb.created_at).to eq timestamp_to_protobuf_timestamp(generic_created_at) expect(generic_pb.updated_at).to eq timestamp_to_protobuf_timestamp(generic_updated_at) expect(generic_pb.action).to be ::Spamcheck::Action.lookup(::Spamcheck::Action::CREATE) |