From df127518192b01e494f2eb90d7955e568502f52f Mon Sep 17 00:00:00 2001 From: Sergey Dzeranov Date: Mon, 13 Jan 2025 16:45:14 +0300 Subject: [PATCH 1/5] hCaptcha token validation moved to the `HCaptchaGuard` --- .../src/common/config/auth-config.service.ts | 7 +++ .../server/src/common/constants/errors.ts | 8 --- .../server/src/common/guards/hcaptcha.ts | 57 +++++++++++++++++ .../src/modules/auth/auth.controller.ts | 7 ++- .../server/src/modules/auth/auth.errors.ts | 3 +- .../server/src/modules/auth/auth.service.ts | 61 +------------------ .../src/modules/user/user.controller.ts | 2 + .../src/modules/user/user.error.filter.ts | 0 .../server/src/modules/user/user.error.ts | 22 +++++++ .../src/modules/user/user.service.spec.ts | 29 --------- .../server/src/modules/user/user.service.ts | 25 +------- 11 files changed, 98 insertions(+), 123 deletions(-) create mode 100644 packages/apps/reputation-oracle/server/src/common/guards/hcaptcha.ts create mode 100644 packages/apps/reputation-oracle/server/src/modules/user/user.error.filter.ts create mode 100644 packages/apps/reputation-oracle/server/src/modules/user/user.error.ts diff --git a/packages/apps/reputation-oracle/server/src/common/config/auth-config.service.ts b/packages/apps/reputation-oracle/server/src/common/config/auth-config.service.ts index 2cca2a6bee..81c24aa0e1 100644 --- a/packages/apps/reputation-oracle/server/src/common/config/auth-config.service.ts +++ b/packages/apps/reputation-oracle/server/src/common/config/auth-config.service.ts @@ -61,4 +61,11 @@ export class AuthConfigService { 86400, ); } + + /** + * Human APP email. + */ + get humanAppEmail(): string { + return this.configService.getOrThrow('HUMAN_APP_EMAIL'); + } } diff --git a/packages/apps/reputation-oracle/server/src/common/constants/errors.ts b/packages/apps/reputation-oracle/server/src/common/constants/errors.ts index 44fc676bf0..cee20b71b5 100644 --- a/packages/apps/reputation-oracle/server/src/common/constants/errors.ts +++ b/packages/apps/reputation-oracle/server/src/common/constants/errors.ts @@ -52,14 +52,6 @@ export enum ErrorUser { DuplicatedAddress = 'The address you are trying to use already exists. Please check that the address is correct or use a different address.', } -/** - * Represents error messages related to captcha. - */ -export enum ErrorCapthca { - InvalidToken = 'Invalid captcha token provided', - VerificationFailed = 'Captcha verification failed', -} - /** * Represents error messages related to send grid. */ diff --git a/packages/apps/reputation-oracle/server/src/common/guards/hcaptcha.ts b/packages/apps/reputation-oracle/server/src/common/guards/hcaptcha.ts new file mode 100644 index 0000000000..d7b8f0a22e --- /dev/null +++ b/packages/apps/reputation-oracle/server/src/common/guards/hcaptcha.ts @@ -0,0 +1,57 @@ +import { + Injectable, + CanActivate, + ExecutionContext, + HttpStatus, + HttpException, + Logger, +} from '@nestjs/common'; +import { Request } from 'express'; +import { HCaptchaService } from '../../integrations/hcaptcha/hcaptcha.service'; +import { AuthConfigService } from '../config/auth-config.service'; + +@Injectable() +export class HCaptchaGuard implements CanActivate { + logger = new Logger(HCaptchaGuard.name); + constructor( + private readonly hCaptchaService: HCaptchaService, + private readonly authConfigSerice: AuthConfigService, + ) {} + public async canActivate(context: ExecutionContext): Promise { + const request: Request = context.switchToHttp().getRequest(); + + const { body } = request; + const hCaptchaToken = body['h_captcha_token']; + + // TODO: Remove 27-46 lines once we figure out how to replace human app user + if (request.path === '/auth/signin') { + const email = body['email']; + // Need to validate email because guards being called before any interceptors or pipes + // Basically to avoid any SQL injections and calling DB to check if user is correct. + if (email === this.authConfigSerice.humanAppEmail) { + return true; + } + } + + if (!hCaptchaToken) { + const message = 'hCaptcha token not provided'; + this.logger.error(message, request.path); + throw new HttpException( + { + message, + timestamp: new Date().toISOString(), + }, + HttpStatus.BAD_REQUEST, + ); + } + + const captchaVerificationResult = await this.hCaptchaService.verifyToken({ + token: hCaptchaToken, + }); + if (!captchaVerificationResult.success) { + throw new HttpException('Invalid hCaptcha token', HttpStatus.BAD_REQUEST); + } + + return true; + } +} diff --git a/packages/apps/reputation-oracle/server/src/modules/auth/auth.controller.ts b/packages/apps/reputation-oracle/server/src/modules/auth/auth.controller.ts index 9fa0ba1a90..2620fe40bf 100644 --- a/packages/apps/reputation-oracle/server/src/modules/auth/auth.controller.ts +++ b/packages/apps/reputation-oracle/server/src/modules/auth/auth.controller.ts @@ -32,6 +32,7 @@ import { } from './auth.dto'; import { AuthService } from './auth.service'; import { JwtAuthGuard } from '../../common/guards'; +import { HCaptchaGuard } from '../../common/guards/hcaptcha'; import { RequestWithUser } from '../../common/types'; import { TokenRepository } from './token.repository'; import { TokenType } from './token.entity'; @@ -66,6 +67,7 @@ export class AuthJwtController { @Public() @Post('/signup') + @UseGuards(HCaptchaGuard) @UseInterceptors(ClassSerializerInterceptor) @ApiOperation({ summary: 'User Signup', @@ -87,6 +89,7 @@ export class AuthJwtController { @Public() @Post('/signin') + @UseGuards(HCaptchaGuard) @HttpCode(200) @ApiOperation({ summary: 'User Signin', @@ -188,6 +191,7 @@ export class AuthJwtController { @Public() @Post('/forgot-password') + @UseGuards(HCaptchaGuard) @HttpCode(204) @ApiOperation({ summary: 'Forgot Password', @@ -212,6 +216,7 @@ export class AuthJwtController { @Public() @Post('/restore-password') + @UseGuards(HCaptchaGuard) @HttpCode(204) @ApiOperation({ summary: 'Restore Password', @@ -251,7 +256,7 @@ export class AuthJwtController { } @ApiBearerAuth() - @UseGuards(JwtAuthGuard) + @UseGuards(HCaptchaGuard, JwtAuthGuard) @HttpCode(204) @Post('/resend-email-verification') @ApiOperation({ diff --git a/packages/apps/reputation-oracle/server/src/modules/auth/auth.errors.ts b/packages/apps/reputation-oracle/server/src/modules/auth/auth.errors.ts index edf8e651e1..120c9b9594 100644 --- a/packages/apps/reputation-oracle/server/src/modules/auth/auth.errors.ts +++ b/packages/apps/reputation-oracle/server/src/modules/auth/auth.errors.ts @@ -1,4 +1,3 @@ -import { ErrorCapthca } from '../../common/constants/errors'; import { BaseError } from '../../common/errors/base'; export enum AuthErrorMessage { @@ -9,7 +8,7 @@ export enum AuthErrorMessage { } export class AuthError extends BaseError { - constructor(message: AuthErrorMessage | ErrorCapthca) { + constructor(message: AuthErrorMessage) { super(message); } } diff --git a/packages/apps/reputation-oracle/server/src/modules/auth/auth.service.ts b/packages/apps/reputation-oracle/server/src/modules/auth/auth.service.ts index 69faa8e82a..e6b71665d1 100644 --- a/packages/apps/reputation-oracle/server/src/modules/auth/auth.service.ts +++ b/packages/apps/reputation-oracle/server/src/modules/auth/auth.service.ts @@ -1,7 +1,6 @@ import { Injectable } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; -import { ErrorCapthca } from '../../common/constants/errors'; import { OperatorStatus, Role as UserRole, @@ -65,14 +64,9 @@ export class AuthService { private readonly sendgridService: SendGridService, private readonly web3Service: Web3Service, private readonly userRepository: UserRepository, - private readonly hCaptchaService: HCaptchaService, ) {} - public async signin({ - email, - password, - hCaptchaToken, - }: SignInDto): Promise { + public async signin({ email, password }: SignInDto): Promise { const userEntity = await this.userRepository.findOneByEmail(email); if (!userEntity) { throw new AuthError(AuthErrorMessage.INVALID_CREDENTIALS); @@ -82,33 +76,10 @@ export class AuthService { throw new AuthError(AuthErrorMessage.INVALID_CREDENTIALS); } - if (userEntity.role !== UserRole.HUMAN_APP) { - if (!hCaptchaToken) { - throw new AuthError(ErrorCapthca.InvalidToken); - } - - const captchaVerificationResult = await this.hCaptchaService.verifyToken({ - token: hCaptchaToken, - }); - if (!captchaVerificationResult.success) { - throw new AuthError(ErrorCapthca.VerificationFailed); - } - } - return this.auth(userEntity); } public async signup(data: UserCreateDto): Promise { - if (!data.hCaptchaToken) { - throw new AuthError(ErrorCapthca.InvalidToken); - } - const captchaVerificationResult = await this.hCaptchaService.verifyToken({ - token: data.hCaptchaToken, - }); - if (!captchaVerificationResult.success) { - throw new AuthError(ErrorCapthca.VerificationFailed); - } - const storedUser = await this.userRepository.findOneByEmail(data.email); if (storedUser) { throw new DuplicatedUserError(data.email); @@ -237,16 +208,6 @@ export class AuthService { } public async forgotPassword(data: ForgotPasswordDto): Promise { - if (!data.hCaptchaToken) { - throw new AuthError(ErrorCapthca.InvalidToken); - } - const captchaVerificationResult = await this.hCaptchaService.verifyToken({ - token: data.hCaptchaToken, - }); - if (!captchaVerificationResult.success) { - throw new AuthError(ErrorCapthca.VerificationFailed); - } - const userEntity = await this.userRepository.findOneByEmail(data.email); if (!userEntity) { @@ -287,16 +248,6 @@ export class AuthService { } public async restorePassword(data: RestorePasswordDto): Promise { - if (!data.hCaptchaToken) { - throw new AuthError(ErrorCapthca.InvalidToken); - } - const captchaVerificationResult = await this.hCaptchaService.verifyToken({ - token: data.hCaptchaToken, - }); - if (!captchaVerificationResult.success) { - throw new AuthError(ErrorCapthca.VerificationFailed); - } - const tokenEntity = await this.tokenRepository.findOneByUuidAndType( data.token, TokenType.PASSWORD, @@ -347,16 +298,6 @@ export class AuthService { public async resendEmailVerification( data: ResendEmailVerificationDto, ): Promise { - if (!data.hCaptchaToken) { - throw new AuthError(ErrorCapthca.InvalidToken); - } - const captchaVerificationResult = await this.hCaptchaService.verifyToken({ - token: data.hCaptchaToken, - }); - if (!captchaVerificationResult.success) { - throw new AuthError(ErrorCapthca.VerificationFailed); - } - const userEntity = await this.userRepository.findOneByEmail(data.email); if (!userEntity || userEntity.status !== UserStatus.PENDING) { return; diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts index 4e2fe18bd0..5cfdfe992f 100644 --- a/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts @@ -27,6 +27,7 @@ import { RegistrationInExchangeOracleResponseDto, } from './user.dto'; import { JwtAuthGuard } from '../../common/guards'; +import { HCaptchaGuard } from '../../common/guards/hcaptcha'; import { RequestWithUser } from '../../common/types'; import { UserService } from './user.service'; import { Public } from '../../common/decorators'; @@ -170,6 +171,7 @@ export class UserController { @Post('/exchange-oracle-registration') @HttpCode(200) + @UseGuards(HCaptchaGuard) @ApiOperation({ summary: 'Notifies registration in Exchange Oracle completed', description: diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.error.filter.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.error.filter.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.error.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.error.ts new file mode 100644 index 0000000000..a76c207c63 --- /dev/null +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.error.ts @@ -0,0 +1,22 @@ +import { BaseError } from '../../common/errors/base'; + +export enum UserErrorMessage { + NOT_FOUND = 'User not found.', + ACCOUNT_CANNOT_BE_REGISTERED = 'Account cannot be registered.', + BALANCE_COULD_NOT_BE_RETRIEVED = 'User balance could not be retrieved.', + INVALID_CREDENTIALS = 'Invalid credentials.', + ALREADY_ASSIGNED = 'User already has an address assigned.', + NO_WALLET_ADDRESS_REGISTERED = 'No wallet address registered on your account.', + KYC_NOT_APPROVED = 'KYC not approved.', + LABELING_ENABLE_FAILED = 'Failed to enable labeling for this account.', + INVALID_ROLE = 'User has an invalid role.', + DUPLICATED_ADDRESS = 'The address you are trying to use already exists. Please check that the address is correct or use a different address.', +} + +export class UserError extends BaseError { + userId: number; + constructor(message: UserErrorMessage, userId: number) { + super(message); + this.userId = userId; + } +} diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.service.spec.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.service.spec.ts index ca10165c42..d4b4a69511 100644 --- a/packages/apps/reputation-oracle/server/src/modules/user/user.service.spec.ts +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.service.spec.ts @@ -30,7 +30,6 @@ import { HCaptchaConfigService } from '../../common/config/hcaptcha-config.servi import { HttpService } from '@nestjs/axios'; import { ControlledError } from '../../common/errors/controlled'; import { - ErrorCapthca, ErrorOperator, ErrorSignature, ErrorUser, @@ -881,34 +880,6 @@ describe('UserService', () => { expect(result).toEqual(siteKeyMock); }); - - it('should throw if captcha verification fails', async () => { - const userEntity: DeepPartial = { - id: 1, - email: 'test@example.com', - }; - - const oracleRegistration: RegistrationInExchangeOracleDto = { - oracleAddress: '0xOracleAddress', - hCaptchaToken: 'hcaptcha-token', - }; - - jest - .spyOn(hcaptchaService, 'verifyToken') - .mockResolvedValueOnce({ success: false }); - - await expect( - userService.registrationInExchangeOracle( - userEntity as UserEntity, - oracleRegistration, - ), - ).rejects.toThrow( - new ControlledError( - ErrorCapthca.VerificationFailed, - HttpStatus.BAD_REQUEST, - ), - ); - }); }); describe('getRegisteredOracles', () => { diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts index 0a2ba26fd7..dfc8cdb66d 100644 --- a/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts @@ -5,11 +5,7 @@ import { Logger, } from '@nestjs/common'; import * as bcrypt from 'bcrypt'; -import { - ErrorCapthca, - ErrorOperator, - ErrorUser, -} from '../../common/constants/errors'; +import { ErrorOperator, ErrorUser } from '../../common/constants/errors'; import { KycStatus, OperatorStatus, @@ -52,7 +48,6 @@ export class UserService { private readonly web3ConfigService: Web3ConfigService, private readonly hcaptchaConfigService: HCaptchaConfigService, private readonly networkConfigService: NetworkConfigService, - private readonly hCaptchaService: HCaptchaService, ) {} static checkPasswordMatchesHash( @@ -369,24 +364,8 @@ export class UserService { public async registrationInExchangeOracle( user: UserEntity, - { hCaptchaToken, oracleAddress }: RegistrationInExchangeOracleDto, + { oracleAddress }: RegistrationInExchangeOracleDto, ): Promise { - if (!hCaptchaToken) { - throw new ControlledError( - ErrorCapthca.InvalidToken, - HttpStatus.BAD_REQUEST, - ); - } - const captchaVerificationResult = await this.hCaptchaService.verifyToken({ - token: hCaptchaToken, - }); - if (!captchaVerificationResult.success) { - throw new ControlledError( - ErrorCapthca.VerificationFailed, - HttpStatus.BAD_REQUEST, - ); - } - const siteKey = await this.siteKeyRepository.findByUserSiteKeyAndType( user, oracleAddress, From d0d87dedd718be35e539fdb2173960f1dd0da83d Mon Sep 17 00:00:00 2001 From: Sergey Dzeranov Date: Mon, 13 Jan 2025 16:51:38 +0300 Subject: [PATCH 2/5] fix: remove redundant files --- .../src/modules/user/user.error.filter.ts | 0 .../server/src/modules/user/user.error.ts | 22 ------------------- 2 files changed, 22 deletions(-) delete mode 100644 packages/apps/reputation-oracle/server/src/modules/user/user.error.filter.ts delete mode 100644 packages/apps/reputation-oracle/server/src/modules/user/user.error.ts diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.error.filter.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.error.filter.ts deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.error.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.error.ts deleted file mode 100644 index a76c207c63..0000000000 --- a/packages/apps/reputation-oracle/server/src/modules/user/user.error.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { BaseError } from '../../common/errors/base'; - -export enum UserErrorMessage { - NOT_FOUND = 'User not found.', - ACCOUNT_CANNOT_BE_REGISTERED = 'Account cannot be registered.', - BALANCE_COULD_NOT_BE_RETRIEVED = 'User balance could not be retrieved.', - INVALID_CREDENTIALS = 'Invalid credentials.', - ALREADY_ASSIGNED = 'User already has an address assigned.', - NO_WALLET_ADDRESS_REGISTERED = 'No wallet address registered on your account.', - KYC_NOT_APPROVED = 'KYC not approved.', - LABELING_ENABLE_FAILED = 'Failed to enable labeling for this account.', - INVALID_ROLE = 'User has an invalid role.', - DUPLICATED_ADDRESS = 'The address you are trying to use already exists. Please check that the address is correct or use a different address.', -} - -export class UserError extends BaseError { - userId: number; - constructor(message: UserErrorMessage, userId: number) { - super(message); - this.userId = userId; - } -} From 4d88e27992d27e288092593d18dbcfbe577a84c8 Mon Sep 17 00:00:00 2001 From: Sergey Dzeranov Date: Wed, 15 Jan 2025 15:19:37 +0300 Subject: [PATCH 3/5] fix: `@UseGuards` used separately for each endpoint in `User` controller to maintain the correct order of guards (`HCaptchaGuard` before `JwtAuthGuard`) --- .../server/src/modules/user/user.controller.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts index 5cfdfe992f..740a6f0b68 100644 --- a/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts @@ -36,12 +36,12 @@ import { KycSignedAddressDto } from '../kyc/kyc.dto'; @ApiTags('User') @Controller('/user') @ApiBearerAuth() -@UseGuards(JwtAuthGuard) export class UserController { constructor(private readonly userService: UserService) {} @Post('/register-labeler') @HttpCode(200) + @UseGuards(JwtAuthGuard) @ApiOperation({ summary: 'Register Labeler', description: 'Endpoint to register user as a labeler on hcaptcha services.', @@ -73,6 +73,7 @@ export class UserController { @Post('/register-address') @HttpCode(200) + @UseGuards(JwtAuthGuard) @ApiOperation({ summary: 'Register Blockchain Address', description: 'Endpoint to register blockchain address.', @@ -104,6 +105,7 @@ export class UserController { @Post('/enable-operator') @HttpCode(204) + @UseGuards(JwtAuthGuard) @ApiOperation({ summary: 'Enable an operator', description: 'Endpoint to enable an operator.', @@ -126,6 +128,7 @@ export class UserController { @Post('/disable-operator') @HttpCode(204) + @UseGuards(JwtAuthGuard) @ApiOperation({ summary: 'Disable an operator', description: 'Endpoint to disable an operator.', @@ -148,6 +151,7 @@ export class UserController { @Public() @Post('/prepare-signature') + @UseGuards(JwtAuthGuard) @ApiOperation({ summary: 'Web3 signature body', description: @@ -171,7 +175,7 @@ export class UserController { @Post('/exchange-oracle-registration') @HttpCode(200) - @UseGuards(HCaptchaGuard) + @UseGuards(HCaptchaGuard, JwtAuthGuard) @ApiOperation({ summary: 'Notifies registration in Exchange Oracle completed', description: @@ -202,6 +206,7 @@ export class UserController { @Get('/exchange-oracle-registration') @HttpCode(200) + @UseGuards(JwtAuthGuard) @ApiOperation({ summary: 'Retrieves Exchange Oracles the user is registered in', description: From 67cdd507214ea7b306d1b16cd43a0e812d27bc0b Mon Sep 17 00:00:00 2001 From: Sergey Dzeranov Date: Wed, 15 Jan 2025 15:22:53 +0300 Subject: [PATCH 4/5] refactor: comment changed in `guards/hcaptcha.ts` file --- .../apps/reputation-oracle/server/src/common/guards/hcaptcha.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/apps/reputation-oracle/server/src/common/guards/hcaptcha.ts b/packages/apps/reputation-oracle/server/src/common/guards/hcaptcha.ts index d7b8f0a22e..eb1f9b3379 100644 --- a/packages/apps/reputation-oracle/server/src/common/guards/hcaptcha.ts +++ b/packages/apps/reputation-oracle/server/src/common/guards/hcaptcha.ts @@ -27,7 +27,7 @@ export class HCaptchaGuard implements CanActivate { if (request.path === '/auth/signin') { const email = body['email']; // Need to validate email because guards being called before any interceptors or pipes - // Basically to avoid any SQL injections and calling DB to check if user is correct. + // Basically to avoid unnecessary db calls if (email === this.authConfigSerice.humanAppEmail) { return true; } From 3d137b768fba3ba24034484bd30e360f93ac1a00 Mon Sep 17 00:00:00 2001 From: Sergey Dzeranov Date: Thu, 16 Jan 2025 13:40:55 +0300 Subject: [PATCH 5/5] fix: resolve PR comments --- .../reputation-oracle/server/src/common/config/env-schema.ts | 3 +++ .../reputation-oracle/server/src/common/guards/hcaptcha.ts | 5 ++--- .../server/src/modules/user/user.controller.ts | 5 ++++- .../server/src/modules/user/user.service.spec.ts | 4 ++-- .../server/src/modules/user/user.service.ts | 2 +- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/apps/reputation-oracle/server/src/common/config/env-schema.ts b/packages/apps/reputation-oracle/server/src/common/config/env-schema.ts index 1a1a8a05c7..98609817c7 100644 --- a/packages/apps/reputation-oracle/server/src/common/config/env-schema.ts +++ b/packages/apps/reputation-oracle/server/src/common/config/env-schema.ts @@ -69,4 +69,7 @@ export const envValidator = Joi.object({ KYC_API_KEY: Joi.string(), KYC_API_PRIVATE_KEY: Joi.string().required(), KYC_BASE_URL: Joi.string(), + + // Human App + HUMAN_APP_EMAIL: Joi.string().email().required(), }); diff --git a/packages/apps/reputation-oracle/server/src/common/guards/hcaptcha.ts b/packages/apps/reputation-oracle/server/src/common/guards/hcaptcha.ts index eb1f9b3379..72c5ef8209 100644 --- a/packages/apps/reputation-oracle/server/src/common/guards/hcaptcha.ts +++ b/packages/apps/reputation-oracle/server/src/common/guards/hcaptcha.ts @@ -23,11 +23,10 @@ export class HCaptchaGuard implements CanActivate { const { body } = request; const hCaptchaToken = body['h_captcha_token']; - // TODO: Remove 27-46 lines once we figure out how to replace human app user + // TODO: Remove 27-45 lines once we figure out how to replace human app user if (request.path === '/auth/signin') { const email = body['email']; - // Need to validate email because guards being called before any interceptors or pipes - // Basically to avoid unnecessary db calls + // Checking email here to avoid unnecessary db calls if (email === this.authConfigSerice.humanAppEmail) { return true; } diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts index 740a6f0b68..b8c08a7d33 100644 --- a/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.controller.ts @@ -199,7 +199,10 @@ export class UserController { @Req() request: RequestWithUser, @Body() data: RegistrationInExchangeOracleDto, ): Promise { - await this.userService.registrationInExchangeOracle(request.user, data); + await this.userService.registrationInExchangeOracle( + request.user, + data.oracleAddress, + ); return { oracleAddress: data.oracleAddress }; } diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.service.spec.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.service.spec.ts index d4b4a69511..75f05289c9 100644 --- a/packages/apps/reputation-oracle/server/src/modules/user/user.service.spec.ts +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.service.spec.ts @@ -834,7 +834,7 @@ describe('UserService', () => { const result = await userService.registrationInExchangeOracle( userEntity as UserEntity, - oracleRegistration, + oracleRegistration.oracleAddress, ); expect(siteKeyRepository.createUnique).toHaveBeenCalledWith( @@ -873,7 +873,7 @@ describe('UserService', () => { const result = await userService.registrationInExchangeOracle( userEntity as UserEntity, - oracleRegistration, + oracleRegistration.oracleAddress, ); expect(siteKeyRepository.createUnique).not.toHaveBeenCalled(); diff --git a/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts b/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts index dfc8cdb66d..8da0e63bac 100644 --- a/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts +++ b/packages/apps/reputation-oracle/server/src/modules/user/user.service.ts @@ -364,7 +364,7 @@ export class UserService { public async registrationInExchangeOracle( user: UserEntity, - { oracleAddress }: RegistrationInExchangeOracleDto, + oracleAddress: string, ): Promise { const siteKey = await this.siteKeyRepository.findByUserSiteKeyAndType( user,