-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathaws_iot_shared.spec.ts
More file actions
102 lines (79 loc) · 3.79 KB
/
aws_iot_shared.spec.ts
File metadata and controls
102 lines (79 loc) · 3.79 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
94
95
96
97
98
99
100
101
102
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
import * as iot_shared from "./aws_iot_shared";
jest.setTimeout(10000);
test('Aws IoT Mqtt5 Username Construction - No Custom Auth', async () => {
let finalUsername : string = iot_shared.buildMqtt5FinalUsername(undefined);
expect(finalUsername).toEqual(expect.stringContaining("?SDK=IoTDeviceSDK/JS&Version="));
});
test('Aws IoT Mqtt5 Username Construction - Empty custom auth', async () => {
let finalUsername : string = iot_shared.buildMqtt5FinalUsername({});
expect(finalUsername).toEqual(expect.stringContaining("?SDK=IoTDeviceSDK/JS&Version="));
});
test('Aws IoT Mqtt5 Username Construction - Simple username', async () => {
let finalUsername : string = iot_shared.buildMqtt5FinalUsername({
username: "Derp"
});
expect(finalUsername).toEqual(expect.stringContaining("Derp?SDK=IoTDeviceSDK/JS&Version="));
});
test('Aws IoT Mqtt5 Username Construction - Query param username', async () => {
let finalUsername : string = iot_shared.buildMqtt5FinalUsername({
username: "Derp?Param1=Value1"
});
expect(finalUsername).toEqual(expect.stringContaining("Derp?Param1=Value1&SDK=IoTDeviceSDK/JS&Version="));
});
test('Aws IoT Mqtt5 Username Construction - Authorizer Name', async () => {
let finalUsername : string = iot_shared.buildMqtt5FinalUsername({
username: "Hello",
authorizerName: "MyAuthorizer"
});
expect(finalUsername).toEqual(expect.stringContaining("Hello?x-amz-customauthorizer-name=MyAuthorizer&SDK=IoTDeviceSDK/JS&Version="));
});
test('Aws IoT Mqtt5 Username Construction - Token Signing', async () => {
let finalUsername : string = iot_shared.buildMqtt5FinalUsername({
username: "Hello",
authorizerName: "MyAuthorizer",
tokenKeyName: "MyToken",
tokenValue: "TheToken",
tokenSignature: "SignedToken"
});
expect(finalUsername).toEqual(expect.stringContaining("Hello?x-amz-customauthorizer-name=MyAuthorizer&MyToken=TheToken&x-amz-customauthorizer-signature=SignedToken&SDK=IoTDeviceSDK/JS&Version="));
});
test('Aws IoT Mqtt5 Username Construction Failure - Missing token key name', async () => {
let customAuthConfig : iot_shared.MqttConnectCustomAuthConfig = {
username: "Hello",
authorizerName: "MyAuthorizer",
tokenValue: "TheToken",
tokenSignature: "SignedToken"
};
expect(() => { return iot_shared.buildMqtt5FinalUsername(customAuthConfig); }).toThrow();
});
test('Aws IoT Mqtt5 Username Construction Failure - Missing token value', async () => {
let customAuthConfig : iot_shared.MqttConnectCustomAuthConfig = {
username: "Hello",
authorizerName: "MyAuthorizer",
tokenKeyName: "MyToken",
tokenSignature: "SignedToken"
};
expect(() => { return iot_shared.buildMqtt5FinalUsername(customAuthConfig); }).toThrow();
});
test('Aws IoT Mqtt5 Username Construction Failure - Missing token signature', async () => {
let customAuthConfig : iot_shared.MqttConnectCustomAuthConfig = {
username: "Hello",
authorizerName: "MyAuthorizer",
tokenKeyName: "MyToken",
tokenValue: "TheToken"
};
expect(() => { return iot_shared.buildMqtt5FinalUsername(customAuthConfig); }).toThrow();
});
test('Aws IoT Mqtt5 Username Construction Failure - bad query username', async () => {
let customAuthConfig : iot_shared.MqttConnectCustomAuthConfig = {
username: "Derp?Param1=Value1?What"
};
expect(() => { return iot_shared.buildMqtt5FinalUsername(customAuthConfig); }).toThrow();
});
test('Extract region from endpoint success', async () => {
expect(iot_shared.extractRegionFromEndpoint("blahblah-ats.iot.us-west-2.amazonaws.com")).toEqual("us-west-2");
});