ssl_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'SSL Verification', :aggregate_failures, authenticated_as: false, type: :system do
  4. let(:url) { "https://#{Setting.get('fqdn')}/robots.txt" }
  5. let(:localhost_autority) { Localhost::Authority.fetch(CAPYBARA_HOSTNAME) }
  6. context 'without self-signed certificate present' do
  7. context 'with verify_ssl: true' do
  8. it 'UserAgent fails' do
  9. expect(UserAgent.get(url, {}, { verify_ssl: true })).not_to be_success
  10. expect(UserAgent.get(url, {}, { verify_ssl: true }).error).to include('certificate verify failed (self signed certificate)')
  11. end
  12. end
  13. context 'without verify_ssl' do
  14. it 'UserAgent fails' do
  15. expect(UserAgent.get(url)).not_to be_success
  16. expect(UserAgent.get(url).error).to include('certificate verify failed (self signed certificate)')
  17. end
  18. end
  19. context 'with verify_ssl: false' do
  20. it 'UserAgent succeeds' do
  21. expect(UserAgent.get(url, {}, { verify_ssl: false })).to be_success
  22. end
  23. end
  24. end
  25. context 'with self-signed certificate present' do
  26. before do
  27. create(:ssl_certificate, certificate: File.read(localhost_autority.certificate_path))
  28. end
  29. context 'with verify_ssl: true' do
  30. it 'UserAgent succeeds' do
  31. expect(UserAgent.get(url, {}, { verify_ssl: true })).to be_success
  32. end
  33. end
  34. context 'without verify_ssl: true' do
  35. it 'UserAgent succeeds' do
  36. expect(UserAgent.get(url)).to be_success
  37. end
  38. end
  39. context 'with verify_ssl: false' do
  40. it 'UserAgent succeeds' do
  41. expect(UserAgent.get(url, {}, { verify_ssl: false })).to be_success
  42. end
  43. end
  44. end
  45. end