Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
fix: Added usernameInIdp property to update user schema (#292)
Browse files Browse the repository at this point in the history
This change fixes authentication of users who are added by admin from ServiceWorkbench UI directly
  • Loading branch information
jn1119 authored Feb 8, 2021
1 parent 228061a commit 13be62e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
"type": "string",
"pattern": "^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"
},
"usernameInIdp": {
"type": "string",
"minLength": 3,
"maxLength": 300,
"pattern": "^[A-Za-z0-9-_.]+$|^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"
},
"firstName": {
"type": "string",
"maxLength": 500
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,56 @@ describe('UserService', () => {
service.assertAuthorized = jest.fn();
});

describe('updateUser', () => {
it('should not fail validation when usernameInIdp in schema', async () => {
const user = {
email: '[email protected]',
usernameInIdp: 'example',
uid: 'user1',
rev: 0,
};

// mocked functions
service.toUserType = jest.fn(() => {
return { userType: 'root' };
});
service.getUserByPrincipal = jest.fn(() => {
return null;
});
service.findUser = jest.fn(() => {
return user;
});
await service.updateUser({}, user);
});

it('should fail validation when unknown property in schema', async () => {
const user = {
email: '[email protected]',
usernameInIdp: 'example',
uid: 'user1',
rev: 0,
unknown: 'unknownProperty',
};

// mocked functions
service.toUserType = jest.fn(() => {
return { userType: 'root' };
});
service.getUserByPrincipal = jest.fn(() => {
return null;
});
service.findUser = jest.fn(() => {
return user;
});
try {
await service.updateUser({}, user);
expect.fail('Expected to throw error validation errors');
} catch (err) {
expect(err.message).toEqual('Input has validation errors');
}
});
});

describe('createUsers', () => {
it('should try to create a user', async () => {
const user = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
"uid": {
"type": "string"
},
"usernameInIdp": {
"type": "string",
"minLength": 3,
"maxLength": 300,
"pattern": "^[A-Za-z0-9-_.]+$|^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"
},
"email": {
"type": "string",
"pattern": "^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ describe('UserService', () => {
// BUILD
const toUpdate = {
uid,
usernameInIdp: 'user1',
rev: 2,
};

Expand Down

0 comments on commit 13be62e

Please sign in to comment.