-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SIMSBIOHUB-308: System API User Add Bug (#1127)
* add back removed functionality * Fixed 'Failed to identify authenticated user' test * Added back numeric type parser to db * Fixed remaining tests --------- Co-authored-by: Curtis Upshall <[email protected]> Co-authored-by: Nick Phura <[email protected]> Co-authored-by: Nick Phura <[email protected]>
- Loading branch information
1 parent
2960d9b
commit 69f4781
Showing
12 changed files
with
1,903 additions
and
921 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,15 @@ | ||
import { expect } from 'chai'; | ||
import { QueryResult } from 'pg'; | ||
import sinon from 'sinon'; | ||
import { z } from 'zod'; | ||
import { getZodQueryResult } from './db-utils'; | ||
import { SYSTEM_IDENTITY_SOURCE } from '../constants/database'; | ||
import { | ||
BceidBasicUserInformation, | ||
BceidBusinessUserInformation, | ||
DatabaseUserInformation, | ||
IdirUserInformation | ||
} from '../utils/keycloak-utils'; | ||
import { getGenericizedKeycloakUserInformation, getZodQueryResult } from './db-utils'; | ||
|
||
/** | ||
* Enforces that a zod schema satisfies an existing type definition. | ||
|
@@ -49,5 +58,110 @@ describe('getZodQueryResult', () => { | |
|
||
// Not a traditional test: will just cause a compile error if the zod schema doesn't satisfy the `QueryResult` type | ||
zodImplements<QueryResult>().with(zodQueryResult.shape); | ||
|
||
// Dummy assertion to satisfy linter | ||
expect(true).to.be.true; | ||
}); | ||
}); | ||
|
||
describe('getGenericizedKeycloakUserInformation', () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('identifies a database user information object and returns null', () => { | ||
const keycloakUserInformation: DatabaseUserInformation = { | ||
database_user_guid: '123456789', | ||
identity_provider: 'database', | ||
username: 'biohub_dapi_v1' | ||
}; | ||
|
||
const result = getGenericizedKeycloakUserInformation(keycloakUserInformation); | ||
|
||
expect(result).to.be.null; | ||
}); | ||
|
||
it('identifies an idir user information object and returns a genericized object', () => { | ||
const keycloakUserInformation: IdirUserInformation = { | ||
idir_user_guid: '123456789', | ||
identity_provider: 'idir', | ||
idir_username: 'testuser', | ||
email_verified: false, | ||
name: 'test user', | ||
preferred_username: 'testguid@idir', | ||
display_name: 'test user', | ||
given_name: 'test', | ||
family_name: 'user', | ||
email: '[email protected]' | ||
}; | ||
|
||
const result = getGenericizedKeycloakUserInformation(keycloakUserInformation); | ||
|
||
expect(result).to.eql({ | ||
user_guid: keycloakUserInformation.idir_user_guid, | ||
user_identifier: keycloakUserInformation.idir_username, | ||
user_identity_source: SYSTEM_IDENTITY_SOURCE.IDIR, | ||
display_name: keycloakUserInformation.display_name, | ||
email: keycloakUserInformation.email, | ||
given_name: keycloakUserInformation.given_name, | ||
family_name: keycloakUserInformation.family_name | ||
}); | ||
}); | ||
|
||
it('identifies a bceid business user information object and returns a genericized object', () => { | ||
const keycloakUserInformation: BceidBusinessUserInformation = { | ||
bceid_business_guid: '1122334455', | ||
bceid_business_name: 'Business Name', | ||
bceid_user_guid: '123456789', | ||
identity_provider: 'bceidbusiness', | ||
bceid_username: 'tname', | ||
name: 'Test Name', | ||
preferred_username: '123456789@bceidbusiness', | ||
display_name: 'Test Name', | ||
email: '[email protected]', | ||
email_verified: false, | ||
given_name: 'Test', | ||
family_name: '' | ||
}; | ||
|
||
const result = getGenericizedKeycloakUserInformation(keycloakUserInformation); | ||
|
||
expect(result).to.eql({ | ||
user_guid: keycloakUserInformation.bceid_user_guid, | ||
user_identifier: keycloakUserInformation.bceid_username, | ||
user_identity_source: SYSTEM_IDENTITY_SOURCE.BCEID_BUSINESS, | ||
display_name: keycloakUserInformation.display_name, | ||
email: keycloakUserInformation.email, | ||
given_name: keycloakUserInformation.given_name, | ||
family_name: keycloakUserInformation.family_name, | ||
agency: keycloakUserInformation.bceid_business_name | ||
}); | ||
}); | ||
|
||
it('identifies a bceid basic user information object and returns a genericized object', () => { | ||
const keycloakUserInformation: BceidBasicUserInformation = { | ||
bceid_user_guid: '123456789', | ||
identity_provider: 'bceidbasic', | ||
bceid_username: 'tname', | ||
name: 'Test Name', | ||
preferred_username: '123456789@bceidbasic', | ||
display_name: 'Test Name', | ||
email: '[email protected]', | ||
email_verified: false, | ||
given_name: 'Test', | ||
family_name: '' | ||
}; | ||
|
||
const result = getGenericizedKeycloakUserInformation(keycloakUserInformation); | ||
|
||
expect(result).to.eql({ | ||
user_guid: keycloakUserInformation.bceid_user_guid, | ||
user_identifier: keycloakUserInformation.bceid_username, | ||
user_identity_source: SYSTEM_IDENTITY_SOURCE.BCEID_BASIC, | ||
display_name: keycloakUserInformation.display_name, | ||
email: keycloakUserInformation.email, | ||
given_name: keycloakUserInformation.given_name, | ||
family_name: keycloakUserInformation.family_name | ||
}); | ||
}); | ||
}); |
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
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
Oops, something went wrong.