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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
718ea942
Commit
718ea942
authored
Nov 23, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve test cases description in token-related specs
parent
636b038e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
14 deletions
+12
-14
app/models/concerns/token_authenticatable_strategies/encrypted.rb
...ls/concerns/token_authenticatable_strategies/encrypted.rb
+3
-5
lib/gitlab/background_migration/models/encrypt_columns/runner.rb
...lab/background_migration/models/encrypt_columns/runner.rb
+1
-1
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+2
-2
spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb
...ncerns/token_authenticatable_strategies/encrypted_spec.rb
+6
-6
No files found.
app/models/concerns/token_authenticatable_strategies/encrypted.rb
View file @
718ea942
...
...
@@ -15,8 +15,6 @@ module TokenAuthenticatableStrategies
end
token_authenticatable
rescue
ActiveRecord
::
StatementInvalid
nil
end
def
ensure_token
(
instance
)
...
...
@@ -38,8 +36,8 @@ module TokenAuthenticatableStrategies
end
def
get_token
(
instance
)
raw
_token
=
instance
.
read_attribute
(
encrypted_field
)
token
=
Gitlab
::
CryptoHelper
.
aes256_gcm_decrypt
(
raw
_token
)
encrypted
_token
=
instance
.
read_attribute
(
encrypted_field
)
token
=
Gitlab
::
CryptoHelper
.
aes256_gcm_decrypt
(
encrypted
_token
)
token
||
(
fallback_strategy
.
get_token
(
instance
)
if
fallback?
)
end
...
...
@@ -61,7 +59,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
||=
(
fallback_strategy
.
get_token
(
instance
)
if
fallback?
)
raw_token
.
present?
end
...
...
lib/gitlab/background_migration/models/encrypt_columns/runner.rb
View file @
718ea942
...
...
@@ -13,7 +13,7 @@ module Gitlab
self
.
table_name
=
'ci_runners'
self
.
inheritance_column
=
:_type_disabled
def
runners_
token
=
(
value
)
def
token
=
(
value
)
self
.
token_encrypted
=
::
Gitlab
::
CryptoHelper
.
aes256_gcm_encrypt
(
value
)
end
...
...
spec/models/ci/build_spec.rb
View file @
718ea942
...
...
@@ -771,13 +771,13 @@ describe Ci::Build do
context
'hide runners token'
do
let
(
:data
)
{
"new
#{
project
.
runners_token
}
data"
}
it
{
is_expected
.
to
match
(
/^new
[x]
+ data$/
)
}
it
{
is_expected
.
to
match
(
/^new
x
+ data$/
)
}
end
context
'hide build token'
do
let
(
:data
)
{
"new
#{
build
.
token
}
data"
}
it
{
is_expected
.
to
match
(
/^new
[x]
+ data$/
)
}
it
{
is_expected
.
to
match
(
/^new
x
+ data$/
)
}
end
end
...
...
spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb
View file @
718ea942
...
...
@@ -14,7 +14,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
end
describe
'#find_token_authenticatable'
do
it
'finds
a relevant resource by encrypted value
'
do
it
'finds
the encrypted resource by cleartext
'
do
allow
(
model
).
to
receive
(
:find_by
)
.
with
(
'some_field_encrypted'
=>
encrypted
)
.
and_return
(
'encrypted resource'
)
...
...
@@ -23,8 +23,8 @@ describe TokenAuthenticatableStrategies::Encrypted do
.
to
eq
'encrypted resource'
end
it
'uses fallback strategy when
token can
not be found'
do
allow
_any_instance_of
(
TokenAuthenticatableStrategies
::
Insecure
)
it
'uses fallback strategy when
encrypted token can
not be found'
do
allow
(
subject
.
send
(
:fallback_strategy
)
)
.
to
receive
(
:find_token_authenticatable
)
.
and_return
(
'plaintext resource'
)
...
...
@@ -38,7 +38,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
end
describe
'#get_token'
do
it
'
decrypts a token whe
n encrypted token is present'
do
it
'
returns decrypted token when a
n encrypted token is present'
do
allow
(
instance
).
to
receive
(
:read_attribute
)
.
with
(
'some_field_encrypted'
)
.
and_return
(
encrypted
)
...
...
@@ -46,7 +46,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
expect
(
subject
.
get_token
(
instance
)).
to
eq
'my-value'
end
it
're
ads a
plaintext token when encrypted token is not present'
do
it
're
turns the
plaintext token when encrypted token is not present'
do
allow
(
instance
).
to
receive
(
:read_attribute
)
.
with
(
'some_field_encrypted'
)
.
and_return
(
nil
)
...
...
@@ -60,7 +60,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
end
describe
'#set_token'
do
it
'writes encrypted token
to a model instance
and returns it'
do
it
'writes encrypted token
and removes plaintext token
and returns it'
do
expect
(
instance
).
to
receive
(
:[]=
)
.
with
(
'some_field_encrypted'
,
encrypted
)
expect
(
instance
).
to
receive
(
:[]=
)
...
...
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