Skip to content

Commit

Permalink
fix PassportProfileMapper.prototype.getNameIdentifier won't return email
Browse files Browse the repository at this point in the history
  • Loading branch information
yokotaso committed Nov 15, 2024
1 parent 7158002 commit 21d9806
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/claims/PassportProfileMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ PassportProfileMapper.prototype.getNameIdentifier = function () {
return {
nameIdentifier: claims[fm.nameIdentifier] ||
claims[fm.name] ||
claims[fm.emailaddress]
claims[fm.email]
};

};
Expand Down
62 changes: 62 additions & 0 deletions test/passportprofilemapper.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
var expect = require('chai').expect;
var PassportProfileMapper = require('../lib/claims/PassportProfileMapper')

describe('PassportProfileMapper', function () {
it('PassportProfileMapper.prototype.getNameIdentifier returns id', function() {
var profileMapper = new PassportProfileMapper({
'id': 'e9f7ac44-3f9c-488c-88a2-5b4b437749a9',
'emails': [],
'displayName': null,
'name': {
'familyName': null,
'givenName': null,
}
})
var output = profileMapper.getNameIdentifier()
expect(output.nameIdentifier).to.eql('e9f7ac44-3f9c-488c-88a2-5b4b437749a9')
})

it('PassportProfileMapper.prototype.getNameIdentifier returns name', function() {
var profileMapper = new PassportProfileMapper({
'id': null,
'emails': [],
'displayName': 'Curious George',
'name': {
'familyName': null,
'givenName': null,
}
})
var output = profileMapper.getNameIdentifier()
expect(output.nameIdentifier).to.eql('Curious George')
})

it('PassportProfileMapper.prototype.getNameIdentifier returns emails', function() {
var profileMapper = new PassportProfileMapper({
'id': null,
'emails': [{
'value': '[email protected]'
}],
'displayName': null,
'name': {
'familyName': null,
'givenName': null,
}
})
var output = profileMapper.getNameIdentifier()
expect(output.nameIdentifier).to.eql('[email protected]')
})

it('PassportProfileMapper.prototype.getNameIdentifier returns undefined', function() {
var profileMapper = new PassportProfileMapper({
'id': null,
'emails': [],
'displayName': null,
'name': {
'familyName': 'Curious George',
'givenName': 'George',
}
})
var output = profileMapper.getNameIdentifier()
expect(output.nameIdentifier).to.eql(undefined)
})
})

0 comments on commit 21d9806

Please sign in to comment.