-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow passing
loginHint
option to ensureAuthenticated
add changelog OKTA-448944 <<<Jenkins Check-In of Tested SHA: f608f95 for [email protected]>>> Artifact: okta-oidc-middleware Files changed count: 7 PR Link: "#40"
- Loading branch information
1 parent
23bba66
commit 9c5e3b0
Showing
7 changed files
with
105 additions
and
6 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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"env": { | ||
"node": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2018 | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const connectUtil = require('../../src/connectUtil.js'); | ||
|
||
jest.mock('csurf', function () { | ||
return function () { | ||
|
||
} | ||
}); | ||
|
||
var mockAuthenticate; | ||
jest.mock('passport', function () { | ||
mockAuthenticate = jest.fn().mockReturnValue(() => {}) | ||
return { | ||
authenticate: mockAuthenticate | ||
} | ||
}) | ||
|
||
|
||
|
||
describe('connectUtil', function () { | ||
describe('createLoginHandler', function () { | ||
it('passes known options to passport handler initializer', function () { | ||
const loginHandler = connectUtil.createLoginHandler({ | ||
options: { | ||
routes: { | ||
login: { | ||
} | ||
} | ||
} | ||
}); | ||
const res = {}; | ||
const req = { | ||
query: { | ||
login_hint: '[email protected]', | ||
chown_base: true | ||
} | ||
}; | ||
|
||
loginHandler(req, res); | ||
expect(mockAuthenticate).toBeCalledWith('oidc', { | ||
login_hint: '[email protected]' | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -2,6 +2,16 @@ const passport = require('passport'); | |
const OpenIdClient = require('openid-client'); | ||
const oidcUtil = require('../../src/oidcUtil.js'); | ||
|
||
jest.mock('negotiator', function () { | ||
return function () { | ||
return { | ||
mediaType: function () { | ||
return 'text/html'; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
function createMockOpenIdClient(config={}) { | ||
const Issuer = OpenIdClient.Issuer; | ||
|
||
|
@@ -94,6 +104,21 @@ describe('oidcUtil', function () { | |
expect(error).toEqual(undefined); | ||
}; | ||
passportStrategy.authenticate(createMockRedirectRequest()); | ||
}) | ||
}) | ||
}); | ||
}); | ||
|
||
describe('ensureAuthenticated', () => { | ||
it('appends known options to redirect URL', () => { | ||
const requestHandler = oidcUtil.ensureAuthenticated({}, { | ||
redirectTo: '/login', | ||
loginHint: '[email protected]' | ||
}); | ||
let req = jest.mock(); | ||
let res = { | ||
redirect: jest.fn() | ||
}; | ||
requestHandler(req, res, () => {}); | ||
expect(res.redirect).toBeCalledWith('/login?login_hint=username%40org.org'); | ||
}); | ||
}); | ||
}) |