Skip to content

Commit

Permalink
test(providers): create setup strategy describe block
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-hawk committed Dec 18, 2020
1 parent d3aa3ba commit d0a1032
Showing 1 changed file with 42 additions and 40 deletions.
82 changes: 42 additions & 40 deletions test/providers.test.js
Expand Up @@ -6,46 +6,48 @@ const PassportSAMLStrategy = require('passport-saml').Strategy

const assert = chai.assert

describe('providers setupStrategy', () => {
const passportStrategies = providers.__get__('passportStrategies')
const setupStrategy = providers.__get__('setupStrategy')
const testProvider = {
...testConfig.passportConfigAuthorizedResponse.providers[0],
verifyCallbackArity: 0
}

it('passport strategies array should be empty first time', () => {
assert.deepEqual(passportStrategies, [])
})

it('new strategy should be added in passport strategies', () => {
setupStrategy(testProvider)

assert.lengthOf(passportStrategies, 1)
assert.isFunction(
passportStrategies[0].Strategy,
'Strategy is not a function!'
)
})

it('existing loaded strategy should be found and load again', () => {
setupStrategy(testProvider)

assert.lengthOf(passportStrategies, 1)
assert.isFunction(
passportStrategies[0].Strategy,
'Strategy is not a function!'
)
})

it('Passport SAML Provider with redis setup should initialize the passport-saml strategy', () => {
const testProvider = testConfig.passportConfigAuthorizedResponse.providers.find(provider => provider.id === 'saml-redis-test')
try {
const oPassportSAMLStrategy = new PassportSAMLStrategy(testProvider.options, (profile, done) => { })
// eslint-disable-next-line security/detect-non-literal-fs-filename
assert.exists(oPassportSAMLStrategy, 'Failed to initialize passport saml strategy')
} catch (error) {
assert.fail('Failed to intialize passport-saml strategy with redis setup')
describe('providers.js', () => {
describe('setupStrategy', () => {
const passportStrategies = providers.__get__('passportStrategies')
const setupStrategy = providers.__get__('setupStrategy')
const testProvider = {
...testConfig.passportConfigAuthorizedResponse.providers[0],
verifyCallbackArity: 0
}

it('passport strategies array should be empty first time', () => {
assert.deepEqual(passportStrategies, [])
})

it('new strategy should be added in passport strategies', () => {
setupStrategy(testProvider)

assert.lengthOf(passportStrategies, 1)
assert.isFunction(
passportStrategies[0].Strategy,
'Strategy is not a function!'
)
})

it('existing loaded strategy should be found and load again', () => {
setupStrategy(testProvider)

assert.lengthOf(passportStrategies, 1)
assert.isFunction(
passportStrategies[0].Strategy,
'Strategy is not a function!'
)
})

it('Passport SAML Provider with redis setup should initialize the passport-saml strategy', () => {
const testProvider = testConfig.passportConfigAuthorizedResponse.providers.find(provider => provider.id === 'saml-redis-test')
try {
const oPassportSAMLStrategy = new PassportSAMLStrategy(testProvider.options, (profile, done) => { })
// eslint-disable-next-line security/detect-non-literal-fs-filename
assert.exists(oPassportSAMLStrategy, 'Failed to initialize passport saml strategy')
} catch (error) {
assert.fail('Failed to intialize passport-saml strategy with redis setup')
}
})
})
})

0 comments on commit d0a1032

Please sign in to comment.