fix: fix test script for forgot password
This commit is contained in:
@@ -122,10 +122,17 @@ describe("A04 Cryptographic Failures (runtime adversarial checks)", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("accepts token with correct signature, issuer, and audience", async () => {
|
it("accepts token with correct signature, issuer, and audience", async () => {
|
||||||
|
const user = await app.prisma.user.create({
|
||||||
|
data: {
|
||||||
|
email: `jwt-runtime-${Date.now()}@test.dev`,
|
||||||
|
emailVerified: true,
|
||||||
|
},
|
||||||
|
select: { id: true },
|
||||||
|
});
|
||||||
const nowSeconds = Math.floor(Date.now() / 1000);
|
const nowSeconds = Math.floor(Date.now() / 1000);
|
||||||
const token = signHs256Token(
|
const token = signHs256Token(
|
||||||
{
|
{
|
||||||
sub: `valid-${Date.now()}`,
|
sub: user.id,
|
||||||
iss: "skymoney-api",
|
iss: "skymoney-api",
|
||||||
aud: "skymoney-web",
|
aud: "skymoney-web",
|
||||||
iat: nowSeconds,
|
iat: nowSeconds,
|
||||||
@@ -141,5 +148,7 @@ describe("A04 Cryptographic Failures (runtime adversarial checks)", () => {
|
|||||||
|
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
expect(res.body.ok).toBe(true);
|
expect(res.body.ok).toBe(true);
|
||||||
|
|
||||||
|
await app.prisma.user.delete({ where: { id: user.id } });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
|
||||||
import request from "supertest";
|
import request from "supertest";
|
||||||
import type { FastifyInstance } from "fastify";
|
import type { FastifyInstance } from "fastify";
|
||||||
import { buildApp } from "../src/server";
|
import { buildApp } from "../src/server";
|
||||||
@@ -77,6 +77,9 @@ describe("A09 Security Logging and Monitoring Failures", () => {
|
|||||||
|
|
||||||
it("emits structured security log for forgot-password requests without raw token data", async () => {
|
it("emits structured security log for forgot-password requests without raw token data", async () => {
|
||||||
capturedEvents.length = 0;
|
capturedEvents.length = 0;
|
||||||
|
const findUniqueMock = vi
|
||||||
|
.spyOn((authApp as any).prisma.user, "findUnique")
|
||||||
|
.mockResolvedValue(null);
|
||||||
|
|
||||||
const res = await request(authApp.server)
|
const res = await request(authApp.server)
|
||||||
.post("/auth/forgot-password/request")
|
.post("/auth/forgot-password/request")
|
||||||
@@ -89,5 +92,6 @@ describe("A09 Security Logging and Monitoring Failures", () => {
|
|||||||
expect(event).toBeTruthy();
|
expect(event).toBeTruthy();
|
||||||
expect(event?.outcome).toBe("success");
|
expect(event?.outcome).toBe("success");
|
||||||
expect(event && "token" in event).toBe(false);
|
expect(event && "token" in event).toBe(false);
|
||||||
|
findUniqueMock.mockRestore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user