@@ -118,6 +118,8 @@ import {
118
118
} from "msal-test-utils" ;
119
119
import { INTERACTION_TYPE } from "../../src/utils/BrowserConstants.js" ;
120
120
import { BaseOperatingContext } from "../../src/operatingcontext/BaseOperatingContext.js" ;
121
+ import { PlatformAuthDOMHandler } from "../../src/broker/nativeBroker/PlatformAuthDOMHandler.js" ;
122
+ import { config } from "process" ;
121
123
122
124
const cacheConfig = {
123
125
temporaryCacheLocation : BrowserCacheLocation . SessionStorage ,
@@ -138,7 +140,7 @@ let testAppConfig = {
138
140
} ,
139
141
} ;
140
142
141
- function stubProvider ( config : Configuration ) {
143
+ function stubExtensionProvider ( config : Configuration ) {
142
144
const browserEnvironment = typeof window !== "undefined" ;
143
145
144
146
const newConfig = buildConfiguration ( config , browserEnvironment ) ;
@@ -148,7 +150,6 @@ function stubProvider(config: Configuration) {
148
150
"unittest"
149
151
) ;
150
152
const performanceClient = newConfig . telemetry . client ;
151
-
152
153
return jest
153
154
. spyOn ( PlatformAuthExtensionHandler , "createProvider" )
154
155
. mockImplementation ( async ( ) => {
@@ -161,6 +162,28 @@ function stubProvider(config: Configuration) {
161
162
} ) ;
162
163
}
163
164
165
+ function stubDOMProvider ( config : Configuration ) {
166
+ const browserEnvironment = typeof window !== "undefined" ;
167
+
168
+ const newConfig = buildConfiguration ( config , browserEnvironment ) ;
169
+ const logger = new Logger (
170
+ newConfig . system . loggerOptions ,
171
+ "unittest" ,
172
+ "unittest"
173
+ ) ;
174
+ const performanceClient = newConfig . telemetry . client ;
175
+ console . log ( "stubDOMProvider" ) ;
176
+ return jest
177
+ . spyOn ( PlatformAuthDOMHandler , "createProvider" )
178
+ . mockImplementation ( async ( ) => {
179
+ return new PlatformAuthDOMHandler (
180
+ logger ,
181
+ performanceClient ,
182
+ "test-correlation-id"
183
+ ) ;
184
+ } ) ;
185
+ }
186
+
164
187
const testRequest : CommonAuthorizationUrlRequest = {
165
188
redirectUri : `${ TEST_URIS . DEFAULT_INSTANCE } /` ,
166
189
scopes : TEST_CONFIG . DEFAULT_SCOPES ,
@@ -451,7 +474,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
451
474
}
452
475
} ) ;
453
476
454
- it ( "creates extension provider if allowPlatformBroker is true" , async ( ) => {
477
+ it ( "creates platform auth extension handler if allowPlatformBroker is true" , async ( ) => {
455
478
const config = {
456
479
auth : {
457
480
clientId : TEST_CONFIG . MSAL_CLIENT_ID ,
@@ -467,42 +490,55 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
467
490
) . mockImplementation ( ( ) => {
468
491
return false ;
469
492
} ) ;
493
+
494
+ const getPlatformAuthProviderSpy = jest . spyOn (
495
+ PlatformAuthProvider ,
496
+ "getPlatformAuthProvider"
497
+ ) ;
498
+
470
499
pca = new PublicClientApplication ( config ) ;
471
500
472
- const createProviderSpy = stubProvider ( config ) ;
501
+ const createExtensionProviderSpy = stubExtensionProvider ( config ) ;
473
502
474
503
await pca . initialize ( ) ;
475
504
476
505
// Implementation of PCA was moved to controller.
477
506
// eslint-disable-next-line @typescript-eslint/no-explicit-any
478
507
pca = ( pca as any ) . controller ;
479
508
480
- expect ( createProviderSpy ) . toHaveBeenCalled ( ) ;
509
+ expect ( getPlatformAuthProviderSpy ) . toHaveBeenCalled ( ) ;
510
+ expect ( createExtensionProviderSpy ) . toHaveBeenCalled ( ) ;
481
511
// @ts -ignore
482
512
expect ( pca . platformAuthProvider ) . toBeInstanceOf (
483
513
PlatformAuthExtensionHandler
484
514
) ;
485
515
} ) ;
486
516
487
517
it ( "does not create extension provider if allowPlatformBroker is false" , async ( ) => {
488
- const createProviderSpy = jest . spyOn (
489
- PlatformAuthExtensionHandler ,
490
- "createProvider "
518
+ const getPlatformAuthProviderSpy = jest . spyOn (
519
+ PlatformAuthProvider ,
520
+ "getPlatformAuthProvider "
491
521
) ;
492
- pca = new PublicClientApplication ( {
522
+
523
+ const config = {
493
524
auth : {
494
525
clientId : TEST_CONFIG . MSAL_CLIENT_ID ,
495
526
} ,
496
527
system : {
497
528
allowPlatformBroker : false ,
498
529
} ,
499
- } ) ;
530
+ } ;
531
+
532
+ pca = new PublicClientApplication ( config ) ;
533
+ const createProviderSpy = stubExtensionProvider ( config ) ;
534
+
500
535
await pca . initialize ( ) ;
501
536
502
537
//Implementation of PCA was moved to controller.
503
538
pca = ( pca as any ) . controller ;
504
539
505
540
expect ( createProviderSpy ) . toHaveBeenCalledTimes ( 0 ) ;
541
+ expect ( getPlatformAuthProviderSpy ) . not . toHaveBeenCalled ( ) ;
506
542
// @ts -ignore
507
543
expect ( pca . platformAuthProvider ) . toBeUndefined ( ) ;
508
544
} ) ;
@@ -777,7 +813,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
777
813
} ;
778
814
pca = new PublicClientApplication ( config ) ;
779
815
780
- stubProvider ( config ) ;
816
+ stubExtensionProvider ( config ) ;
781
817
await pca . initialize ( ) ;
782
818
783
819
// Implementation of PCA was moved to controller.
@@ -871,7 +907,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
871
907
} ,
872
908
} ;
873
909
pca = new PublicClientApplication ( config ) ;
874
- stubProvider ( config ) ;
910
+ stubExtensionProvider ( config ) ;
875
911
876
912
pca . initialize ( ) . then ( ( ) => {
877
913
const callbackId = pca . addPerformanceCallback ( ( events ) => {
@@ -970,7 +1006,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
970
1006
} ;
971
1007
pca = new PublicClientApplication ( config ) ;
972
1008
973
- stubProvider ( config ) ;
1009
+ stubExtensionProvider ( config ) ;
974
1010
975
1011
//@ts -ignore
976
1012
pca . controller . browserStorage . setInteractionInProgress ( true ) ;
@@ -1571,7 +1607,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
1571
1607
} ;
1572
1608
pca = new PublicClientApplication ( config ) ;
1573
1609
1574
- stubProvider ( config ) ;
1610
+ stubExtensionProvider ( config ) ;
1575
1611
await pca . initialize ( ) ;
1576
1612
1577
1613
//Implementation of PCA was moved to controller.
@@ -1626,7 +1662,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
1626
1662
} ;
1627
1663
pca = new PublicClientApplication ( config ) ;
1628
1664
1629
- stubProvider ( config ) ;
1665
+ stubExtensionProvider ( config ) ;
1630
1666
1631
1667
const callbackId = pca . addPerformanceCallback ( ( events ) => {
1632
1668
expect ( events . length ) . toBeGreaterThanOrEqual ( 1 ) ;
@@ -1665,7 +1701,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
1665
1701
pca = new PublicClientApplication ( config ) ;
1666
1702
1667
1703
await pca . initialize ( ) ;
1668
- stubProvider ( config ) ;
1704
+ stubExtensionProvider ( config ) ;
1669
1705
1670
1706
//Implementation of PCA was moved to controller.
1671
1707
pca = ( pca as any ) . controller ;
@@ -1707,7 +1743,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
1707
1743
} ;
1708
1744
pca = new PublicClientApplication ( config ) ;
1709
1745
1710
- stubProvider ( config ) ;
1746
+ stubExtensionProvider ( config ) ;
1711
1747
await pca . initialize ( ) ;
1712
1748
1713
1749
// Implementation of PCA was moved to controller.
@@ -1754,7 +1790,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
1754
1790
} ;
1755
1791
pca = new PublicClientApplication ( config ) ;
1756
1792
1757
- stubProvider ( config ) ;
1793
+ stubExtensionProvider ( config ) ;
1758
1794
await pca . initialize ( ) ;
1759
1795
1760
1796
// Implementation of PCA was moved to controller.
@@ -1803,7 +1839,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
1803
1839
} ;
1804
1840
pca = new PublicClientApplication ( config ) ;
1805
1841
1806
- stubProvider ( config ) ;
1842
+ stubExtensionProvider ( config ) ;
1807
1843
await pca . initialize ( ) ;
1808
1844
1809
1845
//PCA implementation moved to controller
@@ -2107,7 +2143,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
2107
2143
} ,
2108
2144
} ;
2109
2145
2110
- stubProvider ( config ) ;
2146
+ stubExtensionProvider ( config ) ;
2111
2147
pca = new PublicClientApplication ( {
2112
2148
...config ,
2113
2149
telemetry : {
@@ -2519,7 +2555,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
2519
2555
} ;
2520
2556
pca = new PublicClientApplication ( config ) ;
2521
2557
2522
- stubProvider ( config ) ;
2558
+ stubExtensionProvider ( config ) ;
2523
2559
await pca . initialize ( ) ;
2524
2560
2525
2561
//Implementation of PCA was moved to controller.
@@ -2582,7 +2618,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
2582
2618
} ;
2583
2619
pca = new PublicClientApplication ( config ) ;
2584
2620
2585
- stubProvider ( config ) ;
2621
+ stubExtensionProvider ( config ) ;
2586
2622
await pca . initialize ( ) ;
2587
2623
2588
2624
const testAccount : AccountInfo = {
@@ -2637,7 +2673,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
2637
2673
} ;
2638
2674
pca = new PublicClientApplication ( config ) ;
2639
2675
2640
- stubProvider ( config ) ;
2676
+ stubExtensionProvider ( config ) ;
2641
2677
await pca . initialize ( ) ;
2642
2678
2643
2679
//Implementation of PCA was moved to controller.
@@ -2695,7 +2731,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
2695
2731
} ;
2696
2732
pca = new PublicClientApplication ( config ) ;
2697
2733
2698
- stubProvider ( config ) ;
2734
+ stubExtensionProvider ( config ) ;
2699
2735
await pca . initialize ( ) ;
2700
2736
2701
2737
//Implementation of PCA was moved to controller.
@@ -2755,7 +2791,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
2755
2791
} ;
2756
2792
pca = new PublicClientApplication ( config ) ;
2757
2793
2758
- stubProvider ( config ) ;
2794
+ stubExtensionProvider ( config ) ;
2759
2795
await pca . initialize ( ) ;
2760
2796
2761
2797
//PCA implementation moved to controller
@@ -3308,7 +3344,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
3308
3344
} ;
3309
3345
pca = new PublicClientApplication ( config ) ;
3310
3346
3311
- stubProvider ( config ) ;
3347
+ stubExtensionProvider ( config ) ;
3312
3348
await pca . initialize ( ) ;
3313
3349
3314
3350
//Implementation of PCA was moved to controller.
@@ -3365,7 +3401,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
3365
3401
} ;
3366
3402
pca = new PublicClientApplication ( config ) ;
3367
3403
3368
- stubProvider ( config ) ;
3404
+ stubExtensionProvider ( config ) ;
3369
3405
await pca . initialize ( ) ;
3370
3406
3371
3407
//Implementation of PCA was moved to controller.
@@ -3423,7 +3459,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
3423
3459
} ;
3424
3460
pca = new PublicClientApplication ( config ) ;
3425
3461
3426
- stubProvider ( config ) ;
3462
+ stubExtensionProvider ( config ) ;
3427
3463
await pca . initialize ( ) ;
3428
3464
3429
3465
//Implementation of PCA was moved to controller.
@@ -3714,7 +3750,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
3714
3750
} ;
3715
3751
pca = new PublicClientApplication ( config ) ;
3716
3752
3717
- stubProvider ( config ) ;
3753
+ stubExtensionProvider ( config ) ;
3718
3754
await pca . initialize ( ) ;
3719
3755
3720
3756
//Implementation of PCA was moved to controller.
@@ -3766,7 +3802,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
3766
3802
} ;
3767
3803
pca = new PublicClientApplication ( config ) ;
3768
3804
3769
- stubProvider ( config ) ;
3805
+ stubExtensionProvider ( config ) ;
3770
3806
await pca . initialize ( ) ;
3771
3807
3772
3808
//Implementation of PCA was moved to controller.
@@ -4211,7 +4247,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
4211
4247
} ;
4212
4248
pca = new PublicClientApplication ( config ) ;
4213
4249
4214
- stubProvider ( config ) ;
4250
+ stubExtensionProvider ( config ) ;
4215
4251
await pca . initialize ( ) ;
4216
4252
4217
4253
//Implementation of PCA was moved to controller.
@@ -4268,7 +4304,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
4268
4304
} ;
4269
4305
pca = new PublicClientApplication ( config ) ;
4270
4306
4271
- stubProvider ( config ) ;
4307
+ stubExtensionProvider ( config ) ;
4272
4308
await pca . initialize ( ) ;
4273
4309
4274
4310
//Implementation of PCA was moved to controller.
@@ -4328,7 +4364,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
4328
4364
} ;
4329
4365
pca = new PublicClientApplication ( config ) ;
4330
4366
4331
- stubProvider ( config ) ;
4367
+ stubExtensionProvider ( config ) ;
4332
4368
await pca . initialize ( ) ;
4333
4369
//Implementation of PCA was moved to controller.
4334
4370
pca = ( pca as any ) . controller ;
@@ -7311,7 +7347,7 @@ describe("PublicClientApplication.ts Class Unit Tests", () => {
7311
7347
} ;
7312
7348
pca = new PublicClientApplication ( config ) ;
7313
7349
7314
- stubProvider ( config ) ;
7350
+ stubExtensionProvider ( config ) ;
7315
7351
await pca . initialize ( ) ;
7316
7352
7317
7353
//Implementation of PCA was moved to controller.
0 commit comments