proxy_spec.rb 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Manage > Settings > System > Network', required_envs: %w[CI_PROXY_URL CI_PROXY_USER CI_PROXY_PASSWORD], type: :system do
  4. before { visit 'settings/system' }
  5. let(:proxy) { ENV['CI_PROXY_URL'] }
  6. let(:proxy_username) { ENV['CI_PROXY_USER'] }
  7. let(:proxy_password) { ENV['CI_PROXY_PASSWORD'] }
  8. describe 'configure proxy setting' do
  9. it 'test proxy settings with correct config' do
  10. within(:active_content) do
  11. click(:href, '#network')
  12. fill_in 'proxy', with: proxy
  13. fill_in 'proxy_username', with: proxy_username
  14. fill_in 'proxy_password', with: proxy_password
  15. click_on 'Test Connection'
  16. expect(page).to have_button('Test Connection', visible: :hidden)
  17. expect(page).to have_button('Submit', visible: :visible)
  18. find('.js-submit:not(.hide)').click
  19. expect(page).to have_button('Submit', visible: :hidden)
  20. expect(page).to have_button('Test Connection', visible: :visible)
  21. end
  22. end
  23. context 'test proxy settings when invalid config is used' do
  24. it 'with invalid proxy' do
  25. within(:active_content) do
  26. click(:href, '#network')
  27. fill_in 'proxy', with: 'invalid_proxy'
  28. fill_in 'proxy_username', with: proxy_username
  29. fill_in 'proxy_password', with: proxy_password
  30. click_on 'Test Connection'
  31. in_modal do
  32. expect(page).to have_css('h1', text: 'Error')
  33. expect(page).to have_css('div', text: %r{Invalid proxy address})
  34. end
  35. expect(page).to have_button('Test Connection', visible: :visible)
  36. expect(page).to have_button('Submit', visible: :hidden)
  37. end
  38. end
  39. it 'with unknown proxy' do
  40. within(:active_content) do
  41. click(:href, '#network')
  42. fill_in 'proxy', with: 'proxy.example.com:3128'
  43. fill_in 'proxy_username', with: proxy_username
  44. fill_in 'proxy_password', with: proxy_password
  45. click_on 'Test Connection'
  46. in_modal do
  47. expect(page).to have_css('h1', text: 'Error')
  48. expect(page).to have_css('div', text: %r{Failed to open TCP connection})
  49. end
  50. expect(page).to have_button('Test Connection', visible: :visible)
  51. expect(page).to have_button('Submit', visible: :hidden)
  52. end
  53. end
  54. it 'with invalid proxy username' do
  55. within(:active_content) do
  56. click(:href, '#network')
  57. fill_in 'proxy', with: proxy
  58. fill_in 'proxy_username', with: 'invalid_username'
  59. fill_in 'proxy_password', with: proxy_password
  60. click_on 'Test Connection'
  61. in_modal do
  62. expect(page).to have_css('h1', text: 'Error')
  63. expect(page).to have_css('div', text: %r{Access Denied})
  64. end
  65. expect(page).to have_button('Test Connection', visible: :visible)
  66. expect(page).to have_button('Submit', visible: :hidden)
  67. end
  68. end
  69. it 'with invalid proxy password' do
  70. within(:active_content) do
  71. click(:href, '#network')
  72. fill_in 'proxy', with: proxy
  73. fill_in 'proxy_username', with: proxy_username
  74. fill_in 'proxy_password', with: 'invalid_password'
  75. click_on 'Test Connection'
  76. in_modal do
  77. expect(page).to have_css('h1', text: 'Error')
  78. expect(page).to have_css('div', text: %r{Access Denied})
  79. end
  80. expect(page).to have_button('Test Connection', visible: :visible)
  81. expect(page).to have_button('Submit', visible: :hidden)
  82. end
  83. end
  84. end
  85. end
  86. end