diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-11-23 10:25:36 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-11-23 10:25:52 +0100 |
commit | 636b038e01c7064c6d1a88359f0370dbefc323e1 (patch) | |
tree | a22bfcec8fda9c806d0c935b92ffed59bbf703b6 | |
parent | d31a3873f4e25697bb65a00cb9cf7cdd0bdb6a5f (diff) | |
download | gitlab-ce-636b038e01c7064c6d1a88359f0370dbefc323e1.tar.gz |
Only allow valid options when configuring tokens
-rw-r--r-- | app/models/concerns/token_authenticatable_strategies/base.rb | 4 | ||||
-rw-r--r-- | spec/models/concerns/token_authenticatable_strategies/base_spec.rb | 7 |
2 files changed, 11 insertions, 0 deletions
diff --git a/app/models/concerns/token_authenticatable_strategies/base.rb b/app/models/concerns/token_authenticatable_strategies/base.rb index c2c644558c0..23ee34962c7 100644 --- a/app/models/concerns/token_authenticatable_strategies/base.rb +++ b/app/models/concerns/token_authenticatable_strategies/base.rb @@ -48,6 +48,10 @@ module TokenAuthenticatableStrategies end def self.fabricate(instance, field, options) + if options[:digest] && options[:encrypted] + raise ArgumentError, 'Incompatible options set!' + end + if options[:digest] TokenAuthenticatableStrategies::Digest.new(instance, field, options) elsif options[:encrypted] diff --git a/spec/models/concerns/token_authenticatable_strategies/base_spec.rb b/spec/models/concerns/token_authenticatable_strategies/base_spec.rb index acf5c656ea9..6605f1f5a5f 100644 --- a/spec/models/concerns/token_authenticatable_strategies/base_spec.rb +++ b/spec/models/concerns/token_authenticatable_strategies/base_spec.rb @@ -28,6 +28,13 @@ describe TokenAuthenticatableStrategies::Base do expect(strategy).to be_a TokenAuthenticatableStrategies::Insecure 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 describe '#fallback?' do |