Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict'
const logger = require('../lib').logger;
const iotClient = require('./iotClient');
const deviceManager = require('./deviceManager');
const testService = require('./testService');
const async = require('async');
const errors = require('azure-iot-common').errors;
function runTest(deviceConnectionString, protocol, label, done) {
logger.info('');
logger.info('Starting ' + label + ' Test...');
iotClient.runTest(deviceConnectionString, protocol, function(err) {
if(err) {
logger.crit('--> Failed to run ' + label + ' test, error: ' + err);
} else {
logger.info('--> Successfully ran ' + label + ' test.');
}
// Don't pass out error (if the test completed, it will just state it failed, but still run the next test)
return done(null, deviceConnectionString);
});
}
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var amqp10 = require('amqp10');
var Promise = require('bluebird');
var anHourFromNow = require('azure-iot-common').anHourFromNow;
var ConnectionString = require('azure-iot-common').ConnectionString;
var EventHubReceiver = require('./eventhubreceiver.js');
var SharedAccessSignature = require('azure-iothub').SharedAccessSignature;
var managementEndpoint = '$management';
function createConfig(connectionString, entityPath) {
var cn = ConnectionString.parse(connectionString);
var host = cn.HostName || (cn.Endpoint || '').slice('sb://'.length);
return {
host: host,
namespace: host.split('.')[0],
keyName: cn.SharedAccessKeyName,
key: cn.SharedAccessKey,
eventHubName: entityPath
};
}
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var ConnectionString = require('azure-iot-common').ConnectionString;
var runTests = require('azure-iot-device-amqp/lib/_client_test_integration.js');
var AmqpWs = require('./amqp_ws.js');
var host = ConnectionString.parse(process.env.IOTHUB_CONNECTION_STRING).HostName;
var deviceId = process.env.IOTHUB_DEVICE_ID;
var key = process.env.IOTHUB_DEVICE_KEY;
function makeConnectionString(host, device, key) {
return 'HostName='+host+';DeviceId='+device+';SharedAccessKey='+key;
}
var connectionString = makeConnectionString(host, deviceId, key);
var badConnStrings = [
makeConnectionString('bad', 'device', 'key'),
makeConnectionString('host', 'bad', 'key'),
makeConnectionString('host', 'device', 'bad')
];
describe('Over AMQP/WS', function () {
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var assert = require('chai').assert;
var Client = require('azure-iot-device').Client;
var ConnectionString = require('azure-iot-common').ConnectionString;
var Message = require('azure-iot-common').Message;
var Amqp = require('./amqp.js');
var host = ConnectionString.parse(process.env.IOTHUB_CONNECTION_STRING).HostName;
var deviceId = process.env.IOTHUB_DEVICE_ID;
var key = process.env.IOTHUB_DEVICE_KEY;
function makeConnectionString(host, device, key) {
return 'HostName='+host+';DeviceId='+device+';SharedAccessKey='+key;
}
var connectionString = makeConnectionString(host, deviceId, key);
var badConnStrings = [
makeConnectionString('bad', deviceId, key),
makeConnectionString(host, 'bad', key),
makeConnectionString(host, deviceId, 'bad')
];
function badConfigTests(opName, badConnStrings, Transport, requestFn) {
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict'
const logger = require('../lib').logger;
const iothub = require('azure-iothub');
const errors = require('azure-iot-common').errors;
const Registry = iothub.Registry;
const ConnectionString = require('azure-iothub').ConnectionString;
function getDevice(iotHubConnectionString, deviceId, done) {
var registry = Registry.fromConnectionString(iotHubConnectionString);
registry.get(deviceId, done);
}
function getDeviceConnectionString(iotHubConnectionString, deviceInfo) {
var deviceConnectionString = 'HostName=' + ConnectionString.parse(iotHubConnectionString).HostName + ';DeviceId=' + deviceInfo.deviceId + ';SharedAccessKey=' + deviceInfo.authentication.symmetricKey.primaryKey;
logger.trace('Connectionstring: ' + deviceConnectionString);
return deviceConnectionString;
}
// Create a new device
function createDevice(iotHubConnectionString, deviceId, done) {
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var assert = require('chai').assert;
var Client = require('./client.js');
var errors = require('azure-iot-common').errors;
var Message = require('azure-iot-common').Message;
var AmqpReceiver = require('azure-iot-amqp-base').AmqpReceiver;
function transportSpecificTests(opts) {
describe('Client', function () {
var testSubject;
var deviceId;
before('prepare test subject', function (done) {
/*Tests_SRS_NODE_IOTHUB_CLIENT_05_008: [The open method shall open a connection to the IoT Hub that was identified when the Client object was created (e.g., in Client.fromConnectionString).]*/
/*Tests_SRS_NODE_IOTHUB_CLIENT_05_009: [When the open method completes, the callback function (indicated by the done argument) shall be invoked with the following arguments:
err - standard JavaScript Error object (or subclass)]*/
/*Tests_SRS_NODE_IOTHUB_CLIENT_05_010: [The argument err passed to the callback done shall be null if the protocol operation was successful.]*/
if (opts.transport && opts.connectionString) assert.fail('test setup error');
if (opts.transport) testSubject = new Client(opts.transport());
else testSubject = Client.fromConnectionString(opts.connectionString);
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var assert = require('chai').assert;
var Client = require('azure-iot-device').Client;
var ConnectionString = require('azure-iot-common').ConnectionString;
var Message = require('azure-iot-common').Message;
var Amqp = require('./amqp.js');
var host = ConnectionString.parse(process.env.IOTHUB_CONNECTION_STRING).HostName;
var deviceId = process.env.IOTHUB_DEVICE_ID;
var key = process.env.IOTHUB_DEVICE_KEY;
function makeConnectionString(host, device, key) {
return 'HostName='+host+';DeviceId='+device+';SharedAccessKey='+key;
}
var connectionString = makeConnectionString(host, deviceId, key);
var badConnStrings = [
makeConnectionString('bad', deviceId, key),
makeConnectionString(host, 'bad', key),
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var ConnectionString = require('azure-iot-common').ConnectionString;
var runTests = require('azure-iot-device/lib/_client_test.js');
var Http = require('./http.js');
var host = ConnectionString.parse(process.env.IOTHUB_CONNECTION_STRING).HostName;
var deviceId = process.env.IOTHUB_DEVICE_ID;
var key = process.env.IOTHUB_DEVICE_KEY;
var connectionString = 'HostName=' + host + ';DeviceId=' + deviceId + ';SharedAccessKey=' + key;
var badConnStrings = [
'HostName=bad;DeviceId=' + deviceId + ';SharedAccessKey=' + key,
'HostName=' + host + ';DeviceId=bad;SharedAccessKey=' + key,
'HostName=' + host + ';DeviceId=' + deviceId + ';SharedAccessKey=bad;'
];
describe('Over real HTTPS', function () {
this.timeout(15000);
iotHubClient.open(function(err) {
if (err) {
console.error('Could not connect: ' + err.message);
} else { // {"Name":"TurnFanOn","Parameters":""}
var data = JSON.stringify({ "Name":command,"Parameters":null });
var message = new Message (data);
console.log('Sending message: ' + data);
iotHubClient.send(deviceId, message, printResultFor('send'));
}
});
function ConnectionConfig(connectionString, path) {
var cn = aziot.ConnectionString.parse(connectionString);
this.isIotHub = !!cn.HostName; // HostName is present in IoTHub connection strings, Endpoint in the case of Event Hubs
this.keyName = cn.SharedAccessKeyName;
this.key = cn.SharedAccessKey;
if(this.isIotHub) {
this.host = cn.HostName;
var hubName = this.host.split('.')[0];
this.sharedAccessSignature = aziot.SharedAccessSignature.create(this.host, this.keyName, this.key, aziot.anHourFromNow());
this.path = path || 'messages/events/';
this.saslPlainUri = 'amqps://' +
encodeURIComponent(this.keyName) +
'%40sas.root.' +
hubName +
':' +
encodeURIComponent(this.sharedAccessSignature) +
'@' +
this.host;
} else {
var endpoint = cn.Endpoint || '';
this.host = (endpoint.match('sb://([^/]*)') || [])[1];
this.path = cn.EntityPath || path;
this.saslPlainUri = 'amqps://' +
encodeURIComponent(this.keyName) + ':' +
encodeURIComponent(this.key) + '@' +