Bring up to date with master.
This commit is contained in:
Коммит
06c651119f
|
@ -47,6 +47,12 @@ export class ConnectionString {
|
|||
*/
|
||||
// tslint:disable-next-line:variable-name
|
||||
GatewayHostName?: string;
|
||||
/**
|
||||
* A shared access signature which encapsulates "device connect" permissions on an IoT hub.
|
||||
* @memberof {azure-iot-common.ConnectionString}
|
||||
*/
|
||||
// tslint:disable-next-line:variable-name
|
||||
SharedAccessSignature?: string;
|
||||
/**
|
||||
* This property exists only if a device uses x509 certificates for authentication and if it exists, will be set to True.
|
||||
* @memberof {azure-iot-common.ConnectionString}
|
||||
|
|
|
@ -29,7 +29,13 @@ The `parse` static method returns a new instance of the `ConnectionString` objec
|
|||
|
||||
**SRS_NODE_DEVICE_CONNSTR_05_002: [** It shall throw `ArgumentError` if any of `HostName` or `DeviceId` fields are not found in the source argument.**]**
|
||||
|
||||
**SRS_NODE_DEVICE_CONNSTR_16_001: [** It shall throw `ArgumentError` if `SharedAccessKey` and `x509` are present at the same time or if none of them are present. **]**
|
||||
**SRS_NODE_DEVICE_CONNSTR_16_001: [** It shall throw `ArgumentError` if `SharedAccessKey` and `x509` are present at the same time. **]**
|
||||
|
||||
**SRS_NODE_DEVICE_CONNSTR_16_006: [** It shall throw `ArgumentError` if `SharedAccessSignature` and `x509` are present at the same time. **]**
|
||||
|
||||
**SRS_NODE_DEVICE_CONNSTR_16_007: [** It shall throw `ArgumentError` if `SharedAccessKey` and `SharedAccessSignature` are present at the same time. **]**
|
||||
|
||||
**SRS_NODE_DEVICE_CONNSTR_16_008: [** It shall throw `ArgumentError` if none of `SharedAccessKey`, `SharedAccessSignature` and `x509` are present. **]**
|
||||
|
||||
### createWithSharedAccessKey(hostName, deviceId, sharedAccessKey) [static]
|
||||
|
||||
|
@ -41,4 +47,4 @@ The `parse` static method returns a new instance of the `ConnectionString` objec
|
|||
|
||||
**SRS_NODE_DEVICE_CONNSTR_16_004: [** The `createWithX509Certificate` static method shall returns a valid x509 connection string with the values passed as arguments. **]**
|
||||
|
||||
**SRS_NODE_DEVICE_CONNSTR_16_005: [** The `createWithX509Certificate` static method shall throw a `ReferenceError` if one or more of the `hostName` or `deviceId` are falsy. **]**
|
||||
**SRS_NODE_DEVICE_CONNSTR_16_005: [** The `createWithX509Certificate` static method shall throw a `ReferenceError` if one or more of the `hostName` or `deviceId` are falsy. **]**
|
||||
|
|
|
@ -27,6 +27,8 @@ class Client extends InternalClient {
|
|||
|
||||
**SRS_NODE_DEVICE_CLIENT_16_093: [** The `fromConnectionString` method shall create a new `X509AuthorizationProvider` object with the connection string passed as argument if it contains an X509 parameter and pass this object to the transport constructor. **]**
|
||||
|
||||
**SRS_NODE_DEVICE_CLIENT_16_094: [** The `fromConnectionString` method shall create a new `SharedAccessSignatureAuthenticationProvider` object with the connection string passed as argument if it contains a SharedAccessSignature parameter and pass this object to the transport constructor. **]**
|
||||
|
||||
### fromSharedAccessSignature
|
||||
|
||||
**SRS_NODE_DEVICE_CLIENT_16_029: [** The `fromSharedAccessSignature` method shall throw a `ReferenceError` if the sharedAccessSignature argument is falsy. **]**
|
||||
|
|
|
@ -17,9 +17,18 @@ export function parse(source: string): ConnectionString {
|
|||
/*Codes_SRS_NODE_DEVICE_CONNSTR_05_001: [The parse method shall return the result of calling azure-iot-common.ConnectionString.parse.]*/
|
||||
/*Codes_SRS_NODE_DEVICE_CONNSTR_05_002: [It shall throw ArgumentError if any of 'HostName' or 'DeviceId' fields are not found in the source argument.]*/
|
||||
const connectionString = ConnectionString.parse(source, ['HostName', 'DeviceId']);
|
||||
/*Codes_SRS_NODE_DEVICE_CONNSTR_16_001: [It shall throw `ArgumentError` if `SharedAccessKey` and `x509` are present at the same time or if none of them are present.]*/
|
||||
if ((connectionString.SharedAccessKey && connectionString.x509) || (!connectionString.SharedAccessKey && !connectionString.x509)) {
|
||||
/*Codes_SRS_NODE_DEVICE_CONNSTR_16_001: [It shall throw `ArgumentError` if `SharedAccessKey` and `x509` are present at the same time.]*/
|
||||
/*Codes_SRS_NODE_DEVICE_CONNSTR_16_006: [It shall throw `ArgumentError` if `SharedAccessKey` and `SharedAccessSignature` are present at the same time.]*/
|
||||
/*Codes_SRS_NODE_DEVICE_CONNSTR_16_007: [It shall throw `ArgumentError` if `SharedAccessSignature` and `x509` are present at the same time.]*/
|
||||
/*Codes_SRS_NODE_DEVICE_CONNSTR_16_008: [It shall throw `ArgumentError` if none of `SharedAccessKey`, `SharedAccessSignature` and `x509` are present.]*/
|
||||
if (connectionString.SharedAccessKey && connectionString.x509) {
|
||||
throw new errors.ArgumentError('The connection string must contain either a SharedAccessKey or x509=true');
|
||||
} else if (connectionString.SharedAccessKey && connectionString.SharedAccessSignature) {
|
||||
throw new errors.ArgumentError('The connection string must contain either a SharedAccessKey or SharedAccessSignature');
|
||||
} else if (connectionString.SharedAccessSignature && connectionString.x509) {
|
||||
throw new errors.ArgumentError('The connection string must contain either a SharedAccessSignature or x509=true');
|
||||
} else if ((!connectionString.SharedAccessKey && !connectionString.SharedAccessSignature && !connectionString.x509)) {
|
||||
throw new errors.ArgumentError('The connection string must contain either a SharedAccessKey, SharedAccessSignature or x509=true');
|
||||
}
|
||||
|
||||
return connectionString;
|
||||
|
|
|
@ -197,6 +197,9 @@ export class Client extends InternalClient {
|
|||
|
||||
if (cn.SharedAccessKey) {
|
||||
authenticationProvider = SharedAccessKeyAuthenticationProvider.fromConnectionString(connStr);
|
||||
} else if (cn.SharedAccessSignature) {
|
||||
/*Codes_SRS_NODE_DEVICE_CLIENT_16_094: [The `fromConnectionString` method shall create a new `SharedAccessSignatureAuthenticationProvider` object with the connection string passed as argument if it contains a SharedAccessSignature parameter and pass this object to the transport constructor.]*/
|
||||
authenticationProvider = SharedAccessSignatureAuthenticationProvider.fromSharedAccessSignature(cn.SharedAccessSignature);
|
||||
} else {
|
||||
/*Codes_SRS_NODE_DEVICE_CLIENT_16_093: [The `fromConnectionString` method shall create a new `X509AuthorizationProvider` object with the connection string passed as argument if it contains an X509 parameter and pass this object to the transport constructor.]*/
|
||||
authenticationProvider = new X509AuthenticationProvider({
|
||||
|
|
|
@ -14,7 +14,9 @@ var incompleteConnectionStrings = {
|
|||
|
||||
var invalidConnectionStrings = {
|
||||
BothSharedAccessKeyAndx509:'DeviceId=id;HostName=name;SharedAccessKey=key;x509=true',
|
||||
NeitherSharedAccessKeyNorx509: 'DeviceId=id;HostName=name'
|
||||
BothSharedAccessKeyAndSharedAccessSignature:'DeviceId=id;HostName=name;SharedAccessKey=key;SharedAccessSignature=key',
|
||||
BothSharedAccessSignatureAndx509:'DeviceId=id;HostName=name;SharedAccessSignature=key;x509=true',
|
||||
NeitherSharedAccessKeyNorSharedAccessSignatureNorx509: 'DeviceId=id;HostName=name'
|
||||
};
|
||||
|
||||
describe('ConnectionString', function () {
|
||||
|
@ -35,8 +37,11 @@ describe('ConnectionString', function () {
|
|||
}, ArgumentError);
|
||||
});
|
||||
|
||||
/*Codes_SRS_NODE_DEVICE_CONNSTR_16_001: [It shall throw `ArgumentError` if `SharedAccessKey` and `x509` are present at the same time or if none of them are present.]*/
|
||||
['BothSharedAccessKeyAndx509', 'NeitherSharedAccessKeyNorx509'].forEach(function(key) {
|
||||
/*Tests_SRS_NODE_DEVICE_CONNSTR_16_001: [It shall throw `ArgumentError` if `SharedAccessKey` and `x509` are present at the same time.]*/
|
||||
/*Tests_SRS_NODE_DEVICE_CONNSTR_16_006: [It shall throw `ArgumentError` if `SharedAccessSignature` and `x509` are present at the same time.]*/
|
||||
/*Tests_SRS_NODE_DEVICE_CONNSTR_16_007: [It shall throw `ArgumentError` if `SharedAccessKey` and `SharedAccessSignature` are present at the same time.]*/
|
||||
/*Tests_SRS_NODE_DEVICE_CONNSTR_16_008: [It shall throw `ArgumentError` if none of `SharedAccessKey`, `SharedAccessSignature` and `x509` are present.]*/
|
||||
['BothSharedAccessKeyAndx509', 'BothSharedAccessKeyAndSharedAccessSignature', 'BothSharedAccessSignatureAndx509', 'NeitherSharedAccessKeyNorx509'].forEach(function(key) {
|
||||
it('throws if the connection string is invalid because ' + key, function() {
|
||||
assert.throws(function() {
|
||||
ConnectionString.parse(invalidConnectionStrings[key]);
|
||||
|
|
|
@ -13,6 +13,7 @@ var Message = require('azure-iot-common').Message;
|
|||
var errors = require('azure-iot-common').errors;
|
||||
var results = require('azure-iot-common').results;
|
||||
var X509AuthenticationProvider = require('../lib/x509_authentication_provider').X509AuthenticationProvider;
|
||||
var SharedAccessSignatureAuthenticationProvider = require('../lib/sas_authentication_provider').SharedAccessSignatureAuthenticationProvider;
|
||||
var Client = require('../lib/device_client').Client;
|
||||
|
||||
describe('Device Client', function () {
|
||||
|
@ -60,6 +61,15 @@ describe('Device Client', function () {
|
|||
testCallback();
|
||||
});
|
||||
});
|
||||
|
||||
/*Tests_SRS_NODE_DEVICE_CLIENT_16_094: [The `fromConnectionString` method shall create a new `SharedAccessSignatureAuthenticationProvider` object with the connection string passed as argument if it contains a SharedAccessSignature parameter and pass this object to the transport constructor.]*/
|
||||
it('creates a SharedAccessSignatureAuthenticationProvider and passes it to the transport', function (testCallback) {
|
||||
var SharedAccessSignatureConnectionString = 'HostName=host;DeviceId=id;SharedAccessSignature=' + sharedAccessSignature;
|
||||
Client.fromConnectionString(SharedAccessSignatureConnectionString, function (authProvider) {
|
||||
assert.instanceOf(authProvider, SharedAccessSignatureAuthenticationProvider);
|
||||
testCallback();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#fromSharedAccessSignature', function () {
|
||||
|
@ -473,4 +483,4 @@ describe('Device Client', function () {
|
|||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
@ -561,21 +561,6 @@
|
|||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
|
||||
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
|
||||
},
|
||||
"event-stream": {
|
||||
"version": "3.3.6",
|
||||
"resolved": "https://registry.npmjs.org/event-stream/-/event-stream-3.3.6.tgz",
|
||||
"integrity": "sha512-dGXNg4F/FgVzlApjzItL+7naHutA3fDqbV/zAZqDDlXTjiMnQmZKu+prImWKszeBM5UQeGvAl3u1wBiKeDh61g==",
|
||||
"requires": {
|
||||
"duplexer": "^0.1.1",
|
||||
"flatmap-stream": "^0.1.0",
|
||||
"from": "^0.1.7",
|
||||
"map-stream": "0.0.7",
|
||||
"pause-stream": "^0.0.11",
|
||||
"split": "^1.0.1",
|
||||
"stream-combiner": "^0.2.2",
|
||||
"through": "^2.3.8"
|
||||
}
|
||||
},
|
||||
"execa": {
|
||||
"version": "0.10.0",
|
||||
"resolved": "https://registry.npmjs.org/execa/-/execa-0.10.0.tgz",
|
||||
|
@ -661,11 +646,6 @@
|
|||
"locate-path": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"flatmap-stream": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/flatmap-stream/-/flatmap-stream-0.1.1.tgz",
|
||||
"integrity": "sha512-lAq4tLbm3sidmdCN8G3ExaxH7cUCtP5mgDvrYowsx84dcYkJJ4I28N7gkxA6+YlSXzaGLJYIDEi9WGfXzMiXdw=="
|
||||
},
|
||||
"forever-agent": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
|
||||
|
@ -681,11 +661,6 @@
|
|||
"mime-types": "^2.1.12"
|
||||
}
|
||||
},
|
||||
"from": {
|
||||
"version": "0.1.7",
|
||||
"resolved": "https://registry.npmjs.org/from/-/from-0.1.7.tgz",
|
||||
"integrity": "sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4="
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-1.0.0.tgz",
|
||||
|
@ -890,7 +865,7 @@
|
|||
},
|
||||
"is-builtin-module": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz",
|
||||
"resolved": "http://registry.npmjs.org/is-builtin-module/-/is-builtin-module-1.0.0.tgz",
|
||||
"integrity": "sha1-VAVy0096wxGfj3bDDLwbHgN6/74=",
|
||||
"requires": {
|
||||
"builtin-modules": "^1.0.0"
|
||||
|
@ -1089,11 +1064,6 @@
|
|||
"p-defer": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"map-stream": {
|
||||
"version": "0.0.7",
|
||||
"resolved": "https://registry.npmjs.org/map-stream/-/map-stream-0.0.7.tgz",
|
||||
"integrity": "sha1-ih8HiW2CsQkmvTdEokIACfiJdKg="
|
||||
},
|
||||
"md5": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmjs.org/md5/-/md5-2.2.1.tgz",
|
||||
|
@ -1289,16 +1259,16 @@
|
|||
}
|
||||
},
|
||||
"npm-run-all": {
|
||||
"version": "4.1.3",
|
||||
"resolved": "https://registry.npmjs.org/npm-run-all/-/npm-run-all-4.1.3.tgz",
|
||||
"integrity": "sha512-aOG0N3Eo/WW+q6sUIdzcV2COS8VnTZCmdji0VQIAZF3b+a3YWb0AD0vFIyjKec18A7beLGbaQ5jFTNI2bPt9Cg==",
|
||||
"version": "4.1.5",
|
||||
"resolved": "https://registry.npmjs.org/npm-run-all/-/npm-run-all-4.1.5.tgz",
|
||||
"integrity": "sha512-Oo82gJDAVcaMdi3nuoKFavkIHBRVqQ1qvMb+9LHk/cF4P6B2m8aP04hGf7oL6wZ9BuGwX1onlLhpuoofSyoQDQ==",
|
||||
"requires": {
|
||||
"ansi-styles": "^3.2.0",
|
||||
"chalk": "^2.1.0",
|
||||
"cross-spawn": "^6.0.4",
|
||||
"ansi-styles": "^3.2.1",
|
||||
"chalk": "^2.4.1",
|
||||
"cross-spawn": "^6.0.5",
|
||||
"memorystream": "^0.3.1",
|
||||
"minimatch": "^3.0.4",
|
||||
"ps-tree": "^1.1.0",
|
||||
"pidtree": "^0.3.0",
|
||||
"read-pkg": "^3.0.0",
|
||||
"shell-quote": "^1.6.1",
|
||||
"string.prototype.padend": "^3.0.0"
|
||||
|
@ -1423,14 +1393,6 @@
|
|||
"resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz",
|
||||
"integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA="
|
||||
},
|
||||
"pause-stream": {
|
||||
"version": "0.0.11",
|
||||
"resolved": "https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz",
|
||||
"integrity": "sha1-/lo0sMvOErWqaitAPuLnO2AvFEU=",
|
||||
"requires": {
|
||||
"through": "~2.3"
|
||||
}
|
||||
},
|
||||
"pem": {
|
||||
"version": "1.13.2",
|
||||
"resolved": "https://registry.npmjs.org/pem/-/pem-1.13.2.tgz",
|
||||
|
@ -1481,6 +1443,11 @@
|
|||
"which": "^1.2.10"
|
||||
}
|
||||
},
|
||||
"pidtree": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/pidtree/-/pidtree-0.3.0.tgz",
|
||||
"integrity": "sha512-9CT4NFlDcosssyg8KVFltgokyKZIFjoBxw8CTGy+5F38Y1eQWrt8tRayiUOXE+zVKQnYu5BR8JjCtvK3BcnBhg=="
|
||||
},
|
||||
"pify": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/pify/-/pify-3.0.0.tgz",
|
||||
|
@ -1512,14 +1479,6 @@
|
|||
"integrity": "sha1-4mDHj2Fhzdmw5WzD4Khd4Xx6V74=",
|
||||
"optional": true
|
||||
},
|
||||
"ps-tree": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/ps-tree/-/ps-tree-1.1.0.tgz",
|
||||
"integrity": "sha1-tCGyQUDWID8e08dplrRCewjowBQ=",
|
||||
"requires": {
|
||||
"event-stream": "~3.3.0"
|
||||
}
|
||||
},
|
||||
"psl": {
|
||||
"version": "1.1.29",
|
||||
"resolved": "https://registry.npmjs.org/psl/-/psl-1.1.29.tgz",
|
||||
|
@ -1695,14 +1654,15 @@
|
|||
}
|
||||
},
|
||||
"spdx-license-ids": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.1.tgz",
|
||||
"integrity": "sha512-TfOfPcYGBB5sDuPn3deByxPhmfegAhpDYKSOXZQN81Oyrrif8ZCodOLzK3AesELnCx03kikhyDwh0pfvvQvF8w=="
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.2.tgz",
|
||||
"integrity": "sha512-qky9CVt0lVIECkEsYbNILVnPvycuEBkXoMFLRWsREkomQLevYhtRKC+R91a5TOAQ3bCMjikRwhyaRqj1VYatYg=="
|
||||
},
|
||||
"split": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz",
|
||||
"integrity": "sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"through": "2"
|
||||
}
|
||||
|
@ -1734,15 +1694,6 @@
|
|||
"resolved": "https://registry.npmjs.org/stately.js/-/stately.js-1.3.0.tgz",
|
||||
"integrity": "sha1-UtDRwVKgaaZ8sUUDrF3c24vh13c="
|
||||
},
|
||||
"stream-combiner": {
|
||||
"version": "0.2.2",
|
||||
"resolved": "http://registry.npmjs.org/stream-combiner/-/stream-combiner-0.2.2.tgz",
|
||||
"integrity": "sha1-rsjLrBd7Vrb0+kec7YwZEs7lKFg=",
|
||||
"requires": {
|
||||
"duplexer": "~0.1.1",
|
||||
"through": "~2.3.4"
|
||||
}
|
||||
},
|
||||
"string-width": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
|
||||
|
@ -1810,7 +1761,8 @@
|
|||
"through": {
|
||||
"version": "2.3.8",
|
||||
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
|
||||
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU="
|
||||
"integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=",
|
||||
"optional": true
|
||||
},
|
||||
"tough-cookie": {
|
||||
"version": "2.4.3",
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
"bluebird": "^3.5.2",
|
||||
"debug": "^4.1.0",
|
||||
"lodash": "^4.17.11",
|
||||
"npm-run-all": "^4.1.3",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"pem": "^1.13.2",
|
||||
"uuid": "^3.3.2",
|
||||
"yargs": "^12.0.2"
|
||||
|
|
Загрузка…
Ссылка в новой задаче