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
Boxiang Sun
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
Show 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
...
@@ -15,8 +15,6 @@ module TokenAuthenticatableStrategies
end
end
token_authenticatable
token_authenticatable
rescue
ActiveRecord
::
StatementInvalid
nil
end
end
def
ensure_token
(
instance
)
def
ensure_token
(
instance
)
...
@@ -38,8 +36,8 @@ module TokenAuthenticatableStrategies
...
@@ -38,8 +36,8 @@ module TokenAuthenticatableStrategies
end
end
def
get_token
(
instance
)
def
get_token
(
instance
)
raw
_token
=
instance
.
read_attribute
(
encrypted_field
)
encrypted
_token
=
instance
.
read_attribute
(
encrypted_field
)
token
=
Gitlab
::
CryptoHelper
.
aes256_gcm_decrypt
(
raw
_token
)
token
=
Gitlab
::
CryptoHelper
.
aes256_gcm_decrypt
(
encrypted
_token
)
token
||
(
fallback_strategy
.
get_token
(
instance
)
if
fallback?
)
token
||
(
fallback_strategy
.
get_token
(
instance
)
if
fallback?
)
end
end
...
@@ -61,7 +59,7 @@ module TokenAuthenticatableStrategies
...
@@ -61,7 +59,7 @@ module TokenAuthenticatableStrategies
def
token_set?
(
instance
)
def
token_set?
(
instance
)
raw_token
=
instance
.
read_attribute
(
encrypted_field
)
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?
raw_token
.
present?
end
end
...
...
lib/gitlab/background_migration/models/encrypt_columns/runner.rb
View file @
718ea942
...
@@ -13,7 +13,7 @@ module Gitlab
...
@@ -13,7 +13,7 @@ module Gitlab
self
.
table_name
=
'ci_runners'
self
.
table_name
=
'ci_runners'
self
.
inheritance_column
=
:_type_disabled
self
.
inheritance_column
=
:_type_disabled
def
runners_
token
=
(
value
)
def
token
=
(
value
)
self
.
token_encrypted
=
self
.
token_encrypted
=
::
Gitlab
::
CryptoHelper
.
aes256_gcm_encrypt
(
value
)
::
Gitlab
::
CryptoHelper
.
aes256_gcm_encrypt
(
value
)
end
end
...
...
spec/models/ci/build_spec.rb
View file @
718ea942
...
@@ -771,13 +771,13 @@ describe Ci::Build do
...
@@ -771,13 +771,13 @@ describe Ci::Build do
context
'hide runners token'
do
context
'hide runners token'
do
let
(
:data
)
{
"new
#{
project
.
runners_token
}
data"
}
let
(
:data
)
{
"new
#{
project
.
runners_token
}
data"
}
it
{
is_expected
.
to
match
(
/^new
[x]
+ data$/
)
}
it
{
is_expected
.
to
match
(
/^new
x
+ data$/
)
}
end
end
context
'hide build token'
do
context
'hide build token'
do
let
(
:data
)
{
"new
#{
build
.
token
}
data"
}
let
(
:data
)
{
"new
#{
build
.
token
}
data"
}
it
{
is_expected
.
to
match
(
/^new
[x]
+ data$/
)
}
it
{
is_expected
.
to
match
(
/^new
x
+ data$/
)
}
end
end
end
end
...
...
spec/models/concerns/token_authenticatable_strategies/encrypted_spec.rb
View file @
718ea942
...
@@ -14,7 +14,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
...
@@ -14,7 +14,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
end
end
describe
'#find_token_authenticatable'
do
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
)
allow
(
model
).
to
receive
(
:find_by
)
.
with
(
'some_field_encrypted'
=>
encrypted
)
.
with
(
'some_field_encrypted'
=>
encrypted
)
.
and_return
(
'encrypted resource'
)
.
and_return
(
'encrypted resource'
)
...
@@ -23,8 +23,8 @@ describe TokenAuthenticatableStrategies::Encrypted do
...
@@ -23,8 +23,8 @@ describe TokenAuthenticatableStrategies::Encrypted do
.
to
eq
'encrypted resource'
.
to
eq
'encrypted resource'
end
end
it
'uses fallback strategy when
token can
not be found'
do
it
'uses fallback strategy when
encrypted token can
not be found'
do
allow
_any_instance_of
(
TokenAuthenticatableStrategies
::
Insecure
)
allow
(
subject
.
send
(
:fallback_strategy
)
)
.
to
receive
(
:find_token_authenticatable
)
.
to
receive
(
:find_token_authenticatable
)
.
and_return
(
'plaintext resource'
)
.
and_return
(
'plaintext resource'
)
...
@@ -38,7 +38,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
...
@@ -38,7 +38,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
end
end
describe
'#get_token'
do
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
)
allow
(
instance
).
to
receive
(
:read_attribute
)
.
with
(
'some_field_encrypted'
)
.
with
(
'some_field_encrypted'
)
.
and_return
(
encrypted
)
.
and_return
(
encrypted
)
...
@@ -46,7 +46,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
...
@@ -46,7 +46,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
expect
(
subject
.
get_token
(
instance
)).
to
eq
'my-value'
expect
(
subject
.
get_token
(
instance
)).
to
eq
'my-value'
end
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
)
allow
(
instance
).
to
receive
(
:read_attribute
)
.
with
(
'some_field_encrypted'
)
.
with
(
'some_field_encrypted'
)
.
and_return
(
nil
)
.
and_return
(
nil
)
...
@@ -60,7 +60,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
...
@@ -60,7 +60,7 @@ describe TokenAuthenticatableStrategies::Encrypted do
end
end
describe
'#set_token'
do
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
(
:[]=
)
expect
(
instance
).
to
receive
(
:[]=
)
.
with
(
'some_field_encrypted'
,
encrypted
)
.
with
(
'some_field_encrypted'
,
encrypted
)
expect
(
instance
).
to
receive
(
:[]=
)
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