self_destruct_helper_spec.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe SelfDestructHelper do
  4. describe 'self_destruct?' do
  5. context 'when SELF_DESTRUCT is unset' do
  6. it 'returns false' do
  7. expect(helper.self_destruct?).to be false
  8. end
  9. end
  10. context 'when SELF_DESTRUCT is set to an invalid value' do
  11. around do |example|
  12. ClimateControl.modify SELF_DESTRUCT: 'true' do
  13. example.run
  14. end
  15. end
  16. it 'returns false' do
  17. expect(helper.self_destruct?).to be false
  18. end
  19. end
  20. context 'when SELF_DESTRUCT is set to value signed for the wrong purpose' do
  21. around do |example|
  22. ClimateControl.modify(
  23. SELF_DESTRUCT: Rails.application.message_verifier('foo').generate('example.com'),
  24. LOCAL_DOMAIN: 'example.com'
  25. ) do
  26. example.run
  27. end
  28. end
  29. it 'returns false' do
  30. expect(helper.self_destruct?).to be false
  31. end
  32. end
  33. context 'when SELF_DESTRUCT is set to value signed for the wrong domain' do
  34. around do |example|
  35. ClimateControl.modify(
  36. SELF_DESTRUCT: Rails.application.message_verifier('self-destruct').generate('foo.com'),
  37. LOCAL_DOMAIN: 'example.com'
  38. ) do
  39. example.run
  40. end
  41. end
  42. it 'returns false' do
  43. expect(helper.self_destruct?).to be false
  44. end
  45. end
  46. context 'when SELF_DESTRUCT is set to a correctly-signed value' do
  47. around do |example|
  48. ClimateControl.modify(
  49. SELF_DESTRUCT: Rails.application.message_verifier('self-destruct').generate('example.com'),
  50. LOCAL_DOMAIN: 'example.com'
  51. ) do
  52. example.run
  53. end
  54. end
  55. it 'returns true' do
  56. expect(helper.self_destruct?).to be true
  57. end
  58. end
  59. end
  60. end