Commit 636b038e authored by Grzegorz Bizon's avatar Grzegorz Bizon

Only allow valid options when configuring tokens

parent d31a3873
...@@ -48,6 +48,10 @@ module TokenAuthenticatableStrategies ...@@ -48,6 +48,10 @@ module TokenAuthenticatableStrategies
end end
def self.fabricate(instance, field, options) def self.fabricate(instance, field, options)
if options[:digest] && options[:encrypted]
raise ArgumentError, 'Incompatible options set!'
end
if options[:digest] if options[:digest]
TokenAuthenticatableStrategies::Digest.new(instance, field, options) TokenAuthenticatableStrategies::Digest.new(instance, field, options)
elsif options[:encrypted] elsif options[:encrypted]
......
...@@ -28,6 +28,13 @@ describe TokenAuthenticatableStrategies::Base do ...@@ -28,6 +28,13 @@ describe TokenAuthenticatableStrategies::Base do
expect(strategy).to be_a TokenAuthenticatableStrategies::Insecure expect(strategy).to be_a TokenAuthenticatableStrategies::Insecure
end end
end end
context 'when incompatible options are provided' do
it 'raises an error' do
expect { described_class.fabricate(instance, field, digest: true, encrypted: true) }
.to raise_error ArgumentError
end
end
end end
describe '#fallback?' do describe '#fallback?' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment