Skip to content

Commit

Permalink
Merge 6720c39 into 2e8f1f5
Browse files Browse the repository at this point in the history
  • Loading branch information
dcalvoalonso committed Mar 5, 2019
2 parents 2e8f1f5 + 6720c39 commit 7469679
Show file tree
Hide file tree
Showing 4 changed files with 589 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Fix: modified engine version >=6 in packages.json
Fix: update logops dependency from 1.0.8 to 2.1.0
Fix: user provider timestamp correctly propagated to mapped entities when multientity pluging is used (#748)
Add: new functions to set callbacks for removal of devices and groups (#735)
Fix: add ?type parameter in CB request updates to avoid potential entity ambiguities (#733)
Fix: add ?type parameter in CB request updates to avoid potential entity ambiguities (#733)
Fix: incomplete HTTPS support for NGSI subscriptions (#593)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"protocol": "GENERIC_PROTOCOL",
"description": "A generic protocol",
"iotagent": "http://smartGondor.com/iot",
"resource": "/iot/d",
"services": [
{
"apikey": "801230BJKL23Y9090DSFL123HJK09H324HV8732",
"token": "8970A9078A803H3BL98PINEQRW8342HBAMS",
"entity_type": "SensorMachine",
"resource": "/deviceTest",
"service": "theService",
"service_path": "theSubService",
"attributes": [
{
"name": "status",
"type": "Boolean"
}
]
}
]
}
271 changes: 271 additions & 0 deletions test/unit/general/https-support-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
/*
* Copyright 2015 Telefonica Investigación y Desarrollo, S.A.U
*
* This file is part of fiware-iotagent-lib
*
* fiware-iotagent-lib is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* fiware-iotagent-lib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with fiware-iotagent-lib.
* If not, seehttp://www.gnu.org/licenses/.
*
* For those usages not covered by the GNU Affero General Public License
* please contact with::[contacto@tid.es]
*
* Modified by: Federico M. Facca - Martel Innovate
* Modified by: Daniel Calvo - ATOS Research & Innovation
*/
'use strict';

/* jshint camelcase: false */

var iotAgentLib = require('../../../lib/fiware-iotagent-lib'),
request = require('request'),
nock = require('nock'),
utils = require('../../tools/utils'),
groupRegistryMemory = require('../../../lib/services/groups/groupRegistryMemory'),
should = require('should'),
iotAgentConfig = {
logLevel: 'FATAL',
contextBroker: {
url: 'https://192.168.1.1:1026'
},
server: {
port: 4041
},
types: {
'Light': {
commands: [],
lazy: [
{
name: 'temperature',
type: 'centigrades'
}
],
active: [
{
name: 'pressure',
type: 'Hgmm'
}
],
service: 'smartGondor',
subservice: 'gardens'
},
'Termometer': {
commands: [],
lazy: [
{
name: 'temp',
type: 'kelvin'
}
],
active: [
],
service: 'smartGondor',
subservice: 'gardens'
}
},
service: 'smartGondor',
subservice: 'gardens',
providerUrl: 'http://smartGondor.com',
deviceRegistrationDuration: 'P1M',
throttling: 'PT5S',
iotManager: {
url: 'https://mockediotam.com:9876',
path: '/protocols',
protocol: 'GENERIC_PROTOCOL',
description: 'A generic protocol',
agentPath: '/iot'
},
defaultResource: '/iot/d'
},
groupCreation = {
service: 'theService',
subservice: 'theSubService',
resource: '/deviceTest',
apikey: '801230BJKL23Y9090DSFL123HJK09H324HV8732',
type: 'SensorMachine',
trust: '8970A9078A803H3BL98PINEQRW8342HBAMS',
commands: [
{
name: 'wheel1',
type: 'Wheel'
}
],
lazy: [
{
name: 'luminescence',
type: 'Lumens'
}
],
attributes: [
{
name: 'status',
type: 'Boolean'
}
]
},
device1 = {
id: 'light1',
type: 'Light',
service: 'smartGondor',
subservice: 'gardens'
},
contextBrokerMock,
iotamMock;


describe('HTTPS support tests IOTAM', function() {

describe('When the IoT Agents is started with https "iotManager" config', function() {
beforeEach(function(done) {
nock.cleanAll();

iotamMock = nock('https://mockediotam.com:9876')
.post('/protocols',
utils.readExampleFile('./test/unit/examples/iotamRequests/registrationWithGroupsWithoutCB.json'))
.reply(200,
utils.readExampleFile('./test/unit/examples/iotamResponses/registrationSuccess.json'));

groupRegistryMemory.create(groupCreation, done);
});

afterEach(function(done) {
nock.cleanAll();
groupRegistryMemory.clear(function() {
iotAgentLib.deactivate(done);
});
});

it('should register without errors to the IoT Manager', function(done) {
iotAgentLib.activate(iotAgentConfig, function(error) {
should.not.exist(error);
iotamMock.done();
done();
});
});
});
});

describe('HTTPS support tests', function() {

describe('When subscription is sent to HTTPS context broker', function() {
beforeEach(function(done) {
var optionsProvision = {
url: 'http://localhost:' + iotAgentConfig.server.port + '/iot/devices',
method: 'POST',
json: utils.readExampleFile(
'./test/unit/examples/deviceProvisioningRequests/provisionMinimumDevice.json'),
headers: {
'fiware-service': 'smartGondor',
'fiware-servicepath': '/gardens'
}
};

iotAgentConfig.iotManager = {};

nock.cleanAll();

iotAgentLib.activate(iotAgentConfig, function() {
contextBrokerMock = nock('https://192.168.1.1:1026')
.matchHeader('fiware-service', 'smartGondor')
.matchHeader('fiware-servicepath', '/gardens')
.post('/v1/updateContext',
utils.readExampleFile(
'./test/unit/examples/contextRequests/createMinimumProvisionedDevice.json'))
.reply(200,
utils.readExampleFile(
'./test/unit/examples/contextResponses/createProvisionedDeviceSuccess.json'));

contextBrokerMock = nock('https://192.168.1.1:1026')
.matchHeader('fiware-service', 'smartGondor')
.matchHeader('fiware-servicepath', '/gardens')
.post('/v1/subscribeContext',
utils.readExampleFile(
'./test/unit/examples/subscriptionRequests/simpleSubscriptionRequest.json'))
.reply(200,
utils.readExampleFile(
'./test/unit/examples/subscriptionResponses/simpleSubscriptionSuccess.json'));

iotAgentLib.clearAll(function() {
request(optionsProvision, function(error, result, body) {
done();
});
});
});
});

afterEach(function(done) {
nock.cleanAll();
iotAgentLib.setNotificationHandler();
iotAgentLib.clearAll(function() {
iotAgentLib.deactivate(done);
});
});

it('should send the appropriate request to the Context Broker', function(done) {
iotAgentLib.getDevice('MicroLight1', 'smartGondor', '/gardens', function(error, device) {
iotAgentLib.subscribe(device, ['attr_name'], null, function(error) {
should.not.exist(error);

contextBrokerMock.done();

done();
});
});
});
});

describe('When a new device is connected to the IoT Agent', function() {
beforeEach(function(done) {
nock.cleanAll();

iotAgentConfig.iotManager = {};

contextBrokerMock = nock('https://192.168.1.1:1026')
.matchHeader('fiware-service', 'smartGondor')
.matchHeader('fiware-servicepath', 'gardens')
.post('/NGSI9/registerContext', utils.readExampleFile(
'./test/unit/examples/contextAvailabilityRequests/registerIoTAgent1.json'))
.reply(200, utils.readExampleFile(
'./test/unit/examples/contextAvailabilityResponses/registerIoTAgent1Success.json'));

contextBrokerMock
.matchHeader('fiware-service', 'smartGondor')
.matchHeader('fiware-servicepath', 'gardens')
.post('/v1/updateContext')
.reply(200, utils.readExampleFile(
'./test/unit/examples/contextResponses/createProvisionedDeviceSuccess.json'));

iotAgentLib.activate(iotAgentConfig, function(error) {
iotAgentLib.clearAll(done);
});
});

it('should register as ContextProvider using HTTPS', function(done) {
iotAgentLib.register(device1, function(error) {
should.not.exist(error);
contextBrokerMock.done();
done();
});
});

afterEach(function(done) {
nock.cleanAll();
iotAgentLib.clearAll(function() {
// We need to remove the registrationId so that the library does not consider next operatios as updates.
delete device1.registrationId;
iotAgentLib.deactivate(done);
});
});

});
});
Loading

0 comments on commit 7469679

Please sign in to comment.