-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Access checker providers expect to be able to modify the config that is passed to them. With the switch to node-config, changing the configs is not allowed. Access checker now creates a copy of the access checker config to pass to the provider. Also added some additional logging and converted the config access to use `config.get` Had to update a few tests to use sinon to stub config. These tests were previously directly mutating the config and not returning it properly to its original state.
- Loading branch information
Showing
4 changed files
with
81 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,21 +114,21 @@ module.exports = { | |
*/ | ||
// strategy: 'proxy-pki', | ||
|
||
// accessChecker: { | ||
// provider: { | ||
// file: 'src/app/core/access-checker/providers/example.provider', | ||
// config: { | ||
// 'user cn string': { | ||
// name: 'User Name', | ||
// profileOrganization: 'User Organization', | ||
// email: '[email protected]', | ||
// username: 'username', | ||
// roles: [ 'ROLE' ] | ||
// } | ||
// } | ||
// }, | ||
// cacheExpire: 1000*60*60*24 // expiration of cache entries | ||
// }, | ||
accessChecker: { | ||
cacheExpire: 1000 * 60 * 60 * 24, // expiration of cache entries | ||
provider: { | ||
// file: 'src/app/core/access-checker/providers/example.provider', | ||
config: { | ||
// 'user cn string': { | ||
// name: 'User Name', | ||
// profileOrganization: 'User Organization', | ||
// email: '[email protected]', | ||
// username: 'username', | ||
// roles: ['ROLE'] | ||
// } | ||
} | ||
} | ||
}, | ||
|
||
autoLogin: false, | ||
autoCreateAccounts: false, | ||
|
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ import _ from 'lodash'; | |
import { DateTime } from 'luxon'; | ||
import passport from 'passport'; | ||
import should from 'should'; | ||
import { assert } from 'sinon'; | ||
import { assert, createSandbox } from 'sinon'; | ||
|
||
import * as userAuthenticationController from './user-authentication.controller'; | ||
import { config } from '../../../../dependencies'; | ||
|
@@ -71,6 +71,7 @@ function cacheSpec(key): Partial<ICacheEntry> { | |
*/ | ||
describe('User Auth Controller:', () => { | ||
let res; | ||
let sandbox; | ||
|
||
before(() => { | ||
return clearDatabase(); | ||
|
@@ -81,9 +82,14 @@ describe('User Auth Controller:', () => { | |
}); | ||
|
||
beforeEach(() => { | ||
sandbox = createSandbox(); | ||
res = getResponseSpy(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
describe('signout', () => { | ||
it('should successfully redirect after logout', () => { | ||
const req = { | ||
|
@@ -104,16 +110,16 @@ describe('User Auth Controller:', () => { | |
const spec = { user: localUserSpec('user1') }; | ||
let user; | ||
|
||
before(async () => { | ||
beforeEach(async () => { | ||
await clearDatabase(); | ||
user = await new User(spec.user).save(); | ||
|
||
//setup to use local passport | ||
config.auth.strategy = 'local'; | ||
sandbox.stub(config.auth, 'strategy').value('local'); | ||
passport.use(local); | ||
}); | ||
|
||
after(() => { | ||
afterEach(() => { | ||
return clearDatabase(); | ||
}); | ||
|
||
|
@@ -299,7 +305,7 @@ describe('User Auth Controller:', () => { | |
const cache = {}; | ||
const user = {}; | ||
|
||
before(async () => { | ||
beforeEach(async () => { | ||
await clearDatabase(); | ||
let defers = []; | ||
defers = defers.concat( | ||
|
@@ -314,26 +320,24 @@ describe('User Auth Controller:', () => { | |
); | ||
await Promise.all(defers); | ||
|
||
const accessCheckerConfig = { | ||
userbypassed: { | ||
name: 'Invalid Name', | ||
organization: 'Invalid Org', | ||
email: '[email protected]', | ||
username: 'invalid' | ||
sandbox.stub(config.auth, 'strategy').value('proxy-pki'); | ||
sandbox.stub(config.auth.accessChecker, 'provider').value({ | ||
file: 'src/app/core/access-checker/providers/example.provider', | ||
config: { | ||
userbypassed: { | ||
name: 'Invalid Name', | ||
organization: 'Invalid Org', | ||
email: '[email protected]', | ||
username: 'invalid' | ||
} | ||
} | ||
}; | ||
}); | ||
|
||
// All of the data is loaded, so initialize proxy-pki | ||
config.auth.strategy = 'proxy-pki'; | ||
config.auth.accessChecker = { | ||
provider: { | ||
file: 'src/app/core/access-checker/providers/example.provider', | ||
config: accessCheckerConfig | ||
} | ||
}; | ||
passport.use(proxyPki); | ||
}); | ||
|
||
after(() => { | ||
afterEach(() => { | ||
return clearDatabase(); | ||
}); | ||
|
||
|
@@ -393,7 +397,7 @@ describe('User Auth Controller:', () => { | |
|
||
// Unknown DN header | ||
it('should fail when the dn is unknown and auto create is disabled', async () => { | ||
config.auth.autoCreateAccounts = false; | ||
sandbox.stub(config.auth, 'autoCreateAccounts').value(false); | ||
req.headers = { [config.proxyPkiPrimaryUserHeader]: 'unknown' }; | ||
let err; | ||
try { | ||
|
@@ -606,7 +610,7 @@ describe('User Auth Controller:', () => { | |
}; | ||
|
||
it('should create a new account from access checker information', async () => { | ||
config.auth.autoCreateAccounts = true; | ||
sandbox.stub(config.auth, 'autoCreateAccounts').value(true); | ||
req.headers = { | ||
[config.proxyPkiPrimaryUserHeader]: spec.cache.cacheOnly.key | ||
}; | ||
|