Skip to content

Commit 1c5b599

Browse files
committed
#RI-4567 - resolve pr comments
1 parent f189736 commit 1c5b599

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export enum CustomErrorCodes {
2-
WindowUnauthorized = 'WindowUnauthorizedException',
2+
WindowUnauthorized = 10_001,
33
}

redisinsight/api/src/modules/auth/window-auth/middleware/window.auth.middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class WindowAuthMiddleware implements NestMiddleware {
1313

1414
async use(req: Request, res: Response, next: NextFunction): Promise<any> {
1515
const { windowId } = WindowAuthMiddleware.getWindowIdFromReq(req);
16-
const isAuthorized = (await this.windowAuthService.getStrategy()?.isAuthorized(windowId)) ?? false;
16+
const isAuthorized = await this.windowAuthService.isAuthorized(windowId);
1717

1818
if (!isAuthorized) {
1919
this.throwError(req, ERROR_MESSAGES.UNDEFINED_WINDOW_ID);

redisinsight/api/src/modules/auth/window-auth/window-auth.service.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AbstractWindowAuthStrategy } from './strategies/abstract.window.auth.st
44

55
export class TestAuthStrategy extends AbstractWindowAuthStrategy {
66
async isAuthorized(): Promise<boolean> {
7-
return false;
7+
return true;
88
}
99
}
1010

@@ -21,8 +21,8 @@ describe('WindowAuthService', () => {
2121

2222
windowAuthService = module.get<WindowAuthService>(WindowAuthService);
2323
});
24-
it('Should set strategy to window auth manager and get it back', () => {
24+
it('Should set strategy to window auth service and call it', async () => {
2525
windowAuthService.setStrategy(testStrategy);
26-
expect(windowAuthService.getStrategy()).toEqual(testStrategy);
26+
expect(await windowAuthService.isAuthorized('')).toEqual(true);
2727
});
2828
});

redisinsight/api/src/modules/auth/window-auth/window-auth.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class WindowAuthService {
1313
this.strategy = strategy;
1414
}
1515

16-
getStrategy(): AbstractWindowAuthStrategy {
17-
return this.strategy;
16+
isAuthorized(id: string = ''): Promise<boolean> {
17+
return this.strategy?.isAuthorized?.(id);
1818
}
1919
}

0 commit comments

Comments
 (0)