Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BCEID bug fix + improvements #717

Merged
merged 8 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/constants/database.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export enum SYSTEM_IDENTITY_SOURCE {
DATABASE = 'DATABASE',
IDIR = 'IDIR',
BCEID = 'BCEID'
BCEID = 'BCEID-BASIC-AND-BUSINESS'
}
15 changes: 8 additions & 7 deletions api/src/paths/access-request.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import chai, { expect } from 'chai';
import { describe } from 'mocha';
import { QueryResult } from 'pg';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import SQL from 'sql-template-strings';
import { SYSTEM_IDENTITY_SOURCE } from '../constants/database';
import * as db from '../database/db';
import { HTTPError } from '../errors/custom-error';
import { IgcNotifyPostReturn } from '../models/gcnotify';
import { UserObject } from '../models/user';
import * as administrative_activity from '../paths/administrative-activity';
import { queries } from '../queries/queries';
import { GCNotifyService } from '../services/gcnotify-service';
import { KeycloakService, KeycloakUser } from '../services/keycloak-service';
import { UserService } from '../services/user-service';
import { getMockDBConnection, getRequestHandlerMocks } from '../__mocks__/db';
import * as access_request from './access-request';
import { queries } from '../queries/queries';
import SQL from 'sql-template-strings';
import { QueryResult } from 'pg';
import { KeycloakService, KeycloakUser } from '../services/keycloak-service';
import { IgcNotifyPostReturn } from '../models/gcnotify';
import { GCNotifyService } from '../services/gcnotify-service';

chai.use(sinonChai);

Expand Down Expand Up @@ -245,7 +246,7 @@ describe('updateAccessRequest', () => {
.stub(GCNotifyService.prototype, 'sendEmailGCNotification')
.resolves(GCNotifyPostReturnObject);

await access_request.sendApprovalEmail(2, mockDBConnection, 'name', 'idir');
await access_request.sendApprovalEmail(2, mockDBConnection, 'name', SYSTEM_IDENTITY_SOURCE.IDIR);

expect(queriesStub).to.be.calledOnce;
expect(getUserByUsernameStub).to.be.calledOnce;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import chai, { expect } from 'chai';
import { describe } from 'mocha';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import { SYSTEM_IDENTITY_SOURCE } from '../../../../constants/database';
import * as db from '../../../../database/db';
import { HTTPError } from '../../../../errors/custom-error';
import { UserService } from '../../../../services/user-service';
Expand All @@ -16,7 +17,7 @@ describe('createProjectParticipants', () => {
const sampleReq = {
keycloak_token: {},
body: {
participants: [['jsmith', 'IDIR', 1]]
participants: [['jsmith', SYSTEM_IDENTITY_SOURCE.IDIR, 1]]
},
params: {
projectId: 1
Expand Down
3 changes: 2 additions & 1 deletion api/src/paths/project/{projectId}/participants/create.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RequestHandler } from 'express';
import { Operation } from 'express-openapi';
import { SYSTEM_IDENTITY_SOURCE } from '../../../../constants/database';
import { PROJECT_ROLE } from '../../../../constants/roles';
import { getDBConnection, IDBConnection } from '../../../../database/db';
import { HTTP400 } from '../../../../errors/custom-error';
Expand Down Expand Up @@ -62,7 +63,7 @@ POST.apiDoc = {
},
identitySource: {
type: 'string',
enum: ['IDIR', 'BCEID']
enum: [SYSTEM_IDENTITY_SOURCE.IDIR, SYSTEM_IDENTITY_SOURCE.BCEID]
},
roleId: {
description: 'The id of the project role to assign to the participant.',
Expand Down
3 changes: 2 additions & 1 deletion api/src/paths/user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RequestHandler } from 'express';
import { Operation } from 'express-openapi';
import { SYSTEM_IDENTITY_SOURCE } from '../constants/database';
import { SYSTEM_ROLE } from '../constants/roles';
import { getDBConnection } from '../database/db';
import { HTTP400 } from '../errors/custom-error';
Expand Down Expand Up @@ -45,7 +46,7 @@ DELETE.apiDoc = {
},
identitySource: {
type: 'string',
enum: ['idir', 'bceid']
enum: [SYSTEM_IDENTITY_SOURCE.IDIR, SYSTEM_IDENTITY_SOURCE.BCEID]
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions api/src/paths/user/add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import chai, { expect } from 'chai';
import { describe } from 'mocha';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import { SYSTEM_IDENTITY_SOURCE } from '../../constants/database';
import * as db from '../../database/db';
import { HTTPError } from '../../errors/custom-error';
import { UserObject } from '../../models/user';
Expand Down Expand Up @@ -45,7 +46,7 @@ describe('user', () => {
const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();

mockReq.body = {
identitySource: 'IDIR',
identitySource: SYSTEM_IDENTITY_SOURCE.IDIR,
roleId: 1
};

Expand Down Expand Up @@ -92,7 +93,7 @@ describe('user', () => {

mockReq.body = {
userIdentifier: 'username',
identitySource: 'IDIR'
identitySource: SYSTEM_IDENTITY_SOURCE.IDIR
};

try {
Expand All @@ -115,7 +116,7 @@ describe('user', () => {

mockReq.body = {
userIdentifier: 'username',
identitySource: 'IDIR',
identitySource: SYSTEM_IDENTITY_SOURCE.IDIR,
roleId: 1
};

Expand Down
3 changes: 2 additions & 1 deletion api/src/paths/user/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { HTTP400 } from '../../errors/custom-error';
import { authorizeRequestHandler } from '../../request-handlers/security/authorization';
import { UserService } from '../../services/user-service';
import { getLogger } from '../../utils/logger';
import { SYSTEM_IDENTITY_SOURCE } from '../../constants/database';

const defaultLog = getLogger('paths/user/add');

Expand Down Expand Up @@ -45,7 +46,7 @@ POST.apiDoc = {
},
identitySource: {
type: 'string',
enum: ['idir', 'bceid']
enum: [SYSTEM_IDENTITY_SOURCE.IDIR, SYSTEM_IDENTITY_SOURCE.BCEID]
},
roleId: {
type: 'number',
Expand Down
25 changes: 13 additions & 12 deletions api/src/services/user-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { QueryResult } from 'pg';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import SQL from 'sql-template-strings';
import { SYSTEM_IDENTITY_SOURCE } from '../constants/database';
import { ApiError } from '../errors/custom-error';
import { UserObject } from '../models/user';
import { queries } from '../queries/queries';
Expand Down Expand Up @@ -128,7 +129,7 @@ describe('UserService', () => {
sinon.stub(queries.users, 'addSystemUserSQL').returns(null);

const userIdentifier = 'username';
const identitySource = 'idir';
const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR;

try {
await userService.addSystemUser(userIdentifier, identitySource);
Expand All @@ -147,7 +148,7 @@ describe('UserService', () => {
sinon.stub(queries.users, 'addSystemUserSQL').returns(SQL`valid sql`);

const userIdentifier = 'username';
const identitySource = 'idir';
const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR;

try {
await userService.addSystemUser(userIdentifier, identitySource);
Expand All @@ -168,7 +169,7 @@ describe('UserService', () => {
const addSystemUserSQLStub = sinon.stub(queries.users, 'addSystemUserSQL').returns(SQL`valid sql`);

const userIdentifier = 'username';
const identitySource = 'idir';
const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR;

const result = await userService.addSystemUser(userIdentifier, identitySource);

Expand Down Expand Up @@ -255,7 +256,7 @@ describe('UserService', () => {
const activateSystemUserStub = sinon.stub(UserService.prototype, 'activateSystemUser');

const userIdentifier = 'username';
const identitySource = 'idir';
const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR;

const userService = new UserService(mockDBConnection);

Expand Down Expand Up @@ -285,7 +286,7 @@ describe('UserService', () => {
const activateSystemUserStub = sinon.stub(UserService.prototype, 'activateSystemUser');

const userIdentifier = 'username';
const identitySource = 'idir';
const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR;

const userService = new UserService(mockDBConnection);

Expand All @@ -304,7 +305,7 @@ describe('UserService', () => {

const existingInactiveSystemUser = new UserObject({
system_user_id: 2,
user_identifier: 'idir',
user_identifier: SYSTEM_IDENTITY_SOURCE.IDIR,
record_end_date: null,
role_ids: [1],
role_names: ['Editor']
Expand All @@ -318,7 +319,7 @@ describe('UserService', () => {
const activateSystemUserStub = sinon.stub(UserService.prototype, 'activateSystemUser');

const userIdentifier = 'username';
const identitySource = 'idir';
const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR;

const userService = new UserService(mockDBConnection);

Expand All @@ -337,7 +338,7 @@ describe('UserService', () => {

const existingSystemUser = new UserObject({
system_user_id: 2,
user_identifier: 'idir',
user_identifier: SYSTEM_IDENTITY_SOURCE.IDIR,
record_end_date: '2021-11-22',
role_ids: [1],
role_names: ['Editor']
Expand All @@ -354,7 +355,7 @@ describe('UserService', () => {
const getUserByIdStub = sinon.stub(UserService.prototype, 'getUserById').resolves(activatedSystemUser);

const userIdentifier = 'username';
const identitySource = 'idir';
const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR;

const userService = new UserService(mockDBConnection);

Expand All @@ -376,7 +377,7 @@ describe('UserService', () => {

const existingSystemUser = new UserObject({
system_user_id: 2,
user_identifier: 'idir',
user_identifier: SYSTEM_IDENTITY_SOURCE.IDIR,
record_end_date: '2021-11-22',
role_ids: [1],
role_names: ['Editor']
Expand All @@ -391,15 +392,15 @@ describe('UserService', () => {

const activatedSystemUser = new UserObject({
system_user_id: 2,
user_identifier: 'idir',
user_identifier: SYSTEM_IDENTITY_SOURCE.IDIR,
record_end_date: null,
role_ids: [1],
role_names: ['Editor']
});
const getUserByIdStub = sinon.stub(UserService.prototype, 'getUserById').resolves(activatedSystemUser);

const userIdentifier = 'username';
const identitySource = 'idir';
const identitySource = SYSTEM_IDENTITY_SOURCE.IDIR;

const userService = new UserService(mockDBConnection);

Expand Down
2 changes: 1 addition & 1 deletion api/src/utils/keycloak-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('getUserIdentitySource', () => {
});

it('returns non null response when valid keycloakToken provided with bceid source', () => {
const response = getUserIdentitySource({ preferred_username: 'username@bceid' });
const response = getUserIdentitySource({ preferred_username: 'username@bceid-basic-and-business' });

expect(response).to.equal(SYSTEM_IDENTITY_SOURCE.BCEID);
});
Expand Down
12 changes: 6 additions & 6 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/src/components/layout/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AuthStateContext } from 'contexts/authStateContext';
import { createMemoryHistory } from 'history';
import React from 'react';
import { Router } from 'react-router-dom';
import Header from './Header';
import Header, { SYSTEM_IDENTITY_SOURCE } from './Header';

const history = createMemoryHistory();

Expand Down Expand Up @@ -73,7 +73,7 @@ describe('Header', () => {
getUserIdentifier: () => 'testuser',
hasAccessRequest: false,
hasSystemRole: mockHasSystemRole,
getIdentitySource: () => 'bceid',
getIdentitySource: () => SYSTEM_IDENTITY_SOURCE.BCEID,
username: 'testusername',
displayName: 'testdisplayname',
email: '[email protected]',
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('Header', () => {
getUserIdentifier: () => 'testuser',
hasAccessRequest: false,
hasSystemRole: jest.fn(),
getIdentitySource: () => 'bceid',
getIdentitySource: () => SYSTEM_IDENTITY_SOURCE.BCEID,
username: 'testusername',
displayName: 'testdisplayname',
email: '[email protected]',
Expand Down
13 changes: 12 additions & 1 deletion app/src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ const useStyles = makeStyles((theme: Theme) => ({
}
}));

export enum SYSTEM_IDENTITY_SOURCE {
DATABASE = 'DATABASE',
IDIR = 'IDIR',
BCEID = 'BCEID-BASIC-AND-BUSINESS'
}

const Header: React.FC = () => {
const classes = useStyles();
const config = useContext(ConfigContext);
Expand All @@ -121,7 +127,12 @@ const Header: React.FC = () => {

// Authenticated view
const LoggedInUser = () => {
const loggedInUserDisplayName = `${keycloakWrapper?.getIdentitySource()} / ${keycloakWrapper?.getUserIdentifier()}`.toUpperCase();
const identitySource = keycloakWrapper?.getIdentitySource()?.toUpperCase();

const userIdentifier = keycloakWrapper?.getUserIdentifier()?.toUpperCase();

const loggedInUserDisplayName =
identitySource === SYSTEM_IDENTITY_SOURCE.BCEID ? `BCEID / ${userIdentifier}` : `IDIR / ${userIdentifier}`;

return (
<Box display="flex" className={classes.userProfile} my="auto" alignItems="center">
Expand Down
Loading