1
0

self_destruct_helper_spec.rb 2.1 KB

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