Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-11-19 17:01:37 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-11-20 15:46:39 +0300
commitbc00b814d4eaf83a3a52c7693139eaed9b7c2b34 (patch)
treeca16cd9481aeeff5886bda1035a9065e8898c1c1 /app/models/concerns/token_authenticatable_strategies
parentfa33a2eedc4014ffbc450a74fcd112e663ac5b01 (diff)
Do not raise if encrypted tokens field does not exist
This is mostly important in specs for migration, where we are still using factories, despite that we have a Rubocop cop that should prevent doing that.
Diffstat (limited to 'app/models/concerns/token_authenticatable_strategies')
-rw-r--r--app/models/concerns/token_authenticatable_strategies/encrypted.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/app/models/concerns/token_authenticatable_strategies/encrypted.rb b/app/models/concerns/token_authenticatable_strategies/encrypted.rb
index e6cf4f4ac58..71ef18a8d8f 100644
--- a/app/models/concerns/token_authenticatable_strategies/encrypted.rb
+++ b/app/models/concerns/token_authenticatable_strategies/encrypted.rb
@@ -15,6 +15,17 @@ module TokenAuthenticatableStrategies
end
token_authenticatable
+ rescue ActiveRecord::StatementInvalid
+ nil
+ end
+
+ def ensure_token(instance)
+ # TODO, tech debt, because some specs are testing migrations, but are still
+ # using factory bot to create resources, it might happen that a database
+ # schema does not have "#{token_name}_encrypted" field yet, however a bunch
+ # of models call `ensure_#{token_name}` in `before_save`.
+ #
+ super if instance.has_attribute?(encrypted_field)
end
def get_token(instance)
@@ -40,7 +51,7 @@ module TokenAuthenticatableStrategies
def token_set?(instance)
raw_token = instance.read_attribute(encrypted_field)
- raw_token ||= instance.read_attribute(token_field) if fallback?
+ raw_token ||= (instance.read_attribute(token_field) if fallback?)
raw_token.present?
end