diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-19 21:09:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-19 21:09:33 +0300 |
commit | d1be3e6f776e1c77976537548c1daa9af2fb2650 (patch) | |
tree | 387d3c8f06e18bbfa24a4b0b015a7245e166927c /spec/lib | |
parent | 8f3a9dbb94b5a9ae4570a22bbc2a75e7572407c8 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/beyond_identity/client_spec.rb | 81 | ||||
-rw-r--r-- | spec/lib/gitlab/git_spec.rb | 16 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/all_models.yml | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/instrumentation/connection_pool_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/patch/database_config_spec.rb | 16 |
5 files changed, 118 insertions, 0 deletions
diff --git a/spec/lib/gitlab/beyond_identity/client_spec.rb b/spec/lib/gitlab/beyond_identity/client_spec.rb new file mode 100644 index 00000000000..250db1bbb23 --- /dev/null +++ b/spec/lib/gitlab/beyond_identity/client_spec.rb @@ -0,0 +1,81 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Gitlab::BeyondIdentity::Client, feature_category: :source_code_management do + let_it_be_with_reload(:integration) { create(:beyond_identity_integration) } + + let(:stubbed_response) do + { 'authorized' => true }.to_json + end + + let(:params) { { key_id: 'key-id', committer_email: 'email@example.com' } } + let(:status) { 200 } + + let!(:request) do + stub_request(:get, ::Gitlab::BeyondIdentity::Client::API_URL).with( + query: params, + headers: { 'Content-Type' => 'application/json', Authorization: "Bearer #{integration.token}" } + ).to_return( + status: status, + body: stubbed_response + ) + end + + subject(:client) { described_class.new(integration) } + + context 'when integration is not activated' do + it 'raises a config error' do + integration.active = false + + expect do + client.execute(params) + end.to raise_error(::Gitlab::BeyondIdentity::Client::Error).with_message( + 'integration is not activated' + ) + + expect(request).not_to have_been_requested + end + end + + it 'executes successfully' do + expect(client.execute(params)).to eq({ 'authorized' => true }) + expect(request).to have_been_requested + end + + context 'with invalid response' do + let(:stubbed_response) { 'invalid' } + + it 'executes successfully' do + expect { client.execute(params) }.to raise_error( + ::Gitlab::BeyondIdentity::Client::Error + ).with_message('invalid response format') + end + end + + context 'with an error response' do + let(:stubbed_response) do + { 'error' => { 'message' => 'gpg_key is invalid' } }.to_json + end + + let(:status) { 400 } + + it 'returns an error' do + expect { client.execute(params) }.to raise_error( + ::Gitlab::BeyondIdentity::Client::Error + ).with_message('gpg_key is invalid') + end + end + + context 'when key is unauthorized' do + let(:stubbed_response) do + { 'unauthorized' => false, 'message' => 'key is unauthorized' }.to_json + end + + it 'returns an error' do + expect { client.execute(params) }.to raise_error( + ::Gitlab::BeyondIdentity::Client::Error + ).with_message('authorization denied: key is unauthorized') + end + end +end diff --git a/spec/lib/gitlab/git_spec.rb b/spec/lib/gitlab/git_spec.rb index 61f66c9cd0c..354ef377c94 100644 --- a/spec/lib/gitlab/git_spec.rb +++ b/spec/lib/gitlab/git_spec.rb @@ -68,4 +68,20 @@ RSpec.describe Gitlab::Git do end end end + + describe '.blank_ref?' do + using RSpec::Parameterized::TableSyntax + + where(:sha, :result) do + '4b825dc642cb6eb9a060e54bf8d69288fbee4904' | false + '0000000000000000000000000000000000000000' | true + '0000000000000000000000000000000000000000000000000000000000000000' | true + end + + with_them do + it 'returns the expected result' do + expect(described_class.blank_ref?(sha)).to eq(result) + end + end + end end diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 9e83b7d85e9..acf39a02b28 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -585,6 +585,7 @@ project: - prometheus_integration - assembla_integration - asana_integration +- beyond_identity_integration - slack_integration - microsoft_teams_integration - mattermost_integration diff --git a/spec/lib/gitlab/instrumentation/connection_pool_spec.rb b/spec/lib/gitlab/instrumentation/connection_pool_spec.rb index b7cab2e9900..ce869659c67 100644 --- a/spec/lib/gitlab/instrumentation/connection_pool_spec.rb +++ b/spec/lib/gitlab/instrumentation/connection_pool_spec.rb @@ -4,6 +4,10 @@ require 'spec_helper' require 'support/helpers/rails_helpers' RSpec.describe Gitlab::Instrumentation::ConnectionPool, feature_category: :redis do + before do + ::ConnectionPool.prepend(::Gitlab::Instrumentation::ConnectionPool) + end + let(:option) { { name: 'test', size: 5 } } let(:pool) { ConnectionPool.new(option) { 'nothing' } } diff --git a/spec/lib/gitlab/patch/database_config_spec.rb b/spec/lib/gitlab/patch/database_config_spec.rb index 73452853050..eb987319160 100644 --- a/spec/lib/gitlab/patch/database_config_spec.rb +++ b/spec/lib/gitlab/patch/database_config_spec.rb @@ -143,6 +143,22 @@ RSpec.describe Gitlab::Patch::DatabaseConfig do end end + context 'when the parsed external command output returns invalid hash' do + before do + allow(Gitlab::Popen) + .to receive(:popen) + .and_return(["hello", 0]) + end + + it 'raises an error' do + expect { configuration.database_configuration } + .to raise_error( + Gitlab::Patch::DatabaseConfig::CommandExecutionError, + %r{database.yml: The output of `/opt/database-config.sh` must be a Hash, String given} + ) + end + end + context 'when the external command fails' do before do allow(Gitlab::Popen).to receive(:popen).and_return(["", 125]) |