From 21d98068a6a917da3cfa3439715f3e19004d264f Mon Sep 17 00:00:00 2001 From: tomoya YOKOTA Date: Fri, 15 Nov 2024 12:29:11 +0900 Subject: [PATCH] fix PassportProfileMapper.prototype.getNameIdentifier won't return email --- lib/claims/PassportProfileMapper.js | 2 +- test/passportprofilemapper.tests.js | 62 +++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 test/passportprofilemapper.tests.js diff --git a/lib/claims/PassportProfileMapper.js b/lib/claims/PassportProfileMapper.js index 6bc09ec..9b39387 100644 --- a/lib/claims/PassportProfileMapper.js +++ b/lib/claims/PassportProfileMapper.js @@ -66,7 +66,7 @@ PassportProfileMapper.prototype.getNameIdentifier = function () { return { nameIdentifier: claims[fm.nameIdentifier] || claims[fm.name] || - claims[fm.emailaddress] + claims[fm.email] }; }; diff --git a/test/passportprofilemapper.tests.js b/test/passportprofilemapper.tests.js new file mode 100644 index 0000000..919ab43 --- /dev/null +++ b/test/passportprofilemapper.tests.js @@ -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': 'george@example.com' + }], + 'displayName': null, + 'name': { + 'familyName': null, + 'givenName': null, + } + }) + var output = profileMapper.getNameIdentifier() + expect(output.nameIdentifier).to.eql('george@example.com') + }) + + 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) + }) +}) \ No newline at end of file