Merge remote-tracking branch 'upstream/master' into bertk-merge
This commit is contained in:
Коммит
0fe9e7e2b3
|
@ -44,6 +44,8 @@ The `connect` method establishes a connection with the server using the config o
|
|||
|
||||
**SRS_NODE_COMMON_MQTT_BASE_18_001: [** The `connect` method shall set the `ca` option based on the `ca` string passed in the `options` structure via the `setOptions` function. **]**
|
||||
|
||||
**SRS_NODE_COMMON_MQTT_BASE_18_002: [** The `connect` method shall set the `wsOptions.agent` option based on the `mqtt.webSocketAgent` object passed in the `options` structure via the `setOptions` function. **]**
|
||||
|
||||
**SRS_NODE_COMMON_MQTT_BASE_12_005: [** The `connect` method shall call connect on MQTT.JS library and call the `done` callback with a `null` error object and the result as a second argument. **]**
|
||||
|
||||
**SRS_NODE_COMMON_MQTT_BASE_16_003: [** The `connect` method shall call the `done` callback with a standard javascript `Error` object if the connection failed. **]**
|
||||
|
|
|
@ -12,6 +12,9 @@ import { errors, results, SharedAccessSignature, X509 } from 'azure-iot-common';
|
|||
|
||||
/*Codes_SRS_NODE_COMMON_MQTT_BASE_16_004: [The `MqttBase` constructor shall instanciate the default MQTT.JS library if no argument is passed to it.]*/
|
||||
/*Codes_SRS_NODE_COMMON_MQTT_BASE_16_005: [The `MqttBase` constructor shall use the object passed as argument instead of the default MQTT.JS library if it's not falsy.]*/
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export class MqttBase extends EventEmitter {
|
||||
private mqttprovider: any;
|
||||
private _config: MqttBaseTransportConfig;
|
||||
|
@ -222,6 +225,19 @@ export class MqttBase extends EventEmitter {
|
|||
reschedulePings: false
|
||||
};
|
||||
|
||||
/*Codes_SRS_NODE_COMMON_MQTT_BASE_18_001: [The `connect` method shall set the `ca` option based on the `ca` string passed in the `options` structure via the `setOptions` function.]*/
|
||||
if (this._options) {
|
||||
if (this._options.ca) {
|
||||
options.ca = this._options.ca;
|
||||
}
|
||||
/*Codes_SRS_NODE_COMMON_MQTT_BASE_18_002: [The `connect` method shall set the `wsOptions.agent` option based on the `mqtt.webSocketAgent` object passed in the `options` structure via the `setOptions` function.]*/
|
||||
if (this._options.mqtt && this._options.mqtt.webSocketAgent) {
|
||||
options.wsOptions = {
|
||||
agent: this._options.mqtt.webSocketAgent
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/*Codes_SRS_NODE_COMMON_MQTT_BASE_18_001: [The `connect` method shall set the `ca` option based on the `ca` string passed in the `options` structure via the `setOptions` function.]*/
|
||||
if (this._options && this._options.ca) {
|
||||
options.ca = this._options.ca;
|
||||
|
@ -281,6 +297,9 @@ export class MqttBase extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export interface MqttBaseTransportConfig {
|
||||
sharedAccessSignature?: string | SharedAccessSignature;
|
||||
clientId: string;
|
||||
|
|
|
@ -163,6 +163,45 @@ describe('MqttBase', function () {
|
|||
transport.connect(fakeConfig, function () {});
|
||||
});
|
||||
|
||||
/*Tests_SRS_NODE_COMMON_MQTT_BASE_18_001: [The `connect` method shall set the `ca` option based on the `ca` string passed in the `options` structure via the `setOptions` function.]*/
|
||||
it('uses the ca passed into setOptions', function(done) {
|
||||
var fakeConfig = {
|
||||
host: "host.name",
|
||||
deviceId: "deviceId",
|
||||
sharedAccessSignature: "sasToken"
|
||||
};
|
||||
var fakeCa = '__FAKE_CA__';
|
||||
var fakemqtt = new FakeMqtt();
|
||||
var transport = new MqttBase('test', fakemqtt);
|
||||
|
||||
transport.setOptions({ca: fakeCa});
|
||||
fakemqtt.connect = function(host, options) {
|
||||
assert.strictEqual(options.ca, fakeCa);
|
||||
done();
|
||||
};
|
||||
transport.connect(fakeConfig, function () {});
|
||||
});
|
||||
|
||||
/*Tests_SRS_NODE_COMMON_MQTT_BASE_18_002: [The `connect` method shall set the `wsOptions.agent` option based on the `mqtt.webSocketAgent` object passed in the `options` structure via the `setOptions` function.]*/
|
||||
it('uses the agent passed into setOptions', function(done) {
|
||||
var fakeConfig = {
|
||||
host: "host.name",
|
||||
deviceId: "deviceId",
|
||||
sharedAccessSignature: "sasToken"
|
||||
};
|
||||
var fakeAgent = '__FAKE_AGENT__';
|
||||
var fakemqtt = new FakeMqtt();
|
||||
var transport = new MqttBase('test', fakemqtt);
|
||||
|
||||
transport.setOptions({mqtt: { webSocketAgent: fakeAgent }});
|
||||
fakemqtt.connect = function(host, options) {
|
||||
assert.strictEqual(options.wsOptions.agent, fakeAgent);
|
||||
done();
|
||||
};
|
||||
transport.connect(fakeConfig, function () {});
|
||||
});
|
||||
|
||||
|
||||
/*Tests_SRS_NODE_COMMON_MQTT_BASE_12_005: [The `connect` method shall call connect on MQTT.JS library and call the `done` callback with a `null` error object and the result as a second argument.]*/
|
||||
it('calls the done callback once successfully connected to the server', function(done) {
|
||||
var fakemqtt = new FakeMqtt();
|
||||
|
|
|
@ -77,6 +77,10 @@ export interface HttpTransportOptions {
|
|||
* This is passed into {@link Client.setOptions} as a property named `mqtt` inside of an {@link DeviceClientOptions} object.
|
||||
*/
|
||||
export interface MqttTransportOptions {
|
||||
/**
|
||||
* Optional [Agent]{@link https://nodejs.org/api/https.html#https_class_https_agent} object to use with MQTT-WS connections
|
||||
*/
|
||||
webSocketAgent?: Agent;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "node-red-contrib-azureiothubnode",
|
||||
"version": "0.1.26",
|
||||
"version": "0.1.27",
|
||||
"description": "An Azure IoT Hub node for node-red",
|
||||
"author": "Microsoft Corp.",
|
||||
"license": "MIT",
|
||||
|
|
|
@ -14,7 +14,7 @@ import { translateError } from './http_errors.js';
|
|||
import { IncomingMessage } from 'http';
|
||||
import { DeviceMethodResponse, Client, TwinProperties } from 'azure-iot-device';
|
||||
import { X509AuthenticationProvider, SharedAccessSignatureAuthenticationProvider } from 'azure-iot-device';
|
||||
import { DeviceClientOptions, HttpReceiverOptions as _clientReceiverOptions } from 'azure-iot-device';
|
||||
import { DeviceClientOptions, HttpReceiverOptions } from 'azure-iot-device';
|
||||
|
||||
// tslint:disable-next-line:no-var-requires
|
||||
const packageJson = require('../package.json');
|
||||
|
@ -323,6 +323,8 @@ export class Http extends EventEmitter implements Client.Transport {
|
|||
/*Codes_SRS_NODE_DEVICE_HTTP_16_009: [If `done` has been specified the `setOptions` method shall call the `done` callback with a standard javascript `Error` object when unsuccessful.]*/
|
||||
this._http.setOptions(options);
|
||||
|
||||
this._http.setOptions(options);
|
||||
|
||||
// setOptions used to exist both on Http and HttpReceiver with different options class. In order not to break backward compatibility we have
|
||||
// to check what properties this options object has to figure out what to do with it.
|
||||
if (options.hasOwnProperty('http') && options.http.hasOwnProperty('receivePolicy')) {
|
||||
|
@ -335,7 +337,7 @@ export class Http extends EventEmitter implements Client.Transport {
|
|||
|| options.hasOwnProperty('manualPolling')
|
||||
|| options.hasOwnProperty('drain')) {
|
||||
this._setReceiverOptions(options as any);
|
||||
if (done) done();
|
||||
calldoneifspecified();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -766,10 +768,4 @@ export class Http extends EventEmitter implements Client.Transport {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link azure-iot-device:HttpReceiverOptions} instead.
|
||||
*/
|
||||
export interface HttpReceiverOptions extends _clientReceiverOptions {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -49,10 +49,9 @@
|
|||
"job_client": "mocha --reporter spec test/job_client.js",
|
||||
"authentication": "mocha --reporter spec test/authentication.js",
|
||||
"provisioning": "cd ../provisioning/e2e && npm run ci && cd ../../e2etests",
|
||||
"configurations": "mocha --reporter spec test/configurations.js",
|
||||
"modules": "mocha --reporter spec test/modules.js",
|
||||
"phase1_fast": "npm-run-all -p -l twin_disconnect service registry device_acknowledge_tests upload_disconnect authentication job_client configurations modules",
|
||||
"phase2_slow": "npm-run-all -p -l method_disconnect device_method twin_e2e_tests sas_token_tests device_service c2d_disconnect d2c_disconnect provisioning",
|
||||
"phase1_fast": "npm-run-all -p -l twin_disconnect service registry device_acknowledge_tests upload_disconnect authentication job_client",
|
||||
"phase2_slow": "npm-run-all -p -l device_method twin_e2e_tests sas_token_tests device_service provisioning",
|
||||
"alltest": "npm run phase1_fast && npm run phase2_slow",
|
||||
"ci": "npm -s run lint && npm -s run alltest",
|
||||
"test": "npm -s run lint && npm -s run alltest"
|
||||
|
|
|
@ -280,7 +280,7 @@ delete nullMergeResult.tweedle;
|
|||
mergeTags(newProps, moreNewProps, "*", mergeResult, done);
|
||||
});
|
||||
|
||||
it('can send reported properties to the service after renewing the sas token', function(done) {
|
||||
it.skip('can send reported properties to the service after renewing the sas token', function(done) {
|
||||
deviceClient.on('_sharedAccessSignatureUpdated', function() {
|
||||
// _sharedAccessSignatureUpdated fired when the signature has been updated,
|
||||
// but we still have to wait for the library to connect and register for events.
|
||||
|
@ -292,7 +292,7 @@ delete nullMergeResult.tweedle;
|
|||
deviceClient.updateSharedAccessSignature(deviceSas.create(ConnectionString.parse(hubConnectionString).HostName, deviceDescription.deviceId, deviceDescription.authentication.symmetricKey.primaryKey, anHourFromNow()).toString());
|
||||
});
|
||||
|
||||
it('can receive desired properties from the service after renewing the sas token', function(done) {
|
||||
it.skip('can receive desired properties from the service after renewing the sas token', function(done) {
|
||||
deviceClient.on('_sharedAccessSignatureUpdated', function() {
|
||||
// See note above about "twinReady" event.
|
||||
setTimeout(function() {
|
||||
|
|
|
@ -12,10 +12,27 @@ import { errors } from 'azure-iot-common';
|
|||
*/
|
||||
export class ProvisioningDeviceClient {
|
||||
/**
|
||||
* Factory method to use to create a DeviceClient object.
|
||||
* Construct a client object which can be used to communicate with the Azure Device Provisioning Service.
|
||||
*
|
||||
* @param transport Transport instance to use
|
||||
* @param securityClient: Security client object which can provide access to the necessary secrets and/or encryption functions
|
||||
* @param provisioningHost Host running the Device Provisioning Service. Can be found in the Azure portal in the 'Essentials' section of the 'Overview' tab as the string 'Global device endpoint'
|
||||
* @param idScope Scope of IDs for the Device Provisioning Service. Can be found in the Azure portal in the 'Essentials' section of the 'Overview' tab as the string 'ID Scope'
|
||||
* @param transport Constructor function for provisioning transport to use. Can be one of the following:
|
||||
* [azure-iot-provisioning-device-http.Http]{@link module:azure-iot-provisioning-device-http.Http}
|
||||
* [azure-iot-provisioning-device-amqp.Amqp]{@link module:azure-iot-provisioning-device-amqp.Amqp}
|
||||
* [azure-iot-provisioning-device-amqp.AmqpWs]{@link module:azure-iot-provisioning-device-amqp.AmqpWs}
|
||||
* [azure-iot-provisioning-device-mqtt.Mqtt]{@link module:azure-iot-provisioning-device-mqtt.Mqtt}
|
||||
* [azure-iot-provisioning-device-mqtt.MqttWs]{@link module:azure-iot-provisioning-device-mqtt.MqttWs}
|
||||
* @param securityClient Instance of Scurity client object implementing either the
|
||||
* [X509SecurityClient]{@link module:azure-iot-provisioning-device:X509SecurityClient} or the
|
||||
* [TpmSecurityClient]{@link module:azure-iot-provisioning-device:TpmSecurityClient} interface.
|
||||
* Suggested implementations of these interfaces include
|
||||
* [X509Security]{@link module:azure-iot-security-x509.X509Security} or
|
||||
* [TpmSecurityClient]{@link module:azure-iot-security-tpm.TpmSecurityClient}
|
||||
*
|
||||
* @returns An object supporting the [RegistrationClient]{@link module:azure-iot-provisioning-device:RegistrationClient}
|
||||
* interface which can be usd to register the device/
|
||||
*
|
||||
* @
|
||||
*/
|
||||
static create(provisioningHost: string, idScope: string, transport: X509ProvisioningTransport | TpmProvisioningTransport, securityClient: X509SecurityClient | TpmSecurityClient): RegistrationClient {
|
||||
/*Codes_SRS_PROVISIONING_CLIENT_06_001: [The `create` method shall throw `ReferenceError` if the `provisioningHost` argument is falsy.] */
|
||||
|
|
|
@ -8,12 +8,27 @@ import * as Promise from 'bluebird';
|
|||
import * as dbg from 'debug';
|
||||
const debug = dbg('azure-iot-provisioning-device-amqp:SaslTpm');
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export type GetSasTokenCallback = (err: Error, sasToken?: string) => void;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
|
||||
export type GetSasToken = (challenge: Buffer, callback: GetSasTokenCallback) => void;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export type SaslResponseFrame = {
|
||||
response: Buffer
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export class SaslTpm {
|
||||
public name: string = 'TPM';
|
||||
|
||||
|
|
|
@ -103,6 +103,9 @@ export class Http extends EventEmitter implements X509ProvisioningTransport, Tpm
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
setAuthentication(auth: X509): void {
|
||||
this._auth = auth;
|
||||
}
|
||||
|
@ -122,7 +125,7 @@ export class Http extends EventEmitter implements X509ProvisioningTransport, Tpm
|
|||
}
|
||||
|
||||
/**
|
||||
* private
|
||||
* @private
|
||||
*/
|
||||
cancel(callback: (err?: Error) => void): void {
|
||||
/* Codes_SRS_NODE_PROVISIONING_HTTP_18_041: [ `cancel` shall immediately call `callback` passing null. ] */
|
||||
|
@ -130,7 +133,7 @@ export class Http extends EventEmitter implements X509ProvisioningTransport, Tpm
|
|||
}
|
||||
|
||||
/**
|
||||
* private
|
||||
* @private
|
||||
*/
|
||||
disconnect(callback: (err?: Error) => void): void {
|
||||
// nothing to do
|
||||
|
@ -139,7 +142,7 @@ export class Http extends EventEmitter implements X509ProvisioningTransport, Tpm
|
|||
}
|
||||
|
||||
/**
|
||||
* private
|
||||
* @private
|
||||
*/
|
||||
registrationRequest(request: RegistrationRequest, callback: (err?: Error, result?: DeviceRegistrationResult, response?: any, pollingInterval?: number) => void): void {
|
||||
/* Codes_SRS_NODE_PROVISIONING_HTTP_18_007: [ If an X509 cert if provided, `registrationRequest` shall include it in the Http authorization header. ] */
|
||||
|
@ -192,7 +195,7 @@ export class Http extends EventEmitter implements X509ProvisioningTransport, Tpm
|
|||
}
|
||||
|
||||
/**
|
||||
* private
|
||||
* @private
|
||||
*/
|
||||
queryOperationStatus(request: RegistrationRequest, operationId: string, callback: (err?: Error, result?: DeviceRegistrationResult, response?: any, pollingInterval?: number) => void): void {
|
||||
/* Codes_SRS_NODE_PROVISIONING_HTTP_18_021: [ If an X509 cert if provided, `queryOperationStatus` shall include it in the Http authorization header. ] */
|
||||
|
@ -233,7 +236,7 @@ export class Http extends EventEmitter implements X509ProvisioningTransport, Tpm
|
|||
}
|
||||
|
||||
/**
|
||||
* private
|
||||
* @private
|
||||
*/
|
||||
private _ensureRestApiClient(request: RegistrationRequest): void {
|
||||
if (!this._restApiClient) {
|
||||
|
|
|
@ -202,7 +202,7 @@ export class Mqtt extends EventEmitter implements X509ProvisioningTransport {
|
|||
}
|
||||
|
||||
/**
|
||||
* private
|
||||
* @private
|
||||
*/
|
||||
registrationRequest(request: RegistrationRequest, callback: (err?: Error, result?: DeviceRegistrationResult, response?: any, pollingInterval?: number) => void): void {
|
||||
let rid = uuid.v4();
|
||||
|
@ -217,7 +217,7 @@ export class Mqtt extends EventEmitter implements X509ProvisioningTransport {
|
|||
}
|
||||
|
||||
/**
|
||||
* private
|
||||
* @private
|
||||
*/
|
||||
queryOperationStatus(request: RegistrationRequest, operationId: string, callback: (err?: Error, result?: DeviceRegistrationResult, response?: any, pollingInterval?: number) => void): void {
|
||||
let rid = uuid.v4();
|
||||
|
|
Загрузка…
Ссылка в новой задаче