Skip to content

Commit e2a3a77

Browse files
Andrew Bernatwolpert
authored andcommitted
rename the test helper registration.ts -> ceremony.ts
The rename is necessary b/c authentication operations will be added which is no longer a "registration" type of operation
1 parent 79550d8 commit e2a3a77

3 files changed

Lines changed: 39 additions & 36 deletions

File tree

clients/passkeys-browser/test/ceremonies.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
newHttpHandler
2424
} from "./helpers/httpServer";
2525
import * as http from "node:http";
26-
import {RegistrationService} from "./helpers/registration";
26+
import {CeremonyService} from "./helpers/ceremony";
2727
import {FakeAuthenticator} from "./helpers/fakeAuthenticator";
2828

2929
const CREATE_OPTIONS_JSON: PublicKeyCredentialCreationOptionsJson = {
@@ -158,11 +158,11 @@ describe("PkAuthCeremonyClient http test", () => {
158158

159159
await expect(client.register({ username: "alice", label: "key" })).rejects.toThrow("HTTP 500: unit test error from errorHttpHandler");
160160

161-
expect(credentialsContainer.create).not.toHaveBeenCalled(); // this proves the client did not attempt to create a credential upon failure to start registration.ts
161+
expect(credentialsContainer.create).not.toHaveBeenCalled(); // this proves the client did not attempt to create a credential upon failure to start ceremony.ts
162162
})
163163

164164
it("when start registration succeeds but no credential is created, then the client fails with credential cancellation", async() => {
165-
const registration = new RegistrationService("localhost", "alice", "bob")
165+
const registration = new CeremonyService("localhost", "alice", "bob")
166166
using server= await startHttpServer({
167167
[startPath]: newStartHandler(registration),
168168
[finishPath]: newFinishHandler(registration)
@@ -178,7 +178,7 @@ describe("PkAuthCeremonyClient http test", () => {
178178
})
179179

180180
it("when finish registration fails, the credential was still created", async() => {
181-
const registration = new RegistrationService("localhost", "alice", "bob")
181+
const registration = new CeremonyService("localhost", "alice", "bob")
182182
using server= await startHttpServer({
183183
[startPath]: newStartHandler(registration),
184184
[finishPath]: errorHttpHandler
@@ -196,7 +196,7 @@ describe("PkAuthCeremonyClient http test", () => {
196196
})
197197

198198
it("when registering a credential, then the server returns a finished response", async() => {
199-
const registration = new RegistrationService("localhost", "alice", "bob")
199+
const registration = new CeremonyService("localhost", "alice", "bob")
200200
using server = await startHttpServer({
201201
[startPath]: newStartHandler(registration),
202202
[finishPath]: newFinishHandler(registration)
@@ -237,17 +237,17 @@ describe("PkAuthCeremonyClient http test", () => {
237237
res.end("unit test error from errorHttpHandler")
238238
}
239239

240-
function newStartHandler(registration: RegistrationService) : HttpHandler{
240+
function newStartHandler(registration: CeremonyService) : HttpHandler{
241241
const endpoint = async (req: StartRegistrationRequest) : Promise<StartRegistrationResponse> => {
242-
return registration.start(req);
242+
return registration.startRegistration(req);
243243
};
244244
const handler = new Handler(decodePost, endpoint, encodeJson);
245245
return newHttpHandler(handler);
246246
}
247247

248-
function newFinishHandler(registration: RegistrationService) : HttpHandler{
248+
function newFinishHandler(registration: CeremonyService) : HttpHandler{
249249
const endpoint = async (req: FinishRegistrationRequest) : Promise<FinishRegistrationResponse> => {
250-
return registration.finish(req);
250+
return registration.finishRegistration(req);
251251
};
252252
const handler = new Handler(decodePost, endpoint, encodeJson);
253253
return newHttpHandler(handler);

clients/passkeys-browser/test/helpers/registration.test.ts renamed to clients/passkeys-browser/test/helpers/ceremony.test.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import { Encoder } from "cbor-x";
33
import * as b64u from "../../src/base64url";
44
import { decodeCreationOptions, encodeRegistrationResponse } from "../../src/ceremonies";
55
import { FakeAuthenticator } from "./fakeAuthenticator";
6-
import { RegistrationService } from "./registration";
6+
import { CeremonyService } from "./ceremony";
77

88
describe("RegistrationService", () => {
99
describe("start a registration", () => {
1010
it("returns 403 when a username is not in the allowlist", async () => {
11-
const service = new RegistrationService("localhost", "alice");
11+
const service = new CeremonyService("localhost", "alice");
1212
await expect(
13-
service.start({ username: "eve", displayName: null, label: null, challenge: null }),
13+
service.startRegistration({ username: "eve", displayName: null, label: null, challenge: null }),
1414
).rejects.toThrow("HTTP 403");
1515
});
1616

1717
it("returns a StartRegistrationResponse when the request is valid", async () => {
18-
const service = new RegistrationService("localhost", "alice")
18+
const service = new CeremonyService("localhost", "alice")
1919

20-
const response = await service.start({ username: "alice", displayName: null, label: null, challenge: null })
20+
const response = await service.startRegistration({ username: "alice", displayName: null, label: null, challenge: null })
2121

2222
expect(response.challengeId).toBeTypeOf("string");
2323
expect(response.publicKey.user.id).toBeTypeOf("string");
@@ -33,9 +33,9 @@ describe("RegistrationService", () => {
3333

3434
describe("finish a registration", () => {
3535
it("returns 400 for an unknown challengeId", async () => {
36-
const service = new RegistrationService("localhost", "alice");
36+
const service = new CeremonyService("localhost", "alice");
3737
await expect(
38-
service.finish({
38+
service.finishRegistration({
3939
challengeId: "does-not-exist",
4040
username: "alice",
4141
label: "key",
@@ -50,27 +50,27 @@ describe("RegistrationService", () => {
5050
});
5151

5252
it("returns 400 for a username that does not match the started session", async () => {
53-
const service = new RegistrationService("localhost", "alice", "bob");
54-
const { challengeId, publicKey } = await service.start({ username: "alice", displayName: null, label: null, challenge: null });
53+
const service = new CeremonyService("localhost", "alice", "bob");
54+
const { challengeId, publicKey } = await service.startRegistration({ username: "alice", displayName: null, label: null, challenge: null });
5555

5656
const auth = new FakeAuthenticator();
5757
const credential = await auth.create({ publicKey: decodeCreationOptions(publicKey) });
5858
const encoded = encodeRegistrationResponse(credential);
5959

6060
await expect(
61-
service.finish({ challengeId, username: "bob", label: null, response: encoded }),
61+
service.finishRegistration({ challengeId, username: "bob", label: null, response: encoded }),
6262
).rejects.toThrow("HTTP 400");
6363
});
6464

6565
it("verifies the attestation and returns credential metadata", async () => {
66-
const service = new RegistrationService("localhost", "alice");
67-
const { challengeId, publicKey } = await service.start({ username: "alice", displayName: "Alice", label: null, challenge: null });
66+
const service = new CeremonyService("localhost", "alice");
67+
const { challengeId, publicKey } = await service.startRegistration({ username: "alice", displayName: "Alice", label: null, challenge: null });
6868

6969
const auth = new FakeAuthenticator();
7070
const credential = await auth.create({ publicKey: decodeCreationOptions(publicKey) });
7171
const encoded = encodeRegistrationResponse(credential);
7272

73-
const { credential: cred } = await service.finish({ challengeId, username: "alice", label: "my-key", response: encoded });
73+
const { credential: cred } = await service.finishRegistration({ challengeId, username: "alice", label: "my-key", response: encoded });
7474

7575
expect(cred.credentialId).toBeTypeOf("string");
7676
expect(cred.userHandle).toBeTypeOf("string");
@@ -81,8 +81,8 @@ describe("RegistrationService", () => {
8181
});
8282

8383
it("returns 400 when the attestation signature is tampered", async () => {
84-
const service = new RegistrationService("localhost", "alice");
85-
const { challengeId, publicKey } = await service.start({ username: "alice", displayName: null, label: null, challenge: null });
84+
const service = new CeremonyService("localhost", "alice");
85+
const { challengeId, publicKey } = await service.startRegistration({ username: "alice", displayName: null, label: null, challenge: null });
8686

8787
const auth = new FakeAuthenticator();
8888
const credential = await auth.create({ publicKey: decodeCreationOptions(publicKey) });
@@ -99,22 +99,22 @@ describe("RegistrationService", () => {
9999
const tampered = { ...encoded, response: { ...encoded.response, attestationObject: b64u.encode(cbor.encode(attObj) as Uint8Array) } };
100100

101101
await expect(
102-
service.finish({ challengeId, username: "alice", label: null, response: tampered }),
102+
service.finishRegistration({ challengeId, username: "alice", label: null, response: tampered }),
103103
).rejects.toThrow("HTTP 400");
104104
});
105105

106106
it("returns 400 when the challenge in clientDataJSON belongs to a different session", async () => {
107-
const service = new RegistrationService("localhost", "alice");
108-
const s1 = await service.start({ username: "alice", displayName: null, label: null, challenge: null });
109-
const s2 = await service.start({ username: "alice", displayName: null, label: null, challenge: null });
107+
const service = new CeremonyService("localhost", "alice");
108+
const s1 = await service.startRegistration({ username: "alice", displayName: null, label: null, challenge: null });
109+
const s2 = await service.startRegistration({ username: "alice", displayName: null, label: null, challenge: null });
110110

111111
const auth = new FakeAuthenticator();
112112
const credential = await auth.create({ publicKey: decodeCreationOptions(s2.publicKey) });
113113
const encoded = encodeRegistrationResponse(credential);
114114

115115
// finish using s1 challengeId but with s2's credential -- this should fail
116116
await expect(
117-
service.finish({ challengeId: s1.challengeId, username: "alice", label: null, response: encoded }),
117+
service.finishRegistration({ challengeId: s1.challengeId, username: "alice", label: null, response: encoded }),
118118
).rejects.toThrow("HTTP 400");
119119
});
120120
});

clients/passkeys-browser/test/helpers/registration.ts renamed to clients/passkeys-browser/test/helpers/ceremony.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ interface PendingEntry {
1919
}
2020

2121
/*
22-
RegistrationService is a server side service that can start and finish
23-
client registrations.
22+
CeremonyService is a server side service that can:
23+
- start registration
24+
- finish registration
25+
- start authentication
26+
- finish authentication
2427
Instantiate the service with a relying party id [rpId] and a list of allowed users.
25-
A registration is started with a call to start which will produce a challenge that
26-
the client must respond to with a call to finish.
28+
A registration is started with a call to startRegistration which will produce a challenge that
29+
the client must respond to with a call to finishRegistration.
2730
*/
28-
export class RegistrationService {
31+
export class CeremonyService {
2932
// pending is the map of registrations which have been started; but not yet finished.
3033
// Maps challenge id to a PendingEntry structure.
3134
private readonly pending : Map<string, PendingEntry>;
@@ -38,7 +41,7 @@ export class RegistrationService {
3841
this.allowedUsernames = allowedUsernames ?? [];
3942
}
4043

41-
async start(req : StartRegistrationRequest) : Promise<StartRegistrationResponse> {
44+
async startRegistration(req : StartRegistrationRequest) : Promise<StartRegistrationResponse> {
4245
if (!this.allowedUsernames.includes(req.username)) {
4346
throw new HttpError(403, { error: `username '${req.username}' not allowed` });
4447
}
@@ -60,7 +63,7 @@ export class RegistrationService {
6063
return newStartRegistrationResponse(pendingEntry)
6164
}
6265

63-
async finish(req: FinishRegistrationRequest): Promise<FinishRegistrationResponse> {
66+
async finishRegistration(req: FinishRegistrationRequest): Promise<FinishRegistrationResponse> {
6467
const entry = this.pending.get(req.challengeId);
6568
if (!entry) {
6669
throw new HttpError(400, { error: `unknown challengeId: ${req.challengeId}` });

0 commit comments

Comments
 (0)