Skip to content

Commit

Permalink
Merge refs/heads/master into version_4.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Sep 27, 2021
2 parents 1c19639 + 228ae5f commit 6a0b6c9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function applyMapping (profile, provider) {
const additionalParams = profile.extras

delete profile.extras
logger.log2('silly', `Raw profile is ${JSON.stringify(profile._json)}`)
logger.log2('debug', `Raw profile is ${JSON.stringify(profile)}`)
logger.log2('info', `Applying mapping '${mapping}' to profile`)

mappedProfile = require('./mappings/' + mapping)(profile, additionalParams)
Expand Down
44 changes: 42 additions & 2 deletions test/providers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ const providers = rewire('../server/providers.js')
const config = require('config')
const PassportSAMLStrategy = require('passport-saml').Strategy
const helper = require('./helper')
const fs = require('fs').promises
const path = require('path')

const assert = chai.assert
const passportConfigAuthorizedResponse = config.get('passportConfigAuthorizedResponse')

describe('providers.js', () => {
describe('setupStrategy', () => {
Expand All @@ -20,7 +23,7 @@ describe('providers.js', () => {
const passportStrategies = providers.__get__('passportStrategies')
const setupStrategy = providers.__get__('setupStrategy')
const testProvider = {
...config.passportConfigAuthorizedResponse.providers[0],
...passportConfigAuthorizedResponse.providers[0],
verifyCallbackArity: 0
}

Expand Down Expand Up @@ -57,7 +60,7 @@ describe('providers.js', () => {
})

it('Passport SAML Provider with redis setup should initialize the passport-saml strategy', () => {
const testProvider = config.passportConfigAuthorizedResponse.providers.find(
const testProvider = passportConfigAuthorizedResponse.providers.find(
provider => provider.id === 'saml-redis-test'
)
try {
Expand All @@ -70,4 +73,41 @@ describe('providers.js', () => {
}
})
})

describe('applyMapping', () => {
const applyMappingRewire = providers.__get__('applyMapping')
const fakeProfile = {
sub: 'loganXMen',
email: '[email protected]',
name: 'Logan',
given_name: 'Hugh Jackman'
}

it('should be a function', () => {
assert.isFunction(applyMappingRewire)
})

it('should return mapped data as per mapping file config', () => {
global.providers = passportConfigAuthorizedResponse.providers
const mappedProfileResult = applyMappingRewire(fakeProfile, 'oidccedev6privatejwt')
const fakeMappedProfile = {
uid: fakeProfile.sub,
mail: fakeProfile.email,
cn: fakeProfile.given_name,
displayName: fakeProfile.name,
givenName: fakeProfile.given_name,
sn: undefined
}

assert.deepStrictEqual(mappedProfileResult, fakeMappedProfile)
})

it('should log user profile data in log file', async () => {
const passportLogFilePath = path.join(__dirname, '../server/utils/logs/passport.log')
const data = await fs.readFile(passportLogFilePath, 'binary')
assert(data.includes('Raw profile is'))
assert(data.includes(fakeProfile.email))
assert(data.includes(fakeProfile.name))
})
})
})

0 comments on commit 6a0b6c9

Please sign in to comment.