Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
56e5a2a3
Commit
56e5a2a3
authored
Nov 20, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reset insecure token when setting an encrypted one
parent
b32a9947
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
1 deletion
+7
-1
app/models/concerns/token_authenticatable_strategies/encrypted.rb
...ls/concerns/token_authenticatable_strategies/encrypted.rb
+5
-1
spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb
...ncerns/token_authenticatable_strategies/encrypted_spec.rb
+2
-0
No files found.
app/models/concerns/token_authenticatable_strategies/encrypted.rb
View file @
56e5a2a3
...
@@ -24,13 +24,16 @@ module TokenAuthenticatableStrategies
...
@@ -24,13 +24,16 @@ module TokenAuthenticatableStrategies
# using factory bot to create resources, it might happen that a database
# using factory bot to create resources, it might happen that a database
# schema does not have "#{token_name}_encrypted" field yet, however a bunch
# schema does not have "#{token_name}_encrypted" field yet, however a bunch
# of models call `ensure_#{token_name}` in `before_save`.
# of models call `ensure_#{token_name}` in `before_save`.
#
# In that case we are using insecure strategy, but this should only happen
# in tests, because otherwise `encrypted_field` is going to exist.
return
super
if
instance
.
has_attribute?
(
encrypted_field
)
return
super
if
instance
.
has_attribute?
(
encrypted_field
)
if
fallback?
if
fallback?
fallback_strategy
.
ensure_token
(
instance
)
fallback_strategy
.
ensure_token
(
instance
)
else
else
raise
ArgumentError
,
'
Encrypted field does not exist without fallback
'
raise
ArgumentError
,
'
No fallback defined when encrypted field is missing!
'
end
end
end
end
...
@@ -45,6 +48,7 @@ module TokenAuthenticatableStrategies
...
@@ -45,6 +48,7 @@ module TokenAuthenticatableStrategies
raise
ArgumentError
unless
token
.
present?
raise
ArgumentError
unless
token
.
present?
instance
[
encrypted_field
]
=
Gitlab
::
CryptoHelper
.
aes256_gcm_encrypt
(
token
)
instance
[
encrypted_field
]
=
Gitlab
::
CryptoHelper
.
aes256_gcm_encrypt
(
token
)
instance
[
token_field
]
=
nil
token
token
end
end
...
...
spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb
View file @
56e5a2a3
...
@@ -63,6 +63,8 @@ describe TokenAuthenticatableStrategies::Encrypted do
...
@@ -63,6 +63,8 @@ describe TokenAuthenticatableStrategies::Encrypted do
it
'writes encrypted token to a model instance and returns it'
do
it
'writes encrypted token to a model instance and returns it'
do
expect
(
instance
).
to
receive
(
:[]=
)
expect
(
instance
).
to
receive
(
:[]=
)
.
with
(
'some_field_encrypted'
,
encrypted
)
.
with
(
'some_field_encrypted'
,
encrypted
)
expect
(
instance
).
to
receive
(
:[]=
)
.
with
(
'some_field'
,
nil
)
expect
(
subject
.
set_token
(
instance
,
'my-value'
)).
to
eq
'my-value'
expect
(
subject
.
set_token
(
instance
,
'my-value'
)).
to
eq
'my-value'
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment