Test case added to Check correct principalType for users belonging to different user models

This commit is contained in:
Akshayaprakash Sharma 2018-03-09 02:13:59 +05:30
parent b4cfc249e2
commit a42c2413b8
2 changed files with 46 additions and 3 deletions

View File

@ -87,8 +87,7 @@ function AccessContext(context) {
var token = this.accessToken || {};
if (token.userId) {
var userPrincipalType =
(this.accessToken && this.accessToken.principalType) || Principal.USER;
const userPrincipalType = token.principalType || Principal.USER;
this.addPrincipal(userPrincipalType, token.userId);
}
if (token.appId != null) {

View File

@ -22,7 +22,7 @@ describe('Multiple users with custom principalType', function() {
var commonCredentials = {email: 'foo@bar.com', password: 'bar'};
var app, OneUser, AnotherUser, AccessToken, Role,
userFromOneModel, userFromAnotherModel, userRole, userOneBaseContext;
userFromOneModel, userFromAnotherModel, accessTokenForUserFromOneModel, accessTokenForUserFromAnotherModel, userRole, userOneBaseContext;
beforeEach(function setupAppAndModels() {
// create a local app object that does not share state with other tests
@ -213,6 +213,50 @@ describe('Multiple users with custom principalType', function() {
});
describe('getUser()', function() {
it("Check correct principalType for users belonging to different user models", function() {
Promise.all([
OneUser.login(commonCredentials),
AnotherUser.login(commonCredentials)
]).spread(function(t1, t2) {
accessTokenForUserFromOneModel = t1;
accessTokenForUserFromAnotherModel = t2;
const accessContextForUserFromOneModel = new AccessContext({registry: OneUser.registry, accessToken: accessTokenForUserFromOneModel});
const accessContextForUserFromAnotherModel = new AccessContext({registry: AnotherUser.registry, accessToken: accessTokenForUserFromAnotherModel});
var user1 = accessContextForUserFromOneModel.getUser();
expect(user1).to.eql({
id: userFromOneModel.id,
principalType: OneUser.modelName,
});
var user2 = accessContextForUserFromAnotherModel.getUser();
expect(user2).to.eql({
id: userFromAnotherModel.id,
principalType: AnotherUser.modelName,
});
})
return Promise.try(function() {
addToAccessContext([
{type: Principal.ROLE},
{type: Principal.APP},
{type: Principal.SCOPE},
{type: OneUser.modelName, id: userFromOneModel.id},
]);
var user = accessContext.getUser();
expect(user).to.eql({
id: userFromOneModel.id,
principalType: OneUser.modelName,
});
});
})
it('returns user although principals contain non USER principals',
function() {
return Promise.try(function() {