-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Enable retrieval of a user's email address from IMS given an ac…
…cess token #193
- Loading branch information
Showing
1 changed file
with
39 additions
and
2 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 |
---|---|---|
|
@@ -283,20 +283,57 @@ describe('ImsClient', () => { | |
}); | ||
|
||
describe('getImsUserProfile', () => { | ||
const testAccessToken = 'eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjEyMzQ1IiwidHlwZSI6ImFjY2Vzc190b2tlbiIsImNsaWVudF9pZCI6ImV4YW1wbGVfYXBwIiwidXNlcl9pZCI6Ijk4NzY1NDc4OTBBQkNERUYxMjM0NTY3OEBhYmNkZWYxMjM0NTY3ODkuZSIsImFzIjoiaW1zLW5hMSIsImFhX2lkIjoiMTIzNDU2Nzg5MEFCQ0RFRjEyMzQ1Njc4QGFkb2JlLmNvbSIsImNyZWF0ZWRfYXQiOiIxNzEwMjQ3MDAwMDAwIn0.MRDpxgxSHDj4DmA182hPnjMAnKkly-VUJ_bXpQ-J8EQ'; | ||
Check failure Code scanning / CodeQL Hard-coded credentials Critical test
The hard-coded value "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjEyMzQ1IiwidHlwZSI6ImFjY2Vzc190b2tlbiIsImNsaWVudF9pZCI6ImV4YW1wbGVfYXBwIiwidXNlcl9pZCI6Ijk4NzY1NDc4OTBBQkNERUYxMjM0NTY3OEBhYmNkZWYxMjM0NTY3ODkuZSIsImFzIjoiaW1zLW5hMSIsImFhX2lkIjoiMTIzNDU2Nzg5MEFCQ0RFRjEyMzQ1Njc4QGFkb2JlLmNvbSIsImNyZWF0ZWRfYXQiOiIxNzEwMjQ3MDAwMDAwIn0.MRDpxgxSHDj4DmA182hPnjMAnKkly-VUJ_bXpQ-J8EQ" is used as
authorization header Error loading related location Loading |
||
let client; | ||
|
||
beforeEach(() => { | ||
client = ImsClient.createFrom(mockContext); | ||
}); | ||
|
||
it('should fail for edge cases: no token', async () => { | ||
nock(`https://${DUMMY_HOST}`) | ||
.get('/ims/profile/v1') | ||
.matchHeader('Authorization', (val) => val === `Bearer ${testAccessToken}`) | ||
.reply(200, { | ||
preferred_languages: ['en-us'], | ||
displayName: 'Example User', | ||
roles: [ | ||
{ | ||
organization: '1234567890ABCDEF12345678@AdobeOrg', | ||
named_role: 'user_admin_grp', | ||
}, | ||
{ | ||
organization: '1234567890ABCDEF12345678@AdobeOrg', | ||
named_role: 'PRODUCT_ADMIN', | ||
}, | ||
], | ||
userId: '[email protected]', | ||
countryCode: 'CA', | ||
email: '[email protected]', | ||
}); | ||
|
||
// Fallback | ||
nock(`https://${DUMMY_HOST}`) | ||
.get('/ims/profile/v1') | ||
.reply(401, { | ||
error: 'invalid_token', | ||
error_description: 'Invalid or expired token.', | ||
}); | ||
}); | ||
|
||
it('should fail for edge cases: no token', async () => { | ||
await expect(client.getImsUserProfile(null)).to.be.rejectedWith('IMS getImsUserProfile request failed with status: 401'); | ||
}); | ||
|
||
it('should fail for edge cases: invalid token', async () => { | ||
await expect(client.getImsUserProfile('eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjEyMzQ1IiwidHlwZSI6')).to.be.rejectedWith('IMS getImsUserProfile request failed with status: 401'); | ||
Check failure Code scanning / CodeQL Hard-coded credentials Critical test
The hard-coded value "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjEyMzQ1IiwidHlwZSI6" is used as
authorization header Error loading related location Loading |
||
}); | ||
|
||
it('should succeed for a valid token', async () => { | ||
const result = await client.getImsUserProfile(testAccessToken); | ||
await expect(result).to.deep.equal({ | ||
email: '[email protected]', | ||
userId: '[email protected]', | ||
organizations: ['1234567890ABCDEF12345678@AdobeOrg'], | ||
}); | ||
}); | ||
}); | ||
}); |