-
Notifications
You must be signed in to change notification settings - Fork 559
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'refs/pull/231/head' of https://github.com/eduardoboucas…
…/staticman into deploy
- Loading branch information
Showing
3 changed files
with
61 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,17 +18,10 @@ beforeEach(() => { | |
|
||
describe('Auth controller', () => { | ||
describe('GitHub', () => { | ||
test('authenticates to GitHub with the given code and returns the authenticated user', () => { | ||
const mockAccessToken = 'qwertyuiop' | ||
const mockCode = '1q2w3e4r' | ||
const mockUser = { | ||
login: 'johndoe', | ||
name: 'John Doe', | ||
email: '[email protected]' | ||
} | ||
|
||
const siteConfig = helpers.getConfig() | ||
const siteConfig = helpers.getConfig() | ||
const mockCode = '1q2w3e4r' | ||
|
||
const oauthRequest = | ||
nock(/github\.com/) | ||
.post('/login/oauth/access_token') | ||
.query({ | ||
|
@@ -37,6 +30,16 @@ describe('Auth controller', () => { | |
code: mockCode, | ||
redirect_uri: siteConfig.get('githubAuth.redirectUri') | ||
}) | ||
|
||
test('authenticates to GitHub with the given code and returns the authenticated user', () => { | ||
const mockAccessToken = 'qwertyuiop' | ||
const mockUser = { | ||
login: 'johndoe', | ||
name: 'John Doe', | ||
email: '[email protected]' | ||
} | ||
|
||
oauthRequest | ||
.reply(200, { | ||
access_token: mockAccessToken | ||
}) | ||
|
@@ -50,7 +53,8 @@ describe('Auth controller', () => { | |
|
||
const reqWithQuery = Object.assign({}, req, { | ||
query: { | ||
code: mockCode | ||
code: mockCode, | ||
provider: 'github' | ||
} | ||
}) | ||
|
||
|
@@ -64,21 +68,11 @@ describe('Auth controller', () => { | |
|
||
test('authenticates to GitHub with the given code and returns the original GitHub user when using v2 API', () => { | ||
const mockAccessToken = 'qwertyuiop' | ||
const mockCode = '1q2w3e4r' | ||
const mockUser = { | ||
login: 'johndoe' | ||
} | ||
|
||
const siteConfig = helpers.getConfig() | ||
|
||
nock(/github\.com/) | ||
.post('/login/oauth/access_token') | ||
.query({ | ||
client_id: siteConfig.get('githubAuth.clientId'), | ||
client_secret: siteConfig.get('githubAuth.clientSecret'), | ||
code: mockCode, | ||
redirect_uri: siteConfig.get('githubAuth.redirectUri') | ||
}) | ||
oauthRequest | ||
.reply(200, { | ||
access_token: mockAccessToken | ||
}) | ||
|
@@ -92,11 +86,11 @@ describe('Auth controller', () => { | |
|
||
const reqWithQuery = Object.assign({}, req, { | ||
params: { | ||
service: 'github', | ||
version: '2' | ||
}, | ||
query: { | ||
code: mockCode | ||
code: mockCode, | ||
provider: 'github' | ||
} | ||
}) | ||
|
||
|
@@ -108,25 +102,12 @@ describe('Auth controller', () => { | |
}) | ||
|
||
test('returns a 401 response when unable to get an access token from GitHub', () => { | ||
const mockCode = '1q2w3e4r' | ||
const siteConfig = helpers.getConfig() | ||
|
||
nock(/github\.com/) | ||
.post('/login/oauth/access_token') | ||
.query({ | ||
client_id: siteConfig.get('githubAuth.clientId'), | ||
client_secret: siteConfig.get('githubAuth.clientSecret'), | ||
code: mockCode, | ||
redirect_uri: siteConfig.get('githubAuth.redirectUri') | ||
}) | ||
oauthRequest | ||
.reply(401, { | ||
error: 'invalid_code' | ||
}) | ||
|
||
const reqWithQuery = Object.assign({}, req, { | ||
params: { | ||
service: 'github' | ||
}, | ||
query: { | ||
code: mockCode | ||
} | ||
|
@@ -167,7 +148,8 @@ describe('Auth controller', () => { | |
|
||
const reqWithQuery = Object.assign({}, req, { | ||
query: { | ||
code: mockCode | ||
code: mockCode, | ||
provider: 'github' | ||
} | ||
}) | ||
|
||
|
@@ -180,17 +162,10 @@ describe('Auth controller', () => { | |
}) | ||
|
||
describe('GitLab', () => { | ||
test('authenticates to GitLab with the given code and returns the authenticated user', () => { | ||
const mockAccessToken = 'qwertyuiop' | ||
const mockCode = '1q2w3e4r' | ||
const mockUser = { | ||
username: 'johndoe', | ||
name: 'John Doe', | ||
email: '[email protected]' | ||
} | ||
|
||
const siteConfig = helpers.getConfig() | ||
const siteConfig = helpers.getConfig() | ||
const mockCode = '1q2w3e4r' | ||
|
||
const oauthRequest = | ||
nock(/gitlab\.com/) | ||
.post('/oauth/token') | ||
.query({ | ||
|
@@ -200,6 +175,16 @@ describe('Auth controller', () => { | |
grant_type: 'authorization_code', | ||
redirect_uri: siteConfig.get('gitlabAuth.redirectUri') | ||
}) | ||
|
||
test('authenticates to GitLab with the given code and returns the authenticated user', () => { | ||
const mockAccessToken = 'qwertyuiop' | ||
const mockUser = { | ||
username: 'johndoe', | ||
name: 'John Doe', | ||
email: '[email protected]' | ||
} | ||
|
||
oauthRequest | ||
.reply(200, { | ||
access_token: mockAccessToken | ||
}) | ||
|
@@ -213,11 +198,9 @@ describe('Auth controller', () => { | |
.reply(200, mockUser) | ||
|
||
const reqWithQuery = Object.assign({}, req, { | ||
params: { | ||
service: 'gitlab' | ||
}, | ||
query: { | ||
code: mockCode | ||
code: mockCode, | ||
provider: 'gitlab' | ||
} | ||
}) | ||
|
||
|
@@ -230,28 +213,15 @@ describe('Auth controller', () => { | |
}) | ||
|
||
test('returns a 401 response when unable to get an access token from GitLab', () => { | ||
const mockCode = '1q2w3e4r' | ||
const siteConfig = helpers.getConfig() | ||
|
||
nock(/gitlab\.com/) | ||
.post('/oauth/token') | ||
.query({ | ||
client_id: siteConfig.get('gitlabAuth.clientId'), | ||
client_secret: siteConfig.get('gitlabAuth.clientSecret'), | ||
code: mockCode, | ||
grant_type: 'authorization_code', | ||
redirect_uri: siteConfig.get('gitlabAuth.redirectUri') | ||
}) | ||
oauthRequest | ||
.reply(401, { | ||
error: 'invalid_code' | ||
}) | ||
|
||
const reqWithQuery = Object.assign({}, req, { | ||
params: { | ||
service: 'gitlab' | ||
}, | ||
query: { | ||
code: mockCode | ||
code: mockCode, | ||
provider: 'gitlab' | ||
} | ||
}) | ||
|
||
|
@@ -264,19 +234,8 @@ describe('Auth controller', () => { | |
|
||
test('returns a 401 response when an incorrect access token is used for the GitLab API', () => { | ||
const mockAccessToken = 'qwertyuiop' | ||
const mockCode = '1q2w3e4r' | ||
|
||
const siteConfig = helpers.getConfig() | ||
|
||
nock(/gitlab\.com/) | ||
.post('/oauth/token') | ||
.query({ | ||
client_id: siteConfig.get('gitlabAuth.clientId'), | ||
client_secret: siteConfig.get('gitlabAuth.clientSecret'), | ||
code: mockCode, | ||
grant_type: 'authorization_code', | ||
redirect_uri: siteConfig.get('gitlabAuth.redirectUri') | ||
}) | ||
oauthRequest | ||
.reply(200, { | ||
access_token: mockAccessToken | ||
}) | ||
|
@@ -292,11 +251,9 @@ describe('Auth controller', () => { | |
}) | ||
|
||
const reqWithQuery = Object.assign({}, req, { | ||
params: { | ||
service: 'gitlab' | ||
}, | ||
query: { | ||
code: mockCode | ||
code: mockCode, | ||
provider: 'gitlab' | ||
} | ||
}) | ||
|
||
|