Skip to content

Commit

Permalink
Merge pull request #1613 from Madhu1029/issue1528
Browse files Browse the repository at this point in the history
Fix Service Header to use upper case value
  • Loading branch information
fgalan authored Jun 26, 2024
2 parents d4e4ce5 + 8a21243 commit 093c96f
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix: service header to use uppercase in case of update and delete (#1528)
2 changes: 1 addition & 1 deletion lib/services/groups/groupService.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function listGroups(service, limit, offset, callback) {
}

function checkServiceIdentity(service, subservice, deviceGroup, callback) {
if (deviceGroup.service === service && deviceGroup.subservice === subservice) {
if (deviceGroup.service === service.toLowerCase() && deviceGroup.subservice === subservice) {
callback(null, deviceGroup);
} else {
callback(new errors.MismatchedService(service, subservice));
Expand Down
160 changes: 160 additions & 0 deletions test/unit/ngsiv2/provisioning/device-group-api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ const optionsDelete = {
apikey: '801230BJKL23Y9090DSFL123HJK09H324HV8732'
}
};
const optionsDeleteGroup = {
url: 'http://localhost:4041/iot/services',
method: 'DELETE',
json: {},
headers: {
'fiware-service': 'Testservice',
'fiware-servicepath': '/testingPath'
},
qs: {
resource: '/deviceTest',
apikey: '801230BJKL23Y9090DSFL123HJK09H324HV8732'
}
};
const optionsDeleteDevice = {
url: 'http://localhost:4041/iot/services',
method: 'DELETE',
Expand Down Expand Up @@ -175,6 +188,49 @@ const optionsUpdate = {
apikey: '801230BJKL23Y9090DSFL123HJK09H324HV8732'
}
};
const optionsUpdateGroup = {
url: 'http://localhost:4041/iot/services',
method: 'PUT',
json: {
trust: '8970A9078A803H3BL98PINEQRW8342HBAMS',
cbHost: 'http://anotherUnexistentHost:1026',
transport: 'MQTT',
endpoint: 'http://yourendpoint.com',
commands: [
{
name: 'wheel1',
type: 'Wheel'
}
],
lazy: [
{
name: 'luminescence',
type: 'Lumens'
}
],
attributes: [
{
name: 'status',
type: 'Boolean'
}
],
static_attributes: [
{
name: 'identifier',
type: 'UUID',
value: 'WERTYUIOP234567890'
}
]
},
headers: {
'fiware-service': 'Testservice',
'fiware-servicepath': '/testingPath'
},
qs: {
resource: '/deviceTest',
apikey: '801230BJKL23Y9090DSFL123HJK09H324HV8732'
}
};
const optionsList = {
url: 'http://localhost:4041/iot/services',
method: 'GET',
Expand Down Expand Up @@ -411,6 +467,33 @@ describe('NGSI-v2 - Device Group Configuration API', function () {
});
});
});
describe('When a device group removal request arrives with service-header in uppercase', function () {
beforeEach(function (done) {
request(optionsCreation, done);
});

it('should return a 204 OK', function (done) {
request(optionsDeleteGroup, function (error, response, body) {
should.not.exist(error);
response.statusCode.should.equal(204);
done();
});
});
it('should remove it from the database', function (done) {
request(optionsDeleteGroup, function (error, response, body) {
request(optionsList, function (error, response, body) {
body.count.should.equal(0);
done();
});
});
});
it('should remove it from the configuration', function (done) {
request(optionsDeleteGroup, function (error, response, body) {
should.not.exist(iotAgentConfig.types.SensorMachine);
done();
});
});
});
describe('When a device group removal request arrives with device=true option', function () {
let contextBrokerMock;

Expand Down Expand Up @@ -704,6 +787,83 @@ describe('NGSI-v2 - Device Group Configuration API', function () {
});
});

describe('When a device group update request arrives with service-header in uppercase', function () {
beforeEach(function (done) {
const optionsCreation1 = _.clone(optionsCreation);
const optionsCreation2 = _.clone(optionsCreation);
const optionsCreation3 = _.clone(optionsCreation);

optionsCreation1.json = { services: [] };
optionsCreation3.json = { services: [] };

optionsCreation1.json.services[0] = _.clone(optionsCreation.json.services[0]);
optionsCreation3.json.services[0] = _.clone(optionsCreation.json.services[0]);

optionsCreation1.json.services[0].apikey = 'qwertyuiop';
optionsCreation3.json.services[0].apikey = 'lkjhgfds';

async.series(
[
async.apply(request, optionsCreation1),
async.apply(request, optionsCreation2),
async.apply(request, optionsCreation3)
],
done
);
});

it('should return a 204 OK', function (done) {
request(optionsUpdateGroup, function (error, response, body) {
should.not.exist(error);
response.statusCode.should.equal(204);
done();
});
});
it('should update the appropriate values in the database', function (done) {
request(optionsUpdateGroup, function (error, response, body) {
request(optionsList, function (error, response, body) {
let found = false;
body.count.should.equal(3);

for (let i = 0; i < body.services.length; i++) {
if (
body.services[i].apikey === '801230BJKL23Y9090DSFL123HJK09H324HV8732' &&
body.services[i].resource === '/deviceTest'
) {
body.services[i].cbHost.should.equal('http://anotherUnexistentHost:1026');
body.services[i].static_attributes.length.should.equal(1);
found = true;
}
}

found.should.equal(true);
done();
});
});
});
it('should call the configuration creation handler', function (done) {
let handlerCalled = false;

iotAgentLib.setConfigurationHandler(function (newConfiguration, callback) {
should.exist(newConfiguration);
should.exist(callback);
newConfiguration.cbHost.should.equal('http://anotherUnexistentHost:1026');
newConfiguration.trust.should.equal('8970A9078A803H3BL98PINEQRW8342HBAMS');
newConfiguration.service.should.equal('Testservice');
newConfiguration.subservice.should.equal('/testingPath');
newConfiguration.resource.should.equal('/deviceTest');
newConfiguration.apikey.should.equal('801230BJKL23Y9090DSFL123HJK09H324HV8732');
handlerCalled = true;
callback();
});

request(optionsUpdateGroup, function (error, response, body) {
handlerCalled.should.equal(true);
done();
});
});
});

describe('When a device group update request arrives declaring a different service', function () {
beforeEach(function (done) {
optionsUpdate.headers['fiware-service'] = 'UnexistentService';
Expand Down

0 comments on commit 093c96f

Please sign in to comment.