Add more tests for self-destruct mode (#30374)
This commit is contained in:
parent
def6b686ff
commit
de4815afda
2 changed files with 162 additions and 0 deletions
70
spec/helpers/self_destruct_helper_spec.rb
Normal file
70
spec/helpers/self_destruct_helper_spec.rb
Normal file
|
@ -0,0 +1,70 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe SelfDestructHelper do
|
||||
describe 'self_destruct?' do
|
||||
context 'when SELF_DESTRUCT is unset' do
|
||||
it 'returns false' do
|
||||
expect(helper.self_destruct?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when SELF_DESTRUCT is set to an invalid value' do
|
||||
around do |example|
|
||||
ClimateControl.modify SELF_DESTRUCT: 'true' do
|
||||
example.run
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns false' do
|
||||
expect(helper.self_destruct?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when SELF_DESTRUCT is set to value signed for the wrong purpose' do
|
||||
around do |example|
|
||||
ClimateControl.modify(
|
||||
SELF_DESTRUCT: Rails.application.message_verifier('foo').generate('example.com'),
|
||||
LOCAL_DOMAIN: 'example.com'
|
||||
) do
|
||||
example.run
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns false' do
|
||||
expect(helper.self_destruct?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when SELF_DESTRUCT is set to value signed for the wrong domain' do
|
||||
around do |example|
|
||||
ClimateControl.modify(
|
||||
SELF_DESTRUCT: Rails.application.message_verifier('self-destruct').generate('foo.com'),
|
||||
LOCAL_DOMAIN: 'example.com'
|
||||
) do
|
||||
example.run
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns false' do
|
||||
expect(helper.self_destruct?).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'when SELF_DESTRUCT is set to a correctly-signed value' do
|
||||
around do |example|
|
||||
ClimateControl.modify(
|
||||
SELF_DESTRUCT: Rails.application.message_verifier('self-destruct').generate('example.com'),
|
||||
LOCAL_DOMAIN: 'example.com'
|
||||
) do
|
||||
example.run
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns true' do
|
||||
expect(helper.self_destruct?).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue