@@ -85,6 +85,12 @@ const DEFAULT_INIT: InternetIdentityInit = {
85
85
feature_flag_enable_generic_open_id_fe : [ ] ,
86
86
} ;
87
87
88
+ vi . mock ( "$lib/globals" , ( ) => ( {
89
+ canisterConfig : {
90
+ new_flow_origins : [ [ "https://id.ai" ] ] ,
91
+ } ,
92
+ } ) ) ;
93
+
88
94
const mockActor = {
89
95
identity_info : vi . fn ( ) . mockImplementation ( async ( ) => {
90
96
// The `await` is necessary to make sure that the `getterResponse` is set before the test continues.
@@ -232,6 +238,39 @@ describe("Connection.login", () => {
232
238
}
233
239
} ) ;
234
240
241
+ it ( "login returns authenticated connection with expected rpID if new flow origins are enabled" , async ( ) => {
242
+ const newOriginDevice = createMockDevice ( "https://id.ai" ) ;
243
+ const mockActor = {
244
+ identity_info : vi . fn ( ) . mockImplementation ( async ( ) => {
245
+ // The `await` is necessary to make sure that the `getterResponse` is set before the test continues.
246
+ infoResponse = await mockRawMetadata ;
247
+ return { Ok : { metadata : mockRawMetadata } } ;
248
+ } ) ,
249
+ identity_metadata_replace : vi . fn ( ) . mockResolvedValue ( { Ok : null } ) ,
250
+ // The order here matters, the first device is the one that would be used normally.
251
+ // But we changed to push the new_flow_origins to the end.
252
+ lookup : vi . fn ( ) . mockResolvedValue ( [ newOriginDevice , mockDevice ] ) ,
253
+ } as unknown as ActorSubclass < _SERVICE > ;
254
+ const connection = new Connection ( "aaaaa-aa" , DEFAULT_INIT , mockActor ) ;
255
+
256
+ const loginResult = await connection . login ( BigInt ( 12345 ) ) ;
257
+
258
+ expect ( loginResult . kind ) . toBe ( "loginSuccess" ) ;
259
+ if ( loginResult . kind === "loginSuccess" ) {
260
+ expect ( loginResult . connection ) . toBeInstanceOf ( AuthenticatedConnection ) ;
261
+ expect ( loginResult . showAddCurrentDevice ) . toBe ( false ) ;
262
+ expect ( MultiWebAuthnIdentity . fromCredentials ) . toHaveBeenCalledTimes ( 1 ) ;
263
+ expect ( MultiWebAuthnIdentity . fromCredentials ) . toHaveBeenCalledWith (
264
+ [
265
+ convertToValidCredentialData ( newOriginDevice ) ,
266
+ convertToValidCredentialData ( mockDevice ) ,
267
+ ] ,
268
+ "identity.ic0.app" ,
269
+ true ,
270
+ ) ;
271
+ }
272
+ } ) ;
273
+
235
274
it ( "login returns undefined RP ID if no related origins are in the config" , async ( ) => {
236
275
const config : InternetIdentityInit = {
237
276
...DEFAULT_INIT ,
0 commit comments