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
d22b3486
Commit
d22b3486
authored
Apr 27, 2018
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix InvalidSignatureTimeError handling on API
Improved specs
parent
cf19910d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
19 deletions
+54
-19
ee/lib/ee/api/helpers.rb
ee/lib/ee/api/helpers.rb
+1
-1
ee/spec/lib/ee/api/helpers_spec.rb
ee/spec/lib/ee/api/helpers_spec.rb
+53
-18
No files found.
ee/lib/ee/api/helpers.rb
View file @
d22b3486
...
@@ -18,7 +18,7 @@ module EE
...
@@ -18,7 +18,7 @@ module EE
unless
auth_header
&&
::
Gitlab
::
Geo
::
JwtRequestDecoder
.
new
(
auth_header
).
decode
unless
auth_header
&&
::
Gitlab
::
Geo
::
JwtRequestDecoder
.
new
(
auth_header
).
decode
unauthorized!
unauthorized!
end
end
rescue
::
Gitlab
::
Geo
::
InvalidDecryptionKeyError
,
::
Gitlab
::
Geo
::
SignatureTimeInvalid
Error
=>
e
rescue
::
Gitlab
::
Geo
::
InvalidDecryptionKeyError
,
::
Gitlab
::
Geo
::
InvalidSignatureTime
Error
=>
e
render_api_error!
(
e
.
to_s
,
401
)
render_api_error!
(
e
.
to_s
,
401
)
end
end
end
end
...
...
ee/spec/lib/ee/api/helpers_spec.rb
View file @
d22b3486
require
'spec_helper'
require
'spec_helper'
describe
EE
::
API
::
Helpers
do
describe
EE
::
API
::
Helpers
do
include
API
::
APIGuard
::
HelperMethods
include
Rack
::
Test
::
Methods
include
API
::
Helpers
let
(
:helper
)
do
let
(
:options
)
{
{}
}
Class
.
new
(
Grape
::
API
)
do
let
(
:params
)
{
{}
}
helpers
EE
::
API
::
Helpers
let
(
:env
)
do
helpers
API
::
APIGuard
::
HelperMethods
{
helpers
API
::
Helpers
'rack.input'
=>
''
,
format
:json
'REQUEST_METHOD'
=>
'GET'
}
get
'user'
do
current_user
?
{
id:
current_user
.
id
}
:
{
found:
false
}
end
get
'protected'
do
authenticate_by_gitlab_geo_node_token!
end
end
end
end
let
(
:header
)
{
}
let
(
:request
)
{
Grape
::
Request
.
new
(
env
)}
before
do
def
app
allow
(
Gitlab
::
Database
::
LoadBalancing
).
to
receive
(
:enable?
).
and_return
(
true
)
helper
end
end
describe
'#current_user'
do
describe
'#current_user'
do
let
(
:user
)
{
build
(
:user
,
id:
42
)
}
let
(
:user
)
{
build
(
:user
,
id:
42
)
}
before
do
allow
(
Gitlab
::
Database
::
LoadBalancing
).
to
receive
(
:enable?
).
and_return
(
true
)
end
it
'handles sticking when a user could be found'
do
it
'handles sticking when a user could be found'
do
allow_any_instance_of
(
API
::
Helpers
).
to
receive
(
:initial_current_user
).
and_return
(
user
)
allow_any_instance_of
(
API
::
Helpers
).
to
receive
(
:initial_current_user
).
and_return
(
user
)
expect
(
Gitlab
::
Database
::
LoadBalancing
::
RackMiddleware
)
expect
(
Gitlab
::
Database
::
LoadBalancing
::
RackMiddleware
)
.
to
receive
(
:stick_or_unstick
).
with
(
env
,
:user
,
42
)
.
to
receive
(
:stick_or_unstick
).
with
(
any_args
,
:user
,
42
)
get
'user'
current_user
expect
(
JSON
.
parse
(
last_response
.
body
)).
to
eq
({
'id'
=>
user
.
id
})
end
end
it
'does not handle sticking if no user could be found'
do
it
'does not handle sticking if no user could be found'
do
...
@@ -37,13 +48,37 @@ describe EE::API::Helpers do
...
@@ -37,13 +48,37 @@ describe EE::API::Helpers do
expect
(
Gitlab
::
Database
::
LoadBalancing
::
RackMiddleware
)
expect
(
Gitlab
::
Database
::
LoadBalancing
::
RackMiddleware
)
.
not_to
receive
(
:stick_or_unstick
)
.
not_to
receive
(
:stick_or_unstick
)
current_user
get
'user'
expect
(
JSON
.
parse
(
last_response
.
body
)).
to
eq
({
'found'
=>
false
})
end
end
it
'returns the user if one could be found'
do
it
'returns the user if one could be found'
do
allow_any_instance_of
(
API
::
Helpers
).
to
receive
(
:initial_current_user
).
and_return
(
user
)
allow_any_instance_of
(
API
::
Helpers
).
to
receive
(
:initial_current_user
).
and_return
(
user
)
expect
(
current_user
).
to
eq
(
user
)
get
'user'
expect
(
JSON
.
parse
(
last_response
.
body
)).
to
eq
({
'id'
=>
user
.
id
})
end
end
describe
'#authenticate_by_gitlab_geo_node_token!'
do
it
'rescues from ::Gitlab::Geo::InvalidDecryptionKeyError'
do
expect_any_instance_of
(
::
Gitlab
::
Geo
::
JwtRequestDecoder
).
to
receive
(
:decode
)
{
raise
::
Gitlab
::
Geo
::
InvalidDecryptionKeyError
}
header
'Authorization'
,
'test'
get
'protected'
,
current_user:
'test'
expect
(
JSON
.
parse
(
last_response
.
body
)).
to
eq
({
'message'
=>
'Gitlab::Geo::InvalidDecryptionKeyError'
})
end
it
'rescues from ::Gitlab::Geo::InvalidSignatureTimeError'
do
allow_any_instance_of
(
::
Gitlab
::
Geo
::
JwtRequestDecoder
).
to
receive
(
:decode
)
{
raise
::
Gitlab
::
Geo
::
InvalidSignatureTimeError
}
header
'Authorization'
,
'test'
get
'protected'
,
current_user:
'test'
expect
(
JSON
.
parse
(
last_response
.
body
)).
to
eq
({
'message'
=>
'Gitlab::Geo::InvalidSignatureTimeError'
})
end
end
end
end
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