Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
ed148af4
Unverified
Commit
ed148af4
authored
Nov 13, 2017
by
Sean Hammond
Committed by
GitHub
Nov 13, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #573 from hypothesis/sort-oauth-tests
Re-arrange OAuth service tests
parents
a27d83b9
8666f000
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
38 deletions
+44
-38
oauth-auth-test.js
src/sidebar/test/oauth-auth-test.js
+44
-38
No files found.
src/sidebar/test/oauth-auth-test.js
View file @
ed148af4
...
...
@@ -169,7 +169,7 @@ describe('sidebar.oauth-auth', function () {
});
describe
(
'#tokenGetter'
,
function
()
{
it
(
'
should request an access token if a grant token was
provided'
,
function
()
{
it
(
'
exchanges the grant token for an access token if
provided'
,
function
()
{
return
auth
.
tokenGetter
().
then
(
function
(
token
)
{
var
expectedBody
=
'assertion=a.jwt.token'
+
...
...
@@ -256,7 +256,7 @@ describe('sidebar.oauth-auth', function () {
return
Promise
.
all
(
tokens
);
});
it
(
'should
return null if no grant token
was provided'
,
function
()
{
it
(
'should
not attempt to exchange a grant token if none
was provided'
,
function
()
{
fakeSettings
.
services
=
[{
authority
:
'publisher.org'
}];
return
auth
.
tokenGetter
().
then
(
function
(
token
)
{
assert
.
notCalled
(
fakeHttp
.
post
);
...
...
@@ -352,14 +352,10 @@ describe('sidebar.oauth-auth', function () {
});
});
});
});
describe
(
'persistence of tokens to storage'
,
()
=>
{
beforeEach
(()
=>
{
it
(
'persists tokens retrieved via auth code exchanges to storage'
,
()
=>
{
fakeSettings
.
services
=
[];
});
it
(
'persists tokens retrieved via auth code exchanges to storage'
,
()
=>
{
return
login
().
then
(()
=>
{
return
auth
.
tokenGetter
();
}).
then
(()
=>
{
...
...
@@ -372,6 +368,8 @@ describe('sidebar.oauth-auth', function () {
});
it
(
'persists refreshed tokens to storage'
,
()
=>
{
fakeSettings
.
services
=
[];
// 1. Perform initial token exchange.
return
login
().
then
(()
=>
{
return
auth
.
tokenGetter
();
...
...
@@ -398,7 +396,9 @@ describe('sidebar.oauth-auth', function () {
});
});
it
(
'loads and uses tokens from storage'
,
()
=>
{
it
(
'fetches and returns tokens from storage'
,
()
=>
{
fakeSettings
.
services
=
[];
fakeLocalStorage
.
getObject
.
withArgs
(
TOKEN_KEY
).
returns
({
accessToken
:
'foo'
,
refreshToken
:
'bar'
,
...
...
@@ -410,7 +410,9 @@ describe('sidebar.oauth-auth', function () {
});
});
it
(
'refreshes the token if it expired after loading from storage'
,
()
=>
{
it
(
'refreshes expired tokens loaded from storage'
,
()
=>
{
fakeSettings
.
services
=
[];
// Store an expired access token.
clock
.
tick
(
200
);
fakeLocalStorage
.
getObject
.
withArgs
(
TOKEN_KEY
).
returns
({
...
...
@@ -458,6 +460,7 @@ describe('sidebar.oauth-auth', function () {
}].
forEach
(({
when
,
data
})
=>
{
context
(
when
,
()
=>
{
it
(
'ignores invalid tokens in storage'
,
()
=>
{
fakeSettings
.
services
=
[];
fakeLocalStorage
.
getObject
.
withArgs
(
'foo'
).
returns
(
data
);
return
auth
.
tokenGetter
().
then
((
token
)
=>
{
assert
.
equal
(
token
,
null
);
...
...
@@ -465,8 +468,13 @@ describe('sidebar.oauth-auth', function () {
});
});
});
});
context
(
'when another client instance saves new tokens'
,
()
=>
{
beforeEach
(()
=>
{
fakeSettings
.
services
=
[];
});
function
notifyStoredTokenChange
()
{
// Trigger "storage" event as if another client refreshed the token.
var
storageEvent
=
new
Event
(
'storage'
);
...
...
@@ -504,10 +512,8 @@ describe('sidebar.oauth-auth', function () {
assert
.
called
(
onTokenChange
);
});
});
});
describe
(
'#login'
,
()
=>
{
beforeEach
(()
=>
{
// login() is only currently used when using the public
// Hypothesis service.
...
...
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