diff --git a/services/liquid-auth-api-js/src/connect/connect.controller.spec.ts b/services/liquid-auth-api-js/src/connect/connect.controller.spec.ts index 0f9a6d1..f6b859f 100644 --- a/services/liquid-auth-api-js/src/connect/connect.controller.spec.ts +++ b/services/liquid-auth-api-js/src/connect/connect.controller.spec.ts @@ -6,6 +6,7 @@ import { Session } from './session.schema'; import { accFixture } from '../../tests/constants'; import { mockAuthService } from '../__mocks__/auth.service.mock'; import { mockAccountLinkService } from '../__mocks__/account-link.service.mock'; +import { ForbiddenException } from '@nestjs/common'; describe('ConnectController', () => { let connectController: ConnectController; @@ -75,7 +76,7 @@ describe('ConnectController', () => { await expect( connectController.linkWalletResponse(session, linkResponseDTO), - ).rejects.toThrowError(); + ).rejects.toThrow(ForbiddenException); }); it('(CREATED) should return undefined when a valid account & auth address signature requests to connect', async () => { diff --git a/services/liquid-auth-api-js/src/connect/connect.controller.ts b/services/liquid-auth-api-js/src/connect/connect.controller.ts index a058947..45acb4c 100644 --- a/services/liquid-auth-api-js/src/connect/connect.controller.ts +++ b/services/liquid-auth-api-js/src/connect/connect.controller.ts @@ -7,6 +7,8 @@ import { Logger, HttpException, HttpStatus, + InternalServerErrorException, + ForbiddenException, } from '@nestjs/common'; import { ClientProxy } from '@nestjs/microservices'; import { AuthService } from '../auth/auth.service.js'; @@ -85,14 +87,11 @@ export class ConnectController { .exclude('all') .do(); } catch (e) { - throw new HttpException( - 'Failed to fetch Account Info', - HttpStatus.INTERNAL_SERVER_ERROR, - ); + throw new InternalServerErrorException('Failed to fetch Account Info'); } if (!accountInfo['auth-addr']) { - throw new HttpException('Invalid signature', HttpStatus.FORBIDDEN); + throw new ForbiddenException('Invalid signature'); } const authPublicKey = algoEncoder.decodeAddress(accountInfo['auth-addr']); @@ -105,7 +104,7 @@ export class ConnectController { authPublicKey, ) ) { - throw new HttpException('Invalid signature', HttpStatus.FORBIDDEN); + throw new ForbiddenException('Invalid signature'); } } @@ -114,10 +113,7 @@ export class ConnectController { try { await this.authService.init(wallet); } catch (e) { - throw new HttpException( - 'Failed to initialize wallet', - HttpStatus.INTERNAL_SERVER_ERROR, - ); + throw new InternalServerErrorException('Failed to initialize wallet'); } const parsedRequest = diff --git a/services/liquid-auth-api-js/tests/constants.ts b/services/liquid-auth-api-js/tests/constants.ts index 315e917..ca59dfb 100644 --- a/services/liquid-auth-api-js/tests/constants.ts +++ b/services/liquid-auth-api-js/tests/constants.ts @@ -1,7 +1,9 @@ +import * as crypto from 'node:crypto'; import { AlgorandEncoder } from "../src/connect/AlgoEncoder"; + export const accFixture = { - challenge: '1234', + challenge: crypto.randomBytes(32).toString('base64url'), accs: [ { addr: 'B7WYCZ6HRBGCH452D24TYAK7BXKNCHEXY2X7S7FWZXMHDVTDOARAOURJEU', @@ -47,5 +49,5 @@ export const dummyOptions = { }; export const dummyAttestationOptions = { - challenge: 'meh', + challenge: crypto.randomBytes(32).toString('base64url'), };