-
-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathaws-saml-assertion-extraction-service.spec.ts
More file actions
93 lines (73 loc) · 4.84 KB
/
Copy pathaws-saml-assertion-extraction-service.spec.ts
File metadata and controls
93 lines (73 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { describe, test, expect, jest } from "@jest/globals";
import { AwsSamlAssertionExtractionService } from "./aws-saml-assertion-extraction-service";
import { CloudProviderType } from "../models/cloud-provider-type";
import { LoggedException, LogLevel } from "./log-service";
describe("AwsSamlAssertionExtractionService", () => {
test("isAuthenticationUrl", () => {
const service = new AwsSamlAssertionExtractionService();
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://XX.onelogin.com/XX")).toBe(true);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "http://XX.onelogin.com/XX")).toBe(false);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://XX/adfs/ls/idpinitiatedsignonXXloginToRp=urn:amazon:webservicesXXX")).toBe(
true
);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://XX/adfs/ls/idpinitiatedsignonXX")).toBe(false);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://login.okta.com/XX")).toBe(true);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://XX.okta.com")).toBe(false);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://accounts.google.com/ServiceLoginXX")).toBe(true);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://accounts.google.com/AccountChooser?continue=testtest")).toBe(true);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://accounts.google.com")).toBe(false);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://login.microsoftonline.com/XX/oauth2/authorizeXXXX")).toBe(true);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://login.microsoftonline.com")).toBe(false);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://signin.aws.amazon.com/saml")).toBe(false);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://tenant-name.us.auth0.com/u/login/subdomain")).toBe(true);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://tenant-name.us.auth0.com")).toBe(false);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://tenant-name.us.auth0.com/samlp/")).toBe(false);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://.auth0.com/samlp/")).toBe(false);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://auth0.com/samlp/")).toBe(false);
/* Tests for keycloak Identity Providers */
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://XX/auth/realms/XX/protocol/saml/clients/XX")).toBe(true);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://XX/realms/XX/protocol/saml/clients/XX")).toBe(true);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://console.jumpcloud.com/login.mocked-suffix")).toBe(true);
/* Tests for GitHub OAuth Identity Providers */
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://github.XX/login/oauth/authorize")).toBe(true);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://github.XX/login")).toBe(false);
expect(service.isAuthenticationUrl(CloudProviderType.aws, "https://github.XX")).toBe(false);
});
test("isSamlAssertionUrl", () => {
const service = new AwsSamlAssertionExtractionService();
expect(service.isSamlAssertionUrl(CloudProviderType.aws, "https://signin.aws.amazon.com/saml")).toBe(true);
expect(service.isSamlAssertionUrl(CloudProviderType.aws, "https://signin.aws.amazon.com/saml?XX")).toBe(true);
expect(service.isSamlAssertionUrl(CloudProviderType.aws, "http://signin.aws.amazon.com/saml")).toBe(false);
});
test("extractAwsSamlResponse", () => {
const responseHookDetails = {
uploadData: [{ bytes: "SAMLResponse=ABCDEFGHIJKLMNOPQRSTUVWXYZ&RelayState=abcdefghijklmnopqrstuvwxyz" }],
};
const service = new AwsSamlAssertionExtractionService();
const awsSamlResponse = service.extractAwsSamlResponse(responseHookDetails as any);
expect(awsSamlResponse).toBe("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
});
test("extractAwsSamlResponse - 2", () => {
const responseHookDetails = {
uploadData: [{ bytes: "SAMLResponse=ABCDEFGHIJKLMNOPQRSTUVWXYZ" }],
};
const service = new AwsSamlAssertionExtractionService();
const awsSamlResponse = service.extractAwsSamlResponse(responseHookDetails as any);
expect(awsSamlResponse).toBe("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
});
test("extractAwsSamlResponse - error", () => {
const responseHookDetails = {
uploadData: [
{
bytes: {
toString: jest.fn(() => {
throw new Error("");
}),
},
},
],
};
const service = new AwsSamlAssertionExtractionService();
expect(() => service.extractAwsSamlResponse(responseHookDetails as any)).toThrow(new LoggedException("", this, LogLevel.warn));
});
});