@@ -1212,10 +1212,14 @@ describe("UserAgentApplication.ts Class", function () {
1212
1212
1213
1213
setAuthInstanceStubs ( ) ;
1214
1214
setTestCacheItems ( ) ;
1215
+
1216
+ delete window . location ;
1217
+ window . location = {
1218
+ ...oldWindowLocation
1219
+ } ;
1215
1220
} ) ;
1216
1221
1217
1222
afterEach ( function ( ) {
1218
- window . location . hash = "" ;
1219
1223
config = { auth : { clientId : "" } } ;
1220
1224
cacheStorage . clear ( ) ;
1221
1225
sinon . restore ( ) ;
@@ -1241,6 +1245,196 @@ describe("UserAgentApplication.ts Class", function () {
1241
1245
msal . handleRedirectCallback ( checkRespFromServer , errorReceivedCallback ) ;
1242
1246
} ) ;
1243
1247
1248
+ it ( "tests navigation to loginRequestUrl after first redirect" , function ( done ) {
1249
+ config . auth . navigateToLoginRequestUrl = true ;
1250
+ const loginStartPage = "http://localhost:8081/test/"
1251
+ const successHash = testHashesForState ( TEST_LIBRARY_STATE ) . TEST_SUCCESS_ID_TOKEN_HASH + TEST_USER_STATE_NUM ;
1252
+
1253
+ window . location = {
1254
+ ...oldWindowLocation ,
1255
+ assign : function ( url ) {
1256
+ try {
1257
+ expect ( url ) . to . equal ( loginStartPage + successHash ) ;
1258
+ done ( ) ;
1259
+ } catch ( e ) {
1260
+ console . error ( e ) ;
1261
+ }
1262
+ } ,
1263
+ href : "http://localhost:8081/"
1264
+ } ;
1265
+
1266
+ sinon . stub ( window , "parent" ) . returns ( window ) ;
1267
+
1268
+ window . location . hash = successHash ;
1269
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . LOGIN_REQUEST } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , loginStartPage ) ;
1270
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . STATE_LOGIN } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , `${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` ) ;
1271
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . NONCE_IDTOKEN } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , TEST_NONCE ) ;
1272
+
1273
+ msal = new UserAgentApplication ( config ) ;
1274
+ } ) ;
1275
+
1276
+ it ( "tests navigation to loginRequestUrl after first redirect" , function ( done ) {
1277
+ config . auth . navigateToLoginRequestUrl = true ;
1278
+ const baseStartUrl = "http://localhost:8081/test/"
1279
+ const loginStartPage = baseStartUrl + "#testHash"
1280
+ const successHash = testHashesForState ( TEST_LIBRARY_STATE ) . TEST_SUCCESS_ID_TOKEN_HASH + TEST_USER_STATE_NUM ;
1281
+
1282
+ window . location = {
1283
+ ...oldWindowLocation ,
1284
+ assign : function ( url ) {
1285
+ try {
1286
+ expect ( url ) . to . equal ( baseStartUrl + successHash ) ;
1287
+ done ( ) ;
1288
+ } catch ( e ) {
1289
+ console . error ( e ) ;
1290
+ }
1291
+ } ,
1292
+ href : "http://localhost:8081/"
1293
+ } ;
1294
+
1295
+ sinon . stub ( window , "parent" ) . returns ( window ) ;
1296
+
1297
+ window . location . hash = successHash ;
1298
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . LOGIN_REQUEST } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , loginStartPage ) ;
1299
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . STATE_LOGIN } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , `${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` ) ;
1300
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . NONCE_IDTOKEN } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , TEST_NONCE ) ;
1301
+
1302
+ msal = new UserAgentApplication ( config ) ;
1303
+ } ) ;
1304
+
1305
+ it ( "tests navigation to loginRequestUrl inc. user querystring after first redirect" , function ( done ) {
1306
+ config . auth . navigateToLoginRequestUrl = true ;
1307
+ const baseStartUrl = "http://localhost:8081/test/"
1308
+ const loginStartPage = baseStartUrl + "?testKey=testVal"
1309
+ const successHash = testHashesForState ( TEST_LIBRARY_STATE ) . TEST_SUCCESS_ID_TOKEN_HASH + TEST_USER_STATE_NUM ;
1310
+
1311
+ window . location = {
1312
+ ...oldWindowLocation ,
1313
+ assign : function ( url ) {
1314
+ try {
1315
+ expect ( url ) . to . equal ( loginStartPage + successHash ) ;
1316
+ done ( ) ;
1317
+ } catch ( e ) {
1318
+ console . error ( e ) ;
1319
+ }
1320
+ } ,
1321
+ href : "http://localhost:8081/"
1322
+ } ;
1323
+
1324
+ sinon . stub ( window , "parent" ) . returns ( window ) ;
1325
+
1326
+ window . location . hash = successHash ;
1327
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . LOGIN_REQUEST } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , loginStartPage ) ;
1328
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . STATE_LOGIN } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , `${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` ) ;
1329
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . NONCE_IDTOKEN } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , TEST_NONCE ) ;
1330
+
1331
+ msal = new UserAgentApplication ( config ) ;
1332
+ } ) ;
1333
+
1334
+ it ( "tests user hash is added back to url on final page and token response is cached" , function ( ) {
1335
+ config . auth . navigateToLoginRequestUrl = true ;
1336
+ const loginUrl = "http://localhost:8081/test/"
1337
+ const userHash = "#testHash"
1338
+ const loginStartPage = loginUrl + userHash
1339
+ const successHash = testHashesForState ( TEST_LIBRARY_STATE ) . TEST_SUCCESS_ID_TOKEN_HASH + TEST_USER_STATE_NUM ;
1340
+
1341
+ window . location . href = loginUrl ;
1342
+
1343
+ sinon . stub ( window , "parent" ) . returns ( window ) ;
1344
+ sinon . stub ( window . location , "href" ) . returns ( loginStartPage + successHash )
1345
+
1346
+ window . location . hash = successHash ;
1347
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . LOGIN_REQUEST } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , loginStartPage ) ;
1348
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . STATE_LOGIN } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , `${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` ) ;
1349
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . NONCE_IDTOKEN } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , TEST_NONCE ) ;
1350
+
1351
+ expect ( window . location . href ) . to . equal ( loginUrl ) ;
1352
+ expect ( window . location . hash ) . to . equal ( successHash ) ;
1353
+ msal = new UserAgentApplication ( config ) ;
1354
+ expect ( window . location . href ) . to . equal ( loginUrl ) ;
1355
+ expect ( window . location . hash ) . to . equal ( userHash ) ;
1356
+ expect ( cacheStorage . getItem ( PersistentCacheKeys . IDTOKEN ) ) . to . equal ( TEST_TOKENS . IDTOKEN_V2 ) ;
1357
+ } ) ;
1358
+
1359
+ it ( "tests user query string present on final page url and token response is cached" , function ( ) {
1360
+ config . auth . navigateToLoginRequestUrl = true ;
1361
+ const loginUrl = "http://localhost:8081/test/"
1362
+ const userQueryString = "?testKey=testVal"
1363
+ const loginStartPage = loginUrl + userQueryString ;
1364
+ const successHash = testHashesForState ( TEST_LIBRARY_STATE ) . TEST_SUCCESS_ID_TOKEN_HASH + TEST_USER_STATE_NUM ;
1365
+
1366
+ window . location . href = loginStartPage ;
1367
+ window . location . search = userQueryString ;
1368
+
1369
+ sinon . stub ( window , "parent" ) . returns ( window ) ;
1370
+ sinon . stub ( window . location , "href" ) . returns ( loginStartPage + successHash )
1371
+
1372
+ window . location . hash = successHash ;
1373
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . LOGIN_REQUEST } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , loginStartPage ) ;
1374
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . STATE_LOGIN } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , `${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` ) ;
1375
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . NONCE_IDTOKEN } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , TEST_NONCE ) ;
1376
+
1377
+ expect ( window . location . href ) . to . equal ( loginStartPage ) ;
1378
+ expect ( window . location . hash ) . to . equal ( successHash ) ;
1379
+ expect ( window . location . search ) . to . equal ( userQueryString ) ;
1380
+ msal = new UserAgentApplication ( config ) ;
1381
+ expect ( window . location . href ) . to . equal ( loginStartPage ) ;
1382
+ expect ( window . location . hash ) . to . equal ( "" ) ;
1383
+ expect ( window . location . search ) . to . equal ( userQueryString ) ;
1384
+ expect ( cacheStorage . getItem ( PersistentCacheKeys . IDTOKEN ) ) . to . equal ( TEST_TOKENS . IDTOKEN_V2 ) ;
1385
+ } ) ;
1386
+
1387
+ it ( "tests user hash is added back to url and query string exists on final page url and token response is cached" , function ( ) {
1388
+ config . auth . navigateToLoginRequestUrl = true ;
1389
+ const loginUrl = "http://localhost:8081/test/"
1390
+ const userQueryString = "?testKey=testVal"
1391
+ const userHash = "#testHash"
1392
+ const loginStartPage = loginUrl + userQueryString + userHash ;
1393
+ const successHash = testHashesForState ( TEST_LIBRARY_STATE ) . TEST_SUCCESS_ID_TOKEN_HASH + TEST_USER_STATE_NUM ;
1394
+
1395
+ window . location . href = loginUrl + userQueryString ;
1396
+ window . location . search = userQueryString ;
1397
+
1398
+ sinon . stub ( window , "parent" ) . returns ( window ) ;
1399
+ sinon . stub ( window . location , "href" ) . returns ( loginStartPage + successHash )
1400
+
1401
+ window . location . hash = successHash ;
1402
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . LOGIN_REQUEST } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , loginStartPage ) ;
1403
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . STATE_LOGIN } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , `${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` ) ;
1404
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . NONCE_IDTOKEN } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , TEST_NONCE ) ;
1405
+
1406
+ expect ( window . location . href ) . to . equal ( loginUrl + userQueryString ) ;
1407
+ expect ( window . location . hash ) . to . equal ( successHash ) ;
1408
+ expect ( window . location . search ) . to . equal ( userQueryString ) ;
1409
+ msal = new UserAgentApplication ( config ) ;
1410
+ expect ( window . location . href ) . to . equal ( loginUrl + userQueryString ) ;
1411
+ expect ( window . location . hash ) . to . equal ( userHash ) ;
1412
+ expect ( window . location . search ) . to . equal ( userQueryString ) ;
1413
+ expect ( cacheStorage . getItem ( PersistentCacheKeys . IDTOKEN ) ) . to . equal ( TEST_TOKENS . IDTOKEN_V2 ) ;
1414
+ } ) ;
1415
+
1416
+ it ( "tests navigation to homepage after first redirect if loginStartPage not set" , function ( done ) {
1417
+ config . auth . navigateToLoginRequestUrl = true ;
1418
+ const successHash = testHashesForState ( TEST_LIBRARY_STATE ) . TEST_SUCCESS_ID_TOKEN_HASH + TEST_USER_STATE_NUM ;
1419
+
1420
+ window . location . assign = function ( url ) {
1421
+ try {
1422
+ expect ( url ) . to . equal ( "/" ) ;
1423
+ done ( ) ;
1424
+ } catch ( e ) {
1425
+ console . error ( e ) ;
1426
+ }
1427
+ } ;
1428
+
1429
+ sinon . stub ( window , "parent" ) . returns ( window ) ;
1430
+
1431
+ window . location . hash = successHash ;
1432
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . STATE_LOGIN } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , `${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` ) ;
1433
+ cacheStorage . setItem ( `${ TemporaryCacheKeys . NONCE_IDTOKEN } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , TEST_NONCE ) ;
1434
+
1435
+ msal = new UserAgentApplication ( config ) ;
1436
+ } ) ;
1437
+
1244
1438
it ( "tests saveTokenForHash in case of error" , function ( done ) {
1245
1439
window . location . hash = testHashesForState ( TEST_LIBRARY_STATE ) . TEST_ERROR_HASH + TEST_USER_STATE_NUM ;
1246
1440
cacheStorage . setItem ( `${ TemporaryCacheKeys . STATE_LOGIN } |${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` , `${ TEST_LIBRARY_STATE } |${ TEST_USER_STATE_NUM } ` ) ;
0 commit comments