UNPKG

2.87 kBPlain TextView Raw
1/*
2 * Copyright 2021 Inrupt Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal in
6 * the Software without restriction, including without limitation the rights to use,
7 * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 * Software, and to permit persons to whom the Software is furnished to do so,
9 * subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21
22// Required by TSyringe:
23import "reflect-metadata";
24import PopUpLoginHandler from "../../../src/login/popUp/PopUpLoginHandler";
25import { SessionInfoManagerMock } from "../../../src/sessionInfo/__mocks__/SessionInfoManager";
26import { LoginHandlerMock } from "../../../src/login/__mocks__/LoginHandler";
27
28describe("PopUpLoginHandler", () => {
29 const defaultMocks = {
30 loginHandler: LoginHandlerMock,
31 sessionCreator: SessionInfoManagerMock,
32 };
33 function getInitialisedHandler(
34 mocks: Partial<typeof defaultMocks> = defaultMocks
35 ): PopUpLoginHandler {
36 return new PopUpLoginHandler(
37 mocks.loginHandler ?? defaultMocks.loginHandler,
38 mocks.sessionCreator ?? defaultMocks.sessionCreator
39 );
40 }
41
42 describe("canHandle", () => {
43 it("Accepts a configuration for popup", async () => {
44 const handler = getInitialisedHandler();
45 expect(
46 await handler.canHandle({
47 sessionId: "mySession",
48 popUp: true,
49 redirectUrl: "/redirect",
50 tokenType: "DPoP",
51 })
52 ).toBe(true);
53 });
54 it("Rejects a configuration not for popup", async () => {
55 const handler = getInitialisedHandler();
56 expect(
57 await handler.canHandle({
58 sessionId: "mySession",
59 popUp: false,
60 redirectUrl: "https://coolsite.com/redirect",
61 tokenType: "DPoP",
62 })
63 ).toBe(false);
64 });
65 });
66
67 describe("handle", () => {
68 it("is unimplemented", async () => {
69 const handler = getInitialisedHandler();
70 await expect(
71 handler.handle({
72 sessionId: "mySession",
73 popUp: true,
74 tokenType: "DPoP",
75 })
76 ).rejects.toThrow("Popup login is not implemented yet");
77 });
78 });
79});