diff options
Diffstat (limited to 'spec/lib/gitlab/auth')
-rw-r--r-- | spec/lib/gitlab/auth/auth_finders_spec.rb | 24 | ||||
-rw-r--r-- | spec/lib/gitlab/auth/ldap/person_spec.rb | 7 |
2 files changed, 25 insertions, 6 deletions
diff --git a/spec/lib/gitlab/auth/auth_finders_spec.rb b/spec/lib/gitlab/auth/auth_finders_spec.rb index 774a87752b9..2aef206c7fd 100644 --- a/spec/lib/gitlab/auth/auth_finders_spec.rb +++ b/spec/lib/gitlab/auth/auth_finders_spec.rb @@ -4,6 +4,7 @@ require 'spec_helper' describe Gitlab::Auth::AuthFinders do include described_class + include HttpBasicAuthHelpers let(:user) { create(:user) } let(:env) do @@ -22,10 +23,7 @@ describe Gitlab::Auth::AuthFinders do end def set_basic_auth_header(username, password) - set_header( - 'HTTP_AUTHORIZATION', - ActionController::HttpAuthentication::Basic.encode_credentials(username, password) - ) + env.merge!(basic_auth_header(username, password)) end describe '#find_user_from_warden' do @@ -653,6 +651,24 @@ describe Gitlab::Auth::AuthFinders do it_behaves_like 'job token params', described_class::JOB_TOKEN_PARAM it_behaves_like 'job token params', described_class::RUNNER_JOB_TOKEN_PARAM end + + context 'when the job token is provided via basic auth' do + let(:route_authentication_setting) { { job_token_allowed: :basic_auth } } + let(:username) { Ci::Build::CI_REGISTRY_USER } + let(:token) { job.token } + + before do + set_basic_auth_header(username, token) + end + + it { is_expected.to eq(user) } + + context 'credentials are provided but route setting is incorrect' do + let(:route_authentication_setting) { { job_token_allowed: :unknown } } + + it { is_expected.to be_nil } + end + end end describe '#find_runner_from_token' do diff --git a/spec/lib/gitlab/auth/ldap/person_spec.rb b/spec/lib/gitlab/auth/ldap/person_spec.rb index e90917cfce1..403a48d40ef 100644 --- a/spec/lib/gitlab/auth/ldap/person_spec.rb +++ b/spec/lib/gitlab/auth/ldap/person_spec.rb @@ -57,14 +57,17 @@ describe Gitlab::Auth::Ldap::Person do 'attributes' => { 'name' => 'cn', 'email' => 'mail', - 'username' => %w(uid mail memberof) + 'username' => %w(uid mail), + 'first_name' => '' } } ) config = Gitlab::Auth::Ldap::Config.new('ldapmain') ldap_attributes = described_class.ldap_attributes(config) - expect(ldap_attributes).to match_array(%w(dn uid cn mail memberof)) + expect(ldap_attributes).to include('dn', 'uid', 'cn', 'mail') + expect(ldap_attributes).to be_present + expect(ldap_attributes.uniq!).to eq(nil) end end |