Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

fixed manual dummy tests

Blue Mouse1361b19902dc
diff --git a/src/captcha/captcha.controller.ts b/src/captcha/captcha.controller.ts
index 8075d6ac8..e9dc765b3 100644
--- a/src/captcha/captcha.controller.ts
+++ b/src/captcha/captcha.controller.ts
@@ -68,6 +68,20 @@ export class CaptchaController {
await this.captchaService.validatePIDForCAPTCHA(pid)
+ const timestamp = dayjs.utc().unix()
+
+ // For dummy (test) PIDs
+ if (pid === DUMMY_PIDS.MANUAL_PASS) {
+ const dummyToken = this.captchaService.generateDummyToken()
+ return {
+ success: true,
+ token: dummyToken,
+ timestamp,
+ hash,
+ pid,
+ }
+ }
+
if (pid === DUMMY_PIDS.ALWAYS_FAIL || !this.captchaService.verifyCaptcha(code, hash)) {
throw new ForbiddenException('Incorrect captcha')
}
@@ -83,20 +97,8 @@ export class CaptchaController {
}
}
- const timestamp = dayjs.utc().unix()
const token = await this.captchaService.generateToken(pid, hash, timestamp, false)
- // For dummy (test) PIDs
- if (pid === DUMMY_PIDS.MANUAL_PASS) {
- return {
- success: true,
- token,
- timestamp,
- hash,
- pid,
- }
- }
-
const {
manuallyVerified, automaticallyVerified,
} = this.captchaService.incrementManuallyVerified(decrypted)
diff --git a/src/captcha/captcha.service.ts b/src/captcha/captcha.service.ts
index 402cb3a88..90e69497f 100644
--- a/src/captcha/captcha.service.ts
+++ b/src/captcha/captcha.service.ts
@@ -151,9 +151,13 @@ export class CaptchaService {
}
}
+ async generateDummyToken() {
+ return encryptString('DUMMY_TOKEN00000111112222233333444445555566666777778888899999', DUMMY_SECRETS.ALWAYS_PASS)
+ }
+
async generateToken(pid: string, hash: string, timestamp: number, autoVerified: boolean): Promise<string> {
if (isDummyPID(pid)) {
- return encryptString('DUMMY_TOKEN00000111112222233333444445555566666777778888899999', DUMMY_SECRETS.ALWAYS_PASS)
+ return this.generateDummyToken()
}
const project = await this.projectService.getRedisProject(pid)