Skip to content

Commit

Permalink
Merge pull request #567 from telefonicaid/task/apply_autoprovision_flag
Browse files Browse the repository at this point in the history
Task/apply autoprovision flag
  • Loading branch information
fgalan authored Jun 14, 2021
2 parents aa5741b + 0f280c4 commit 44c500e
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 75 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Add: check autoprovision flag before register device
- Fix: upgrade underscore dep from 1.9.1 to 1.12.1 due to vulnerability
- (Only tests) Fix: ensure service of groups, device and commands is stored in mongo in lowercase (iota-node-lib#1023)
- Add MQTT options `clean` and `clientId` (env vars IOTA_MQTT_CLEAN and IOTA_MQTT_CLIENT_ID) (#414, #466, #497)
Expand Down
30 changes: 26 additions & 4 deletions lib/iotaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,34 @@ function findOrCreate(deviceId, transport, group, callback) {
if (!newDevice.transport) {
newDevice.transport = transport;
}
if ('timestamp' in group) {
if ('timestamp' in group && group.timestamp !== undefined) {
newDevice.timestamp = group.timestamp;
}
iotAgentLib.register(newDevice, function (error, device) {
callback(error, device, group);
});
if ('ngsiVersion' in group && group.ngsiVersion !== undefined) {
newDevice.ngsiVersion = group.ngsiVersion;
}
if ('explicitAttrs' in group && group.explicitAttrs !== undefined) {
newDevice.explicitAttrs = group.explicitAttrs;
}
if ('expressionLanguage' in group && group.expressionLanguage !== undefined) {
newDevice.expressionLanguage = group.expressionLanguage;
}
// Check autoprovision flag in order to register or not device
if (group.autoprovision === undefined || group.autoprovision === true) {
iotAgentLib.register(newDevice, function (error, device) {
callback(error, device, group);
});
} else {
config
.getLogger()
.info(
context,
'Device %j not provisioned due autoprovision is disabled by its conf %j',
newDevice,
group
);
callback(new errors.DeviceNotFound(deviceId));
}
} else {
callback(error);
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/ngsiv2/HTTP_commands_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('HTTP: Commands', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs?type=AnMQTTDevice',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/updateStatus1.json')
)
Expand All @@ -100,7 +100,7 @@ describe('HTTP: Commands', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs?type=AnMQTTDevice',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/updateStatus6.json')
)
Expand Down
12 changes: 6 additions & 6 deletions test/unit/ngsiv2/HTTP_reveice_measures-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('HTTP: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes.json')
)
Expand Down Expand Up @@ -195,7 +195,7 @@ describe('HTTP: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/e0130101/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures3.json')
)
Expand Down Expand Up @@ -268,7 +268,7 @@ describe('HTTP: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/e0130101/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures.json')
)
Expand Down Expand Up @@ -341,7 +341,7 @@ describe('HTTP: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/e0130101/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures3.json')
)
Expand Down Expand Up @@ -414,7 +414,7 @@ describe('HTTP: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/e0130101/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures.json')
)
Expand Down Expand Up @@ -475,7 +475,7 @@ describe('HTTP: Measure reception ', function () {
contextBrokerUnprovMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/TheLightType:JSON_UNPROVISIONED/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedDevice.json')
)
Expand Down
16 changes: 8 additions & 8 deletions test/unit/ngsiv2/HTTP_reveice_measures-test2.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('HTTP: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes2.json')
)
Expand All @@ -153,7 +153,7 @@ describe('HTTP: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes.json')
)
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('HTTP: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/e0130101/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures.json')
)
Expand All @@ -233,7 +233,7 @@ describe('HTTP: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/e0130101/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures2.json')
)
Expand Down Expand Up @@ -310,7 +310,7 @@ describe('HTTP: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/e0130101/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures.json')
)
Expand All @@ -320,7 +320,7 @@ describe('HTTP: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/e0130101/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timeInstantMeasures2.json')
)
Expand Down Expand Up @@ -387,7 +387,7 @@ describe('HTTP: Measure reception ', function () {
contextBrokerUnprovMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/TheLightType:JSON_UNPROVISIONED/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedDevice2.json')
)
Expand All @@ -397,7 +397,7 @@ describe('HTTP: Measure reception ', function () {
contextBrokerUnprovMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/TheLightType:JSON_UNPROVISIONED/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedDevice.json')
)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ngsiv2/MQTT_commands_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('MQTT: Commands', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs?type=AnMQTTDevice',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/updateStatus1.json')
)
Expand Down
10 changes: 5 additions & 5 deletions test/unit/ngsiv2/MQTT_receive_measures-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('MQTT: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes.json')
)
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('MQTT: Measure reception ', function () {
contextBrokerUnprovMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/TheLightType:JSON_UNPROVISIONED/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedDevice.json')
)
Expand Down Expand Up @@ -228,7 +228,7 @@ describe('MQTT: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unknownMeasures.json')
)
Expand Down Expand Up @@ -268,7 +268,7 @@ describe('MQTT: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timestampMeasure.json')
)
Expand Down Expand Up @@ -310,7 +310,7 @@ describe('MQTT: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasure.json')
)
Expand Down
16 changes: 8 additions & 8 deletions test/unit/ngsiv2/MQTT_receive_measures-test2.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('MQTT: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes.json')
)
Expand All @@ -122,7 +122,7 @@ describe('MQTT: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasuresJsonTypes2.json')
)
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('MQTT: Measure reception ', function () {
contextBrokerUnprovMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/TheLightType:JSON_UNPROVISIONED/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedDevice.json')
)
Expand All @@ -225,7 +225,7 @@ describe('MQTT: Measure reception ', function () {
contextBrokerUnprovMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/TheLightType:JSON_UNPROVISIONED/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedDevice2.json')
)
Expand Down Expand Up @@ -288,7 +288,7 @@ describe('MQTT: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unknownMeasures.json')
)
Expand All @@ -298,7 +298,7 @@ describe('MQTT: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unknownMeasures2.json')
)
Expand Down Expand Up @@ -350,7 +350,7 @@ describe('MQTT: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timestampMeasure.json')
)
Expand All @@ -360,7 +360,7 @@ describe('MQTT: Measure reception ', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/timestampMeasure2.json')
)
Expand Down
8 changes: 4 additions & 4 deletions test/unit/ngsiv2/amqpBinding-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('AMQP Transport binding: measures', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasureAMQP.json')
)
Expand Down Expand Up @@ -145,7 +145,7 @@ describe('AMQP Transport binding: measures', function () {
contextBrokerUnprovMock
.matchHeader('fiware-service', 'TestService')
.matchHeader('fiware-servicepath', '/testingPath')
.post(
.patch(
'/v2/entities/SensorMachine:JSON_UNPROVISIONED/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/unprovisionedMeasure.json')
)
Expand All @@ -172,7 +172,7 @@ describe('AMQP Transport binding: measures', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasureAMQP.json')
)
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('AMQP Transport binding: measures', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasure.json')
)
Expand Down
8 changes: 4 additions & 4 deletions test/unit/ngsiv2/amqpBinding-test2.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('AMQP Transport binding: multiple measures', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasureAMQP.json')
)
Expand All @@ -113,7 +113,7 @@ describe('AMQP Transport binding: multiple measures', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/singleMeasureAMQP2.json')
)
Expand All @@ -140,7 +140,7 @@ describe('AMQP Transport binding: multiple measures', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasure.json')
)
Expand All @@ -150,7 +150,7 @@ describe('AMQP Transport binding: multiple measures', function () {
contextBrokerMock
.matchHeader('fiware-service', 'smartgondor')
.matchHeader('fiware-servicepath', '/gardens')
.post(
.patch(
'/v2/entities/Second%20MQTT%20Device/attrs',
utils.readExampleFile('./test/unit/ngsiv2/contextRequests/multipleMeasure2.json')
)
Expand Down
Loading

0 comments on commit 44c500e

Please sign in to comment.