Skip to content

Commit 080759f

Browse files
committed
fix: registry mocking in e2e tests
1 parent 879098a commit 080759f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

infrastructure/evault-core/src/test-utils/mock-registry-server.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fastify, { FastifyInstance } from "fastify";
2-
import { getSharedTestPublicJWK } from "./shared-test-keys";
2+
import * as jose from "jose";
3+
import { getSharedTestKeyPair, getSharedTestPublicJWK } from "./shared-test-keys";
34

45
// In-memory store for registered eVaults
56
const registeredEVaults = new Map<string, { uri: string; evault: string }>();
@@ -69,13 +70,21 @@ export async function createMockRegistryServer(port: number = 4322): Promise<Fas
6970
return reply.status(400).send({ error: "Missing platform parameter" });
7071
}
7172

72-
// Return a mock JWT token for the platform
73-
// In a real scenario, this would be a proper JWT signed by the registry
74-
const mockToken = `mock.jwt.token.${platform}.${Date.now()}`;
73+
// Generate a proper JWT token signed with the shared test key pair
74+
// This token can be verified by vault-access-guard using the JWKS endpoint
75+
const { privateKey } = await getSharedTestKeyPair();
76+
const now = Date.now();
77+
const expiresAt = now + 3600000; // 1 hour from now
78+
79+
const token = await new jose.SignJWT({ platform })
80+
.setProtectedHeader({ alg: "ES256", kid: "entropy-key-1" })
81+
.setIssuedAt(Math.floor(now / 1000))
82+
.setExpirationTime(Math.floor(expiresAt / 1000))
83+
.sign(privateKey);
7584

7685
return reply.status(200).send({
77-
token: mockToken,
78-
expiresAt: Date.now() + 3600000, // 1 hour from now
86+
token,
87+
expiresAt,
7988
});
8089
});
8190

0 commit comments

Comments
 (0)