2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-18 17:01:07 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-02-23 07:10:39 -05:00
|
|
|
describe Gitlab::Auth::Saml::User do
|
2017-09-25 13:07:45 -04:00
|
|
|
include LdapHelpers
|
2017-10-17 09:20:07 -04:00
|
|
|
include LoginHelpers
|
2017-09-25 13:07:45 -04:00
|
|
|
|
2016-02-18 17:01:07 -05:00
|
|
|
let(:saml_user) { described_class.new(auth_hash) }
|
|
|
|
let(:gl_user) { saml_user.gl_user }
|
|
|
|
let(:uid) { 'my-uid' }
|
2017-10-31 05:52:44 -04:00
|
|
|
let(:dn) { 'uid=user1,ou=people,dc=example' }
|
2016-02-18 17:01:07 -05:00
|
|
|
let(:provider) { 'saml' }
|
2017-10-17 09:20:07 -04:00
|
|
|
let(:raw_info_attr) { { 'groups' => %w(Developers Freelancers Designers) } }
|
|
|
|
let(:auth_hash) { OmniAuth::AuthHash.new(uid: uid, provider: provider, info: info_hash, extra: { raw_info: OneLogin::RubySaml::Attributes.new(raw_info_attr) }) }
|
2016-02-18 17:01:07 -05:00
|
|
|
let(:info_hash) do
|
|
|
|
{
|
|
|
|
name: 'John',
|
|
|
|
email: 'john@mail.com'
|
|
|
|
}
|
|
|
|
end
|
2018-02-23 07:10:39 -05:00
|
|
|
let(:ldap_user) { Gitlab::Auth::LDAP::Person.new(Net::LDAP::Entry.new, 'ldapmain') }
|
2016-02-18 17:01:07 -05:00
|
|
|
|
|
|
|
describe '#save' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
stub_basic_saml_config
|
|
|
|
end
|
2016-04-04 20:09:46 -04:00
|
|
|
|
2016-02-18 17:01:07 -05:00
|
|
|
describe 'account exists on server' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
stub_omniauth_config({ allow_single_sign_on: ['saml'], auto_link_saml_user: true })
|
|
|
|
end
|
|
|
|
|
2016-04-05 20:22:58 -04:00
|
|
|
let!(:existing_user) { create(:user, email: 'john@mail.com', username: 'john') }
|
2017-06-14 14:18:56 -04:00
|
|
|
|
2016-02-18 17:01:07 -05:00
|
|
|
context 'and should bind with SAML' do
|
|
|
|
it 'adds the SAML identity to the existing user' do
|
|
|
|
saml_user.save
|
|
|
|
expect(gl_user).to be_valid
|
|
|
|
expect(gl_user).to eq existing_user
|
|
|
|
identity = gl_user.identities.first
|
|
|
|
expect(identity.extern_uid).to eql uid
|
|
|
|
expect(identity.provider).to eql 'saml'
|
|
|
|
end
|
|
|
|
end
|
2016-04-05 20:22:58 -04:00
|
|
|
|
|
|
|
context 'external groups' do
|
|
|
|
context 'are defined' do
|
|
|
|
it 'marks the user as external' do
|
2016-04-06 19:12:25 -04:00
|
|
|
stub_saml_group_config(%w(Freelancers))
|
2016-04-05 20:22:58 -04:00
|
|
|
saml_user.save
|
2016-04-06 17:03:35 -04:00
|
|
|
expect(gl_user).to be_valid
|
2016-04-05 20:22:58 -04:00
|
|
|
expect(gl_user.external).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
stub_saml_group_config(%w(Interns))
|
|
|
|
end
|
|
|
|
|
2016-04-05 20:22:58 -04:00
|
|
|
context 'are defined but the user does not belong there' do
|
|
|
|
it 'does not mark the user as external' do
|
|
|
|
saml_user.save
|
2016-04-06 17:03:35 -04:00
|
|
|
expect(gl_user).to be_valid
|
2016-04-05 20:22:58 -04:00
|
|
|
expect(gl_user.external).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user was external, now should not be' do
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'makes user internal' do
|
2016-04-05 20:22:58 -04:00
|
|
|
existing_user.update_attribute('external', true)
|
|
|
|
saml_user.save
|
2016-04-06 17:03:35 -04:00
|
|
|
expect(gl_user).to be_valid
|
2016-04-05 20:22:58 -04:00
|
|
|
expect(gl_user.external).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-02-18 17:01:07 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'no account exists on server' do
|
|
|
|
shared_examples 'to verify compliance with allow_single_sign_on' do
|
|
|
|
context 'with allow_single_sign_on enabled' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
stub_omniauth_config(allow_single_sign_on: ['saml'])
|
|
|
|
end
|
2016-02-18 17:01:07 -05:00
|
|
|
|
|
|
|
it 'creates a user from SAML' do
|
|
|
|
saml_user.save
|
|
|
|
|
|
|
|
expect(gl_user).to be_valid
|
|
|
|
identity = gl_user.identities.first
|
|
|
|
expect(identity.extern_uid).to eql uid
|
|
|
|
expect(identity.provider).to eql 'saml'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with allow_single_sign_on default (["saml"])' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
stub_omniauth_config(allow_single_sign_on: ['saml'])
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not throw an error' do
|
2017-08-09 05:52:22 -04:00
|
|
|
expect { saml_user.save }.not_to raise_error
|
2016-02-18 17:01:07 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with allow_single_sign_on disabled' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
stub_omniauth_config(allow_single_sign_on: false)
|
|
|
|
end
|
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'throws an error' do
|
2017-08-09 05:52:22 -04:00
|
|
|
expect { saml_user.save }.to raise_error StandardError
|
2016-02-18 17:01:07 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-05 20:22:58 -04:00
|
|
|
context 'external groups' do
|
|
|
|
context 'are defined' do
|
|
|
|
it 'marks the user as external' do
|
2016-04-06 19:12:25 -04:00
|
|
|
stub_saml_group_config(%w(Freelancers))
|
2016-04-05 20:22:58 -04:00
|
|
|
saml_user.save
|
2016-04-06 17:03:35 -04:00
|
|
|
expect(gl_user).to be_valid
|
2016-04-05 20:22:58 -04:00
|
|
|
expect(gl_user.external).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'are defined but the user does not belong there' do
|
|
|
|
it 'does not mark the user as external' do
|
2016-04-06 19:12:25 -04:00
|
|
|
stub_saml_group_config(%w(Interns))
|
2016-04-05 20:22:58 -04:00
|
|
|
saml_user.save
|
2016-04-06 17:03:35 -04:00
|
|
|
expect(gl_user).to be_valid
|
2016-04-05 20:22:58 -04:00
|
|
|
expect(gl_user.external).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-18 17:01:07 -05:00
|
|
|
context 'with auto_link_ldap_user disabled (default)' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
stub_omniauth_config({ auto_link_ldap_user: false, auto_link_saml_user: false, allow_single_sign_on: ['saml'] })
|
|
|
|
end
|
|
|
|
|
2016-02-18 17:01:07 -05:00
|
|
|
include_examples 'to verify compliance with allow_single_sign_on'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with auto_link_ldap_user enabled' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
stub_omniauth_config({ auto_link_ldap_user: true, auto_link_saml_user: false })
|
|
|
|
end
|
2016-02-18 17:01:07 -05:00
|
|
|
|
|
|
|
context 'and at least one LDAP provider is defined' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
stub_ldap_config(providers: %w(ldapmain))
|
|
|
|
end
|
2016-02-18 17:01:07 -05:00
|
|
|
|
|
|
|
context 'and a corresponding LDAP person' do
|
2017-09-25 13:07:45 -04:00
|
|
|
let(:adapter) { ldap_adapter('ldapmain') }
|
|
|
|
|
2016-02-18 17:01:07 -05:00
|
|
|
before do
|
|
|
|
allow(ldap_user).to receive(:uid) { uid }
|
|
|
|
allow(ldap_user).to receive(:username) { uid }
|
2016-04-06 19:12:25 -04:00
|
|
|
allow(ldap_user).to receive(:email) { %w(john@mail.com john2@example.com) }
|
2017-09-25 13:07:45 -04:00
|
|
|
allow(ldap_user).to receive(:dn) { dn }
|
2018-02-23 07:10:39 -05:00
|
|
|
allow(Gitlab::Auth::LDAP::Adapter).to receive(:new).and_return(adapter)
|
|
|
|
allow(Gitlab::Auth::LDAP::Person).to receive(:find_by_uid).with(uid, adapter).and_return(ldap_user)
|
|
|
|
allow(Gitlab::Auth::LDAP::Person).to receive(:find_by_dn).with(dn, adapter).and_return(ldap_user)
|
|
|
|
allow(Gitlab::Auth::LDAP::Person).to receive(:find_by_email).with('john@mail.com', adapter).and_return(ldap_user)
|
2016-02-18 17:01:07 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'and no account for the LDAP user' do
|
|
|
|
it 'creates a user with dual LDAP and SAML identities' do
|
|
|
|
saml_user.save
|
|
|
|
|
|
|
|
expect(gl_user).to be_valid
|
|
|
|
expect(gl_user.username).to eql uid
|
2016-04-06 19:12:25 -04:00
|
|
|
expect(gl_user.email).to eql 'john@mail.com'
|
2017-02-23 10:04:34 -05:00
|
|
|
expect(gl_user.identities.length).to be 2
|
2016-02-18 17:01:07 -05:00
|
|
|
identities_as_hash = gl_user.identities.map { |id| { provider: id.provider, extern_uid: id.extern_uid } }
|
2017-09-25 13:07:45 -04:00
|
|
|
expect(identities_as_hash).to match_array([{ provider: 'ldapmain', extern_uid: dn },
|
2017-02-22 12:35:20 -05:00
|
|
|
{ provider: 'saml', extern_uid: uid }])
|
2016-02-18 17:01:07 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and LDAP user has an account already' do
|
2017-09-25 13:07:45 -04:00
|
|
|
let(:auth_hash_base_attributes) do
|
|
|
|
{
|
|
|
|
uid: uid,
|
|
|
|
provider: provider,
|
|
|
|
info: info_hash,
|
|
|
|
extra: {
|
|
|
|
raw_info: OneLogin::RubySaml::Attributes.new(
|
|
|
|
{ 'groups' => %w(Developers Freelancers Designers) }
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
let(:auth_hash) { OmniAuth::AuthHash.new(auth_hash_base_attributes) }
|
|
|
|
let(:uid_types) { %w(uid dn email) }
|
|
|
|
|
2016-06-16 16:11:09 -04:00
|
|
|
before do
|
|
|
|
create(:omniauth_user,
|
|
|
|
email: 'john@mail.com',
|
2017-09-25 13:07:45 -04:00
|
|
|
extern_uid: dn,
|
2016-06-16 16:11:09 -04:00
|
|
|
provider: 'ldapmain',
|
|
|
|
username: 'john')
|
|
|
|
end
|
|
|
|
|
2017-09-25 13:07:45 -04:00
|
|
|
shared_examples 'find LDAP person' do |uid_type, uid|
|
|
|
|
let(:auth_hash) { OmniAuth::AuthHash.new(auth_hash_base_attributes.merge(uid: extern_uid)) }
|
|
|
|
|
2017-09-12 05:50:28 -04:00
|
|
|
before do
|
2017-09-25 13:07:45 -04:00
|
|
|
nil_types = uid_types - [uid_type]
|
|
|
|
|
|
|
|
nil_types.each do |type|
|
2018-02-23 07:10:39 -05:00
|
|
|
allow(Gitlab::Auth::LDAP::Person).to receive(:"find_by_#{type}").and_return(nil)
|
2017-09-25 13:07:45 -04:00
|
|
|
end
|
|
|
|
|
2018-02-23 07:10:39 -05:00
|
|
|
allow(Gitlab::Auth::LDAP::Person).to receive(:"find_by_#{uid_type}").and_return(ldap_user)
|
2017-09-12 05:50:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds the omniauth identity to the LDAP account' do
|
|
|
|
identities = [
|
2017-09-25 13:07:45 -04:00
|
|
|
{ provider: 'ldapmain', extern_uid: dn },
|
2017-09-12 05:50:28 -04:00
|
|
|
{ provider: 'saml', extern_uid: extern_uid }
|
|
|
|
]
|
|
|
|
|
|
|
|
identities_as_hash = gl_user.identities.map do |id|
|
|
|
|
{ provider: id.provider, extern_uid: id.extern_uid }
|
|
|
|
end
|
|
|
|
|
|
|
|
saml_user.save
|
|
|
|
|
|
|
|
expect(gl_user).to be_valid
|
|
|
|
expect(gl_user.username).to eql 'john'
|
|
|
|
expect(gl_user.email).to eql 'john@mail.com'
|
|
|
|
expect(gl_user.identities.length).to be 2
|
|
|
|
expect(identities_as_hash).to match_array(identities)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when uid is an uid' do
|
2017-09-25 13:07:45 -04:00
|
|
|
it_behaves_like 'find LDAP person', 'uid' do
|
2017-09-12 05:50:28 -04:00
|
|
|
let(:extern_uid) { uid }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when uid is a dn' do
|
2017-09-25 13:07:45 -04:00
|
|
|
it_behaves_like 'find LDAP person', 'dn' do
|
|
|
|
let(:extern_uid) { dn }
|
2017-09-12 05:50:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when uid is an email' do
|
2017-09-25 13:07:45 -04:00
|
|
|
it_behaves_like 'find LDAP person', 'email' do
|
2017-09-12 05:50:28 -04:00
|
|
|
let(:extern_uid) { 'john@mail.com' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-06 19:12:25 -04:00
|
|
|
it 'adds the omniauth identity to the LDAP account' do
|
2016-02-18 17:01:07 -05:00
|
|
|
saml_user.save
|
|
|
|
|
|
|
|
expect(gl_user).to be_valid
|
|
|
|
expect(gl_user.username).to eql 'john'
|
2016-04-06 19:12:25 -04:00
|
|
|
expect(gl_user.email).to eql 'john@mail.com'
|
2017-02-23 10:04:34 -05:00
|
|
|
expect(gl_user.identities.length).to be 2
|
2016-02-18 17:01:07 -05:00
|
|
|
identities_as_hash = gl_user.identities.map { |id| { provider: id.provider, extern_uid: id.extern_uid } }
|
2017-09-25 13:07:45 -04:00
|
|
|
expect(identities_as_hash).to match_array([{ provider: 'ldapmain', extern_uid: dn },
|
2017-02-22 12:35:20 -05:00
|
|
|
{ provider: 'saml', extern_uid: uid }])
|
2016-02-18 17:01:07 -05:00
|
|
|
end
|
2016-06-16 16:11:09 -04:00
|
|
|
|
|
|
|
it 'saves successfully on subsequent tries, when both identities are present' do
|
|
|
|
saml_user.save
|
|
|
|
local_saml_user = described_class.new(auth_hash)
|
|
|
|
local_saml_user.save
|
|
|
|
|
|
|
|
expect(local_saml_user.gl_user).to be_valid
|
|
|
|
expect(local_saml_user.gl_user).to be_persisted
|
|
|
|
end
|
2016-02-18 17:01:07 -05:00
|
|
|
end
|
2016-06-06 19:47:49 -04:00
|
|
|
|
|
|
|
context 'user has SAML user, and wants to add their LDAP identity' do
|
|
|
|
it 'adds the LDAP identity to the existing SAML user' do
|
2017-09-25 13:07:45 -04:00
|
|
|
create(:omniauth_user, email: 'john@mail.com', extern_uid: dn, provider: 'saml', username: 'john')
|
|
|
|
|
2018-02-23 07:10:39 -05:00
|
|
|
allow(Gitlab::Auth::LDAP::Person).to receive(:find_by_uid).with(dn, adapter).and_return(ldap_user)
|
2017-09-25 13:07:45 -04:00
|
|
|
|
|
|
|
local_hash = OmniAuth::AuthHash.new(uid: dn, provider: provider, info: info_hash)
|
2016-06-06 19:47:49 -04:00
|
|
|
local_saml_user = described_class.new(local_hash)
|
2017-09-25 13:07:45 -04:00
|
|
|
|
2016-06-06 19:47:49 -04:00
|
|
|
local_saml_user.save
|
|
|
|
local_gl_user = local_saml_user.gl_user
|
2016-06-08 19:09:43 -04:00
|
|
|
|
2016-06-06 19:47:49 -04:00
|
|
|
expect(local_gl_user).to be_valid
|
2017-02-23 10:04:34 -05:00
|
|
|
expect(local_gl_user.identities.length).to be 2
|
2016-06-06 19:47:49 -04:00
|
|
|
identities_as_hash = local_gl_user.identities.map { |id| { provider: id.provider, extern_uid: id.extern_uid } }
|
2017-09-25 13:07:45 -04:00
|
|
|
expect(identities_as_hash).to match_array([{ provider: 'ldapmain', extern_uid: dn },
|
|
|
|
{ provider: 'saml', extern_uid: dn }])
|
2016-06-06 19:47:49 -04:00
|
|
|
end
|
|
|
|
end
|
2016-02-18 17:01:07 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-24 17:12:14 -04:00
|
|
|
|
|
|
|
context 'when signup is disabled' do
|
|
|
|
before do
|
|
|
|
stub_application_setting signup_enabled: false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates the user' do
|
|
|
|
saml_user.save
|
|
|
|
|
|
|
|
expect(gl_user).to be_persisted
|
|
|
|
end
|
|
|
|
end
|
2017-04-25 15:51:36 -04:00
|
|
|
|
|
|
|
context 'when user confirmation email is enabled' do
|
|
|
|
before do
|
|
|
|
stub_application_setting send_user_confirmation_email: true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates and confirms the user anyway' do
|
|
|
|
saml_user.save
|
|
|
|
|
|
|
|
expect(gl_user).to be_persisted
|
|
|
|
expect(gl_user).to be_confirmed
|
|
|
|
end
|
|
|
|
end
|
2016-02-18 17:01:07 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'blocking' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
stub_omniauth_config({ allow_single_sign_on: ['saml'], auto_link_saml_user: true })
|
|
|
|
end
|
2016-02-18 17:01:07 -05:00
|
|
|
|
|
|
|
context 'signup with SAML only' do
|
|
|
|
context 'dont block on create' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
stub_omniauth_config(block_auto_created_users: false)
|
|
|
|
end
|
2016-02-18 17:01:07 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'does not block the user' do
|
2016-02-18 17:01:07 -05:00
|
|
|
saml_user.save
|
|
|
|
expect(gl_user).to be_valid
|
|
|
|
expect(gl_user).not_to be_blocked
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'block on create' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
stub_omniauth_config(block_auto_created_users: true)
|
|
|
|
end
|
2016-02-18 17:01:07 -05:00
|
|
|
|
2016-08-01 11:00:44 -04:00
|
|
|
it 'blocks user' do
|
2016-02-18 17:01:07 -05:00
|
|
|
saml_user.save
|
|
|
|
expect(gl_user).to be_valid
|
|
|
|
expect(gl_user).to be_blocked
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'sign-in' do
|
|
|
|
before do
|
|
|
|
saml_user.save
|
|
|
|
saml_user.gl_user.activate
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'dont block on create' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
stub_omniauth_config(block_auto_created_users: false)
|
|
|
|
end
|
2016-02-18 17:01:07 -05:00
|
|
|
|
|
|
|
it do
|
|
|
|
saml_user.save
|
|
|
|
expect(gl_user).to be_valid
|
|
|
|
expect(gl_user).not_to be_blocked
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'block on create' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
|
|
|
stub_omniauth_config(block_auto_created_users: true)
|
|
|
|
end
|
2016-02-18 17:01:07 -05:00
|
|
|
|
|
|
|
it do
|
|
|
|
saml_user.save
|
|
|
|
expect(gl_user).to be_valid
|
|
|
|
expect(gl_user).not_to be_blocked
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-10-17 09:20:07 -04:00
|
|
|
|
|
|
|
describe '#find_user' do
|
|
|
|
context 'raw info hash attributes empty' do
|
|
|
|
let(:raw_info_attr) { {} }
|
|
|
|
|
|
|
|
it 'does not mark user as external' do
|
|
|
|
stub_saml_group_config(%w(Freelancers))
|
|
|
|
|
|
|
|
expect(saml_user.find_user.external).to be_falsy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-06-25 11:32:03 -04:00
|
|
|
|
|
|
|
describe '#bypass_two_factor?' do
|
|
|
|
let(:saml_config) { mock_saml_config_with_upstream_two_factor_authn_contexts }
|
|
|
|
|
|
|
|
subject { saml_user.bypass_two_factor? }
|
|
|
|
|
|
|
|
context 'with authn_contexts_worth_two_factors configured' do
|
|
|
|
before do
|
|
|
|
stub_omniauth_saml_config(enabled: true, auto_link_saml_user: true, allow_single_sign_on: ['saml'], providers: [saml_config])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when authn_context is worth two factors' do
|
|
|
|
allow(saml_user.auth_hash).to receive(:authn_context).and_return('urn:oasis:names:tc:SAML:2.0:ac:classes:SecondFactorOTPSMS')
|
|
|
|
is_expected.to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when authn_context is not worth two factors' do
|
|
|
|
allow(saml_user.auth_hash).to receive(:authn_context).and_return('urn:oasis:names:tc:SAML:2.0:ac:classes:Password')
|
|
|
|
is_expected.to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when authn_context is blank' do
|
|
|
|
is_expected.to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without auth_contexts_worth_two_factors_configured' do
|
|
|
|
before do
|
|
|
|
stub_omniauth_saml_config(enabled: true, auto_link_saml_user: true, allow_single_sign_on: ['saml'], providers: [mock_saml_config])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when authn_context is present' do
|
|
|
|
allow(saml_user.auth_hash).to receive(:authn_context).and_return('urn:oasis:names:tc:SAML:2.0:ac:classes:SecondFactorOTPSMS')
|
|
|
|
is_expected.to be_falsey
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when authn_context is blank' do
|
|
|
|
is_expected.to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-02-18 17:01:07 -05:00
|
|
|
end
|