-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/audit #36
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
Open
manjik-rumsan
wants to merge
17
commits into
dev
Choose a base branch
from
feature/audit
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+315
−323
Open
Feature/audit #36
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
47d820a
Merge pull request #15 from rumsan/dev
manjik-rumsan 13bb3cd
Merge pull request #26 from rumsan/dev
manjik-rumsan 87cf669
Merge pull request #27 from rumsan/stage
manjik-rumsan ba5329d
Merge pull request #30 from rumsan/dev
manjik-rumsan b407ee0
Merge pull request #31 from rumsan/stage
manjik-rumsan ea31327
chore: User Schema & Controller Refactor
7d3f34d
chore: Setting up User Constant in the extensions.
50cea2c
Merge pull request #32 from rumsan/audit-schema
manjik-rumsan 66f42d2
Merge pull request #33 from rumsan/settings-setup-audit
manjik-rumsan 450e1a4
refactor: Move JwtGuard to the extension
f824cf5
refactor: Settings Service for Auditing.
08e538d
Merge remote-tracking branch 'origin/main' into settings-setup-audit
f94aa2d
Merge pull request #34 from rumsan/settings-setup-audit
manjik-rumsan 336331e
refactor: use public decorator for public route & change in auth tabl…
9a393b9
Merge pull request #35 from rumsan/settings-setup-audit
manjik-rumsan d883d04
refactor: Removal of log and Change in schema as per comments
5d4f509
Merge remote-tracking branch 'origin/settings-setup-audit' into featu…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
8 changes: 4 additions & 4 deletions
8
libs/user/src/lib/constants/errors.ts → libs/extensions/src/constants/errors.ts
This file contains hidden or 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
File renamed without changes.
This file contains hidden or 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
2 changes: 1 addition & 1 deletion
2
...auths/decorator/current-user.decorator.ts → ...s/src/decorators/currentUser.decorator.ts
100755 → 100644
This file contains hidden or 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 hidden or 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,2 +1,4 @@ | ||
| export * from './currentUser.decorator'; | ||
| export * from './param.uuid.decorator'; | ||
| export * from './public.decorator'; | ||
| export * from './request.decorator'; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { SetMetadata } from '@nestjs/common'; | ||
| import { IS_PUBLIC_KEY } from '../constants'; | ||
|
|
||
| export const Public = () => SetMetadata(IS_PUBLIC_KEY, true); |
This file contains hidden or 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 hidden or 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
File renamed without changes.
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common'; | ||
| import { Reflector } from '@nestjs/core'; | ||
| import { AuthGuard } from '@nestjs/passport'; | ||
| import { Observable } from 'rxjs'; | ||
| import { IS_PUBLIC_KEY } from '../constants'; | ||
|
|
||
| @Injectable() | ||
| export class JwtGuard extends AuthGuard('jwt') implements CanActivate { | ||
| constructor(private reflector: Reflector) { | ||
| super(); | ||
| } | ||
| override canActivate( | ||
| context: ExecutionContext, | ||
| ): boolean | Promise<boolean> | Observable<boolean> { | ||
| const isPublic = this.reflector.get<boolean>( | ||
| IS_PUBLIC_KEY, | ||
| context.getHandler(), | ||
| ); | ||
|
|
||
| if (isPublic) return true; | ||
| return super.canActivate(context); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,63 +1,101 @@ | ||
| import { SettingsService } from './settings.service'; | ||
|
|
||
| describe('SettingsService', () => { | ||
| let service: SettingsService; | ||
| let prismaMock: any; | ||
|
|
||
| beforeEach(() => { | ||
| prismaMock = { | ||
| setting: { | ||
| findMany: jest.fn(), | ||
| findUnique: jest.fn(), | ||
| }, | ||
| }; | ||
| service = new SettingsService(prismaMock); | ||
| }); | ||
| let service: SettingsService; | ||
| let prismaMock: any; | ||
|
|
||
| it('should return public settings', async () => { | ||
| const mockSettings = [ | ||
| { name: 'SMTP', value: { "HOST": "smtp.gmail.com", "PORT": 465, "SECURE": true, "PASSWORD": "test", "USERNAME": "test" }, isPrivate: false }, | ||
| { name: 'SMTP1', value: { "HOST": "smtp.gmail.com", "PORT": 465, "SECURE": true, "PASSWORD": "test", "USERNAME": "test" }, isPrivate: false }, | ||
| ]; | ||
| beforeEach(() => { | ||
| prismaMock = { | ||
| setting: { | ||
| findMany: jest.fn(), | ||
| findUnique: jest.fn(), | ||
| }, | ||
| }; | ||
| service = new SettingsService(prismaMock); | ||
| }); | ||
|
|
||
| prismaMock.setting.findMany.mockResolvedValue(mockSettings); | ||
| it('should return public settings', async () => { | ||
| const mockSettings = [ | ||
| { | ||
| name: 'SMTP', | ||
| value: { | ||
| HOST: 'smtp.gmail.com', | ||
| PORT: 465, | ||
| SECURE: true, | ||
| PASSWORD: 'test', | ||
| USERNAME: 'test', | ||
| }, | ||
| isPrivate: false, | ||
| }, | ||
| { | ||
| name: 'SMTP1', | ||
| value: { | ||
| HOST: 'smtp.gmail.com', | ||
| PORT: 465, | ||
| SECURE: true, | ||
| PASSWORD: 'test', | ||
| USERNAME: 'test', | ||
| }, | ||
| isPrivate: false, | ||
| }, | ||
| ]; | ||
|
|
||
| const result = await service.listPublic(); | ||
| console.log(result) | ||
| prismaMock.setting.findMany.mockResolvedValue(mockSettings); | ||
|
|
||
| expect(result).toEqual({ | ||
| SMTP: { "HOST": "smtp.gmail.com", "PORT": 465, "SECURE": true, "PASSWORD": "test", "USERNAME": "test" }, | ||
| SMTP1: { "HOST": "smtp.gmail.com", "PORT": 465, "SECURE": true, "PASSWORD": "test", "USERNAME": "test" }, | ||
| }); | ||
| expect(prismaMock.setting.findMany).toHaveBeenCalledWith({ | ||
| where: { isPrivate: false }, | ||
| }); | ||
| }); | ||
| const result = await service.listPublic(); | ||
|
|
||
| expect(result).toEqual({ | ||
| SMTP: { | ||
| HOST: 'smtp.gmail.com', | ||
| PORT: 465, | ||
| SECURE: true, | ||
| PASSWORD: 'test', | ||
| USERNAME: 'test', | ||
| }, | ||
| SMTP1: { | ||
| HOST: 'smtp.gmail.com', | ||
| PORT: 465, | ||
| SECURE: true, | ||
| PASSWORD: 'test', | ||
| USERNAME: 'test', | ||
| }, | ||
| }); | ||
| expect(prismaMock.setting.findMany).toHaveBeenCalledWith({ | ||
| where: { isPrivate: false }, | ||
| }); | ||
| }); | ||
|
|
||
| it('should return a public setting by name', async () => { | ||
| const mockSetting = { name: 'SMTP', value: { "HOST": "smtp.gmail.com", "PORT": 465, "SECURE": true, "PASSWORD": "test", "USERNAME": "test" }, isPrivate: false }; | ||
| it('should return a public setting by name', async () => { | ||
| const mockSetting = { | ||
| name: 'SMTP', | ||
| value: { | ||
| HOST: 'smtp.gmail.com', | ||
| PORT: 465, | ||
| SECURE: true, | ||
| PASSWORD: 'test', | ||
| USERNAME: 'test', | ||
| }, | ||
| isPrivate: false, | ||
| }; | ||
|
|
||
| prismaMock.setting.findUnique.mockResolvedValue(mockSetting); | ||
| prismaMock.setting.findUnique.mockResolvedValue(mockSetting); | ||
|
|
||
| const result = await service.getPublic('SMTP'); | ||
| const result = await service.getPublic('SMTP'); | ||
|
|
||
| expect(result).toEqual(mockSetting); | ||
| expect(prismaMock.setting.findUnique).toHaveBeenCalledWith({ | ||
| where: { name: 'SMTP', isPrivate: false }, | ||
| }); | ||
| expect(result).toEqual(mockSetting); | ||
| expect(prismaMock.setting.findUnique).toHaveBeenCalledWith({ | ||
| where: { name: 'SMTP', isPrivate: false }, | ||
| }); | ||
| }); | ||
|
|
||
| it('should throw an error if a public setting is not found', async () => { | ||
| prismaMock.setting.findUnique.mockResolvedValue(null); | ||
|
|
||
|
|
||
| it('should throw an error if a public setting is not found', async () => { | ||
| prismaMock.setting.findUnique.mockResolvedValue(null); | ||
|
|
||
| await expect(service.getPublic('NONEXISTENT')).rejects.toThrow( | ||
| "Public setting 'NONEXISTENT' not found" | ||
| ); | ||
| expect(prismaMock.setting.findUnique).toHaveBeenCalledWith({ | ||
| where: { name: 'NONEXISTENT', isPrivate: false }, | ||
| }); | ||
| await expect(service.getPublic('NONEXISTENT')).rejects.toThrow( | ||
| "Public setting 'NONEXISTENT' not found", | ||
| ); | ||
| expect(prismaMock.setting.findUnique).toHaveBeenCalledWith({ | ||
| where: { name: 'NONEXISTENT', isPrivate: false }, | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.