11import { AuthStandardClientScopes } from "@t3tools/contracts" ;
22import * as NodeServices from "@effect/platform-node/NodeServices" ;
33import { expect , it } from "@effect/vitest" ;
4+ import * as Crypto from "effect/Crypto" ;
45import * as Duration from "effect/Duration" ;
56import * as Effect from "effect/Effect" ;
67import * as Layer from "effect/Layer" ;
@@ -45,11 +46,11 @@ const layerPairingGrantStore = (
4546 ) ;
4647
4748it . layer ( NodeServices . layer ) ( "PairingGrantStore.layer" , ( it ) => {
48- it . effect ( "issues one-time bootstrap tokens that can only be consumed once" , ( ) =>
49+ it . effect ( "accepts lowercase one-time tokens exactly once" , ( ) =>
4950 Effect . gen ( function * ( ) {
5051 const bootstrapCredentials = yield * PairingGrantStore . PairingGrantStore ;
5152 const issued = yield * bootstrapCredentials . issueOneTimeToken ( { label : "Julius iPhone" } ) ;
52- const first = yield * bootstrapCredentials . consume ( issued . credential ) ;
53+ const first = yield * bootstrapCredentials . consume ( issued . credential . toLowerCase ( ) ) ;
5354 const second = yield * Effect . flip ( bootstrapCredentials . consume ( issued . credential ) ) ;
5455
5556 expect ( first . method ) . toBe ( "one-time-token" ) ;
@@ -59,7 +60,16 @@ it.layer(NodeServices.layer)("PairingGrantStore.layer", (it) => {
5960 expect ( issued . label ) . toBe ( "Julius iPhone" ) ;
6061 expect ( second . _tag ) . toBe ( "UnknownBootstrapCredentialError" ) ;
6162 expect ( second . message ) . toContain ( "Unknown bootstrap credential" ) ;
62- } ) . pipe ( Effect . provide ( layerPairingGrantStore ( ) ) ) ,
63+ } ) . pipe (
64+ Effect . provide ( layerPairingGrantStore ( ) ) ,
65+ Effect . provideServiceEffect (
66+ Crypto . Crypto ,
67+ Effect . map ( Crypto . Crypto , ( crypto ) => ( {
68+ ...crypto ,
69+ randomBytes : ( size ) => Effect . succeed ( new Uint8Array ( size ) . fill ( 8 ) ) ,
70+ } ) ) ,
71+ ) ,
72+ ) ,
6373 ) ;
6474
6575 it . effect ( "atomically consumes a one-time token when multiple requests race" , ( ) =>
@@ -124,6 +134,23 @@ it.layer(NodeServices.layer)("PairingGrantStore.layer", (it) => {
124134 } ) . pipe ( Effect . provide ( layerPairingGrantStore ( ) ) ) ,
125135 ) ;
126136
137+ it . effect ( "matches a seeded desktop bootstrap credential exactly" , ( ) =>
138+ Effect . gen ( function * ( ) {
139+ const bootstrapCredentials = yield * PairingGrantStore . PairingGrantStore ;
140+ const exact = yield * bootstrapCredentials . consume ( "abcdefghjkmn" ) ;
141+ const otherCase = yield * Effect . flip ( bootstrapCredentials . consume ( "ABCDEFGHJKMN" ) ) ;
142+
143+ expect ( exact . method ) . toBe ( "desktop-bootstrap" ) ;
144+ expect ( otherCase . _tag ) . toBe ( "UnknownBootstrapCredentialError" ) ;
145+ } ) . pipe (
146+ Effect . provide (
147+ layerPairingGrantStore ( {
148+ desktopBootstrapToken : "abcdefghjkmn" ,
149+ } ) ,
150+ ) ,
151+ ) ,
152+ ) ;
153+
127154 it . effect ( "reports seeded desktop bootstrap credentials as expired after their ttl" , ( ) =>
128155 Effect . gen ( function * ( ) {
129156 const bootstrapCredentials = yield * PairingGrantStore . PairingGrantStore ;
0 commit comments