@tsed/oidc-provider 8.11.0 → 8.11.2-rc.1
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/lib/esm/OidcModule.js +0 -1
- package/lib/esm/constants/constants.js +0 -1
- package/lib/esm/decorators/grantId.js +0 -1
- package/lib/esm/decorators/interaction.js +0 -1
- package/lib/esm/decorators/interactions.js +0 -1
- package/lib/esm/decorators/noCache.js +0 -1
- package/lib/esm/decorators/oidcCtx.js +0 -1
- package/lib/esm/decorators/oidcSession.js +0 -1
- package/lib/esm/decorators/params.js +0 -1
- package/lib/esm/decorators/prompt.js +0 -1
- package/lib/esm/decorators/uid.js +0 -1
- package/lib/esm/domain/InteractionMethods.js +0 -1
- package/lib/esm/domain/OidcAccountsMethods.js +0 -1
- package/lib/esm/domain/OidcBadInteractionName.js +0 -1
- package/lib/esm/domain/OidcInteractionMethods.js +0 -1
- package/lib/esm/domain/OidcInteractionOptions.js +0 -1
- package/lib/esm/domain/OidcInteractionPromptProps.js +0 -1
- package/lib/esm/domain/OidcSettings.js +0 -1
- package/lib/esm/domain/interfaces.js +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/middlewares/OidcInteractionMiddleware.js +0 -1
- package/lib/esm/middlewares/OidcNoCacheMiddleware.js +0 -1
- package/lib/esm/middlewares/OidcSecureMiddleware.js +0 -1
- package/lib/esm/services/OidcAdapters.js +0 -1
- package/lib/esm/services/OidcInteractionContext.js +0 -1
- package/lib/esm/services/OidcInteractions.js +0 -1
- package/lib/esm/services/OidcJwks.js +0 -1
- package/lib/esm/services/OidcPolicy.js +0 -1
- package/lib/esm/services/OidcProvider.js +0 -1
- package/lib/esm/utils/debug.js +0 -1
- package/lib/esm/utils/events.js +0 -1
- package/package.json +13 -10
- package/lib/esm/OidcModule.js.map +0 -1
- package/lib/esm/constants/constants.js.map +0 -1
- package/lib/esm/decorators/grantId.js.map +0 -1
- package/lib/esm/decorators/interaction.js.map +0 -1
- package/lib/esm/decorators/interactions.js.map +0 -1
- package/lib/esm/decorators/noCache.js.map +0 -1
- package/lib/esm/decorators/oidcCtx.js.map +0 -1
- package/lib/esm/decorators/oidcSession.js.map +0 -1
- package/lib/esm/decorators/params.js.map +0 -1
- package/lib/esm/decorators/prompt.js.map +0 -1
- package/lib/esm/decorators/uid.js.map +0 -1
- package/lib/esm/domain/InteractionMethods.js.map +0 -1
- package/lib/esm/domain/OidcAccountsMethods.js.map +0 -1
- package/lib/esm/domain/OidcBadInteractionName.js.map +0 -1
- package/lib/esm/domain/OidcInteractionMethods.js.map +0 -1
- package/lib/esm/domain/OidcInteractionOptions.js.map +0 -1
- package/lib/esm/domain/OidcInteractionPromptProps.js.map +0 -1
- package/lib/esm/domain/OidcSettings.js.map +0 -1
- package/lib/esm/domain/interfaces.js.map +0 -1
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/middlewares/OidcInteractionMiddleware.js.map +0 -1
- package/lib/esm/middlewares/OidcNoCacheMiddleware.js.map +0 -1
- package/lib/esm/middlewares/OidcSecureMiddleware.js.map +0 -1
- package/lib/esm/services/OidcAdapters.js.map +0 -1
- package/lib/esm/services/OidcInteractionContext.js.map +0 -1
- package/lib/esm/services/OidcInteractions.js.map +0 -1
- package/lib/esm/services/OidcJwks.js.map +0 -1
- package/lib/esm/services/OidcPolicy.js.map +0 -1
- package/lib/esm/services/OidcProvider.js.map +0 -1
- package/lib/esm/utils/debug.js.map +0 -1
- package/lib/esm/utils/events.js.map +0 -1
- package/src/OidcModule.spec.ts +0 -116
- package/src/OidcModule.ts +0 -70
- package/src/constants/constants.ts +0 -10
- package/src/decorators/grantId.spec.ts +0 -17
- package/src/decorators/grantId.ts +0 -10
- package/src/decorators/interaction.spec.ts +0 -27
- package/src/decorators/interaction.ts +0 -18
- package/src/decorators/interactions.spec.ts +0 -23
- package/src/decorators/interactions.ts +0 -21
- package/src/decorators/noCache.ts +0 -7
- package/src/decorators/oidcCtx.spec.ts +0 -17
- package/src/decorators/oidcCtx.ts +0 -11
- package/src/decorators/oidcSession.spec.ts +0 -17
- package/src/decorators/oidcSession.ts +0 -14
- package/src/decorators/params.spec.ts +0 -17
- package/src/decorators/params.ts +0 -10
- package/src/decorators/prompt.spec.ts +0 -17
- package/src/decorators/prompt.ts +0 -11
- package/src/decorators/uid.spec.ts +0 -17
- package/src/decorators/uid.ts +0 -10
- package/src/domain/InteractionMethods.ts +0 -11
- package/src/domain/OidcAccountsMethods.ts +0 -10
- package/src/domain/OidcBadInteractionName.ts +0 -3
- package/src/domain/OidcInteractionMethods.ts +0 -3
- package/src/domain/OidcInteractionOptions.ts +0 -8
- package/src/domain/OidcInteractionPromptProps.ts +0 -11
- package/src/domain/OidcSettings.ts +0 -72
- package/src/domain/interfaces.ts +0 -13
- package/src/index.ts +0 -33
- package/src/middlewares/OidcInteractionMiddleware.spec.ts +0 -40
- package/src/middlewares/OidcInteractionMiddleware.ts +0 -14
- package/src/middlewares/OidcNoCacheMiddleware.spec.ts +0 -18
- package/src/middlewares/OidcNoCacheMiddleware.ts +0 -10
- package/src/middlewares/OidcSecureMiddleware.spec.ts +0 -106
- package/src/middlewares/OidcSecureMiddleware.ts +0 -30
- package/src/services/OidcAdapters.spec.ts +0 -100
- package/src/services/OidcAdapters.ts +0 -92
- package/src/services/OidcInteractionContext.spec.ts +0 -304
- package/src/services/OidcInteractionContext.ts +0 -206
- package/src/services/OidcInteractions.ts +0 -57
- package/src/services/OidcJwks.ts +0 -22
- package/src/services/OidcPolicy.spec.ts +0 -156
- package/src/services/OidcPolicy.ts +0 -92
- package/src/services/OidcProvider.spec.ts +0 -116
- package/src/services/OidcProvider.ts +0 -198
- package/src/utils/debug.spec.ts +0 -12
- package/src/utils/debug.ts +0 -26
- package/src/utils/events.ts +0 -61
- package/vitest.config.mts +0 -21
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import url from "node:url";
|
|
2
|
-
|
|
3
|
-
import {BadRequest} from "@tsed/exceptions";
|
|
4
|
-
import {Middleware, MiddlewareMethods} from "@tsed/platform-middlewares";
|
|
5
|
-
import {Context} from "@tsed/platform-params";
|
|
6
|
-
|
|
7
|
-
@Middleware()
|
|
8
|
-
export class OidcSecureMiddleware implements MiddlewareMethods {
|
|
9
|
-
use(@Context() ctx: Context) {
|
|
10
|
-
const req = ctx.request;
|
|
11
|
-
|
|
12
|
-
if (!req.secure) {
|
|
13
|
-
if (req.method === "GET" || req.method === "HEAD") {
|
|
14
|
-
ctx.response.redirect(
|
|
15
|
-
302,
|
|
16
|
-
url.format({
|
|
17
|
-
protocol: "https",
|
|
18
|
-
host: req.get("host"),
|
|
19
|
-
pathname: req.url
|
|
20
|
-
})
|
|
21
|
-
);
|
|
22
|
-
} else {
|
|
23
|
-
throw new BadRequest("InvalidRequest", {
|
|
24
|
-
error: "invalid_request",
|
|
25
|
-
error_description: "Do yourself a favor and only use https"
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import {faker} from "@faker-js/faker";
|
|
2
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
3
|
-
import type {Adapter} from "oidc-provider";
|
|
4
|
-
|
|
5
|
-
import {OidcAdapters} from "./OidcAdapters.js";
|
|
6
|
-
|
|
7
|
-
describe("OidcAdapters", () => {
|
|
8
|
-
beforeEach(() => PlatformTest.create());
|
|
9
|
-
afterEach(() => PlatformTest.reset());
|
|
10
|
-
|
|
11
|
-
describe("createAdapterClass()", () => {
|
|
12
|
-
let adapter: Adapter;
|
|
13
|
-
|
|
14
|
-
beforeEach(async () => {
|
|
15
|
-
const oidcAdapters = await PlatformTest.invoke<OidcAdapters>(OidcAdapters);
|
|
16
|
-
adapter = new (oidcAdapters.createAdapterClass())("clients");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
describe("adapter.upsert()", () => {
|
|
20
|
-
it("should call upsert", async () => {
|
|
21
|
-
const id = faker.string.uuid();
|
|
22
|
-
|
|
23
|
-
await adapter.upsert(
|
|
24
|
-
id,
|
|
25
|
-
{
|
|
26
|
-
client_id: id
|
|
27
|
-
},
|
|
28
|
-
20000
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
const obj: any = await adapter.find(id);
|
|
32
|
-
|
|
33
|
-
expect(obj._id).toEqual(id);
|
|
34
|
-
expect(obj.client_id).toEqual(id);
|
|
35
|
-
expect(obj.expires_at).toBeInstanceOf(Date);
|
|
36
|
-
|
|
37
|
-
await adapter.destroy(id);
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe("adapter.findByUserCode()", () => {
|
|
42
|
-
it("should find data by userCode", async () => {
|
|
43
|
-
const id = faker.string.uuid();
|
|
44
|
-
|
|
45
|
-
await adapter.upsert(
|
|
46
|
-
id,
|
|
47
|
-
{
|
|
48
|
-
userCode: id
|
|
49
|
-
},
|
|
50
|
-
20000
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const obj: any = await adapter.findByUserCode(id);
|
|
54
|
-
|
|
55
|
-
expect(obj._id).toEqual(id);
|
|
56
|
-
expect(obj.userCode).toEqual(id);
|
|
57
|
-
expect(obj.expires_at).toBeInstanceOf(Date);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
describe("adapter.findByUid()", () => {
|
|
61
|
-
it("should find data by uid", async () => {
|
|
62
|
-
const id = faker.string.uuid();
|
|
63
|
-
|
|
64
|
-
await adapter.upsert(
|
|
65
|
-
id,
|
|
66
|
-
{
|
|
67
|
-
uid: id
|
|
68
|
-
},
|
|
69
|
-
20000
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
const obj: any = await adapter.findByUid(id);
|
|
73
|
-
|
|
74
|
-
expect(obj._id).toEqual(id);
|
|
75
|
-
expect(obj.uid).toEqual(id);
|
|
76
|
-
expect(obj.expires_at).toBeInstanceOf(Date);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
describe("adapter.deleteMany()", () => {
|
|
80
|
-
it("should delete items", async () => {
|
|
81
|
-
const id = faker.string.uuid();
|
|
82
|
-
|
|
83
|
-
await adapter.upsert(
|
|
84
|
-
id,
|
|
85
|
-
{
|
|
86
|
-
grantId: id
|
|
87
|
-
},
|
|
88
|
-
20000
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
await adapter.consume(id);
|
|
92
|
-
const obj: any = await adapter.find(id);
|
|
93
|
-
await adapter.revokeByGrantId(id);
|
|
94
|
-
|
|
95
|
-
expect(obj._id).toEqual(id);
|
|
96
|
-
expect(obj.grantId).toEqual(id);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import {Adapter, Adapters} from "@tsed/adapters";
|
|
2
|
-
import {constant, inject, Injectable} from "@tsed/di";
|
|
3
|
-
import type {Adapter as OidcAdapter, AdapterConstructor} from "oidc-provider";
|
|
4
|
-
|
|
5
|
-
export type OidcAdapterMethods<Model = any> = Adapter<Model> & Partial<Omit<OidcAdapter, "upsert">>;
|
|
6
|
-
|
|
7
|
-
@Injectable()
|
|
8
|
-
export class OidcAdapters {
|
|
9
|
-
protected adapters = inject(Adapters);
|
|
10
|
-
|
|
11
|
-
createAdapterClass(): AdapterConstructor {
|
|
12
|
-
const self = this;
|
|
13
|
-
const adapterBase = constant("oidc.Adapter", constant("adapters.Adapter"));
|
|
14
|
-
const connectionName = constant("oidc.connectionName", "default");
|
|
15
|
-
|
|
16
|
-
return class CustomAdapter implements OidcAdapter {
|
|
17
|
-
adapter: OidcAdapterMethods;
|
|
18
|
-
|
|
19
|
-
constructor(name: string) {
|
|
20
|
-
this.adapter = self.adapters.invokeAdapter<any>({
|
|
21
|
-
adapter: adapterBase,
|
|
22
|
-
collectionName: name,
|
|
23
|
-
connectionName,
|
|
24
|
-
model: Object
|
|
25
|
-
}) as OidcAdapterMethods;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async upsert(id: string, payload: any, expiresIn: number): Promise<void> {
|
|
29
|
-
let expiresAt;
|
|
30
|
-
|
|
31
|
-
if (expiresIn) {
|
|
32
|
-
expiresAt = new Date(Date.now() + expiresIn * 1000);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
await this.adapter.upsert(id, payload, expiresAt);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
find(id: string) {
|
|
39
|
-
return this.adapter.findById(id);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
findByUserCode(userCode: string) {
|
|
43
|
-
// istanbul ignore next
|
|
44
|
-
if (this.adapter.findByUserCode) {
|
|
45
|
-
return this.adapter.findByUserCode(userCode);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return this.adapter.findOne({
|
|
49
|
-
userCode
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
findByUid(uid: string) {
|
|
54
|
-
// istanbul ignore next
|
|
55
|
-
if (this.adapter.findByUid) {
|
|
56
|
-
return this.adapter.findByUid(uid);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return this.adapter.findOne({
|
|
60
|
-
uid
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async destroy(id: string) {
|
|
65
|
-
// istanbul ignore next
|
|
66
|
-
if (this.adapter.destroy) {
|
|
67
|
-
return this.adapter.destroy(id);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
await this.adapter.deleteById(id);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
async revokeByGrantId(grantId: string) {
|
|
74
|
-
// istanbul ignore next
|
|
75
|
-
if (this.adapter.revokeByGrantId) {
|
|
76
|
-
return this.adapter.revokeByGrantId(grantId);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
await this.adapter.deleteMany({grantId});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async consume(grantId: string) {
|
|
83
|
-
// istanbul ignore next
|
|
84
|
-
if (this.adapter.consume) {
|
|
85
|
-
return this.adapter.consume(grantId);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
await this.adapter.update(grantId, {consumed: Math.floor(Date.now() / 1000)});
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
}
|
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import {catchAsyncError, catchError} from "@tsed/core";
|
|
2
|
-
import {runInContext} from "@tsed/di";
|
|
3
|
-
import {PlatformTest} from "@tsed/platform-http/testing";
|
|
4
|
-
|
|
5
|
-
import {OidcInteractionContext} from "./OidcInteractionContext.js";
|
|
6
|
-
import {OidcProvider} from "./OidcProvider.js";
|
|
7
|
-
|
|
8
|
-
async function createOidcInteractionContextFixture(grantId: any = "grantId") {
|
|
9
|
-
const $ctx = PlatformTest.createRequestContext();
|
|
10
|
-
|
|
11
|
-
const session = {
|
|
12
|
-
accountId: "accountId"
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const interactionDetails: any = {
|
|
16
|
-
uid: "uid",
|
|
17
|
-
grantId,
|
|
18
|
-
session,
|
|
19
|
-
prompt: {
|
|
20
|
-
name: "login"
|
|
21
|
-
},
|
|
22
|
-
params: {
|
|
23
|
-
client_id: "client_id",
|
|
24
|
-
email: "email@email.com"
|
|
25
|
-
},
|
|
26
|
-
save: vi.fn()
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const oidcProvider = {
|
|
30
|
-
interactionDetails: vi.fn().mockResolvedValue(interactionDetails),
|
|
31
|
-
interactionFinished: vi.fn().mockResolvedValue(undefined),
|
|
32
|
-
interactionResult: vi.fn().mockResolvedValue(undefined),
|
|
33
|
-
setProviderSession: vi.fn().mockResolvedValue(undefined),
|
|
34
|
-
find: vi.fn().mockResolvedValue("grant"),
|
|
35
|
-
Grant: class {
|
|
36
|
-
static find = vi.fn().mockResolvedValue("grant");
|
|
37
|
-
},
|
|
38
|
-
Client: {
|
|
39
|
-
find: vi.fn().mockResolvedValue({
|
|
40
|
-
client_id: "client_id"
|
|
41
|
-
})
|
|
42
|
-
},
|
|
43
|
-
Account: {
|
|
44
|
-
findAccount: vi.fn().mockResolvedValue({
|
|
45
|
-
accountId: "accountId"
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
const oidcCtx = await PlatformTest.invoke<OidcInteractionContext>(OidcInteractionContext, [
|
|
50
|
-
{
|
|
51
|
-
token: OidcProvider,
|
|
52
|
-
use: {
|
|
53
|
-
get() {
|
|
54
|
-
return oidcProvider;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
]);
|
|
59
|
-
|
|
60
|
-
await runInContext($ctx, () => oidcCtx.interactionDetails());
|
|
61
|
-
|
|
62
|
-
return {$ctx, oidcCtx, oidcProvider, session, interactionDetails};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
describe("OidcInteractionContext", () => {
|
|
66
|
-
beforeEach(() => PlatformTest.create());
|
|
67
|
-
afterEach(() => PlatformTest.reset());
|
|
68
|
-
|
|
69
|
-
describe("uid()", () => {
|
|
70
|
-
it("should return uid", async () => {
|
|
71
|
-
const {$ctx, oidcCtx} = await createOidcInteractionContextFixture();
|
|
72
|
-
|
|
73
|
-
await runInContext($ctx, () => {
|
|
74
|
-
expect(oidcCtx.uid).toEqual("uid");
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe("checkInteractionName()", () => {
|
|
80
|
-
it("should throw error", async () => {
|
|
81
|
-
const {$ctx, oidcCtx} = await createOidcInteractionContextFixture();
|
|
82
|
-
|
|
83
|
-
await runInContext($ctx, () => {
|
|
84
|
-
const error: any = catchError(() => oidcCtx.checkInteractionName("test"));
|
|
85
|
-
|
|
86
|
-
expect(error?.message).toEqual("Bad interaction name");
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe("checkClientId()", () => {
|
|
92
|
-
it("should throw error", async () => {
|
|
93
|
-
const {$ctx, oidcCtx, oidcProvider} = await createOidcInteractionContextFixture();
|
|
94
|
-
oidcProvider.Client.find.mockResolvedValue(undefined);
|
|
95
|
-
|
|
96
|
-
await runInContext($ctx, async () => {
|
|
97
|
-
const error: any = await catchAsyncError(() => oidcCtx.checkClientId());
|
|
98
|
-
|
|
99
|
-
expect(error?.message).toEqual("Unknown client_id client_id");
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe("grantId()", () => {
|
|
105
|
-
it("should return uid", async () => {
|
|
106
|
-
const {$ctx, oidcCtx} = await createOidcInteractionContextFixture();
|
|
107
|
-
await runInContext($ctx, () => {
|
|
108
|
-
expect(oidcCtx.grantId).toEqual("grantId");
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
describe("session()", () => {
|
|
114
|
-
it("should return session", async () => {
|
|
115
|
-
const {$ctx, oidcCtx, interactionDetails} = await createOidcInteractionContextFixture();
|
|
116
|
-
await runInContext($ctx, () => {
|
|
117
|
-
expect(oidcCtx.session).toEqual(interactionDetails.session);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
describe("prompt()", () => {
|
|
123
|
-
it("should return prompt", async () => {
|
|
124
|
-
const {$ctx, oidcCtx} = await createOidcInteractionContextFixture();
|
|
125
|
-
|
|
126
|
-
await runInContext($ctx, () => {
|
|
127
|
-
expect(oidcCtx.prompt).toEqual({
|
|
128
|
-
name: "login"
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
describe("params()", () => {
|
|
135
|
-
it("should return params", async () => {
|
|
136
|
-
const {$ctx, oidcCtx, interactionDetails} = await createOidcInteractionContextFixture();
|
|
137
|
-
await runInContext($ctx, () => {
|
|
138
|
-
expect(oidcCtx.params).toEqual(interactionDetails.params);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe("interactionFinished()", () => {
|
|
144
|
-
it("should return call interactionFinished", async () => {
|
|
145
|
-
const {$ctx, oidcCtx, oidcProvider} = await createOidcInteractionContextFixture();
|
|
146
|
-
|
|
147
|
-
await runInContext($ctx, async () => {
|
|
148
|
-
await oidcCtx.interactionFinished({login: {accountId: "string"}}, {mergeWithLastSubmission: false});
|
|
149
|
-
|
|
150
|
-
expect(oidcProvider.interactionFinished).toHaveBeenCalledWith(
|
|
151
|
-
$ctx.getReq(),
|
|
152
|
-
$ctx.getRes(),
|
|
153
|
-
{login: {accountId: "string"}},
|
|
154
|
-
{mergeWithLastSubmission: false}
|
|
155
|
-
);
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
describe("interactionResult()", () => {
|
|
161
|
-
it("should return call interactionResult", async () => {
|
|
162
|
-
const {$ctx, oidcCtx, oidcProvider} = await createOidcInteractionContextFixture();
|
|
163
|
-
await runInContext($ctx, async () => {
|
|
164
|
-
await oidcCtx.interactionResult({login: {accountId: "string"}}, {mergeWithLastSubmission: false});
|
|
165
|
-
|
|
166
|
-
expect(oidcProvider.interactionResult).toHaveBeenCalledWith(
|
|
167
|
-
$ctx.getReq(),
|
|
168
|
-
$ctx.getRes(),
|
|
169
|
-
{login: {accountId: "string"}},
|
|
170
|
-
{mergeWithLastSubmission: false}
|
|
171
|
-
);
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
it("should return call interactionResult (default)", async () => {
|
|
175
|
-
const {$ctx, oidcCtx, oidcProvider} = await createOidcInteractionContextFixture();
|
|
176
|
-
await runInContext($ctx, async () => {
|
|
177
|
-
await oidcCtx.interactionResult({login: {accountId: "string"}});
|
|
178
|
-
|
|
179
|
-
expect(oidcProvider.interactionResult).toHaveBeenCalledWith(
|
|
180
|
-
$ctx.getReq(),
|
|
181
|
-
$ctx.getRes(),
|
|
182
|
-
{login: {accountId: "string"}},
|
|
183
|
-
{mergeWithLastSubmission: false}
|
|
184
|
-
);
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
describe("render()", () => {
|
|
190
|
-
it("should return call render", async () => {
|
|
191
|
-
const {$ctx, oidcCtx} = await createOidcInteractionContextFixture();
|
|
192
|
-
await runInContext($ctx, async () => {
|
|
193
|
-
vi.spyOn($ctx.response, "render").mockResolvedValue("");
|
|
194
|
-
|
|
195
|
-
await oidcCtx.render("login", {});
|
|
196
|
-
|
|
197
|
-
expect($ctx.response.render).toHaveBeenCalledWith("login", {});
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
describe("save()", () => {
|
|
203
|
-
it("should return call save", async () => {
|
|
204
|
-
const {$ctx, oidcCtx, interactionDetails} = await createOidcInteractionContextFixture();
|
|
205
|
-
await runInContext($ctx, async () => {
|
|
206
|
-
await oidcCtx.save(2000);
|
|
207
|
-
|
|
208
|
-
expect(interactionDetails.save).toHaveBeenCalledWith(2000);
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it("should return call save (default)", async () => {
|
|
213
|
-
const {$ctx, oidcCtx, interactionDetails} = await createOidcInteractionContextFixture();
|
|
214
|
-
await runInContext($ctx, async () => {
|
|
215
|
-
await oidcCtx.save(100);
|
|
216
|
-
|
|
217
|
-
expect(interactionDetails.save).toHaveBeenCalledWith(100);
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
describe("findClient()", () => {
|
|
223
|
-
it("should return call findClient", async () => {
|
|
224
|
-
const {$ctx, oidcCtx, oidcProvider} = await createOidcInteractionContextFixture();
|
|
225
|
-
await runInContext($ctx, async () => {
|
|
226
|
-
const result = await oidcCtx.findClient("client_id");
|
|
227
|
-
|
|
228
|
-
expect(result).toEqual({
|
|
229
|
-
client_id: "client_id"
|
|
230
|
-
});
|
|
231
|
-
expect(oidcProvider.Client.find).toHaveBeenCalledWith("client_id");
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it("should return call findClient (default)", async () => {
|
|
236
|
-
const {$ctx, oidcCtx, oidcProvider} = await createOidcInteractionContextFixture();
|
|
237
|
-
|
|
238
|
-
await runInContext($ctx, async () => {
|
|
239
|
-
const result = await oidcCtx.findClient();
|
|
240
|
-
|
|
241
|
-
expect(result).toEqual({
|
|
242
|
-
client_id: "client_id"
|
|
243
|
-
});
|
|
244
|
-
expect(oidcProvider.Client.find).toHaveBeenCalledWith("client_id");
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
describe("findAccount()", () => {
|
|
250
|
-
it("should return call findAccount", async () => {
|
|
251
|
-
const {$ctx, oidcCtx, oidcProvider} = await createOidcInteractionContextFixture();
|
|
252
|
-
await runInContext($ctx, async () => {
|
|
253
|
-
const result = await oidcCtx.findAccount(undefined, "token");
|
|
254
|
-
|
|
255
|
-
expect(oidcProvider.Account.findAccount).toHaveBeenCalledWith(undefined, "accountId", "token");
|
|
256
|
-
expect(result).toEqual({
|
|
257
|
-
accountId: "accountId"
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it("should return call findAccount (with accountId)", async () => {
|
|
263
|
-
const {$ctx, oidcCtx, oidcProvider} = await createOidcInteractionContextFixture();
|
|
264
|
-
await runInContext($ctx, async () => {
|
|
265
|
-
const result = await oidcCtx.findAccount("accountId", "token");
|
|
266
|
-
|
|
267
|
-
expect(oidcProvider.Account.findAccount).toHaveBeenCalledWith(undefined, "accountId", "token");
|
|
268
|
-
expect(result).toEqual({
|
|
269
|
-
accountId: "accountId"
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
it("should return call findAccount (without session/accountId)", async () => {
|
|
275
|
-
const {$ctx, oidcCtx, interactionDetails} = await createOidcInteractionContextFixture();
|
|
276
|
-
|
|
277
|
-
await runInContext($ctx, async () => {
|
|
278
|
-
interactionDetails.session.accountId = undefined;
|
|
279
|
-
|
|
280
|
-
const result = await runInContext($ctx, () => oidcCtx.findAccount(undefined, "token"));
|
|
281
|
-
|
|
282
|
-
expect(result).toBeUndefined();
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
describe("getGrant()", () => {
|
|
288
|
-
it("should return call grant from grantId", async () => {
|
|
289
|
-
const {$ctx, oidcCtx} = await createOidcInteractionContextFixture();
|
|
290
|
-
await runInContext($ctx, async () => {
|
|
291
|
-
const result = await oidcCtx.getGrant();
|
|
292
|
-
expect(result).toEqual("grant");
|
|
293
|
-
});
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
it("should create grant", async () => {
|
|
297
|
-
const {$ctx, oidcCtx} = await createOidcInteractionContextFixture(null);
|
|
298
|
-
await runInContext($ctx, async () => {
|
|
299
|
-
const result = await oidcCtx.getGrant();
|
|
300
|
-
expect(result).toEqual({});
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
});
|