Skip to content

Commit

Permalink
Mock auth guard was emulating incorrect behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Graney-Ward committed Jun 30, 2024
1 parent a325289 commit 657bb66
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
6 changes: 0 additions & 6 deletions src/services/api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ export class UserDetailsInterceptor implements NestInterceptor {
export class MockAuthGuard implements CanActivate {
canActivate(context: ExecutionContext): boolean {
const request = context.switchToHttp().getRequest();
request.user = {
id: 'test_user_id',
sub: 'test_user_id',
network: 'did',
username: 'test',
} satisfies User;
return true;
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/services/auth/auth.controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('AuthController', () => {

it('throws error when user has already created a Hive account', async () => {

await hiveService.requestHiveAccount('yeet', 'test_user_id')
await hiveService.requestHiveAccount('yeet', 'singleton/bob/did')

// Make the request to the endpoint
return request(app.getHttpServer())
Expand Down Expand Up @@ -292,8 +292,9 @@ describe('AuthController', () => {
.expect(401)
.then(response => {
expect(response.body).toEqual({
errorType: "INVALID_SIGNATURE",
reason: "Invalid Signature",
error: "Unauthorized",
message: "The message did not match the signature",
statusCode: 401,
})
})
})
Expand Down
5 changes: 4 additions & 1 deletion src/services/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TransactionConfirmation, cryptoUtils } from '@hiveio/dhive';
import { TransactionConfirmation } from '@hiveio/dhive';
import {
BadRequestException,
Body,
Expand All @@ -13,6 +13,7 @@ import {
Request,
Response,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import {
Expand Down Expand Up @@ -43,6 +44,7 @@ import { WithAuthData } from './auth.interface';
import { parseAndValidateRequest } from './auth.utils';
import { RequestHiveAccountDto } from '../api/dto/RequestHiveAccount.dto';
import { HiveService } from '../hive/hive.service';
import { UserDetailsInterceptor } from '../api/utils';

@Controller('/v1/auth')
export class AuthController {
Expand Down Expand Up @@ -399,6 +401,7 @@ export class AuthController {
},
})
@UseGuards(AuthGuard('jwt'))
@UseInterceptors(UserDetailsInterceptor)
@Post('/request_hive_account')
async requestHiveAccount(
@Body() body: RequestHiveAccountDto,
Expand Down

0 comments on commit 657bb66

Please sign in to comment.