proxy_spec.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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: :request do
  4. let(:group) { create(:group) }
  5. let!(:admin) do
  6. create(:admin, groups: [Group.lookup(name: 'Users'), group])
  7. end
  8. let(:proxy) { ENV['CI_PROXY_URL'] }
  9. let(:proxy_username) { ENV['CI_PROXY_USER'] }
  10. let(:proxy_password) { ENV['CI_PROXY_PASSWORD'] }
  11. let(:valid_params) do
  12. {
  13. proxy: proxy,
  14. proxy_username: proxy_username,
  15. proxy_password: proxy_password
  16. }
  17. end
  18. describe 'request handling' do
  19. it 'does proxy settings - valid params' do
  20. authenticated_as(admin)
  21. post '/api/v1/proxy', params: valid_params, as: :json
  22. expect(json_response['result']).to eq('success')
  23. end
  24. context 'when proxy settings uses invalid config' do
  25. it 'with invalid proxy' do
  26. authenticated_as(admin)
  27. params = valid_params.merge({ proxy: 'invalid_proxy' })
  28. post '/api/v1/proxy', params: params, as: :json
  29. expect(json_response['result']).to eq('failed')
  30. end
  31. it 'with unknown proxy' do
  32. authenticated_as(admin)
  33. params = valid_params.merge({ proxy_password: 'proxy.example.com:3128' })
  34. post '/api/v1/proxy', params: params, as: :json
  35. expect(json_response['result']).to eq('failed')
  36. end
  37. it 'with invalid proxy username' do
  38. authenticated_as(admin)
  39. params = valid_params.merge({ proxy_password: 'invalid_username' })
  40. post '/api/v1/proxy', params: params, as: :json
  41. expect(json_response['result']).to eq('failed')
  42. end
  43. it 'with invalid proxy password' do
  44. authenticated_as(admin)
  45. params = valid_params.merge({ proxy_password: 'invalid_password' })
  46. post '/api/v1/proxy', params: params, as: :json
  47. expect(json_response['result']).to eq('failed')
  48. end
  49. end
  50. end
  51. end