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

Adding health check to the service, also added a global prefix for APIs #10

Merged
merged 3 commits into from
Apr 17, 2024
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
164 changes: 157 additions & 7 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "ISSUER=\"https://dev-18092578.okta.com/oauth2/default\" CLIENT_ID=\"0oa2fqtaz95fqJqbf5d7\" jest",
"test:watch": "ISSUER=\"https://dev-18092578.okta.com/oauth2/default\" CLIENT_ID=\"0oa2fqtaz95fqJqbf5d7\" jest --watch",
"test:cov": "ISSUER=\"https://dev-18092578.okta.com/oauth2/default\" CLIENT_ID=\"0oa2fqtaz95fqJqbf5d7\" jest --coverage",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
Expand All @@ -26,6 +26,7 @@
"@nestjs/core": "^10.3.5",
"@nestjs/jwt": "^10.2.0",
"@nestjs/platform-express": "^10.3.5",
"@nestjs/terminus": "^10.2.3",
"@okta/jwt-verifier": "^3.1.0",
"cqm-models": "4.1.3",
"exceljs": "^4.4.0",
Expand Down
50 changes: 21 additions & 29 deletions src/auth/auth.guard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,31 @@ import { AuthGuard } from './auth.guard';
import { JwtService } from '@nestjs/jwt';
import { createMock } from '@golevelup/ts-jest';
import { ExecutionContext } from '@nestjs/common';
import { Jwt } from '@okta/jwt-verifier';
import * as process from 'process';

jest.mock('@okta/jwt-verifier', () => {
return jest.fn().mockImplementation(() => {
return {
verifyAccessToken: () =>
new Promise((resolve) =>
resolve({
claims: {
sub: 'a_user',
},
} as unknown as Jwt),
),
};
});
});

describe('AuthGuard', () => {
let guard: AuthGuard;

beforeEach(async () => {
process.env.ISSUER = 'https://test-issuer.com';
process.env.CLIENT_ID = 'test-client-id';

const module: TestingModule = await Test.createTestingModule({
providers: [JwtService],
}).compile();
Expand All @@ -22,33 +42,6 @@ describe('AuthGuard', () => {
it('should have a fully mocked Execution Context with good auth token', async () => {
const mockExecutionContext = createMock<ExecutionContext>();
expect(mockExecutionContext.switchToHttp()).toBeDefined();

mockExecutionContext.switchToHttp = jest.fn().mockResolvedValue({
getRequest: () => ({
originalUrl: '/',
method: 'GET',
params: undefined,
query: undefined,
body: undefined,
headers: '',
}),
getResponse: () => ({
statusCode: 200,
}),
});

jest.mock('@okta/jwt-verifier', () => {
return jest.fn().mockImplementation(() => ({
verifyAccessToken: () => ({
oktaToken: {
claims: {
sub: 'a_user',
},
},
}),
}));
});

jest
.spyOn(mockExecutionContext.switchToHttp(), 'getRequest')
.mockImplementation(() => {
Expand All @@ -59,8 +52,7 @@ describe('AuthGuard', () => {
query: undefined,
body: undefined,
headers: {
authorization:
'Bearer eyJraWQiOiJNNG9CMW9DSmthdC0tYTNENFFXUFA3RWZCbUl3NG9BV05KYWJxdEJhUnM4IiwiYWxnIjoiUlMyNTYifQ.eyJ2ZXIiOjEsImp0aSI6IkFULl8xc1BEY0hpekhSdm5CSlZsaWQzak5tVXZjMDIzU3FCZDB0UUhnVldkT0EiLCJpc3MiOiJodHRwczovL2Rldi0xODA5MjU3OC5va3RhLmNvbS9vYXV0aDIvZGVmYXVsdCIsImF1ZCI6ImFwaTovL2RlZmF1bHQiLCJpYXQiOjE3MTI5MzcwNjQsImV4cCI6MTcxMjk0MDY2NCwiY2lkIjoiMG9hMmZxdGF6OTVmcUpxYmY1ZDciLCJ1aWQiOiIwMHUzaTNjM3p6WlhLcjkwMTVkNyIsInNjcCI6WyJvcGVuaWQiLCJwcm9maWxlIl0sImF1dGhfdGltZSI6MTcxMjkzMjU5NSwic3ViIjoiY2VjaWxpYS5saXVAc2VtYW50aWNiaXRzLmNvbSJ9.x_vx7uCGXPyme80erURcS87ZUdibdBRKiNB58yg-AcNoF0ZYoro0lOr9up-ev0j32SQvBnhMXRZOARoOy4ALcT_GovwluH2v_sjXhNtjn26GV5UZU1EaWXsdMWfwg_-6eAmlQ9dLkIZerIYsu7Ut8pfwirgbpME4mMKqiJBXEkRWHUkAh5PEnJO4DvaKj6Tis5ERprNLuUKR5M4bWMhBjAMt74fTu5iLiANOi0uqropZscP72HVNEQhkyqM84hvgAvZvzlVYKUTUBuoWQF21eRSOUpYSE0yvDRW5JS5r0NCXUEZwuNfavuvl3gDUae31hcbtOo7kznQ2Q_-GkfVThA',
authorization: 'Bearer asdf',
},
} as unknown as Request;
});
Expand Down
6 changes: 4 additions & 2 deletions src/export.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { Module } from '@nestjs/common';
import { ExportController } from './controllers/export.controller';
import { ExportService } from './services/export.service';
import { AuthModule } from './auth/auth.module';
import { TerminusModule } from '@nestjs/terminus';
import { HealthController } from './health/health.controller';

@Module({
imports: [AuthModule],
controllers: [ExportController],
imports: [AuthModule, TerminusModule],
controllers: [ExportController, HealthController],
providers: [ExportService],
})
export class ExportModule {}
Loading
Loading