PageRenderTime 31ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/helpers/auth_helper_spec.rb

https://bitbucket.org/terrchen/gitlab-ce
Ruby | 103 lines | 93 code | 10 blank | 0 comment | 0 complexity | 8cac9527a63f2e8270a36eaf2033804e MD5 | raw file
Possible License(s): Apache-2.0, CC0-1.0
  1. require "spec_helper"
  2. describe AuthHelper do
  3. describe "button_based_providers" do
  4. it 'returns all enabled providers from devise' do
  5. allow(helper).to receive(:auth_providers) { [:twitter, :github] }
  6. expect(helper.button_based_providers).to include(*[:twitter, :github])
  7. end
  8. it 'does not return ldap provider' do
  9. allow(helper).to receive(:auth_providers) { [:twitter, :ldapmain] }
  10. expect(helper.button_based_providers).to include(:twitter)
  11. end
  12. it 'returns empty array' do
  13. allow(helper).to receive(:auth_providers) { [] }
  14. expect(helper.button_based_providers).to eq([])
  15. end
  16. end
  17. describe "providers_for_base_controller" do
  18. it 'returns all enabled providers from devise' do
  19. allow(helper).to receive(:auth_providers) { [:twitter, :github] }
  20. expect(helper.providers_for_base_controller).to include(*[:twitter, :github])
  21. end
  22. it 'excludes ldap providers' do
  23. allow(helper).to receive(:auth_providers) { [:twitter, :ldapmain] }
  24. expect(helper.providers_for_base_controller).not_to include(:ldapmain)
  25. end
  26. end
  27. describe "form_based_providers" do
  28. it 'includes LDAP providers' do
  29. allow(helper).to receive(:auth_providers) { [:twitter, :ldapmain] }
  30. expect(helper.form_based_providers).to eq %i(ldapmain)
  31. end
  32. it 'includes crowd provider' do
  33. allow(helper).to receive(:auth_providers) { [:twitter, :crowd] }
  34. expect(helper.form_based_providers).to eq %i(crowd)
  35. end
  36. end
  37. describe 'enabled_button_based_providers' do
  38. before do
  39. allow(helper).to receive(:auth_providers) { [:twitter, :github] }
  40. end
  41. context 'all providers are enabled to sign in' do
  42. it 'returns all the enabled providers from settings' do
  43. expect(helper.enabled_button_based_providers).to include('twitter', 'github')
  44. end
  45. end
  46. context 'GitHub OAuth sign in is disabled from application setting' do
  47. it "doesn't return github as provider" do
  48. stub_application_setting(
  49. disabled_oauth_sign_in_sources: ['github']
  50. )
  51. expect(helper.enabled_button_based_providers).to include('twitter')
  52. expect(helper.enabled_button_based_providers).not_to include('github')
  53. end
  54. end
  55. end
  56. describe 'button_based_providers_enabled?' do
  57. before do
  58. allow(helper).to receive(:auth_providers) { [:twitter, :github] }
  59. end
  60. context 'button based providers enabled' do
  61. it 'returns true' do
  62. expect(helper.button_based_providers_enabled?).to be true
  63. end
  64. end
  65. context 'all the button based providers are disabled via application_setting' do
  66. it 'returns false' do
  67. stub_application_setting(
  68. disabled_oauth_sign_in_sources: %w(github twitter)
  69. )
  70. expect(helper.button_based_providers_enabled?).to be false
  71. end
  72. end
  73. end
  74. describe 'unlink_allowed?' do
  75. [:saml, :cas3].each do |provider|
  76. it "returns true if the provider is #{provider}" do
  77. expect(helper.unlink_allowed?(provider)).to be false
  78. end
  79. end
  80. [:twitter, :facebook, :google_oauth2, :gitlab, :github, :bitbucket, :crowd, :auth0, :authentiq].each do |provider|
  81. it "returns false if the provider is #{provider}" do
  82. expect(helper.unlink_allowed?(provider)).to be true
  83. end
  84. end
  85. end
  86. end