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
772b876a
Commit
772b876a
authored
Apr 26, 2018
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds spec for omni_auth jwt strategy
parent
699ecad7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
0 deletions
+87
-0
spec/lib/omni_auth/strategies/jwt_spec.rb
spec/lib/omni_auth/strategies/jwt_spec.rb
+87
-0
No files found.
spec/lib/omni_auth/strategies/jwt_spec.rb
0 → 100644
View file @
772b876a
require
'spec_helper'
describe
OmniAuth
::
Strategies
::
Jwt
do
include
Rack
::
Test
::
Methods
include
DeviseHelpers
context
'.decoded'
do
let
(
:strategy
)
{
described_class
.
new
({})
}
let
(
:timestamp
)
{
Time
.
now
.
to_i
}
let
(
:jwt_config
)
{
Devise
.
omniauth_configs
[
:jwt
]
}
let
(
:key
)
{
JWT
.
encode
(
claims
,
jwt_config
.
strategy
.
secret
)
}
let
(
:claims
)
do
{
id:
123
,
name:
"user_example"
,
email:
"user@example.com"
,
iat:
timestamp
}
end
before
do
allow_any_instance_of
(
OmniAuth
::
Strategy
).
to
receive
(
:options
).
and_return
(
jwt_config
.
strategy
)
allow_any_instance_of
(
Rack
::
Request
).
to
receive
(
:params
).
and_return
({
'jwt'
=>
key
})
end
it
'decodes the user information'
do
result
=
strategy
.
decoded
expect
(
result
[
"id"
]).
to
eq
(
123
)
expect
(
result
[
"name"
]).
to
eq
(
"user_example"
)
expect
(
result
[
"email"
]).
to
eq
(
"user@example.com"
)
expect
(
result
[
"iat"
]).
to
eq
(
timestamp
)
end
context
'required claims is missing'
do
let
(
:claims
)
do
{
id:
123
,
email:
"user@example.com"
,
iat:
timestamp
}
end
it
'raises error'
do
expect
{
strategy
.
decoded
}.
to
raise_error
(
OmniAuth
::
Strategies
::
JWT
::
ClaimInvalid
)
end
end
context
'when valid_within is specified but iat attribute is missing in response'
do
let
(
:claims
)
do
{
id:
123
,
name:
"user_example"
,
email:
"user@example.com"
}
end
before
do
jwt_config
.
strategy
.
valid_within
=
Time
.
now
.
to_i
end
it
'raises error'
do
expect
{
strategy
.
decoded
}.
to
raise_error
(
OmniAuth
::
Strategies
::
JWT
::
ClaimInvalid
)
end
end
context
'when timestamp claim is too skewed from present'
do
let
(
:claims
)
do
{
id:
123
,
name:
"user_example"
,
email:
"user@example.com"
,
iat:
timestamp
-
10
.
minutes
.
to_i
}
end
before
do
jwt_config
.
strategy
.
valid_within
=
2
.
seconds
end
it
'raises error'
do
expect
{
strategy
.
decoded
}.
to
raise_error
(
OmniAuth
::
Strategies
::
JWT
::
ClaimInvalid
)
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