11import { expect } from "@playwright/test" ;
2+ import { IDL } from "@icp-sdk/core/candid" ;
23import { test } from "../../fixtures" ;
34import {
45 ALTERNATE_OPENID_PORT ,
56 DEFAULT_OPENID_PORT ,
67} from "../../fixtures/openid" ;
78import { II_URL } from "../../utils" ;
89
10+ const Icrc3Value : IDL . Type = IDL . Rec ( ) ;
11+ ( Icrc3Value as IDL . RecClass ) . fill (
12+ IDL . Variant ( {
13+ Nat : IDL . Nat ,
14+ Int : IDL . Int ,
15+ Blob : IDL . Vec ( IDL . Nat8 ) ,
16+ Text : IDL . Text ,
17+ Array : IDL . Vec ( Icrc3Value ) ,
18+ Map : IDL . Vec ( IDL . Tuple ( IDL . Text , Icrc3Value ) ) ,
19+ } ) ,
20+ ) ;
21+
922test . describe ( "Authorize with direct OpenID" , ( ) => {
1023 test . describe ( "without any attributes" , ( ) => {
1124 const name = "John Doe" ;
@@ -154,12 +167,15 @@ test.describe("Authorize with direct OpenID", () => {
154167 } ) ;
155168
156169 test . describe ( "with ICRC-3 name and email attributes" , ( ) => {
170+ const name = "John Doe" ;
171+ const email = "john.doe@example.com" ;
172+
157173 test . use ( {
158174 openIdConfig : {
159175 defaultPort : DEFAULT_OPENID_PORT ,
160176 createUsers : [
161177 {
162- claims : { name : "John Doe" , email : "john.doe@example.com" } ,
178+ claims : { name, email } ,
163179 } ,
164180 ] ,
165181 } ,
@@ -177,10 +193,27 @@ test.describe("Authorize with direct OpenID", () => {
177193 test . afterEach ( ( { authorizedPrincipal, authorizedIcrc3Attributes } ) => {
178194 expect ( authorizedPrincipal ?. isAnonymous ( ) ) . toBe ( false ) ;
179195 expect ( authorizedIcrc3Attributes ) . toBeDefined ( ) ;
180- expect ( typeof authorizedIcrc3Attributes ?. data ) . toBe ( "string" ) ;
181- expect ( typeof authorizedIcrc3Attributes ?. signature ) . toBe ( "string" ) ;
182- expect ( authorizedIcrc3Attributes ?. data . length ) . toBeGreaterThan ( 0 ) ;
183- expect ( authorizedIcrc3Attributes ?. signature . length ) . toBeGreaterThan ( 0 ) ;
196+ if ( authorizedIcrc3Attributes === undefined ) {
197+ return ;
198+ }
199+
200+ expect ( authorizedIcrc3Attributes . signature . length ) . toBeGreaterThan ( 0 ) ;
201+
202+ // Decode the Candid-encoded ICRC-3 Value map.
203+ const dataBytes = Buffer . from ( authorizedIcrc3Attributes . data , "base64" ) ;
204+ const [ decoded ] = IDL . decode ( [ Icrc3Value ] , dataBytes ) ;
205+ const map = ( decoded as { Map : [ string , { Blob : number [ ] } ] [ ] } ) . Map ;
206+ const entries = Object . fromEntries (
207+ map . map ( ( [ key , value ] ) => [
208+ key ,
209+ new TextDecoder ( ) . decode ( new Uint8Array ( value . Blob ) ) ,
210+ ] ) ,
211+ ) ;
212+
213+ expect ( entries ) . toMatchObject ( {
214+ [ `openid:http://localhost:${ DEFAULT_OPENID_PORT } :name` ] : name ,
215+ [ `openid:http://localhost:${ DEFAULT_OPENID_PORT } :email` ] : email ,
216+ } ) ;
184217 } ) ;
185218
186219 test ( "should return ICRC-3 attributes" , async ( {
0 commit comments