security_spec.rb 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Manage > Settings > Security', type: :system do
  4. describe 'configure third-party applications' do
  5. shared_examples 'for third-party applications button in login page' do
  6. context 'for third-party applications button in login page', authenticated_as: false do
  7. context 'when feature is on' do
  8. before { Setting.set(app_setting, true) }
  9. it 'has authentication button in login page' do
  10. visit 'login'
  11. expect(page).to have_button(app_name)
  12. end
  13. end
  14. context 'when feature is off' do
  15. before { Setting.set(app_setting, false) }
  16. it 'does not have authentication button in login page' do
  17. visit 'login'
  18. expect(page).to have_no_button(app_name)
  19. end
  20. end
  21. end
  22. end
  23. shared_examples 'for third-party applications settings' do
  24. context 'for third-party applications settings', authenticated_as: true do
  25. let(:app_checkbox) { "setting-#{app_setting}" }
  26. context 'when app is turned on in setting page' do
  27. before do
  28. Setting.set(app_setting, false)
  29. visit '/#settings/security'
  30. within :active_content do
  31. click 'a[href="#third_party_auth"]'
  32. end
  33. check app_checkbox, allow_label_click: true
  34. await_empty_ajax_queue
  35. end
  36. it 'sets settings to be true' do
  37. expect(Setting.get(app_setting)).to be_truthy
  38. end
  39. end
  40. context 'when app is turned off in setting page' do
  41. before do
  42. Setting.set(app_setting, true)
  43. visit '/#settings/security'
  44. within :active_content do
  45. click 'a[href="#third_party_auth"]'
  46. end
  47. uncheck app_checkbox, allow_label_click: true
  48. await_empty_ajax_queue
  49. end
  50. it 'sets settings to be false' do
  51. expect(Setting.get(app_setting)).to be_falsey
  52. end
  53. end
  54. end
  55. end
  56. shared_examples 'Display callback urls for third-party applications #3622' do
  57. def callback_url
  58. page.evaluate_script("$('[data-name=#{app_setting}]').closest('.page-header').parent().find('[data-attribute-name=callback_url] input').val()")
  59. end
  60. context 'Display callback urls for third-party applications #3622', authenticated_as: true do
  61. before do
  62. visit '/#settings/security'
  63. within :active_content do
  64. click 'a[href="#third_party_auth"]'
  65. end
  66. end
  67. it 'does have a filled callback url' do
  68. expect(callback_url).to be_present
  69. end
  70. end
  71. end
  72. describe 'Authentication via Facebook' do
  73. let(:app_name) { 'Facebook' }
  74. let(:app_setting) { 'auth_facebook' }
  75. include_examples 'for third-party applications button in login page'
  76. include_examples 'for third-party applications settings'
  77. include_examples 'Display callback urls for third-party applications #3622'
  78. end
  79. describe 'Authentication via Github' do
  80. let(:app_name) { 'GitHub' }
  81. let(:app_setting) { 'auth_github' }
  82. include_examples 'for third-party applications button in login page'
  83. include_examples 'for third-party applications settings'
  84. include_examples 'Display callback urls for third-party applications #3622'
  85. end
  86. describe 'Authentication via GitLab' do
  87. let(:app_name) { 'GitLab' }
  88. let(:app_setting) { 'auth_gitlab' }
  89. include_examples 'for third-party applications button in login page'
  90. include_examples 'for third-party applications settings'
  91. include_examples 'Display callback urls for third-party applications #3622'
  92. end
  93. describe 'Authentication via Google' do
  94. let(:app_name) { 'Google' }
  95. let(:app_setting) { 'auth_google_oauth2' }
  96. include_examples 'for third-party applications button in login page'
  97. include_examples 'for third-party applications settings'
  98. include_examples 'Display callback urls for third-party applications #3622'
  99. end
  100. describe 'Authentication via LinkedIn' do
  101. let(:app_name) { 'LinkedIn' }
  102. let(:app_setting) { 'auth_linkedin' }
  103. include_examples 'for third-party applications button in login page'
  104. include_examples 'for third-party applications settings'
  105. include_examples 'Display callback urls for third-party applications #3622'
  106. end
  107. describe 'Authentication via Microsoft' do
  108. let(:app_name) { 'Microsoft' }
  109. let(:app_setting) { 'auth_microsoft_office365' }
  110. include_examples 'for third-party applications button in login page'
  111. include_examples 'for third-party applications settings'
  112. include_examples 'Display callback urls for third-party applications #3622'
  113. end
  114. describe 'Authentication via SAML' do
  115. let(:app_name) { 'SAML' }
  116. let(:app_setting) { 'auth_saml' }
  117. include_examples 'for third-party applications button in login page'
  118. include_examples 'for third-party applications settings'
  119. include_examples 'Display callback urls for third-party applications #3622'
  120. end
  121. describe 'Authentication via SSO' do
  122. let(:app_name) { 'SSO' }
  123. let(:app_setting) { 'auth_sso' }
  124. include_examples 'for third-party applications button in login page'
  125. include_examples 'for third-party applications settings'
  126. end
  127. describe 'Authentication via Twitter' do
  128. let(:app_name) { 'Twitter' }
  129. let(:app_setting) { 'auth_twitter' }
  130. include_examples 'for third-party applications button in login page'
  131. include_examples 'for third-party applications settings'
  132. include_examples 'Display callback urls for third-party applications #3622'
  133. end
  134. describe 'Authentication via Weibo' do
  135. let(:app_name) { 'Weibo' }
  136. let(:app_setting) { 'auth_weibo' }
  137. include_examples 'for third-party applications button in login page'
  138. include_examples 'for third-party applications settings'
  139. include_examples 'Display callback urls for third-party applications #3622'
  140. end
  141. end
  142. end