Skip to content

Commit b5e0098

Browse files
author
anthonyvercolano
committed
Don't attempt to putToken when not connected.
1 parent e6fe764 commit b5e0098

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

device/core/src/client.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,8 @@ export class Client extends EventEmitter {
5959
/*Codes_SRS_NODE_DEVICE_CLIENT_16_026: [The Client constructor shall accept a connection string as an optional second argument] */
6060
this._connectionString = connStr;
6161

62-
if (this._connectionString && ConnectionString.parse(this._connectionString).SharedAccessKey) {
63-
/*Codes_SRS_NODE_DEVICE_CLIENT_16_027: [If a connection string argument is provided and is using SharedAccessKey authentication, the Client shall automatically generate and renew SAS tokens.] */
64-
this._useAutomaticRenewal = true;
65-
this._sasRenewalTimeout = setTimeout(this._renewSharedAccessSignature.bind(this), Client.sasRenewalInterval);
66-
} else {
67-
this._useAutomaticRenewal = false;
68-
}
62+
/*Codes_SRS_NODE_DEVICE_CLIENT_16_027: [If a connection string argument is provided and is using SharedAccessKey authentication, the Client shall automatically generate and renew SAS tokens.] */
63+
this._useAutomaticRenewal = !!(this._connectionString && ConnectionString.parse(this._connectionString).SharedAccessKey);
6964

7065
this.blobUploadClient = blobUploadClient;
7166

@@ -193,6 +188,9 @@ export class Client extends EventEmitter {
193188
},
194189
'connected': {
195190
_onEnter: () => {
191+
if (this._useAutomaticRenewal) {
192+
this._sasRenewalTimeout = setTimeout(this._renewSharedAccessSignature.bind(this), Client.sasRenewalInterval);
193+
}
196194
/*Codes_SRS_NODE_DEVICE_CLIENT_16_065: [The client shall connect the transport if needed to subscribe receive messages.]*/
197195
this._transport.getReceiver((err, receiver) => {
198196
if (err) {
@@ -222,6 +220,9 @@ export class Client extends EventEmitter {
222220
});
223221
},
224222
_onExit: () => {
223+
if (this._sasRenewalTimeout) {
224+
clearTimeout(this._sasRenewalTimeout);
225+
}
225226
this._destroyReceiver();
226227
this._receiver = null;
227228
},

device/core/test/_client_test.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,18 @@ describe('Client', function () {
6464
});
6565

6666
assert.instanceOf(client, Client);
67-
client.sasRenewalInterval = 2700000;
68-
tick = firstTick;
69-
this.clock.tick(tick); // 30 minutes. shouldn't have updated yet.
70-
assert.isFalse(sasUpdated);
71-
tick = secondTick;
72-
this.clock.tick(tick); // +20 => 50 minutes. should've updated so the callback will be called and the test will terminate.
67+
client.open(function (err) {
68+
if (err) {
69+
testCallback(err);
70+
} else {
71+
client.sasRenewalInterval = 2700000;
72+
tick = firstTick;
73+
this.clock.tick(tick); // 30 minutes. shouldn't have updated yet.
74+
assert.isFalse(sasUpdated);
75+
tick = secondTick;
76+
this.clock.tick(tick); // +20 => 50 minutes. should've updated so the callback will be called and the test will terminate.
77+
}
78+
}.bind(this));
7379
});
7480

7581
it('doesn\'t try to renew the SAS token when using x509', function (testCallback) {

e2etests/e2etests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var upload_disconnect = require('./test/upload_disconnect.js');
2525
var device_teardown = require('./test/device_teardown.js');
2626
var twin_e2e_tests = require('./test/twin_e2e_tests.js');
2727
var device_method = require('./test/device_method.js');
28-
var job_client = require('./test/job_client.js');
28+
//var job_client = require('./test/job_client.js');
2929
var authentication_tests = require('./test/authentication.js');
3030

3131
var hubConnectionString = process.env.IOTHUB_CONNECTION_STRING;
@@ -94,5 +94,5 @@ device_provision(hubConnectionString, function (err, provisionedDevices) {
9494

9595
twin_e2e_tests(hubConnectionString, [deviceAmqp.Amqp, deviceMqtt.Mqtt]);
9696
device_method(hubConnectionString, deviceMethodsProtocols);
97-
job_client(hubConnectionString);
97+
// job_client(hubConnectionString);
9898

0 commit comments

Comments
 (0)