PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/features/admin/admin_settings_spec.rb

https://gitlab.com/tbeadle/gitlab-ce
Ruby | 336 lines | 266 code | 67 blank | 3 comment | 0 complexity | a2e50f34bbc0a990c770df419513ee99 MD5 | raw file
  1. require 'spec_helper'
  2. describe 'Admin updates settings' do
  3. include StubENV
  4. include TermsHelper
  5. let(:admin) { create(:admin) }
  6. before do
  7. stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
  8. sign_in(admin)
  9. visit admin_application_settings_path
  10. end
  11. it 'Change visibility settings' do
  12. page.within('.as-visibility-access') do
  13. choose "application_setting_default_project_visibility_20"
  14. click_button 'Save changes'
  15. end
  16. expect(page).to have_content "Application settings saved successfully"
  17. end
  18. it 'Uncheck all restricted visibility levels' do
  19. page.within('.as-visibility-access') do
  20. find('#application_setting_visibility_level_0').set(false)
  21. find('#application_setting_visibility_level_10').set(false)
  22. find('#application_setting_visibility_level_20').set(false)
  23. click_button 'Save changes'
  24. end
  25. expect(page).to have_content "Application settings saved successfully"
  26. expect(find('#application_setting_visibility_level_0')).not_to be_checked
  27. expect(find('#application_setting_visibility_level_10')).not_to be_checked
  28. expect(find('#application_setting_visibility_level_20')).not_to be_checked
  29. end
  30. it 'Modify import sources' do
  31. expect(Gitlab::CurrentSettings.import_sources).not_to be_empty
  32. page.within('.as-visibility-access') do
  33. Gitlab::ImportSources.options.map do |name, _|
  34. uncheck name
  35. end
  36. click_button 'Save changes'
  37. end
  38. expect(page).to have_content "Application settings saved successfully"
  39. expect(Gitlab::CurrentSettings.import_sources).to be_empty
  40. page.within('.as-visibility-access') do
  41. check "Repo by URL"
  42. click_button 'Save changes'
  43. end
  44. expect(page).to have_content "Application settings saved successfully"
  45. expect(Gitlab::CurrentSettings.import_sources).to eq(['git'])
  46. end
  47. it 'Change Visibility and Access Controls' do
  48. page.within('.as-visibility-access') do
  49. uncheck 'Project export enabled'
  50. click_button 'Save changes'
  51. end
  52. expect(Gitlab::CurrentSettings.project_export_enabled).to be_falsey
  53. expect(page).to have_content "Application settings saved successfully"
  54. end
  55. it 'Change Account and Limit Settings' do
  56. page.within('.as-account-limit') do
  57. uncheck 'Gravatar enabled'
  58. click_button 'Save changes'
  59. end
  60. expect(Gitlab::CurrentSettings.gravatar_enabled).to be_falsey
  61. expect(page).to have_content "Application settings saved successfully"
  62. end
  63. it 'Change Sign-in restrictions' do
  64. page.within('.as-signin') do
  65. fill_in 'Home page URL', with: 'https://about.gitlab.com/'
  66. click_button 'Save changes'
  67. end
  68. expect(Gitlab::CurrentSettings.home_page_url).to eq "https://about.gitlab.com/"
  69. expect(page).to have_content "Application settings saved successfully"
  70. end
  71. it 'Terms of Service' do
  72. # Already have the admin accept terms, so they don't need to accept in this spec.
  73. _existing_terms = create(:term)
  74. accept_terms(admin)
  75. page.within('.as-terms') do
  76. check 'Require all users to accept Terms of Service and Privacy Policy when they access GitLab.'
  77. fill_in 'Terms of Service Agreement', with: 'Be nice!'
  78. click_button 'Save changes'
  79. end
  80. expect(Gitlab::CurrentSettings.enforce_terms).to be(true)
  81. expect(Gitlab::CurrentSettings.terms).to eq 'Be nice!'
  82. expect(page).to have_content 'Application settings saved successfully'
  83. end
  84. it 'Modify oauth providers' do
  85. expect(Gitlab::CurrentSettings.disabled_oauth_sign_in_sources).to be_empty
  86. page.within('.as-signin') do
  87. uncheck 'Google'
  88. click_button 'Save changes'
  89. end
  90. expect(page).to have_content "Application settings saved successfully"
  91. expect(Gitlab::CurrentSettings.disabled_oauth_sign_in_sources).to include('google_oauth2')
  92. page.within('.as-signin') do
  93. check "Google"
  94. click_button 'Save changes'
  95. end
  96. expect(page).to have_content "Application settings saved successfully"
  97. expect(Gitlab::CurrentSettings.disabled_oauth_sign_in_sources).not_to include('google_oauth2')
  98. end
  99. it 'Oauth providers do not raise validation errors when saving unrelated changes' do
  100. expect(Gitlab::CurrentSettings.disabled_oauth_sign_in_sources).to be_empty
  101. page.within('.as-signin') do
  102. uncheck 'Google'
  103. click_button 'Save changes'
  104. end
  105. expect(page).to have_content "Application settings saved successfully"
  106. expect(Gitlab::CurrentSettings.disabled_oauth_sign_in_sources).to include('google_oauth2')
  107. # Remove google_oauth2 from the Omniauth strategies
  108. allow(Devise).to receive(:omniauth_providers).and_return([])
  109. # Save an unrelated setting
  110. page.within('.as-ci-cd') do
  111. click_button 'Save changes'
  112. end
  113. expect(page).to have_content "Application settings saved successfully"
  114. expect(Gitlab::CurrentSettings.disabled_oauth_sign_in_sources).to include('google_oauth2')
  115. end
  116. it 'Change Help page' do
  117. page.within('.as-help-page') do
  118. fill_in 'Help page text', with: 'Example text'
  119. check 'Hide marketing-related entries from help'
  120. fill_in 'Support page URL', with: 'http://example.com/help'
  121. click_button 'Save changes'
  122. end
  123. expect(Gitlab::CurrentSettings.help_page_text).to eq "Example text"
  124. expect(Gitlab::CurrentSettings.help_page_hide_commercial_content).to be_truthy
  125. expect(Gitlab::CurrentSettings.help_page_support_url).to eq "http://example.com/help"
  126. expect(page).to have_content "Application settings saved successfully"
  127. end
  128. it 'Change Pages settings' do
  129. page.within('.as-pages') do
  130. fill_in 'Maximum size of pages (MB)', with: 15
  131. check 'Require users to prove ownership of custom domains'
  132. click_button 'Save changes'
  133. end
  134. expect(Gitlab::CurrentSettings.max_pages_size).to eq 15
  135. expect(Gitlab::CurrentSettings.pages_domain_verification_enabled?).to be_truthy
  136. expect(page).to have_content "Application settings saved successfully"
  137. end
  138. it 'Change CI/CD settings' do
  139. page.within('.as-ci-cd') do
  140. check 'Enabled Auto DevOps for projects by default'
  141. fill_in 'Auto devops domain', with: 'domain.com'
  142. click_button 'Save changes'
  143. end
  144. expect(Gitlab::CurrentSettings.auto_devops_enabled?).to be true
  145. expect(Gitlab::CurrentSettings.auto_devops_domain).to eq('domain.com')
  146. expect(page).to have_content "Application settings saved successfully"
  147. end
  148. it 'Change Influx settings' do
  149. page.within('.as-influx') do
  150. check 'Enable InfluxDB Metrics'
  151. click_button 'Save changes'
  152. end
  153. expect(Gitlab::CurrentSettings.metrics_enabled?).to be true
  154. expect(page).to have_content "Application settings saved successfully"
  155. end
  156. it 'Change Prometheus settings' do
  157. page.within('.as-prometheus') do
  158. check 'Enable Prometheus Metrics'
  159. click_button 'Save changes'
  160. end
  161. expect(Gitlab::CurrentSettings.prometheus_metrics_enabled?).to be true
  162. expect(page).to have_content "Application settings saved successfully"
  163. end
  164. it 'Change Performance bar settings' do
  165. group = create(:group)
  166. page.within('.as-performance-bar') do
  167. check 'Enable the Performance Bar'
  168. fill_in 'Allowed group', with: group.path
  169. click_on 'Save changes'
  170. end
  171. expect(page).to have_content "Application settings saved successfully"
  172. expect(find_field('Enable the Performance Bar')).to be_checked
  173. expect(find_field('Allowed group').value).to eq group.path
  174. page.within('.as-performance-bar') do
  175. uncheck 'Enable the Performance Bar'
  176. click_on 'Save changes'
  177. end
  178. expect(page).to have_content 'Application settings saved successfully'
  179. expect(find_field('Enable the Performance Bar')).not_to be_checked
  180. expect(find_field('Allowed group').value).to be_nil
  181. end
  182. it 'Change Background jobs settings' do
  183. page.within('.as-background') do
  184. fill_in 'Throttling Factor', with: 1
  185. click_button 'Save changes'
  186. end
  187. expect(Gitlab::CurrentSettings.sidekiq_throttling_factor).to eq(1)
  188. expect(page).to have_content "Application settings saved successfully"
  189. end
  190. it 'Change Spam settings' do
  191. page.within('.as-spam') do
  192. check 'Enable reCAPTCHA'
  193. fill_in 'reCAPTCHA Site Key', with: 'key'
  194. fill_in 'reCAPTCHA Private Key', with: 'key'
  195. fill_in 'IPs per user', with: 15
  196. click_button 'Save changes'
  197. end
  198. expect(page).to have_content "Application settings saved successfully"
  199. expect(Gitlab::CurrentSettings.recaptcha_enabled).to be true
  200. expect(Gitlab::CurrentSettings.unique_ips_limit_per_user).to eq(15)
  201. end
  202. it 'Configure web terminal' do
  203. page.within('.as-terminal') do
  204. fill_in 'Max session time', with: 15
  205. click_button 'Save changes'
  206. end
  207. expect(page).to have_content "Application settings saved successfully"
  208. expect(Gitlab::CurrentSettings.terminal_max_session_time).to eq(15)
  209. end
  210. it 'Enable outbound requests' do
  211. page.within('.as-outbound') do
  212. check 'Allow requests to the local network from hooks and services'
  213. click_button 'Save changes'
  214. end
  215. expect(page).to have_content "Application settings saved successfully"
  216. expect(Gitlab::CurrentSettings.allow_local_requests_from_hooks_and_services).to be true
  217. end
  218. it 'Enable hiding third party offers' do
  219. page.within('.as-third-party-offers') do
  220. check 'Do not display offers from third parties within GitLab'
  221. click_button 'Save changes'
  222. end
  223. expect(page).to have_content "Application settings saved successfully"
  224. expect(Gitlab::CurrentSettings.hide_third_party_offers).to be true
  225. end
  226. it 'Change Slack Notifications Service template settings' do
  227. first(:link, 'Service Templates').click
  228. click_link 'Slack notifications'
  229. fill_in 'Webhook', with: 'http://localhost'
  230. fill_in 'Username', with: 'test_user'
  231. fill_in 'service_push_channel', with: '#test_channel'
  232. page.check('Notify only broken pipelines')
  233. page.check('Notify only default branch')
  234. check_all_events
  235. click_on 'Save'
  236. expect(page).to have_content 'Application settings saved successfully'
  237. click_link 'Slack notifications'
  238. page.all('input[type=checkbox]').each do |checkbox|
  239. expect(checkbox).to be_checked
  240. end
  241. expect(find_field('Webhook').value).to eq 'http://localhost'
  242. expect(find_field('Username').value).to eq 'test_user'
  243. expect(find('#service_push_channel').value).to eq '#test_channel'
  244. end
  245. it 'Change Keys settings' do
  246. page.within('.as-visibility-access') do
  247. select 'Are forbidden', from: 'RSA SSH keys'
  248. select 'Are allowed', from: 'DSA SSH keys'
  249. select 'Must be at least 384 bits', from: 'ECDSA SSH keys'
  250. select 'Are forbidden', from: 'ED25519 SSH keys'
  251. click_on 'Save changes'
  252. end
  253. forbidden = ApplicationSetting::FORBIDDEN_KEY_VALUE.to_s
  254. expect(page).to have_content 'Application settings saved successfully'
  255. expect(find_field('RSA SSH keys').value).to eq(forbidden)
  256. expect(find_field('DSA SSH keys').value).to eq('0')
  257. expect(find_field('ECDSA SSH keys').value).to eq('384')
  258. expect(find_field('ED25519 SSH keys').value).to eq(forbidden)
  259. end
  260. def check_all_events
  261. page.check('Active')
  262. page.check('Push')
  263. page.check('Tag push')
  264. page.check('Note')
  265. page.check('Issue')
  266. page.check('Merge request')
  267. page.check('Pipeline')
  268. end
  269. end