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
37add27a
Commit
37add27a
authored
Nov 27, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve token authenticable tests and exceptions
parent
3dfbfa4e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
10 additions
and
8 deletions
+10
-8
app/models/concerns/token_authenticatable_strategies/base.rb
app/models/concerns/token_authenticatable_strategies/base.rb
+4
-4
app/models/concerns/token_authenticatable_strategies/encrypted.rb
...ls/concerns/token_authenticatable_strategies/encrypted.rb
+1
-1
lib/gitlab/utils.rb
lib/gitlab/utils.rb
+2
-1
spec/lib/gitlab/crypto_helper_spec.rb
spec/lib/gitlab/crypto_helper_spec.rb
+3
-2
No files found.
app/models/concerns/token_authenticatable_strategies/base.rb
View file @
37add27a
...
...
@@ -47,17 +47,17 @@ module TokenAuthenticatableStrategies
options
[
:fallback
]
==
true
end
def
self
.
fabricate
(
instance
,
field
,
options
)
def
self
.
fabricate
(
model
,
field
,
options
)
if
options
[
:digest
]
&&
options
[
:encrypted
]
raise
ArgumentError
,
'Incompatible options set!'
end
if
options
[
:digest
]
TokenAuthenticatableStrategies
::
Digest
.
new
(
instance
,
field
,
options
)
TokenAuthenticatableStrategies
::
Digest
.
new
(
model
,
field
,
options
)
elsif
options
[
:encrypted
]
TokenAuthenticatableStrategies
::
Encrypted
.
new
(
instance
,
field
,
options
)
TokenAuthenticatableStrategies
::
Encrypted
.
new
(
model
,
field
,
options
)
else
TokenAuthenticatableStrategies
::
Insecure
.
new
(
instance
,
field
,
options
)
TokenAuthenticatableStrategies
::
Insecure
.
new
(
model
,
field
,
options
)
end
end
...
...
app/models/concerns/token_authenticatable_strategies/encrypted.rb
View file @
37add27a
...
...
@@ -46,7 +46,7 @@ module TokenAuthenticatableStrategies
raise
ArgumentError
unless
token
.
present?
instance
[
encrypted_field
]
=
Gitlab
::
CryptoHelper
.
aes256_gcm_encrypt
(
token
)
instance
[
token_field
]
=
nil
fallback_strategy
.
set_token
(
instance
,
nil
)
if
fallback?
token
end
...
...
lib/gitlab/utils.rb
View file @
37add27a
...
...
@@ -17,7 +17,8 @@ module Gitlab
end
def
ensure_utf8_size
(
str
,
bytes
:)
raise
ArgumentError
if
str
.
empty?
||
bytes
.
negative?
raise
ArgumentError
,
'Empty string provided!'
if
str
.
empty?
raise
ArgumentError
,
'Negative string size provided!'
if
bytes
.
negative?
truncated
=
str
.
each_char
.
each_with_object
(
+
''
)
do
|
char
,
object
|
if
object
.
bytesize
+
char
.
bytesize
>
bytes
...
...
spec/lib/gitlab/crypto_helper_spec.rb
View file @
37add27a
...
...
@@ -5,7 +5,7 @@ describe Gitlab::CryptoHelper do
it
'generates SHA256 digest Base46 encoded'
do
digest
=
described_class
.
sha256
(
'some-value'
)
expect
(
digest
).
to
match
%r{
^[A-Za-z0-9+/=]+$
}
expect
(
digest
).
to
match
%r{
\A
[A-Za-z0-9+/=]+
\z
}
expect
(
digest
).
to
eq
digest
.
strip
end
end
...
...
@@ -14,7 +14,8 @@ describe Gitlab::CryptoHelper do
it
'is Base64 encoded string without new line character'
do
encrypted
=
described_class
.
aes256_gcm_encrypt
(
'some-value'
)
expect
(
encrypted
).
to
match
%r{^[A-Za-z0-9+/=]+$}
expect
(
encrypted
).
to
match
%r{
\A
[A-Za-z0-9+/=]+
\z
}
expect
(
encrypted
).
not_to
include
"
\n
"
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