BigW Consortium Gitlab

auth_helper_spec.rb 2.42 KB
Newer Older
1 2 3 4
require "spec_helper"

describe AuthHelper do
  describe "button_based_providers" do
5
    it 'returns all enabled providers from devise' do
6 7 8 9 10 11 12 13 14 15 16 17 18
      allow(helper).to receive(:auth_providers) { [:twitter, :github] }
      expect(helper.button_based_providers).to include(*[:twitter, :github])
    end

    it 'does not return ldap provider' do
      allow(helper).to receive(:auth_providers) { [:twitter, :ldapmain] }
      expect(helper.button_based_providers).to include(:twitter)
    end

    it 'returns empty array' do
      allow(helper).to receive(:auth_providers) { [] }
      expect(helper.button_based_providers).to eq([])
    end
19
  end
20

21
  describe 'enabled_button_based_providers' do
22
    before do
23
      allow(helper).to receive(:auth_providers) { [:twitter, :github] }
24 25
    end

26 27 28 29
    context 'all providers are enabled to sign in' do
      it 'returns all the enabled providers from settings' do
        expect(helper.enabled_button_based_providers).to include('twitter', 'github')
      end
30 31
    end

32 33 34 35 36
    context 'GitHub OAuth sign in is disabled from application setting' do
      it "doesn't return github as provider" do
        stub_application_setting(
          disabled_oauth_sign_in_sources: ['github']
        )
37

38
        expect(helper.enabled_button_based_providers).to include('twitter')
39
        expect(helper.enabled_button_based_providers).not_to include('github')
40 41 42 43 44 45 46
      end
    end
  end

  describe 'button_based_providers_enabled?' do
    before do
      allow(helper).to receive(:auth_providers) { [:twitter, :github] }
47
    end
48

49 50 51 52
    context 'button based providers enabled' do
      it 'returns true' do
        expect(helper.button_based_providers_enabled?).to be true
      end
53 54
    end

55 56 57
    context 'all the button based providers are disabled via application_setting' do
      it 'returns false' do
        stub_application_setting(
Douwe Maan committed
58
          disabled_oauth_sign_in_sources: %w(github twitter)
59
        )
60

61 62
        expect(helper.button_based_providers_enabled?).to be false
      end
63
    end
64
  end
65 66 67 68 69 70 71 72 73 74 75 76 77 78

  describe 'unlink_allowed?' do
    [:saml, :cas3].each do |provider|
      it "returns true if the provider is #{provider}" do
        expect(helper.unlink_allowed?(provider)).to be false
      end
    end

    [:twitter, :facebook, :google_oauth2, :gitlab, :github, :bitbucket, :crowd, :auth0].each do |provider|
      it "returns false if the provider is #{provider}" do
        expect(helper.unlink_allowed?(provider)).to be true
      end
    end
  end
79
end