Skip to content

Commit

Permalink
Merge pull request #1300 from telefonicaid/task/check-empty-device-id
Browse files Browse the repository at this point in the history
Fix empty `device_id` on device registration
  • Loading branch information
fgalan authored Nov 30, 2022
2 parents 38ba03b + eabcbf0 commit ed74c96
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Set Nodejs 12 as minimum version in packages.json (effectively removing Nodev10 from supported versions)
- Fix: INVALID EXPRESSION policy at JEXL expression in attributes and entity_names (default values will be propagated and a warn will be logged instead of exception) (#1292)
- Fix: empty device_id on device registration (#1298)
8 changes: 3 additions & 5 deletions lib/services/northBound/restUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ function checkMandatoryQueryParams(mandatoryAttributes, body, callback) {
for (const p in mandatoryAttributes) {
let found = false;

for (const i in body) {
if (body.hasOwnProperty(i)) {
if (i === mandatoryAttributes[p]) {
found = true;
}
if (body.hasOwnProperty(mandatoryAttributes[p])) {
if (body[mandatoryAttributes[p]] !== '' && body[mandatoryAttributes[p]] !== null) {
found = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"devices": [
{
"device_id": "",
"protocol": "GENERIC_PROTO",
"entity_name": "TheFirstLight",
"entity_type": "TheLightType",
"timezone": "America/Santiago",
"endpoint": "http://fakedEndpoint:1234",
"transport": "MQTT",
"attributes": [
{
"name": "attr_name",
"type": "string"
}
],
"lazy": [
{
"name": "luminance",
"type": "lumens"
}
],
"static_attributes": [
{
"name": "hardcodedAttr",
"type": "hardcodedType",
"value": "hardcodedValue"
}
],
"commands": [
{
"name": "commandAttr",
"type": "commandType"
}
],
"internal_attributes": [
{
"customField": "customValue"
}
]
}
]
}
19 changes: 19 additions & 0 deletions test/unit/ngsiv2/provisioning/device-provisioning-api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1385,4 +1385,23 @@ describe('NGSI-v2 - Device provisioning API: Provision devices', function () {
});
});
});
describe('When a device provisioning request arrives to the Agent without device_id', function () {
const options = {
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
headers: {
'fiware-service': 'smartgondor',
'fiware-servicepath': '/gardens'
},
method: 'POST',
json: utils.readExampleFile('./test/unit/examples/deviceProvisioningRequests/provisionNewDeviceEmpty.json')
};

it('should return a 400 error', function (done) {
request(options, function (error, response, body) {
should.not.exist(error);
response.statusCode.should.equal(400);
done();
});
});
});
});

0 comments on commit ed74c96

Please sign in to comment.