Socket
Socket
Sign inDemoInstall

aws-crt

Package Overview
Dependencies
Maintainers
4
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-crt - npm Package Compare versions

Comparing version 1.15.16 to 1.15.17

lib/browser/mqtt.spec.ts

19

dist.browser/browser/mqtt.js

@@ -389,2 +389,12 @@ "use strict";

return __generator(this, function (_a) {
// Skip payload since it can be several different types
if (typeof (topic) !== 'string') {
return [2 /*return*/, Promise.reject("topic is not a string")];
}
if (typeof (qos) !== 'number') {
return [2 /*return*/, Promise.reject("qos is not a number")];
}
if (typeof (retain) !== 'boolean') {
return [2 /*return*/, Promise.reject('retain is not a boolean')];
}
payload_data = (0, mqtt_shared_1.normalize_payload)(payload);

@@ -430,2 +440,8 @@ return [2 /*return*/, new Promise(function (resolve, reject) {

return __generator(this, function (_a) {
if (typeof (topic) !== 'string') {
return [2 /*return*/, Promise.reject("topic is not a string")];
}
if (typeof (qos) !== 'number') {
return [2 /*return*/, Promise.reject("qos is not a number")];
}
this.subscriptions.insert(topic, on_message);

@@ -457,2 +473,5 @@ return [2 /*return*/, new Promise(function (resolve, reject) {

return __generator(this, function (_a) {
if (typeof (topic) !== 'string') {
return [2 /*return*/, Promise.reject("topic is not a string")];
}
this.subscriptions.remove(topic);

@@ -459,0 +478,0 @@ return [2 /*return*/, new Promise(function (resolve, reject) {

9

dist/native/mqtt.d.ts

@@ -72,3 +72,3 @@ import { NativeResource } from "./native_resource";

* If an existing session is resumed, the server remembers previous subscriptions
* and sends mesages (with QoS1 or higher) that were published while the client was offline.
* and sends messages (with QoS1 or higher) that were published while the client was offline.
*/

@@ -234,4 +234,4 @@ clean_session?: boolean;

/**
* The connection will automatically reconnect. To cease reconnection attempts, call {@link disconnect}.
* To resume the connection, call {@link connect}.
* The connection will automatically reconnect when disconnected, removing the need for this function.
* To cease automatic reconnection attempts, call {@link disconnect}.
* @deprecated

@@ -288,2 +288,5 @@ */

* Close the connection (async).
*
* Will free all native resources, rendering the connection unusable after the disconnect() call.
*
* @returns Promise which completes when the connection is closed.

@@ -290,0 +293,0 @@ */

@@ -181,4 +181,4 @@ "use strict";

/**
* The connection will automatically reconnect. To cease reconnection attempts, call {@link disconnect}.
* To resume the connection, call {@link connect}.
* The connection will automatically reconnect when disconnected, removing the need for this function.
* To cease automatic reconnection attempts, call {@link disconnect}.
* @deprecated

@@ -217,2 +217,12 @@ */

return __awaiter(this, void 0, void 0, function* () {
// Skip payload since it can be several different types
if (typeof (topic) !== 'string') {
return Promise.reject("topic is not a string");
}
if (typeof (qos) !== 'number') {
return Promise.reject("qos is not a number");
}
if (typeof (retain) !== 'boolean') {
return Promise.reject("retain is not a boolean");
}
return new Promise((resolve, reject) => {

@@ -250,2 +260,8 @@ reject = this._reject(reject);

return __awaiter(this, void 0, void 0, function* () {
if (typeof (topic) !== 'string') {
return Promise.reject("topic is not a string");
}
if (typeof (qos) !== 'number') {
return Promise.reject("qos is not a number");
}
return new Promise((resolve, reject) => {

@@ -272,2 +288,5 @@ reject = this._reject(reject);

return __awaiter(this, void 0, void 0, function* () {
if (typeof (topic) !== 'string') {
return Promise.reject("topic is not a string");
}
return new Promise((resolve, reject) => {

@@ -286,2 +305,5 @@ reject = this._reject(reject);

* Close the connection (async).
*
* Will free all native resources, rendering the connection unusable after the disconnect() call.
*
* @returns Promise which completes when the connection is closed.

@@ -288,0 +310,0 @@ */

@@ -14,6 +14,7 @@ /*

test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasIotCoreEnvironment())('Aws Iot Core Mqtt over websockets with environmental credentials - Connection Success', async () => {
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasIoTCoreEnvironmentCred())('Aws Iot Core Mqtt over websockets with environmental credentials - Connection Success', async () => {
let provider: auth.StaticCredentialProvider = new auth.StaticCredentialProvider({
aws_access_id: test_utils.ClientEnvironmentalConfig.AWS_IOT_ACCESS_KEY_ID,
aws_secret_key: test_utils.ClientEnvironmentalConfig.AWS_IOT_SECRET_ACCESS_KEY,
aws_sts_token: test_utils.ClientEnvironmentalConfig.AWS_IOT_SESSION_TOKEN,
aws_region: "us-east-1"

@@ -40,3 +41,3 @@ });

test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasIotCoreEnvironment())('Aws Iot Core Mqtt over websockets with Non-Signing Custom Auth - Connection Success', async () => {
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Mqtt over websockets with Non-Signing Custom Auth - Connection Success', async () => {
let customAuthConfig : aws_iot_mqtt5.MqttConnectCustomAuthConfig = {

@@ -57,3 +58,3 @@ authorizerName: test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_NAME,

test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasIotCoreEnvironment())('Aws Iot Core Mqtt over websockets with Signing Custom Auth - Connection Success', async () => {
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Mqtt over websockets with Signing Custom Auth - Connection Success', async () => {
let customAuthConfig : aws_iot_mqtt5.MqttConnectCustomAuthConfig = {

@@ -77,3 +78,3 @@ authorizerName: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_NAME,

test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasIotCoreEnvironment())('Aws Iot Core Mqtt over websockets with Non-Signing Custom Auth - Connection Failure Bad Password', async () => {
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Mqtt over websockets with Non-Signing Custom Auth - Connection Failure Bad Password', async () => {
let customAuthConfig : aws_iot_mqtt5.MqttConnectCustomAuthConfig = {

@@ -94,3 +95,3 @@ authorizerName: test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_NAME,

test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasIotCoreEnvironment())('Aws Iot Core Mqtt over websockets with Signing Custom Auth - Connection Failure Bad Password', async () => {
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Mqtt over websockets with Signing Custom Auth - Connection Failure Bad Password', async () => {
let customAuthConfig : aws_iot_mqtt5.MqttConnectCustomAuthConfig = {

@@ -114,3 +115,3 @@ authorizerName: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_NAME,

test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasIotCoreEnvironment())('Aws Iot Core Mqtt over websockets with Signing Custom Auth - Connection Failure Bad Token Value', async () => {
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Mqtt over websockets with Signing Custom Auth - Connection Failure Bad Token Value', async () => {
let customAuthConfig : aws_iot_mqtt5.MqttConnectCustomAuthConfig = {

@@ -134,3 +135,3 @@ authorizerName: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_NAME,

test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasIotCoreEnvironment())('Aws Iot Core Mqtt over websockets with Signing Custom Auth - Connection Failure Bad Token Signature', async () => {
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Mqtt over websockets with Signing Custom Auth - Connection Failure Bad Token Signature', async () => {
let customAuthConfig : aws_iot_mqtt5.MqttConnectCustomAuthConfig = {

@@ -137,0 +138,0 @@ authorizerName: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_NAME,

@@ -6,21 +6,19 @@ /*

/**
* NOTE: Will later add more testing and split MQTT5 testing setup from MQTT311 testing setup.
* In the short term, the MQTT311 tests will reuse the majority of MQTT5 material.
*/
import * as test_utils from "@test/mqtt5";
import * as test_env from "@test/test_env"
import * as mqtt311 from "./mqtt";
import * as aws_iot_mqtt311 from "./aws_iot";
import * as io from "./io"
import { v4 as uuid } from 'uuid';
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasIotCoreEnvironment())('Aws Iot Core Mqtt over websockets with Non-Signing Custom Auth - Connection Success', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_custom_auth_unsigned())('Aws Iot Core Mqtt over websockets with Non-Signing Custom Auth - Connection Success', async () => {
let builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_default_builder();
builder.with_custom_authorizer(
test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_USERNAME,
test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_NAME,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_UNSIGNED_USERNAME,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_UNSIGNED_NAME,
"",
test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_PASSWORD
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_UNSIGNED_PASSWORD
)
builder.with_endpoint(test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST);
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)
let config = builder.build();

@@ -33,13 +31,14 @@ let client = new mqtt311.MqttClient();

test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasIotCoreEnvironment())('Aws Iot Core Mqtt over websockets with Signing Custom Auth - Connection Success', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_custom_auth_signed())('Aws Iot Core Mqtt over websockets with Signing Custom Auth - Connection Success', async () => {
let builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_default_builder();
builder.with_custom_authorizer(
test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_USERNAME,
test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_NAME,
test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN_SIGNATURE,
test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_PASSWORD,
test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN_KEY_NAME,
test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_USERNAME,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_NAME,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_SIGNATURE,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_PASSWORD,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_KEY_NAME,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_TOKEN,
)
builder.with_endpoint(test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST);
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)
let config = builder.build();

@@ -51,1 +50,35 @@ let client = new mqtt311.MqttClient();

});
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_cred())('MQTT Native Websocket Connect/Disconnect', async () => {
let builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_with_websockets();
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)
builder.with_credentials(
test_env.AWS_IOT_ENV.MQTT311_REGION,
test_env.AWS_IOT_ENV.MQTT311_CRED_ACCESS_KEY,
test_env.AWS_IOT_ENV.MQTT311_CRED_SECRET_ACCESS_KEY,
test_env.AWS_IOT_ENV.MQTT311_CRED_SESSION_TOKEN
);
let config = builder.build();
let client = new mqtt311.MqttClient(new io.ClientBootstrap());
let connection = client.new_connection(config);
await connection.connect();
await connection.disconnect();
});
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_cred())('MQTT Native Websocket Connect/Disconnect No Bootstrap', async () => {
let builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_with_websockets();
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)
builder.with_credentials(
test_env.AWS_IOT_ENV.MQTT311_REGION,
test_env.AWS_IOT_ENV.MQTT311_CRED_ACCESS_KEY,
test_env.AWS_IOT_ENV.MQTT311_CRED_SECRET_ACCESS_KEY,
test_env.AWS_IOT_ENV.MQTT311_CRED_SESSION_TOKEN
);
let config = builder.build();
let client = new mqtt311.MqttClient();
let connection = client.new_connection(config);
await connection.connect();
await connection.disconnect();
});

@@ -438,2 +438,13 @@ /*

async publish(topic: string, payload: Payload, qos: QoS, retain: boolean = false): Promise<MqttRequest> {
// Skip payload since it can be several different types
if (typeof(topic) !== 'string') {
return Promise.reject("topic is not a string");
}
if (typeof(qos) !== 'number') {
return Promise.reject("qos is not a number");
}
if (typeof(retain) !== 'boolean') {
return Promise.reject('retain is not a boolean');
}
let payload_data = normalize_payload(payload);

@@ -476,2 +487,9 @@ return new Promise((resolve, reject) => {

async subscribe(topic: string, qos: QoS, on_message?: OnMessageCallback): Promise<MqttSubscribeRequest> {
if (typeof(topic) !== 'string') {
return Promise.reject("topic is not a string");
}
if (typeof(qos) !== 'number') {
return Promise.reject("qos is not a number");
}
this.subscriptions.insert(topic, on_message);

@@ -499,2 +517,6 @@ return new Promise((resolve, reject) => {

async unsubscribe(topic: string): Promise<MqttRequest> {
if (typeof(topic) !== 'string') {
return Promise.reject("topic is not a string");
}
this.subscriptions.remove(topic);

@@ -501,0 +523,0 @@ return new Promise((resolve, reject) => {

@@ -293,2 +293,3 @@ /*

aws_secret_key: test_utils.ClientEnvironmentalConfig.AWS_IOT_SECRET_ACCESS_KEY,
aws_sts_token: test_utils.ClientEnvironmentalConfig.AWS_IOT_SESSION_TOKEN,
aws_region: "us-east-1"

@@ -409,3 +410,3 @@ });

test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasIotCoreEnvironment())('Sub - Pub QoS 0 - Unsub', async () => {
let topic : string = `test-${uuid()}`;
let topic : string = `test/${uuid()}`;
let testPayload : Buffer = Buffer.from("Derp", "utf-8");

@@ -433,3 +434,3 @@

test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasIotCoreEnvironment())('Sub - Pub QoS 1 - Unsub', async () => {
let topic : string = `test-${uuid()}`;
let topic : string = `test/${uuid()}`;
let testPayload : Buffer = Buffer.from("Derp", "utf-8");

@@ -458,3 +459,3 @@

let willPayload : Buffer = Buffer.from("ToMyChildrenIBequeathNothing", "utf-8");
let willTopic : string = `will/test${uuid()}`;
let willTopic : string = `test/will/test${uuid()}`;

@@ -516,2 +517,2 @@ let publisherConfig: mqtt5.Mqtt5ClientConfig = createWsIotCoreClientConfig();

await test_utils.doRetainTest(new mqtt5.Mqtt5Client(config), new mqtt5.Mqtt5Client(config), new mqtt5.Mqtt5Client(config));
});
});

@@ -8,6 +8,6 @@ /*

import * as test_env from "@test/test_env"
import { ClientBootstrap } from '@awscrt/io';
import { MqttClient, MqttClientConnection, QoS, MqttWill, Payload } from '@awscrt/mqtt';
import { AwsIotMqttConnectionConfigBuilder } from '@awscrt/aws_iot';
import { Config, fetch_credentials } from '@test/credentials';
import { fromUtf8 } from '@aws-sdk/util-utf8-browser';

@@ -21,9 +21,11 @@ import {once} from "events";

try {
let aws_opts: Config = await fetch_credentials();
const builder = AwsIotMqttConnectionConfigBuilder.new_mtls_builder(aws_opts.certificate, aws_opts.private_key)
let builder = AwsIotMqttConnectionConfigBuilder.new_with_websockets()
.with_clean_session(true)
.with_client_id(`node-mqtt-unit-test-${uuid()}`)
.with_endpoint(aws_opts.endpoint)
.with_credentials(Config.region, aws_opts.access_key, aws_opts.secret_key, aws_opts.session_token)
.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST)
.with_credentials(
test_env.AWS_IOT_ENV.MQTT311_REGION,
test_env.AWS_IOT_ENV.MQTT311_CRED_ACCESS_KEY,
test_env.AWS_IOT_ENV.MQTT311_CRED_SECRET_ACCESS_KEY,
test_env.AWS_IOT_ENV.MQTT311_CRED_SESSION_TOKEN)
.with_ping_timeout_ms(5000);

@@ -46,3 +48,3 @@

test('MQTT Connect/Disconnect', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_iot_cred())('MQTT Connect/Disconnect', async () => {
const connection = await makeConnection();

@@ -62,3 +64,3 @@

test('MQTT Pub/Sub', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_iot_cred())('MQTT Pub/Sub', async () => {
const connection = await makeConnection();

@@ -74,3 +76,3 @@

const test_topic = `/test/me/senpai/${uuid()}`;
const test_topic = `test/me/senpai/${uuid()}`;
const test_payload = 'NOTICE ME';

@@ -103,3 +105,3 @@

test('MQTT Will', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_iot_cred())('MQTT Will', async () => {
/* TODO: this doesn't really test anything. Unfortunately, there's no easy way to break the

@@ -111,3 +113,3 @@ * MQTT311 connection without it sending a client-side DISCONNECT packet which removes the will. It's not

const connection = await makeConnection(new MqttWill(
'/last/will/and/testament',
'test/last/will/and/testament',
QoS.AtLeastOnce,

@@ -129,3 +131,3 @@ 'AVENGE ME'

test('MQTT On Any Publish', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_iot_cred())('MQTT On Any Publish', async () => {
const connection = await makeConnection();

@@ -141,3 +143,3 @@

const test_topic = `/test/me/senpai/${uuid()}`;
const test_topic = `test/me/senpai/${uuid()}`;
const test_payload = 'NOTICE ME';

@@ -168,3 +170,3 @@

test('MQTT payload types', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_iot_cred())('MQTT payload types', async () => {
const connection = await makeConnection();

@@ -179,11 +181,11 @@

const tests: { [key: string]: { send: Payload, recv: ArrayBuffer } } = {
[`/test/types/${id}/string`]: {
[`test/types/${id}/string`]: {
send: 'utf-8 👁👄👁 time',
recv: fromUtf8('utf-8 👁👄👁 time').buffer,
},
[`/test/types/${id}/dataview`]: {
[`test/types/${id}/dataview`]: {
send: new DataView(fromUtf8('I was a DataView').buffer),
recv: fromUtf8('I was a DataView').buffer,
},
[`/test/types/${id}/uint8array`]: {
[`test/types/${id}/uint8array`]: {
// note: sending partial view of a larger buffer

@@ -193,7 +195,7 @@ send: new Uint8Array(new Uint8Array([0, 1, 2, 3, 4, 5, 6]).buffer, 2, 3),

},
[`/test/types/${id}/arraybuffer`]: {
[`test/types/${id}/arraybuffer`]: {
send: new Uint8Array([0, 255, 255, 255, 255, 255, 1]).buffer,
recv: new Uint8Array([0, 255, 255, 255, 255, 255, 1]).buffer,
},
[`/test/types/${id}/json`]: {
[`test/types/${id}/json`]: {
send: { I: "was JSON" },

@@ -231,3 +233,3 @@ recv: fromUtf8('{"I": "was JSON"}').buffer,

await connection.subscribe(`/test/types/${id}/#`, QoS.AtLeastOnce);
await connection.subscribe(`test/types/${id}/#`, QoS.AtLeastOnce);

@@ -234,0 +236,0 @@ for (const topic in tests) {

@@ -7,2 +7,3 @@ /*

import * as test_utils from "@test/mqtt5";
import * as test_env from "@test/test_env"
import * as mqtt5 from "./mqtt5";

@@ -12,12 +13,12 @@ import * as iot from "./iot";

import * as auth from "./auth";
import * as io from "./io";
jest.setTimeout(10000);
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasIotCoreEnvironment())('Aws Iot Core Direct Mqtt By File - Connection Success', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_mtls_rsa())('Aws Iot Core Direct Mqtt By File - Connection Success', async () => {
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newDirectMqttBuilderWithMtlsFromPath(
test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST,
test_utils.ClientEnvironmentalConfig.AWS_IOT_CERTIFICATE_PATH,
test_utils.ClientEnvironmentalConfig.AWS_IOT_KEY_PATH
test_env.AWS_IOT_ENV.MQTT5_HOST,
test_env.AWS_IOT_ENV.MQTT5_RSA_CERT,
test_env.AWS_IOT_ENV.MQTT5_RSA_KEY
);
await test_utils.testConnect(new mqtt5.Mqtt5Client(builder.build()));

@@ -27,46 +28,54 @@ });

test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasIotCoreEnvironment())('Aws Iot Core Direct Mqtt By In-Memory - Connection Success', async () => {
let cert = fs.readFileSync(test_utils.ClientEnvironmentalConfig.AWS_IOT_CERTIFICATE_PATH,'utf8');
let key = fs.readFileSync(test_utils.ClientEnvironmentalConfig.AWS_IOT_KEY_PATH,'utf8');
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_mtls_rsa())('Aws Iot Core Direct Mqtt By In-Memory - Connection Success', async () => {
let cert = fs.readFileSync(test_env.AWS_IOT_ENV.MQTT5_RSA_CERT,'utf8');
let key = fs.readFileSync(test_env.AWS_IOT_ENV.MQTT5_RSA_KEY,'utf8');
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newDirectMqttBuilderWithMtlsFromMemory(
test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST,
test_env.AWS_IOT_ENV.MQTT5_HOST,
cert,
key
);
await test_utils.testConnect(new mqtt5.Mqtt5Client(builder.build()));
});
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Direct Mqtt Non-Signing Custom Auth - Connection Success', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_custom_auth_unsigned())('Aws Iot Core Direct Mqtt Non-Signing Custom Auth - Connection Success', async () => {
let customAuthConfig : iot.MqttConnectCustomAuthConfig = {
authorizerName: test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_NAME,
username: test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_USERNAME,
password: Buffer.from(test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_PASSWORD, "utf-8")
authorizerName: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_UNSIGNED_NAME,
username: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_UNSIGNED_USERNAME,
password: Buffer.from(test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_UNSIGNED_PASSWORD, "utf-8")
};
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newDirectMqttBuilderWithCustomAuth(
test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST,
test_env.AWS_IOT_ENV.MQTT5_HOST,
customAuthConfig
);
await test_utils.testConnect(new mqtt5.Mqtt5Client(builder.build()));
});
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Direct Mqtt Signing Custom Auth - Connection Success', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_custom_auth_signed())('Aws Iot Core Direct Mqtt Signing Custom Auth - Connection Success', async () => {
let customAuthConfig : iot.MqttConnectCustomAuthConfig = {
authorizerName: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_NAME,
username: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_USERNAME,
password: Buffer.from(test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_PASSWORD, "utf-8"),
tokenKeyName: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN_KEY_NAME,
tokenValue: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN,
tokenSignature: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN_SIGNATURE
authorizerName: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_NAME,
username: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_USERNAME,
password: Buffer.from(test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_PASSWORD, "utf-8"),
tokenKeyName: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_KEY_NAME,
tokenValue: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_TOKEN,
tokenSignature: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_SIGNATURE
};
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newDirectMqttBuilderWithCustomAuth(
test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST,
test_env.AWS_IOT_ENV.MQTT5_HOST,
customAuthConfig
);
await test_utils.testConnect(new mqtt5.Mqtt5Client(builder.build()));
});
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_cred())('Aws Iot Core Websocket by Sigv4 - Connection Success', async () => {
let provider: auth.AwsCredentialsProvider = auth.AwsCredentialsProvider.newStatic(
test_env.AWS_IOT_ENV.MQTT5_CRED_ACCESS_KEY,
test_env.AWS_IOT_ENV.MQTT5_CRED_SECRET_ACCESS_KEY,
test_env.AWS_IOT_ENV.MQTT5_CRED_SESSION_TOKEN
);
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newWebsocketMqttBuilderWithSigv4Auth(
test_env.AWS_IOT_ENV.MQTT5_HOST,
{
credentialsProvider: provider
}
);
await test_utils.testConnect(new mqtt5.Mqtt5Client(builder.build()));

@@ -76,11 +85,45 @@ });

// requires correct credentials to be sourced from the default credentials provider chain
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasIotCoreEnvironment())('Aws Iot Core Websocket by Sigv4 - Connection Success', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_websocket())('Aws Iot Core Websocket Default Credentials - Connection Success', async () => {
let provider: auth.AwsCredentialsProvider = auth.AwsCredentialsProvider.newDefault();
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newWebsocketMqttBuilderWithSigv4Auth(
test_env.AWS_IOT_ENV.MQTT5_HOST,
{
credentialsProvider: provider
}
);
await test_utils.testConnect(new mqtt5.Mqtt5Client(builder.build()));
});
let provider: auth.AwsCredentialsProvider = auth.AwsCredentialsProvider.newStatic(
test_utils.ClientEnvironmentalConfig.AWS_IOT_ACCESS_KEY_ID,
test_utils.ClientEnvironmentalConfig.AWS_IOT_SECRET_ACCESS_KEY
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_cognito())('Aws Iot Core Websocket Cognito Credentials - Connection Success', async () => {
let provider: auth.AwsCredentialsProvider = auth.AwsCredentialsProvider.newCognito(
{
identity: test_env.AWS_IOT_ENV.MQTT5_COGNITO_IDENTITY,
endpoint: test_env.AWS_IOT_ENV.MQTT5_COGNITO_ENDPOINT
}
);
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newWebsocketMqttBuilderWithSigv4Auth(
test_env.AWS_IOT_ENV.MQTT5_HOST,
{
credentialsProvider: provider
}
);
await test_utils.testConnect(new mqtt5.Mqtt5Client(builder.build()));
});
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_x509())('Aws Iot Core Websocket X509 Credentials - Connection Success', async () => {
let tls_ctx_options: io.TlsContextOptions = io.TlsContextOptions.create_client_with_mtls_from_path(
test_env.AWS_IOT_ENV.MQTT5_X509_CERT,
test_env.AWS_IOT_ENV.MQTT5_X509_KEY
);
let tls_ctx = new io.ClientTlsContext(tls_ctx_options);
let provider: auth.AwsCredentialsProvider = auth.AwsCredentialsProvider.newX509(
{
endpoint: test_env.AWS_IOT_ENV.MQTT5_X509_ENDPOINT,
thingName: test_env.AWS_IOT_ENV.MQTT5_X509_THING_NAME,
roleAlias: test_env.AWS_IOT_ENV.MQTT5_X509_ROLE_ALIAS,
tlsContext: tls_ctx
}
);
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newWebsocketMqttBuilderWithSigv4Auth(
test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST,
test_env.AWS_IOT_ENV.MQTT5_HOST,
{

@@ -90,114 +133,116 @@ credentialsProvider: provider

);
await test_utils.testConnect(new mqtt5.Mqtt5Client(builder.build()));
});
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Direct Mqtt Non-Signing Custom Auth - Connection Failure Bad Password', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_custom_auth_unsigned())('Aws Iot Core Direct Mqtt Non-Signing Custom Auth - Connection Failure Bad Password', async () => {
let customAuthConfig : iot.MqttConnectCustomAuthConfig = {
authorizerName: test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_NAME,
username: test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_USERNAME,
authorizerName: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_UNSIGNED_NAME,
username: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_UNSIGNED_USERNAME,
password: Buffer.from("Thisisnotthepassword", "utf-8")
};
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newDirectMqttBuilderWithCustomAuth(
test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST,
test_env.AWS_IOT_ENV.MQTT5_HOST,
customAuthConfig
);
await test_utils.testFailedConnection(new mqtt5.Mqtt5Client(builder.build()));
});
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Direct Mqtt Signing Custom Auth - Connection Failure Bad Password', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_custom_auth_signed())('Aws Iot Core Direct Mqtt Signing Custom Auth - Connection Failure Bad Password', async () => {
let customAuthConfig : iot.MqttConnectCustomAuthConfig = {
authorizerName: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_NAME,
username: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_USERNAME,
authorizerName: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_NAME,
username: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_USERNAME,
password: Buffer.from("Thisisnotthepassword", "utf-8"),
tokenKeyName: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN_KEY_NAME,
tokenValue: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN,
tokenSignature: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN_SIGNATURE
tokenKeyName: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_KEY_NAME,
tokenValue: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_TOKEN,
tokenSignature: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_SIGNATURE
};
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newDirectMqttBuilderWithCustomAuth(
test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST,
test_env.AWS_IOT_ENV.MQTT5_HOST,
customAuthConfig
);
await test_utils.testFailedConnection(new mqtt5.Mqtt5Client(builder.build()));
});
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Direct Mqtt Signing Custom Auth - Connection Failure Bad Token Value', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_custom_auth_signed())('Aws Iot Core Direct Mqtt Signing Custom Auth - Connection Failure Bad Token Value', async () => {
let customAuthConfig : iot.MqttConnectCustomAuthConfig = {
authorizerName: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_NAME,
username: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_USERNAME,
password: Buffer.from(test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_PASSWORD, "utf-8"),
tokenKeyName: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN_KEY_NAME,
authorizerName: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_NAME,
username: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_USERNAME,
password: Buffer.from(test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_PASSWORD, "utf-8"),
tokenKeyName: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_KEY_NAME,
tokenValue: "ThisIsNotTheTokenValue",
tokenSignature: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN_SIGNATURE
tokenSignature: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_SIGNATURE
};
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newDirectMqttBuilderWithCustomAuth(
test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST,
test_env.AWS_IOT_ENV.MQTT5_HOST,
customAuthConfig
);
await test_utils.testFailedConnection(new mqtt5.Mqtt5Client(builder.build()));
});
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Direct Mqtt Signing Custom Auth - Connection Failure Bad Token Signature', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_custom_auth_signed())('Aws Iot Core Direct Mqtt Signing Custom Auth - Connection Failure Bad Token Signature', async () => {
let customAuthConfig : iot.MqttConnectCustomAuthConfig = {
authorizerName: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_NAME,
username: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_USERNAME,
password: Buffer.from(test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_PASSWORD, "utf-8"),
tokenKeyName: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN_KEY_NAME,
tokenValue: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN,
authorizerName: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_NAME,
username: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_USERNAME,
password: Buffer.from(test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_PASSWORD, "utf-8"),
tokenKeyName: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_KEY_NAME,
tokenValue: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_TOKEN,
tokenSignature: "ThisIsNotTheTokenSignature"
};
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newDirectMqttBuilderWithCustomAuth(
test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST,
test_env.AWS_IOT_ENV.MQTT5_HOST,
customAuthConfig
);
await test_utils.testFailedConnection(new mqtt5.Mqtt5Client(builder.build()));
});
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Websocket Mqtt Non-Signing Custom Auth - Connection Success', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_custom_auth_unsigned())('Aws Iot Core Websocket Mqtt Non-Signing Custom Auth - Connection Success', async () => {
let customAuthConfig : iot.MqttConnectCustomAuthConfig = {
authorizerName: test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_NAME,
username: test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_USERNAME,
password: Buffer.from(test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_PASSWORD, "utf-8")
authorizerName: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_UNSIGNED_NAME,
username: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_UNSIGNED_USERNAME,
password: Buffer.from(test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_UNSIGNED_PASSWORD, "utf-8")
};
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newWebsocketMqttBuilderWithCustomAuth(
test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST,
test_env.AWS_IOT_ENV.MQTT5_HOST,
customAuthConfig
);
await test_utils.testConnect(new mqtt5.Mqtt5Client(builder.build()));
});
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Websocket Mqtt Signing Custom Auth - Connection Success', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_custom_auth_signed())('Aws Iot Core Websocket Mqtt Signing Custom Auth - Connection Success', async () => {
let customAuthConfig : iot.MqttConnectCustomAuthConfig = {
authorizerName: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_NAME,
username: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_USERNAME,
password: Buffer.from(test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_PASSWORD, "utf-8"),
tokenKeyName: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN_KEY_NAME,
tokenValue: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN,
tokenSignature: test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN_SIGNATURE
authorizerName: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_NAME,
username: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_USERNAME,
password: Buffer.from(test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_PASSWORD, "utf-8"),
tokenKeyName: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_KEY_NAME,
tokenValue: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_TOKEN,
tokenSignature: test_env.AWS_IOT_ENV.MQTT5_CUSTOM_AUTH_SIGNED_SIGNATURE
};
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newWebsocketMqttBuilderWithCustomAuth(
test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST,
test_env.AWS_IOT_ENV.MQTT5_HOST,
customAuthConfig
);
await test_utils.testConnect(new mqtt5.Mqtt5Client(builder.build()));
});
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_pkcs11())('Aws Iot Core PKCS11 - Connection Success', async () => {
const pkcs11_lib = new io.Pkcs11Lib(test_env.AWS_IOT_ENV.MQTT5_PKCS11_LIB_PATH);
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newDirectMqttBuilderWithMtlsFromPkcs11(
test_env.AWS_IOT_ENV.MQTT5_HOST,
{
pkcs11_lib: pkcs11_lib,
user_pin: test_env.AWS_IOT_ENV.MQTT5_PKCS11_PIN,
token_label: test_env.AWS_IOT_ENV.MQTT5_PKCS11_TOKEN_LABEL,
private_key_object_label: test_env.AWS_IOT_ENV.MQTT5_PKCS11_PRIVATE_KEY_LABEL,
cert_file_path: test_env.AWS_IOT_ENV.MQTT5_PKCS11_CERT,
}
);
await test_utils.testConnect(new mqtt5.Mqtt5Client(builder.build()));
});
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasPKCS12Environment())('Aws Iot Core PKCS12 - Connection Success', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_pkcs12())('Aws Iot Core PKCS12 - Connection Success', async () => {
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newDirectMqttBuilderWithMtlsFromPkcs12(
test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST,
test_env.AWS_IOT_ENV.MQTT5_HOST,
{
pkcs12_file : test_utils.ClientEnvironmentalConfig.AWS_TEST_MQTT311_IOT_CORE_PKCS12_KEY,
pkcs12_password : test_utils.ClientEnvironmentalConfig.AWS_TEST_MQTT311_IOT_CORE_PKCS12_KEY_PASSWORD
pkcs12_file : test_env.AWS_IOT_ENV.MQTT5_PKCS12_FILE,
pkcs12_password : test_env.AWS_IOT_ENV.MQTT5_PKCS12_PASSWORD
}

@@ -208,1 +253,9 @@ );

test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt5_is_valid_windows_cert())('Aws Iot Core Window Cert - Connection Success', async () => {
let builder = iot.AwsIotMqtt5ClientConfigBuilder.newDirectMqttBuilderWithMtlsFromWindowsCertStorePath(
test_env.AWS_IOT_ENV.MQTT5_HOST,
test_env.AWS_IOT_ENV.MQTT5_WINDOWS_CERT
);
await test_utils.testConnect(new mqtt5.Mqtt5Client(builder.build()));
});

@@ -6,24 +6,21 @@ /*

/**
* NOTE: Will later add more testing and split MQTT5 testing setup from MQTT311 testing setup.
* In the short term, the MQTT311 tests will reuse the majority of MQTT5 material.
*/
import * as test_utils from "@test/mqtt5";
import * as test_env from "@test/test_env"
import * as mqtt311 from "./mqtt";
import * as aws_iot_mqtt311 from "./aws_iot";
import * as io from "./io"
import * as auth from "./auth"
import { v4 as uuid } from 'uuid';
test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Mqtt over websockets with Non-Signing Custom Auth - Connection Success', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_custom_auth_unsigned())('Aws Iot Core Mqtt over websockets with Non-Signing Custom Auth - Connection Success', async () => {
let builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_builder_for_websocket();
builder.with_custom_authorizer(
test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_USERNAME,
test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_NAME,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_UNSIGNED_USERNAME,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_UNSIGNED_NAME,
"",
test_utils.ClientEnvironmentalConfig.AWS_IOT_NO_SIGNING_AUTHORIZER_PASSWORD,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_UNSIGNED_PASSWORD,
undefined,
undefined,
)
builder.with_endpoint(test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST);
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)

@@ -37,13 +34,13 @@ let config = builder.build();

test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasCustomAuthEnvironment())('Aws Iot Core Mqtt over websockets with Signing Custom Auth - Connection Success', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_custom_auth_signed())('Aws Iot Core Mqtt over websockets with Signing Custom Auth - Connection Success', async () => {
let builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_builder_for_websocket();
builder.with_custom_authorizer(
test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_USERNAME,
test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_NAME,
test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN_SIGNATURE,
test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_PASSWORD,
test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN_KEY_NAME,
test_utils.ClientEnvironmentalConfig.AWS_IOT_SIGNING_AUTHORIZER_TOKEN,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_USERNAME,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_NAME,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_SIGNATURE,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_PASSWORD,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_KEY_NAME,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_TOKEN,
)
builder.with_endpoint(test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST);
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)

@@ -57,7 +54,25 @@ let config = builder.build();

test_utils.conditional_test(test_utils.ClientEnvironmentalConfig.hasPKCS12Environment())('Aws Iot Core PKCS12 connection', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_pkcs11())('Aws Iot Core PKCS11 connection', async () => {
const pkcs11_lib = new io.Pkcs11Lib(test_env.AWS_IOT_ENV.MQTT311_PKCS11_LIB_PATH);
const builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_mtls_pkcs11_builder({
pkcs11_lib: pkcs11_lib,
user_pin: test_env.AWS_IOT_ENV.MQTT311_PKCS11_PIN,
token_label: test_env.AWS_IOT_ENV.MQTT311_PKCS11_TOKEN_LABEL,
private_key_object_label: test_env.AWS_IOT_ENV.MQTT311_PKCS11_PRIVATE_KEY_LABEL,
cert_file_path: test_env.AWS_IOT_ENV.MQTT311_PKCS11_CERT,
});
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)
let config = builder.build();
let client = new mqtt311.MqttClient();
let connection = client.new_connection(config);
await connection.connect();
await connection.disconnect();
});
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_pkcs12())('Aws Iot Core PKCS12 connection', async () => {
let builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_mtls_pkcs12_builder({
pkcs12_file : test_utils.ClientEnvironmentalConfig.AWS_TEST_MQTT311_IOT_CORE_PKCS12_KEY,
pkcs12_password : test_utils.ClientEnvironmentalConfig.AWS_TEST_MQTT311_IOT_CORE_PKCS12_KEY_PASSWORD});
builder.with_endpoint(test_utils.ClientEnvironmentalConfig.AWS_IOT_HOST);
pkcs12_file : test_env.AWS_IOT_ENV.MQTT311_PKCS12_FILE,
pkcs12_password : test_env.AWS_IOT_ENV.MQTT311_PKCS12_PASSWORD});
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)

@@ -70,1 +85,146 @@ let config = builder.build();

});
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_windows_cert())('Aws Iot Core Windows Cert connection', async () => {
let builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_mtls_windows_cert_store_path_builder(
test_env.AWS_IOT_ENV.MQTT311_WINDOWS_CERT);
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)
let config = builder.build();
let client = new mqtt311.MqttClient();
let connection = client.new_connection(config);
await connection.connect();
await connection.disconnect();
});
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_custom_auth_unsigned())('Aws Iot Core - Direct MQTT Custom Auth unsigned', async () => {
let builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_default_builder();
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)
builder.with_custom_authorizer(
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_UNSIGNED_USERNAME,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_UNSIGNED_NAME,
"",
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_UNSIGNED_PASSWORD,
undefined,
undefined)
let config = builder.build();
let client = new mqtt311.MqttClient();
let connection = client.new_connection(config);
await connection.connect();
await connection.disconnect();
});
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_custom_auth_signed())('Aws Iot Core - Direct MQTT Custom Auth signed', async () => {
let builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_default_builder();
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)
builder.with_custom_authorizer(
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_USERNAME,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_NAME,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_SIGNATURE,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_PASSWORD,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_KEY_NAME,
test_env.AWS_IOT_ENV.MQTT311_CUSTOM_AUTH_SIGNED_TOKEN)
let config = builder.build();
let client = new mqtt311.MqttClient();
let connection = client.new_connection(config);
await connection.connect();
await connection.disconnect();
});
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_cred())('MQTT Native Websocket Connect/Disconnect', async () => {
let websocket_config = {
region: test_env.AWS_IOT_ENV.MQTT311_REGION,
credentials_provider: auth.AwsCredentialsProvider.newStatic(
test_env.AWS_IOT_ENV.MQTT311_CRED_ACCESS_KEY,
test_env.AWS_IOT_ENV.MQTT311_CRED_SECRET_ACCESS_KEY,
test_env.AWS_IOT_ENV.MQTT311_CRED_SESSION_TOKEN
),
}
let builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_with_websockets(websocket_config);
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)
let config = builder.build();
let client = new mqtt311.MqttClient(new io.ClientBootstrap());
let connection = client.new_connection(config);
await connection.connect();
await connection.disconnect();
});
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_cred())('MQTT Native Websocket Connect/Disconnect No Bootstrap', async () => {
let websocket_config = {
region: test_env.AWS_IOT_ENV.MQTT311_REGION,
credentials_provider: auth.AwsCredentialsProvider.newStatic(
test_env.AWS_IOT_ENV.MQTT311_CRED_ACCESS_KEY,
test_env.AWS_IOT_ENV.MQTT311_CRED_SECRET_ACCESS_KEY,
test_env.AWS_IOT_ENV.MQTT311_CRED_SESSION_TOKEN
),
}
let builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_with_websockets(websocket_config);
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)
let config = builder.build();
let client = new mqtt311.MqttClient();
let connection = client.new_connection(config);
await connection.connect();
await connection.disconnect();
});
// requires correct credentials to be sourced from the default credentials provider chain
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_websocket())('MQTT Native Websocket Default AWS Credentials', async () => {
let websocket_config = {
region: test_env.AWS_IOT_ENV.MQTT311_REGION,
credentials_provider: auth.AwsCredentialsProvider.newDefault()
}
let builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_with_websockets(websocket_config);
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)
let config = builder.build();
let client = new mqtt311.MqttClient();
let connection = client.new_connection(config);
await connection.connect();
await connection.disconnect();
});
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_cognito())('MQTT Native Websocket Cognito Credentials', async () => {
let websocket_config = {
region: test_env.AWS_IOT_ENV.MQTT311_REGION,
credentials_provider: auth.AwsCredentialsProvider.newCognito({
identity: test_env.AWS_IOT_ENV.MQTT311_COGNITO_IDENTITY,
endpoint: test_env.AWS_IOT_ENV.MQTT311_COGNITO_ENDPOINT
})
}
let builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_with_websockets(websocket_config);
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)
let config = builder.build();
let client = new mqtt311.MqttClient();
let connection = client.new_connection(config);
await connection.connect();
await connection.disconnect();
});
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_x509())('MQTT Native Websocket X509 Credentials', async () => {
let tls_ctx_options: io.TlsContextOptions = io.TlsContextOptions.create_client_with_mtls_from_path(
test_env.AWS_IOT_ENV.MQTT311_X509_CERT,
test_env.AWS_IOT_ENV.MQTT311_X509_KEY
);
let tls_ctx = new io.ClientTlsContext(tls_ctx_options);
let websocket_config = {
region: test_env.AWS_IOT_ENV.MQTT311_REGION,
credentials_provider: auth.AwsCredentialsProvider.newX509({
endpoint: test_env.AWS_IOT_ENV.MQTT311_X509_ENDPOINT,
thingName: test_env.AWS_IOT_ENV.MQTT311_X509_THING_NAME,
roleAlias: test_env.AWS_IOT_ENV.MQTT311_X509_ROLE_ALIAS,
tlsContext: tls_ctx
})
}
let builder = aws_iot_mqtt311.AwsIotMqttConnectionConfigBuilder.new_with_websockets(websocket_config);
builder.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_HOST);
builder.with_client_id(`node-mqtt-unit-test-${uuid()}`)
let config = builder.build();
let client = new mqtt311.MqttClient();
let connection = client.new_connection(config);
await connection.connect();
await connection.disconnect();
});

@@ -6,38 +6,12 @@ /*

import { ClientBootstrap, Pkcs11Lib, TlsContextOptions } from '@awscrt/io';
import { MqttClient, QoS } from '@awscrt/mqtt';
import { AwsIotMqttConnectionConfigBuilder, WebsocketConfig } from '@awscrt/aws_iot';
import { AwsCredentialsProvider } from '@awscrt/auth';
import { Config, fetch_credentials } from '@test/credentials';
import * as test_env from "@test/test_env"
import { ClientBootstrap, TlsContextOptions, ClientTlsContext, SocketOptions } from './io';
import { MqttClient, MqttConnectionConfig, QoS } from './mqtt';
import { v4 as uuid } from 'uuid';
import {HttpProxyOptions, HttpProxyAuthenticationType, HttpProxyConnectionType} from "./http"
import { AwsIotMqttConnectionConfigBuilder } from './aws_iot';
jest.setTimeout(10000);
const conditional_test = (condition: boolean) => condition ? it : it.skip;
class Pkcs11Config {
public static LIB_PATH = process.env.AWS_TEST_PKCS11_LIB ?? ""
public static PIN = process.env.AWS_TEST_PKCS11_PIN ?? ""
public static TOKEN_LABEL = process.env.AWS_TEST_PKCS11_TOKEN_LABEL ?? ""
public static KEY_LABEL = process.env.AWS_TEST_PKCS11_KEY_LABEL ?? ""
public static is_valid() {
return Pkcs11Config.LIB_PATH !== "" &&
Pkcs11Config.PIN !== "" &&
Pkcs11Config.TOKEN_LABEL !== "" &&
Pkcs11Config.KEY_LABEL !== "";
}
}
async function test_websockets(aws_opts: Config, websocket_config: WebsocketConfig, client: MqttClient) {
const builder = AwsIotMqttConnectionConfigBuilder.new_with_websockets(websocket_config);
await test_builder(aws_opts, builder, client);
}
async function test_builder(aws_opts: Config, builder: AwsIotMqttConnectionConfigBuilder, client: MqttClient) {
const config = builder
.with_clean_session(true)
.with_client_id(`node-mqtt-unit-test-${uuid()}`)
.with_endpoint(aws_opts.endpoint)
.build();
async function test_connection(config: MqttConnectionConfig, client: MqttClient) {
const connection = client.new_connection(config);

@@ -65,88 +39,201 @@ const promise = new Promise(async (resolve, reject) => {

test('MQTT Native Websocket Connect/Disconnect', async () => {
let aws_opts: Config = await fetch_credentials();
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_direct_mqtt())('MQTT311 Connection - no credentials', async () => {
const config : MqttConnectionConfig = {
client_id : `node-mqtt-unit-test-${uuid()}`,
host_name: test_env.AWS_IOT_ENV.MQTT311_DIRECT_MQTT_HOST,
port: parseInt(test_env.AWS_IOT_ENV.MQTT311_DIRECT_MQTT_PORT),
clean_session: true,
socket_options: new SocketOptions()
}
await test_connection(config, new MqttClient(new ClientBootstrap()));
});
await test_websockets(aws_opts, {
region: "us-east-1",
credentials_provider: AwsCredentialsProvider.newStatic(
aws_opts.access_key,
aws_opts.secret_key,
aws_opts.session_token
),
}, new MqttClient(new ClientBootstrap()));
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_direct_auth_mqtt())('MQTT311 Connection - basic auth', async () => {
const config : MqttConnectionConfig = {
client_id : `node-mqtt-unit-test-${uuid()}`,
host_name: test_env.AWS_IOT_ENV.MQTT311_DIRECT_AUTH_MQTT_HOST,
port: parseInt(test_env.AWS_IOT_ENV.MQTT311_DIRECT_AUTH_MQTT_PORT),
clean_session: true,
username: test_env.AWS_IOT_ENV.MQTT311_BASIC_AUTH_USERNAME,
password: test_env.AWS_IOT_ENV.MQTT311_BASIC_AUTH_PASSWORD,
socket_options: new SocketOptions()
}
await test_connection(config, new MqttClient(new ClientBootstrap()));
});
test('MQTT Native Websocket Connect/Disconnect No Bootstrap', async () => {
let aws_opts: Config = await fetch_credentials();
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_direct_tls_mqtt())('MQTT311 Connection - TLS', async () => {
const tls_ctx_options = new TlsContextOptions();
tls_ctx_options.verify_peer = false;
const config : MqttConnectionConfig = {
client_id : `node-mqtt-unit-test-${uuid()}`,
host_name: test_env.AWS_IOT_ENV.MQTT311_DIRECT_TLS_MQTT_HOST,
port: parseInt(test_env.AWS_IOT_ENV.MQTT311_DIRECT_TLS_MQTT_PORT),
clean_session: true,
socket_options: new SocketOptions(),
tls_ctx: new ClientTlsContext(tls_ctx_options)
};
await test_connection(config, new MqttClient(new ClientBootstrap()));
});
await test_websockets(aws_opts, {
region: "us-east-1",
credentials_provider: AwsCredentialsProvider.newStatic(
aws_opts.access_key,
aws_opts.secret_key,
aws_opts.session_token
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_direct_proxy())('MQTT311 Connection - Proxy', async () => {
const tls_ctx_options = new TlsContextOptions();
tls_ctx_options.verify_peer = false;
let tls_ctx = new ClientTlsContext(tls_ctx_options);
const config : MqttConnectionConfig = {
client_id : `node-mqtt-unit-test-${uuid()}`,
host_name: test_env.AWS_IOT_ENV.MQTT311_DIRECT_TLS_MQTT_HOST,
port: parseInt(test_env.AWS_IOT_ENV.MQTT311_DIRECT_TLS_MQTT_PORT),
clean_session: true,
proxy_options: new HttpProxyOptions(
test_env.AWS_IOT_ENV.MQTT311_PROXY_HOST,
parseInt(test_env.AWS_IOT_ENV.MQTT311_PROXY_PORT),
HttpProxyAuthenticationType.None,
undefined,
undefined,
undefined,
HttpProxyConnectionType.Tunneling
),
}, new MqttClient());
socket_options: new SocketOptions(),
tls_ctx: tls_ctx
}
await test_connection(config, new MqttClient(new ClientBootstrap()));
});
test('MQTT Native Websocket Connect/Disconnect with TLS Context Options', async () => {
let aws_opts: Config = await fetch_credentials();
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_iot_rsa())('MQTT311 Connection - mTLS RSA', async () => {
const config : MqttConnectionConfig = {
client_id : `node-mqtt-unit-test-${uuid()}`,
host_name: test_env.AWS_IOT_ENV.MQTT311_IOT_MQTT_HOST,
port: 8883,
clean_session: true,
socket_options: new SocketOptions()
}
let tls_ctx_options: TlsContextOptions = TlsContextOptions.create_client_with_mtls_from_path(
test_env.AWS_IOT_ENV.MQTT311_IOT_MQTT_RSA_CERT,
test_env.AWS_IOT_ENV.MQTT311_IOT_MQTT_RSA_KEY
);
config.tls_ctx = new ClientTlsContext(tls_ctx_options);
await test_connection(config, new MqttClient(new ClientBootstrap()));
});
let tls_ctx_options = new TlsContextOptions();
tls_ctx_options.alpn_list = [];
tls_ctx_options.verify_peer = true;
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_iot_ecc())('MQTT311 Connection - mTLS ECC', async () => {
const config : MqttConnectionConfig = {
client_id : `node-mqtt-unit-test-${uuid()}`,
host_name: test_env.AWS_IOT_ENV.MQTT311_IOT_MQTT_HOST,
port: 8883,
clean_session: true,
socket_options: new SocketOptions()
}
let tls_ctx_options: TlsContextOptions = TlsContextOptions.create_client_with_mtls_from_path(
test_env.AWS_IOT_ENV.MQTT311_IOT_MQTT_ECC_CERT,
test_env.AWS_IOT_ENV.MQTT311_IOT_MQTT_ECC_KEY
);
config.tls_ctx = new ClientTlsContext(tls_ctx_options);
await test_connection(config, new MqttClient(new ClientBootstrap()));
});
await test_websockets(aws_opts, {
region: "us-east-1",
tls_ctx_options: tls_ctx_options,
credentials_provider: AwsCredentialsProvider.newStatic(
aws_opts.access_key,
aws_opts.secret_key,
aws_opts.session_token
),
}, new MqttClient(new ClientBootstrap()));
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_ws_mqtt())('MQTT311 WS Connection - no credentials', async () => {
const config : MqttConnectionConfig = {
client_id : `node-mqtt-unit-test-${uuid()}`,
host_name: test_env.AWS_IOT_ENV.MQTT311_WS_MQTT_HOST,
port: parseInt(test_env.AWS_IOT_ENV.MQTT311_WS_MQTT_PORT),
clean_session: true,
use_websocket: true,
socket_options: new SocketOptions()
}
config.websocket_handshake_transform = async (request, done) => {
done();
}
await test_connection(config, new MqttClient(new ClientBootstrap()));
});
conditional_test(Pkcs11Config.is_valid())('MQTT Native PKCS#11 Connect/Disconnect', async () => {
const aws_opts: Config = await fetch_credentials();
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_ws_auth_mqtt())('MQTT311 WS Connection - basic auth', async () => {
const config : MqttConnectionConfig = {
client_id : `node-mqtt-unit-test-${uuid()}`,
host_name: test_env.AWS_IOT_ENV.MQTT311_WS_AUTH_MQTT_HOST,
port: parseInt(test_env.AWS_IOT_ENV.MQTT311_WS_AUTH_MQTT_PORT),
clean_session: true,
use_websocket: true,
username: test_env.AWS_IOT_ENV.MQTT311_BASIC_AUTH_USERNAME,
password: test_env.AWS_IOT_ENV.MQTT311_BASIC_AUTH_PASSWORD,
socket_options: new SocketOptions()
}
config.websocket_handshake_transform = async (request, done) => {
done();
}
await test_connection(config, new MqttClient(new ClientBootstrap()));
});
const pkcs11_lib = new Pkcs11Lib(Pkcs11Config.LIB_PATH);
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_ws_tls_mqtt())('MQTT311 WS Connection - TLS', async () => {
const tls_ctx_options = new TlsContextOptions();
tls_ctx_options.verify_peer = false;
let tls_ctx = new ClientTlsContext(tls_ctx_options);
const config : MqttConnectionConfig = {
client_id : `node-mqtt-unit-test-${uuid()}`,
host_name: test_env.AWS_IOT_ENV.MQTT311_WS_TLS_MQTT_HOST,
port: parseInt(test_env.AWS_IOT_ENV.MQTT311_WS_TLS_MQTT_PORT),
clean_session: true,
use_websocket: true,
socket_options: new SocketOptions(),
tls_ctx: tls_ctx
}
config.websocket_handshake_transform = async (request, done) => {
done();
}
await test_connection(config, new MqttClient(new ClientBootstrap()));
});
const builder = AwsIotMqttConnectionConfigBuilder.new_mtls_pkcs11_builder({
pkcs11_lib: pkcs11_lib,
user_pin: Pkcs11Config.PIN,
token_label: Pkcs11Config.TOKEN_LABEL,
private_key_object_label: Pkcs11Config.KEY_LABEL,
cert_file_contents: aws_opts.certificate,
});
await test_builder(aws_opts, builder, new MqttClient(new ClientBootstrap()));
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_ws_proxy())('MQTT311 WS Connection - Proxy', async () => {
const tls_ctx_options = new TlsContextOptions();
tls_ctx_options.verify_peer = false;
let tls_ctx = new ClientTlsContext(tls_ctx_options);
const config : MqttConnectionConfig = {
client_id : `node-mqtt-unit-test-${uuid()}`,
host_name: test_env.AWS_IOT_ENV.MQTT311_WS_TLS_MQTT_HOST,
port: parseInt(test_env.AWS_IOT_ENV.MQTT311_WS_TLS_MQTT_PORT),
clean_session: true,
use_websocket: true,
proxy_options: new HttpProxyOptions(
test_env.AWS_IOT_ENV.MQTT311_PROXY_HOST,
parseInt(test_env.AWS_IOT_ENV.MQTT311_PROXY_PORT),
HttpProxyAuthenticationType.None,
undefined,
undefined,
undefined,
HttpProxyConnectionType.Tunneling
),
socket_options: new SocketOptions(),
tls_ctx: tls_ctx
}
config.websocket_handshake_transform = async (request, done) => {
done();
}
await test_connection(config, new MqttClient(new ClientBootstrap()));
});
/**
* Helper function to make creating an IoT Core connection easier.
*/
function make_test_iot_core_connection(clean_session?: boolean) {
const config = AwsIotMqttConnectionConfigBuilder.new_mtls_builder_from_path(
test_env.AWS_IOT_ENV.MQTT311_IOT_MQTT_RSA_CERT, test_env.AWS_IOT_ENV.MQTT311_IOT_MQTT_RSA_KEY)
.with_client_id(`node-mqtt-unit-test-${uuid()}`)
.with_endpoint(test_env.AWS_IOT_ENV.MQTT311_IOT_MQTT_HOST)
.with_credentials(
test_env.AWS_IOT_ENV.MQTT311_IOT_MQTT_REGION, test_env.AWS_IOT_ENV.MQTT311_IOT_CRED_ACCESS_KEY,
test_env.AWS_IOT_ENV.MQTT311_IOT_CRED_SECRET_ACCESS_KEY, test_env.AWS_IOT_ENV.MQTT311_IOT_CRED_SESSION_TOKEN);
if (clean_session != undefined) {
config.with_clean_session(clean_session);
} else {
config.with_clean_session(true)
}
test('MQTT Native ECC key Connect/Disconnect', async () => {
const aws_opts: Config = await fetch_credentials();
const builder = AwsIotMqttConnectionConfigBuilder.new_mtls_builder(aws_opts.ecc_certificate, aws_opts.ecc_private_key);
const client = new MqttClient(new ClientBootstrap());
return client.new_connection(config.build());
}
await test_builder(aws_opts, builder, new MqttClient(new ClientBootstrap()));
});
test('MQTT Operation statistics simple', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_iot_cred())('MQTT Operation statistics simple', async () => {
const promise = new Promise(async (resolve, reject) => {
let aws_opts: Config;
try {
aws_opts = await fetch_credentials();
} catch (err) {
reject(err);
return;
}
const config = AwsIotMqttConnectionConfigBuilder.new_mtls_builder(aws_opts.certificate, aws_opts.private_key)
.with_clean_session(true)
.with_client_id(`node-mqtt-unit-test-${uuid()}`)
.with_endpoint(aws_opts.endpoint)
.with_credentials(Config.region, aws_opts.access_key, aws_opts.secret_key, aws_opts.session_token)
.build()
const client = new MqttClient(new ClientBootstrap());
const connection = client.new_connection(config);
const connection = make_test_iot_core_connection();

@@ -193,20 +280,6 @@ connection.on('connect', async (session_present) => {

test('MQTT Operation statistics check publish', async () => {
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_iot_cred())('MQTT Operation statistics check publish', async () => {
const promise = new Promise(async (resolve, reject) => {
let aws_opts: Config;
try {
aws_opts = await fetch_credentials();
} catch (err) {
reject(err);
return;
}
const config = AwsIotMqttConnectionConfigBuilder.new_mtls_builder(aws_opts.certificate, aws_opts.private_key)
.with_clean_session(true)
.with_client_id(`node-mqtt-unit-test-${uuid()}`)
.with_endpoint(aws_opts.endpoint)
.with_credentials(Config.region, aws_opts.access_key, aws_opts.secret_key, aws_opts.session_token)
.build()
const client = new MqttClient(new ClientBootstrap());
const connection = client.new_connection(config);
const connection = make_test_iot_core_connection();

@@ -252,1 +325,39 @@ connection.on('connect', async (session_present) => {

});
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_iot_cred())('MQTT Disconnect behavior hard-disconnect - default functions like expected', async () => {
const promise = new Promise(async (resolve, reject) => {
const connection = make_test_iot_core_connection(
false /* clean start */);
await connection.connect();
await connection.disconnect();
// Native resources should have been cleaned on the disconnect, so the connect attempt should throw.
let did_throw = false;
await connection.connect().catch(err => {
did_throw = true;
})
expect(did_throw).toBeTruthy();
resolve(true);
});
await expect(promise).resolves.toBeTruthy();
});
test_env.conditional_test(test_env.AWS_IOT_ENV.mqtt311_is_valid_iot_cred())('MQTT Disconnect behavior hard-disconnect - ensure operations do not work after disconnect', async () => {
const promise = new Promise(async (resolve, reject) => {
const connection = make_test_iot_core_connection(
false /* clean start */);
await connection.connect();
await connection.disconnect();
// Doing any operations after disconnect should throw because the client is cleaned up
let did_throw = false;
await connection.publish("test/example/topic", "payload", QoS.AtLeastOnce).catch(err => {
did_throw = true;
})
expect(did_throw).toBeTruthy();
resolve(true);
});
await expect(promise).resolves.toBeTruthy();
});

@@ -114,3 +114,3 @@ /*

* If an existing session is resumed, the server remembers previous subscriptions
* and sends mesages (with QoS1 or higher) that were published while the client was offline.
* and sends messages (with QoS1 or higher) that were published while the client was offline.
*/

@@ -401,4 +401,4 @@ clean_session?: boolean;

/**
* The connection will automatically reconnect. To cease reconnection attempts, call {@link disconnect}.
* To resume the connection, call {@link connect}.
* The connection will automatically reconnect when disconnected, removing the need for this function.
* To cease automatic reconnection attempts, call {@link disconnect}.
* @deprecated

@@ -435,2 +435,13 @@ */

async publish(topic: string, payload: Payload, qos: QoS, retain: boolean = false) {
// Skip payload since it can be several different types
if (typeof(topic) !== 'string') {
return Promise.reject("topic is not a string");
}
if (typeof(qos) !== 'number') {
return Promise.reject("qos is not a number");
}
if (typeof(retain) !== 'boolean') {
return Promise.reject("retain is not a boolean");
}
return new Promise<MqttRequest>((resolve, reject) => {

@@ -466,2 +477,9 @@ reject = this._reject(reject);

async subscribe(topic: string, qos: QoS, on_message?: OnMessageCallback) {
if (typeof(topic) !== 'string') {
return Promise.reject("topic is not a string");
}
if (typeof(qos) !== 'number') {
return Promise.reject("qos is not a number");
}
return new Promise<MqttSubscribeRequest>((resolve, reject) => {

@@ -487,2 +505,6 @@ reject = this._reject(reject);

async unsubscribe(topic: string) {
if (typeof(topic) !== 'string') {
return Promise.reject("topic is not a string");
}
return new Promise<MqttRequest>((resolve, reject) => {

@@ -501,2 +523,5 @@ reject = this._reject(reject);

* Close the connection (async).
*
* Will free all native resources, rendering the connection unusable after the disconnect() call.
*
* @returns Promise which completes when the connection is closed.

@@ -503,0 +528,0 @@ */

{
"name": "aws-crt",
"version": "1.15.16",
"version": "1.15.17",
"description": "NodeJS/browser bindings to the aws-c-* libraries",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/awslabs/aws-crt-nodejs",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc