@azure/msal-angular 4.0.13 → 4.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/IMsalService.d.ts +17 -0
- package/README.md +1 -1
- package/constants.d.ts +5 -0
- package/esm2020/IMsalService.mjs +6 -0
- package/esm2020/azure-msal-angular.mjs +5 -0
- package/esm2020/constants.mjs +10 -0
- package/esm2020/msal.broadcast.config.mjs +6 -0
- package/esm2020/msal.broadcast.service.mjs +66 -0
- package/esm2020/msal.guard.config.mjs +6 -0
- package/esm2020/msal.guard.mjs +218 -0
- package/esm2020/msal.interceptor.config.mjs +6 -0
- package/esm2020/msal.interceptor.mjs +270 -0
- package/esm2020/msal.module.mjs +46 -0
- package/esm2020/msal.navigation.client.mjs +53 -0
- package/esm2020/msal.redirect.component.mjs +31 -0
- package/esm2020/msal.service.mjs +88 -0
- package/esm2020/packageMetadata.mjs +4 -0
- package/esm2020/public-api.mjs +18 -0
- package/fesm2015/azure-msal-angular.mjs +762 -0
- package/fesm2015/azure-msal-angular.mjs.map +1 -0
- package/fesm2020/azure-msal-angular.mjs +758 -0
- package/fesm2020/azure-msal-angular.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/msal.broadcast.config.d.ts +3 -0
- package/msal.broadcast.service.d.ts +19 -0
- package/msal.guard.config.d.ts +9 -0
- package/msal.guard.d.ts +43 -0
- package/msal.interceptor.config.d.ts +13 -0
- package/msal.interceptor.d.ts +70 -0
- package/msal.module.d.ts +13 -0
- package/msal.navigation.client.d.ts +19 -0
- package/msal.redirect.component.d.ts +15 -0
- package/msal.service.d.ts +33 -0
- package/package.json +26 -56
- package/packageMetadata.d.ts +2 -0
- package/{src/public-api.ts → public-api.d.ts} +17 -35
- package/.beachballrc +0 -3
- package/.editorconfig +0 -16
- package/.eslintrc.json +0 -3
- package/CHANGELOG.json +0 -2315
- package/CHANGELOG.md +0 -869
- package/FAQ.md +0 -182
- package/angular.json +0 -51
- package/docs/angular-universal.md +0 -64
- package/docs/configuration.md +0 -609
- package/docs/errors.md +0 -89
- package/docs/events.md +0 -262
- package/docs/initialization.md +0 -206
- package/docs/known-issues.md +0 -19
- package/docs/logging.md +0 -47
- package/docs/msal-guard.md +0 -208
- package/docs/msal-interceptor.md +0 -160
- package/docs/multi-tenant.md +0 -90
- package/docs/performance.md +0 -50
- package/docs/public-apis.md +0 -29
- package/docs/redirects.md +0 -257
- package/docs/security.md +0 -4
- package/docs/ssosilent.md +0 -84
- package/docs/v0-v1-upgrade-guide.md +0 -61
- package/docs/v1-v2-upgrade-guide.md +0 -70
- package/docs/v2-v3-upgrade-guide.md +0 -52
- package/docs/v3-v4-upgrade-guide.md +0 -36
- package/karma.conf.js +0 -44
- package/ng-package.json +0 -7
- package/src/IMsalService.ts +0 -34
- package/src/constants.ts +0 -20
- package/src/msal.broadcast.config.ts +0 -8
- package/src/msal.broadcast.service.spec.ts +0 -471
- package/src/msal.broadcast.service.ts +0 -84
- package/src/msal.guard.config.ts +0 -27
- package/src/msal.guard.spec.ts +0 -525
- package/src/msal.guard.ts +0 -290
- package/src/msal.interceptor.config.ts +0 -39
- package/src/msal.interceptor.spec.ts +0 -1168
- package/src/msal.interceptor.ts +0 -388
- package/src/msal.module.ts +0 -51
- package/src/msal.navigation.client.spec.ts +0 -96
- package/src/msal.navigation.client.ts +0 -59
- package/src/msal.redirect.component.spec.ts +0 -64
- package/src/msal.redirect.component.ts +0 -26
- package/src/msal.service.spec.ts +0 -468
- package/src/msal.service.ts +0 -104
- package/src/packageMetadata.ts +0 -3
- package/src/test.ts +0 -19
- package/tsconfig.json +0 -25
- package/tsconfig.lib.json +0 -27
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -17
- package/typedoc.json +0 -10
package/src/msal.guard.spec.ts
DELETED
|
@@ -1,525 +0,0 @@
|
|
|
1
|
-
import { HttpClientTestingModule } from "@angular/common/http/testing";
|
|
2
|
-
import { TestBed } from "@angular/core/testing";
|
|
3
|
-
import { UrlTree } from "@angular/router";
|
|
4
|
-
import { RouterTestingModule } from "@angular/router/testing";
|
|
5
|
-
import { Location } from "@angular/common";
|
|
6
|
-
import {
|
|
7
|
-
BrowserSystemOptions,
|
|
8
|
-
InteractionType,
|
|
9
|
-
IPublicClientApplication,
|
|
10
|
-
LogLevel,
|
|
11
|
-
PublicClientApplication,
|
|
12
|
-
UrlString,
|
|
13
|
-
} from "@azure/msal-browser";
|
|
14
|
-
import { of } from "rxjs";
|
|
15
|
-
import {
|
|
16
|
-
MsalModule,
|
|
17
|
-
MsalGuard,
|
|
18
|
-
MsalService,
|
|
19
|
-
MsalBroadcastService,
|
|
20
|
-
} from "./public-api";
|
|
21
|
-
import { MsalGuardConfiguration } from "./msal.guard.config";
|
|
22
|
-
|
|
23
|
-
let guard: MsalGuard;
|
|
24
|
-
let authService: MsalService;
|
|
25
|
-
let routeMock: any = { snapshot: {} };
|
|
26
|
-
let routeStateMock: any = { snapshot: {}, url: "/" };
|
|
27
|
-
let testInteractionType: InteractionType;
|
|
28
|
-
let testLoginFailedRoute: string;
|
|
29
|
-
let testConfiguration: Partial<MsalGuardConfiguration>;
|
|
30
|
-
let browserSystemOptions: BrowserSystemOptions;
|
|
31
|
-
|
|
32
|
-
function MSALInstanceFactory(): IPublicClientApplication {
|
|
33
|
-
return new PublicClientApplication({
|
|
34
|
-
auth: {
|
|
35
|
-
clientId: "b5c2e510-4a17-4feb-b219-e55aa5b74144",
|
|
36
|
-
redirectUri: "http://localhost:4200",
|
|
37
|
-
},
|
|
38
|
-
system: {
|
|
39
|
-
loggerOptions: {
|
|
40
|
-
loggerCallback: (level, message) => {
|
|
41
|
-
// console.log(message)
|
|
42
|
-
},
|
|
43
|
-
logLevel: LogLevel.Verbose,
|
|
44
|
-
piiLoggingEnabled: true,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function MSALGuardConfigFactory(): MsalGuardConfiguration {
|
|
51
|
-
return {
|
|
52
|
-
//@ts-ignore
|
|
53
|
-
interactionType: testInteractionType,
|
|
54
|
-
loginFailedRoute: testLoginFailedRoute,
|
|
55
|
-
authRequest: testConfiguration?.authRequest,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function initializeMsal(providers: any[] = []) {
|
|
60
|
-
TestBed.resetTestingModule();
|
|
61
|
-
TestBed.configureTestingModule({
|
|
62
|
-
imports: [
|
|
63
|
-
MsalModule.forRoot(MSALInstanceFactory(), MSALGuardConfigFactory(), {
|
|
64
|
-
interactionType: InteractionType.Popup,
|
|
65
|
-
protectedResourceMap: new Map(),
|
|
66
|
-
}),
|
|
67
|
-
HttpClientTestingModule,
|
|
68
|
-
RouterTestingModule.withRoutes([]),
|
|
69
|
-
],
|
|
70
|
-
providers: [MsalGuard, MsalService, MsalBroadcastService, ...providers],
|
|
71
|
-
teardown: { destroyAfterEach: false },
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
authService = TestBed.inject(MsalService);
|
|
75
|
-
guard = TestBed.inject(MsalGuard);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
describe("MsalGuard", () => {
|
|
79
|
-
beforeEach(() => {
|
|
80
|
-
testInteractionType = InteractionType.Popup;
|
|
81
|
-
testLoginFailedRoute = undefined;
|
|
82
|
-
testConfiguration = {};
|
|
83
|
-
browserSystemOptions = {};
|
|
84
|
-
routeStateMock = { snapshot: {}, url: "/" };
|
|
85
|
-
initializeMsal();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it("is created", () => {
|
|
89
|
-
expect(guard).toBeTruthy();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("throws error for silent interaction type", (done) => {
|
|
93
|
-
testInteractionType = InteractionType.Silent;
|
|
94
|
-
initializeMsal();
|
|
95
|
-
try {
|
|
96
|
-
guard.canActivate(routeMock, routeStateMock).subscribe((result) => {});
|
|
97
|
-
} catch (err) {
|
|
98
|
-
expect(err.errorCode).toBe("invalid_interaction_type");
|
|
99
|
-
done();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("returns false if page with MSAL Guard is set as redirectUri", (done) => {
|
|
104
|
-
spyOn(UrlString, "hashContainsKnownProperties").and.returnValue(true);
|
|
105
|
-
spyOnProperty(window, "parent", "get").and.returnValue({ ...window });
|
|
106
|
-
|
|
107
|
-
guard.canActivate(routeMock, routeStateMock).subscribe((result) => {
|
|
108
|
-
expect(result).toBeFalse();
|
|
109
|
-
done();
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("returns false if page contains known successful response (path routing)", (done) => {
|
|
114
|
-
initializeMsal([
|
|
115
|
-
{
|
|
116
|
-
provide: Location,
|
|
117
|
-
useValue: {
|
|
118
|
-
path: jasmine
|
|
119
|
-
.createSpy("path")
|
|
120
|
-
.and.callFake((hash: boolean) =>
|
|
121
|
-
hash ? "/path?code=123#code=456" : "/path"
|
|
122
|
-
),
|
|
123
|
-
prepareExternalUrl: jasmine
|
|
124
|
-
.createSpy("prepareExternalUrl")
|
|
125
|
-
.and.callFake((url: string) => "/path"),
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
]);
|
|
129
|
-
|
|
130
|
-
routeStateMock = {
|
|
131
|
-
snapshot: {},
|
|
132
|
-
url: "/path?code=123#code=456",
|
|
133
|
-
root: {
|
|
134
|
-
fragment: "code=456",
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
spyOn(MsalService.prototype, "handleRedirectObservable").and.returnValue(
|
|
139
|
-
//@ts-ignore
|
|
140
|
-
of("test")
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
spyOn(PublicClientApplication.prototype, "getAllAccounts").and.returnValue([
|
|
144
|
-
{
|
|
145
|
-
homeAccountId: "test",
|
|
146
|
-
localAccountId: "test",
|
|
147
|
-
environment: "test",
|
|
148
|
-
tenantId: "test",
|
|
149
|
-
username: "test",
|
|
150
|
-
},
|
|
151
|
-
]);
|
|
152
|
-
|
|
153
|
-
guard
|
|
154
|
-
.canActivate(routeMock, routeStateMock)
|
|
155
|
-
.subscribe((result: UrlTree) => {
|
|
156
|
-
expect(result.toString()).toEqual("/path");
|
|
157
|
-
done();
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it("returns true if page contains code= in query parameters only", (done) => {
|
|
162
|
-
initializeMsal([
|
|
163
|
-
{
|
|
164
|
-
provide: Location,
|
|
165
|
-
useValue: {
|
|
166
|
-
path: jasmine
|
|
167
|
-
.createSpy("path")
|
|
168
|
-
.and.callFake((hash: boolean) =>
|
|
169
|
-
hash ? "/path?code=123" : "/path"
|
|
170
|
-
),
|
|
171
|
-
prepareExternalUrl: jasmine
|
|
172
|
-
.createSpy("prepareExternalUrl")
|
|
173
|
-
.and.callFake((url: string) => "/path"),
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
]);
|
|
177
|
-
|
|
178
|
-
routeStateMock = {
|
|
179
|
-
snapshot: {},
|
|
180
|
-
url: "/path?code=123",
|
|
181
|
-
root: {
|
|
182
|
-
fragment: null,
|
|
183
|
-
},
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
spyOn(MsalService.prototype, "handleRedirectObservable").and.returnValue(
|
|
187
|
-
//@ts-ignore
|
|
188
|
-
of("test")
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
spyOn(PublicClientApplication.prototype, "getAllAccounts").and.returnValue([
|
|
192
|
-
{
|
|
193
|
-
homeAccountId: "test",
|
|
194
|
-
localAccountId: "test",
|
|
195
|
-
environment: "test",
|
|
196
|
-
tenantId: "test",
|
|
197
|
-
username: "test",
|
|
198
|
-
},
|
|
199
|
-
]);
|
|
200
|
-
|
|
201
|
-
guard
|
|
202
|
-
.canActivate(routeMock, routeStateMock)
|
|
203
|
-
.subscribe((result: UrlTree) => {
|
|
204
|
-
expect(result).toBeTrue();
|
|
205
|
-
done();
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it("returns true if page route doesnt end with /code", (done) => {
|
|
210
|
-
initializeMsal([
|
|
211
|
-
{
|
|
212
|
-
provide: Location,
|
|
213
|
-
useValue: {
|
|
214
|
-
path: jasmine
|
|
215
|
-
.createSpy("path")
|
|
216
|
-
.and.callFake((hash: boolean) => (hash ? "/codes" : "/")),
|
|
217
|
-
prepareExternalUrl: jasmine
|
|
218
|
-
.createSpy("prepareExternalUrl")
|
|
219
|
-
.and.callFake((url: string) => "#/codes"),
|
|
220
|
-
},
|
|
221
|
-
},
|
|
222
|
-
]);
|
|
223
|
-
|
|
224
|
-
routeStateMock = {
|
|
225
|
-
snapshot: {},
|
|
226
|
-
url: "/codes",
|
|
227
|
-
root: {
|
|
228
|
-
fragment: null,
|
|
229
|
-
},
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
spyOn(MsalService.prototype, "handleRedirectObservable").and.returnValue(
|
|
233
|
-
//@ts-ignore
|
|
234
|
-
of("test")
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
spyOn(PublicClientApplication.prototype, "getAllAccounts").and.returnValue([
|
|
238
|
-
{
|
|
239
|
-
homeAccountId: "test",
|
|
240
|
-
localAccountId: "test",
|
|
241
|
-
environment: "test",
|
|
242
|
-
tenantId: "test",
|
|
243
|
-
username: "test",
|
|
244
|
-
},
|
|
245
|
-
]);
|
|
246
|
-
|
|
247
|
-
guard
|
|
248
|
-
.canActivate(routeMock, routeStateMock)
|
|
249
|
-
.subscribe((result: UrlTree) => {
|
|
250
|
-
expect(result).toBeTrue();
|
|
251
|
-
done();
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it("returns true if page route doesnt end with /code (short path)", (done) => {
|
|
256
|
-
initializeMsal([
|
|
257
|
-
{
|
|
258
|
-
provide: Location,
|
|
259
|
-
useValue: {
|
|
260
|
-
path: jasmine
|
|
261
|
-
.createSpy("path")
|
|
262
|
-
.and.callFake((hash: boolean) => (hash ? "/cod" : "/")),
|
|
263
|
-
prepareExternalUrl: jasmine
|
|
264
|
-
.createSpy("prepareExternalUrl")
|
|
265
|
-
.and.callFake((url: string) => "#/cod"),
|
|
266
|
-
},
|
|
267
|
-
},
|
|
268
|
-
]);
|
|
269
|
-
|
|
270
|
-
routeStateMock = {
|
|
271
|
-
snapshot: {},
|
|
272
|
-
url: "/cod",
|
|
273
|
-
root: {
|
|
274
|
-
fragment: null,
|
|
275
|
-
},
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
spyOn(MsalService.prototype, "handleRedirectObservable").and.returnValue(
|
|
279
|
-
//@ts-ignore
|
|
280
|
-
of("test")
|
|
281
|
-
);
|
|
282
|
-
|
|
283
|
-
spyOn(PublicClientApplication.prototype, "getAllAccounts").and.returnValue([
|
|
284
|
-
{
|
|
285
|
-
homeAccountId: "test",
|
|
286
|
-
localAccountId: "test",
|
|
287
|
-
environment: "test",
|
|
288
|
-
tenantId: "test",
|
|
289
|
-
username: "test",
|
|
290
|
-
},
|
|
291
|
-
]);
|
|
292
|
-
|
|
293
|
-
guard
|
|
294
|
-
.canActivate(routeMock, routeStateMock)
|
|
295
|
-
.subscribe((result: UrlTree) => {
|
|
296
|
-
expect(result).toBeTrue();
|
|
297
|
-
done();
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
it("returns false if page contains known successful response (hash routing)", (done) => {
|
|
302
|
-
initializeMsal([
|
|
303
|
-
{
|
|
304
|
-
provide: Location,
|
|
305
|
-
useValue: {
|
|
306
|
-
path: jasmine
|
|
307
|
-
.createSpy("path")
|
|
308
|
-
.and.callFake((hash: boolean) => (hash ? "/code=" : "/")),
|
|
309
|
-
prepareExternalUrl: jasmine
|
|
310
|
-
.createSpy("prepareExternalUrl")
|
|
311
|
-
.and.callFake((url: string) => "#/"),
|
|
312
|
-
},
|
|
313
|
-
},
|
|
314
|
-
]);
|
|
315
|
-
|
|
316
|
-
routeStateMock = {
|
|
317
|
-
snapshot: {},
|
|
318
|
-
url: "/code",
|
|
319
|
-
root: {
|
|
320
|
-
fragment: null,
|
|
321
|
-
},
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
spyOn(MsalService.prototype, "handleRedirectObservable").and.returnValue(
|
|
325
|
-
//@ts-ignore
|
|
326
|
-
of("test")
|
|
327
|
-
);
|
|
328
|
-
|
|
329
|
-
spyOn(PublicClientApplication.prototype, "getAllAccounts").and.returnValue([
|
|
330
|
-
{
|
|
331
|
-
homeAccountId: "test",
|
|
332
|
-
localAccountId: "test",
|
|
333
|
-
environment: "test",
|
|
334
|
-
tenantId: "test",
|
|
335
|
-
username: "test",
|
|
336
|
-
},
|
|
337
|
-
]);
|
|
338
|
-
|
|
339
|
-
guard
|
|
340
|
-
.canActivate(routeMock, routeStateMock)
|
|
341
|
-
.subscribe((result: UrlTree) => {
|
|
342
|
-
expect(result.toString()).toEqual("/");
|
|
343
|
-
done();
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
it("returns true for a logged in user", (done) => {
|
|
348
|
-
spyOn(MsalService.prototype, "handleRedirectObservable").and.returnValue(
|
|
349
|
-
//@ts-ignore
|
|
350
|
-
of("test")
|
|
351
|
-
);
|
|
352
|
-
|
|
353
|
-
spyOn(PublicClientApplication.prototype, "getAllAccounts").and.returnValue([
|
|
354
|
-
{
|
|
355
|
-
homeAccountId: "test",
|
|
356
|
-
localAccountId: "test",
|
|
357
|
-
environment: "test",
|
|
358
|
-
tenantId: "test",
|
|
359
|
-
username: "test",
|
|
360
|
-
},
|
|
361
|
-
]);
|
|
362
|
-
|
|
363
|
-
guard.canActivate(routeMock, routeStateMock).subscribe((result) => {
|
|
364
|
-
expect(result).toBeTrue();
|
|
365
|
-
done();
|
|
366
|
-
});
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
it("should return true after logging in with popup", (done) => {
|
|
370
|
-
testConfiguration = {
|
|
371
|
-
authRequest: (authService, state) => {
|
|
372
|
-
expect(state).toBeDefined();
|
|
373
|
-
expect(authService).toBeDefined();
|
|
374
|
-
return {};
|
|
375
|
-
},
|
|
376
|
-
};
|
|
377
|
-
initializeMsal();
|
|
378
|
-
spyOn(MsalService.prototype, "handleRedirectObservable").and.returnValue(
|
|
379
|
-
//@ts-ignore
|
|
380
|
-
of("test")
|
|
381
|
-
);
|
|
382
|
-
|
|
383
|
-
spyOn(PublicClientApplication.prototype, "getAllAccounts").and.returnValue(
|
|
384
|
-
[]
|
|
385
|
-
);
|
|
386
|
-
|
|
387
|
-
spyOn(MsalService.prototype, "loginPopup").and.returnValue(
|
|
388
|
-
//@ts-ignore
|
|
389
|
-
of(true)
|
|
390
|
-
);
|
|
391
|
-
|
|
392
|
-
guard.canActivate(routeMock, routeStateMock).subscribe((result) => {
|
|
393
|
-
expect(result).toBeTrue();
|
|
394
|
-
done();
|
|
395
|
-
});
|
|
396
|
-
});
|
|
397
|
-
|
|
398
|
-
it("should return false after login with popup fails and no loginFailedRoute set", (done) => {
|
|
399
|
-
spyOn(MsalService.prototype, "handleRedirectObservable").and.returnValue(
|
|
400
|
-
//@ts-ignore
|
|
401
|
-
of("test")
|
|
402
|
-
);
|
|
403
|
-
|
|
404
|
-
spyOn(PublicClientApplication.prototype, "getAllAccounts").and.returnValue(
|
|
405
|
-
[]
|
|
406
|
-
);
|
|
407
|
-
|
|
408
|
-
spyOn(MsalService.prototype, "loginPopup").and.throwError("login error");
|
|
409
|
-
|
|
410
|
-
guard.canActivate(routeMock, routeStateMock).subscribe((result) => {
|
|
411
|
-
expect(result).toBeFalse();
|
|
412
|
-
done();
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
it("should return loginFailedRoute after login with popup fails and loginFailedRoute set", (done) => {
|
|
417
|
-
testLoginFailedRoute = "failed";
|
|
418
|
-
initializeMsal();
|
|
419
|
-
|
|
420
|
-
spyOn(guard, "parseUrl").and.returnValue(
|
|
421
|
-
testLoginFailedRoute as unknown as UrlTree
|
|
422
|
-
);
|
|
423
|
-
|
|
424
|
-
spyOn(MsalService.prototype, "handleRedirectObservable").and.returnValue(
|
|
425
|
-
//@ts-ignore
|
|
426
|
-
of("test")
|
|
427
|
-
);
|
|
428
|
-
|
|
429
|
-
spyOn(PublicClientApplication.prototype, "getAllAccounts").and.returnValue(
|
|
430
|
-
[]
|
|
431
|
-
);
|
|
432
|
-
|
|
433
|
-
spyOn(MsalService.prototype, "loginPopup").and.throwError("login error");
|
|
434
|
-
|
|
435
|
-
guard.canActivate(routeMock, routeStateMock).subscribe((result) => {
|
|
436
|
-
expect(result).toBe("failed" as unknown as UrlTree);
|
|
437
|
-
done();
|
|
438
|
-
});
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
it("should return false after logging in with redirect", (done) => {
|
|
442
|
-
testInteractionType = InteractionType.Redirect;
|
|
443
|
-
initializeMsal();
|
|
444
|
-
|
|
445
|
-
spyOn(MsalService.prototype, "handleRedirectObservable").and.returnValue(
|
|
446
|
-
//@ts-ignore
|
|
447
|
-
of("test")
|
|
448
|
-
);
|
|
449
|
-
|
|
450
|
-
spyOn(PublicClientApplication.prototype, "getAllAccounts").and.returnValue(
|
|
451
|
-
[]
|
|
452
|
-
);
|
|
453
|
-
|
|
454
|
-
spyOn(PublicClientApplication.prototype, "loginRedirect").and.returnValue(
|
|
455
|
-
new Promise((resolve) => {
|
|
456
|
-
resolve();
|
|
457
|
-
})
|
|
458
|
-
);
|
|
459
|
-
|
|
460
|
-
guard.canActivate(routeMock, routeStateMock).subscribe((result) => {
|
|
461
|
-
expect(result).toBeFalse();
|
|
462
|
-
done();
|
|
463
|
-
});
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
it("canActivateChild returns true with logged in user", (done) => {
|
|
467
|
-
spyOn(MsalService.prototype, "handleRedirectObservable").and.returnValue(
|
|
468
|
-
//@ts-ignore
|
|
469
|
-
of("test")
|
|
470
|
-
);
|
|
471
|
-
|
|
472
|
-
spyOn(PublicClientApplication.prototype, "getAllAccounts").and.returnValue([
|
|
473
|
-
{
|
|
474
|
-
homeAccountId: "test",
|
|
475
|
-
localAccountId: "test",
|
|
476
|
-
environment: "test",
|
|
477
|
-
tenantId: "test",
|
|
478
|
-
username: "test",
|
|
479
|
-
},
|
|
480
|
-
]);
|
|
481
|
-
|
|
482
|
-
guard.canActivateChild(routeMock, routeStateMock).subscribe((result) => {
|
|
483
|
-
expect(result).toBeTrue();
|
|
484
|
-
done();
|
|
485
|
-
});
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
it("canLoad returns true with logged in user", (done) => {
|
|
489
|
-
spyOn(MsalService.prototype, "handleRedirectObservable").and.returnValue(
|
|
490
|
-
//@ts-ignore
|
|
491
|
-
of("test")
|
|
492
|
-
);
|
|
493
|
-
|
|
494
|
-
spyOn(PublicClientApplication.prototype, "getAllAccounts").and.returnValue([
|
|
495
|
-
{
|
|
496
|
-
homeAccountId: "test",
|
|
497
|
-
localAccountId: "test",
|
|
498
|
-
environment: "test",
|
|
499
|
-
tenantId: "test",
|
|
500
|
-
username: "test",
|
|
501
|
-
},
|
|
502
|
-
]);
|
|
503
|
-
|
|
504
|
-
guard.canMatch().subscribe((result) => {
|
|
505
|
-
expect(result).toBeTrue();
|
|
506
|
-
done();
|
|
507
|
-
});
|
|
508
|
-
});
|
|
509
|
-
|
|
510
|
-
it("canLoad returns false with no users logged in", (done) => {
|
|
511
|
-
spyOn(MsalService.prototype, "handleRedirectObservable").and.returnValue(
|
|
512
|
-
//@ts-ignore
|
|
513
|
-
of("test")
|
|
514
|
-
);
|
|
515
|
-
|
|
516
|
-
spyOn(PublicClientApplication.prototype, "getAllAccounts").and.returnValue(
|
|
517
|
-
[]
|
|
518
|
-
);
|
|
519
|
-
|
|
520
|
-
guard.canMatch().subscribe((result) => {
|
|
521
|
-
expect(result).toBeFalse();
|
|
522
|
-
done();
|
|
523
|
-
});
|
|
524
|
-
});
|
|
525
|
-
});
|