proxy_spec.rb 1.9 KB

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