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

chore/testing-cleanup #9

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 () => {
Expand Down
16 changes: 6 additions & 10 deletions services/liquid-auth-api-js/src/connect/connect.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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']);
Expand All @@ -105,7 +104,7 @@ export class ConnectController {
authPublicKey,
)
) {
throw new HttpException('Invalid signature', HttpStatus.FORBIDDEN);
throw new ForbiddenException('Invalid signature');
}
}

Expand All @@ -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 =
Expand Down
6 changes: 4 additions & 2 deletions services/liquid-auth-api-js/tests/constants.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -47,5 +49,5 @@ export const dummyOptions = {
};

export const dummyAttestationOptions = {
challenge: 'meh',
challenge: crypto.randomBytes(32).toString('base64url'),
};