diff options
author | James Edwards-Jones <jedwardsjones@gitlab.com> | 2018-04-18 15:03:27 +0100 |
---|---|---|
committer | James Edwards-Jones <jedwardsjones@gitlab.com> | 2018-04-22 23:50:55 +0100 |
commit | f10c999bca2b5b37b068ff3680a6e35a6707828d (patch) | |
tree | a517f86544c1544ee25d174652a003fff9b199a0 /spec/lib/gitlab/auth | |
parent | c212908aad9b32352653dfe9ca966f148c8dfc1a (diff) | |
download | gitlab-ce-f10c999bca2b5b37b068ff3680a6e35a6707828d.tar.gz |
Refactor OmniauthCallbacksController to remove duplication
Moves LDAP to its own controller with tests
Provides path forward for implementing GroupSaml
Diffstat (limited to 'spec/lib/gitlab/auth')
-rw-r--r-- | spec/lib/gitlab/auth/o_auth/identity_linker_spec.rb | 42 | ||||
-rw-r--r-- | spec/lib/gitlab/auth/saml/identity_linker_spec.rb | 48 |
2 files changed, 90 insertions, 0 deletions
diff --git a/spec/lib/gitlab/auth/o_auth/identity_linker_spec.rb b/spec/lib/gitlab/auth/o_auth/identity_linker_spec.rb new file mode 100644 index 00000000000..dc6aa5de53a --- /dev/null +++ b/spec/lib/gitlab/auth/o_auth/identity_linker_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' + +describe Gitlab::Auth::OAuth::IdentityLinker do + let(:user) { create(:user) } + let(:provider) { 'twitter' } + let(:uid) { user.email } + let(:oauth) { { 'provider' => provider, 'uid' => uid } } + + subject { described_class.new(user, oauth) } + + context 'linked identity exists' do + let!(:identity) { user.identities.create!(provider: provider, extern_uid: uid) } + + it "doesn't create new identity" do + expect { subject.create_or_update }.not_to change { Identity.count } + end + end + + context 'identity needs to be created' do + it 'creates linked identity' do + expect { subject.create_or_update }.to change { user.identities.count } + end + + it 'sets identity provider' do + subject.create_or_update + + expect(user.identities.last.provider).to eq provider + end + + it 'sets identity extern_uid' do + subject.create_or_update + + expect(user.identities.last.extern_uid).to eq uid + end + + it 'sets #created? to true' do + subject.create_or_update + + expect(subject).to be_created + end + end +end diff --git a/spec/lib/gitlab/auth/saml/identity_linker_spec.rb b/spec/lib/gitlab/auth/saml/identity_linker_spec.rb new file mode 100644 index 00000000000..11e8469e9f4 --- /dev/null +++ b/spec/lib/gitlab/auth/saml/identity_linker_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe Gitlab::Auth::Saml::IdentityLinker do + let(:user) { create(:user) } + let(:provider) { 'saml' } + let(:uid) { user.email } + let(:oauth) { { 'provider' => provider, 'uid' => uid } } + + subject { described_class.new(user, oauth) } + + context 'linked identity exists' do + let!(:identity) { user.identities.create!(provider: provider, extern_uid: uid) } + + it "doesn't create new identity" do + expect { subject.create_or_update }.not_to change { Identity.count } + end + + it 'sets #created? to false' do + subject.create_or_update + + expect(subject).not_to be_created + end + end + + context 'identity needs to be created' do + it 'creates linked identity' do + expect { subject.create_or_update }.to change { user.identities.count } + end + + it 'sets identity provider' do + subject.create_or_update + + expect(user.identities.last.provider).to eq provider + end + + it 'sets identity extern_uid' do + subject.create_or_update + + expect(user.identities.last.extern_uid).to eq uid + end + + it 'sets #created? to true' do + subject.create_or_update + + expect(subject).to be_created + end + end +end |