@@ -3,21 +3,21 @@ import { Encoder } from "cbor-x";
33import * as b64u from "../../src/base64url" ;
44import { decodeCreationOptions , encodeRegistrationResponse } from "../../src/ceremonies" ;
55import { FakeAuthenticator } from "./fakeAuthenticator" ;
6- import { RegistrationService } from "./registration " ;
6+ import { CeremonyService } from "./ceremony " ;
77
88describe ( "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 } ) ;
0 commit comments