From eea9400d343980d3ff7cfa2f4cffad08e4a3e2ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Wed, 12 Jun 2024 14:10:31 +0200 Subject: [PATCH 1/3] REMOVE ngsiv1 ops aligned with CB 4.0.0 --- CHANGES_NEXT_RELEASE | 1 + README.md | 67 ----- lib/plugins/orionPlugin.js | 109 +------- lib/plugins/orionUrls.js | 8 - operations.md | 2 - test/orionRequests/entityCreation.json | 22 -- test/orionRequests/entityCreation.xml | 23 -- test/orionRequests/entityDelete.json | 10 - test/orionRequests/entityDelete.xml | 12 - test/orionRequests/entityUpdate.json | 22 -- test/orionRequests/entityUpdate.xml | 23 -- ...{queryContext.json => v2QueryContext.json} | 1 - test/unit/admin_bypass-test.js | 6 +- test/unit/connection-error-tests.js | 6 +- test/unit/extract_cb_convenience_test.js | 6 +- test/unit/extract_csb_actions_test.js | 262 +----------------- test/unit/extract_info_test.js | 18 +- test/unit/headers_test.js | 118 ++------ test/unit/httpOptions_test.js | 6 +- test/unit/keypass_cache-test.js | 6 +- test/unit/keystone_cache-test.js | 12 +- test/unit/reuse_keystone_tokens_test.js | 18 +- test/unit/simultaneous_requests-test.js | 8 +- test/unit/slash-in-templates-test.js | 6 +- test/unit/top_domain_service_path-test.js | 12 +- test/unit/unvalidated-mode-test.js | 10 +- test/unit/validate_user_action_test.js | 72 ++--- 27 files changed, 119 insertions(+), 747 deletions(-) delete mode 100644 test/orionRequests/entityCreation.json delete mode 100644 test/orionRequests/entityCreation.xml delete mode 100644 test/orionRequests/entityDelete.json delete mode 100644 test/orionRequests/entityDelete.xml delete mode 100644 test/orionRequests/entityUpdate.json delete mode 100644 test/orionRequests/entityUpdate.xml rename test/orionRequests/{queryContext.json => v2QueryContext.json} (74%) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 51c3409..c31c401 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,2 +1,3 @@ - Upgrade express dep from 4.18.1 to 4.19.2 due to a vulnerability +- Remove: operations no longer supported in CB API (aligned with Orion 4.0.0) - Remove: RPM stuff diff --git a/README.md b/README.md index 43c43ff..dc53d73 100644 --- a/README.md +++ b/README.md @@ -610,73 +610,6 @@ This is the list of actions available for the Context Broker. For every action, | discover | Dis | | N/A | - | -### Standard operations -* `create`: URL contains `/v1/updateContext` and the `actionType` attribute of the payload (either with XML or JSON) is `APPEND` or `APPEND_STRICT`. -* `update`: URL contains `/v1/updateContext` and the `actionType` attribute of the payload (either with XML or JSON) is `UPDATE` or `REPLACE`. -* `delete`: URL contains `/v1/updateContext` and the `actionType` attribute of the payload (either with XML or JSON) is `DELETE`. -* `read`: URL contains `/v1/queryContext` or `/v1/contextTypes`. -* `subscribe`: URL contains `/v1/subscribeContext`, `/v1/updateContextSubscription` o `/v1/unsubscribeContext`. -* `register`: URL contains `/v1/registry/registerContext`. -* `discover`: URL contains `/v1/registry/discoverContextAvailability`. - -### Convenience operations -The following tables show the rules for detemining the action based on Method and path of the request. - -An up-to-date list of the convenience operations can be found [here](https://docs.google.com/spreadsheet/ccc?key=0Aj_S9VF3rt5DdEhqZHlBaGVURmhZRDY3aDRBdlpHS3c#gid=0). - -#### NGSI9 (context information availability) -| Method | Path | Action | -| ------ |:--------------------------------------------------------------------------------------- | ---:| -| GET | /v1/registry/contextEntities/{EntityId} | Dis | -| POST | /v1/registry/contextEntities/{EntityId} | Reg | -| GET | /v1/registry/contextEntities/{EntityId}/attributes | - | -| POST | /v1/registry/contextEntities/{EntityId}/attributes | - | -| GET | /v1/registry/contextEntities/{EntityId}/attributes/{attributeName} | Dis | -| POST | /v1/registry/contextEntities/{EntityId}/attributes/{attributeName} | Reg | -| GET | /v1/registry/contextEntities/{EntityId}/attributeDomains/{attributeDomainName} | Dis | -| POST | /v1/registry/contextEntities/{EntityId}/attributeDomains/{attributeDomainName} | Reg | -| GET | /v1/registry/contextEntityTypes/{typeName} | Dis | -| POST | /v1/registry/contextEntityTypes/{typeName} | Reg | -| GET | /v1/registry/contextEntityTypes/{typeName}/attributes | - | -| POST | /v1/registry/contextEntityTypes/{typeName}/attributes | - | -| GET | /v1/registry/contextEntityTypes/{typeName}/attributes/{attributeName} | Dis | -| POST | /v1/registry/contextEntityTypes/{typeName}/attributes/{attributeName} | Reg | -| GET | /v1/registry/contextEntityTypes/{typeName}/attributeDomains/{attributeDomainName} | Dis | -| POST | /v1/registry/contextEntityTypes/{typeName}/attributeDomains/{attributeDomainName} | Reg | - -#### NGS10 (context information availability) -| Method | Path | Action | -| ------ |:--------------------------------------------------------------------------------------- | ---:| -| GET | /v1/contextEntities | R | -| POST | /v1/contextEntities | C | -| GET | /v1/contextEntities/{EntityID} | R | -| PUT | /v1/contextEntities/{EntityID} | U | -| POST | /v1/contextEntities/{EntityID} | C | -| DELETE | /v1/contextEntities/{EntityID} | D | -| GET | /v1/contextEntities/{EntityID}/attributes | - | -| PUT | /v1/contextEntities/{EntityID}/attributes | - | -| POST | /v1/contextEntities/{EntityID}/attributes | - | -| DELETE | /v1/contextEntities/{EntityID}/attributes | - | -| GET | /v1/contextEntities/{EntityID}/attributes/{attributeName} | R | -| POST | /v1/contextEntities/{EntityID}/attributes/{attributeName} | C | -| PUT | /v1/contextEntities/{EntityID}/attributes/{attributeName} | U | -| DELETE | /v1/contextEntities/{EntityID}/attributes/{attributeName} | D | -| GET | /v1/contextEntities/{EntityID}/attributes/{attributeName}/{valueID} | R | -| PUT | /v1/contextEntities/{EntityID}/attributes/{attributeName}/{valueID} | U | -| DELETE | /v1/contextEntities/{EntityID}/attributes/{attributeName}/{valueID} | D | -| GET | /v1/contextEntities/{EntityID}/attributeDomains/{attributeDomainName} | R | -| GET | /v1/contextEntityTypes/{typeName} | R | -| GET | /v1/contextEntityTypes/{typeName}/attributes | - | -| GET | /v1/contextEntityTypes/{typeName}/attributes/{attributeName} | R | -| GET | /v1/contextEntityTypes/{typeName}/attributeDomains/{attributeDomainName} | R | -| POST | /v1/contextSubscriptions | S | -| GET | /v1/contextSubscriptions | R | -| GET | /v1/contextSubscriptions/{subscriptionID} | R | -| PUT | /v1/contextSubscriptions/{subscriptionID} | S | -| DELETE | /v1/contextSubscriptions/{subscriptionID} | S | -| GET | /v1/contextTypes | R | -| GET | /v1/contextTypes{typename} | R | - #### NGSIv2 | Method | Path | Action | | ------ |:--------------------------------------------------------------------------------------- | ---:| diff --git a/lib/plugins/orionPlugin.js b/lib/plugins/orionPlugin.js index 1ec0afd..69f9661 100644 --- a/lib/plugins/orionPlugin.js +++ b/lib/plugins/orionPlugin.js @@ -23,8 +23,7 @@ 'use strict'; -var sax = require('sax'), - errors = require('../errors'), +var errors = require('../errors'), identificationTable = require('./orionUrls'); @@ -42,12 +41,8 @@ function translateAction(logger, originalAction) { case 'append': action = 'create'; break; - - case 'append_strict': // NGSIv1 - action = 'create'; - break; - case 'appendstrict': // NGSIv2 + case 'appendstrict': action = 'create'; break; @@ -72,75 +67,6 @@ function translateAction(logger, originalAction) { return action; } -/** - * Extract the action from an XML body. - * - * @param {Object} logger Instance of logops.Logger - * @param {String} body Raw string payload. - */ -function inspectBodyXML(logger, body, callback) { - var parser = sax.parser(true), - readingAction = false, - errorRaised = false, - action; - - parser.onerror = function(e) { - var error = new errors.WrongXmlPayload(); - - logger.error('[ORION-PLUGIN-006] Wrong XML Payload. Parsing error: %s', e.message); - - if (!errorRaised) { - errorRaised = true; - error.moreInfo = e; - callback(error); - } - }; - - parser.ontext = function(t) { - if (readingAction) { - if (!action) { - action = t; - } else { - action = action + t; - } - } - }; - - parser.onopentag = function(node) { - if (node.name === 'updateAction') { - readingAction = true; - } else { - readingAction = false; - } - }; - - parser.onend = function() { - if (action) { - var translatedAction = translateAction(logger, action.trim()); - - if (translatedAction) { - callback(null, translatedAction); - } else { - callback(new errors.WrongXmlPayload()); - } - - } else { - logger.error('[ORION-PLUGIN-001] Wrong XML Payload. Action not found'); - - callback(new errors.WrongXmlPayload()); - } - }; - - try { - parser.write(body).close(); - } catch (e) { - var error = new errors.WrongXmlPayload(); - - logger.error('[ORION-PLUGIN-002] Wrong XML Payload. Parsing error: %s', e.message); - callback(error); - } -} - /** * Extract the action from a JSON body. * @@ -164,33 +90,6 @@ function inspectBodyJSON(logger, body, field, callback) { } } -/** - * Determines what kind of body to parse to calculate the action, and invoke the appropriate function. - * - * @param {Object} req Incoming request. - * @param {Object} res Outgoing response. - */ -function inspectBodyV1(req, res, callback) { - const logger = req.logger; - var actionHandler = function actionHandler(error, action) { - req.action = action; - callback(error, req, res); - }; - - if (req.is('*/json')) { - logger.debug('Inspecting JSON body to discover action: \n%j\n\n', req.body); - inspectBodyJSON(logger, req.body, 'updateAction', actionHandler); - } else if (req.is('*/xml')) { - logger.debug('Inspecting XML body to discover action: \n%s\n\n', req.rawBody); - inspectBodyXML(logger, req.rawBody, actionHandler); - } else { - // TODO: raise error if the type is not recognized. - logger.error('[ORION-PLUGIN-004] Unknown content type: %s', req.headers['content-type']); - - actionHandler(new errors.UnexpectedContentType(req.headers['content-type'])); - } -} - function inspectBodyV2(req, res, callback) { const logger = req.logger; var actionHandler = function actionHandler(error, action) { @@ -259,9 +158,7 @@ function inspectUrl(req, res, callback) { * @param {Object} res Outgoing response. */ function extractCBAction(req, res, callback) { - if (req.path.toLowerCase().match(/\/(ngsi10|v1)\/updatecontext$/)) { - inspectBodyV1(req, res, callback); - } else if (req.path.toLowerCase().match(/\/v2\/op\/update$/)) { + if (req.path.toLowerCase().match(/\/v2\/op\/update$/)) { inspectBodyV2(req, res, callback); } else { inspectUrl(req, res, callback); diff --git a/lib/plugins/orionUrls.js b/lib/plugins/orionUrls.js index 58e374a..b7f41d2 100644 --- a/lib/plugins/orionUrls.js +++ b/lib/plugins/orionUrls.js @@ -34,14 +34,6 @@ * this table will fail). */ module.exports = [ - /* Legacy NGSI operations (to be removed soon) */ - /* Note POST /(v1|ngsi10)/updateContext is not included here, - /* as it is processed in an special way in orionPlugin.js */ - ['POST', /\/(v1|ngsi10)\/querycontext$/, 'read'], - ['GET', /^\/v1\/contextentities\/.+\/attributes\/.+/, 'read'], - ['PUT', /^\/v1\/contextentities\/.+/, 'update'], - ['DELETE', /^\/v1\/contextentities\/.+/, 'delete'], - /* V2 Operations */ ['POST', /^\/v2\/op\/query$/, 'read'], ['GET', /^\/v2$/, 'read'], diff --git a/operations.md b/operations.md index 7036cd3..26e8f59 100644 --- a/operations.md +++ b/operations.md @@ -120,8 +120,6 @@ Indicates that a received request didn't have the appropriate information to det The proxy received a request with a content type that is not supported. Currently only JSON ('application/json') and XML ('application/xml' and 'text/xml') are supported. This is a client error and should not require human intervention. This may be a problem with the content headers; if repeated, advice the client to check what headers are being sent and the API for the content payload. #### ORION-PLUGIN-005: Action not found This error is raised when a request action should be identifiable with the information in the URL but the proxy was unavailable to do so. It might happen when the request is trying to access a URL that is not known by the Orion plugin (maybe because the client is trying to access version of the Orion Context Broker different of the one supported by the proxy). This is a client error. The client should check the API he is trying to use is the appropriate one for this version of the proxy and the Context Broker. -#### ORION-PLUGIN-006: Wrong XML Payload. Parsing error: %s -An XML payload with syntactic errors has been received. This should be a client error, and it shouldn't require human intervention. Warn the user if the error repeats. ## Expected problems and known solutions | Symptoms | Causes | Procedure diff --git a/test/orionRequests/entityCreation.json b/test/orionRequests/entityCreation.json deleted file mode 100644 index c90e01b..0000000 --- a/test/orionRequests/entityCreation.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "contextElements": [ - { - "type": "Room", - "isPattern": "false", - "id": "Room1", - "attributes": [ - { - "name": "temperature", - "type": "centigrade", - "value": "23" - }, - { - "name": "pressure", - "type": "mmHg", - "value": "720" - } - ] - } - ], - "updateAction": "APPEND" -} \ No newline at end of file diff --git a/test/orionRequests/entityCreation.xml b/test/orionRequests/entityCreation.xml deleted file mode 100644 index 7a334ac..0000000 --- a/test/orionRequests/entityCreation.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - Room1 - - - - temperature - centigrade - 23 - - - pressure - mmHg - 720 - - - - - APPEND - \ No newline at end of file diff --git a/test/orionRequests/entityDelete.json b/test/orionRequests/entityDelete.json deleted file mode 100644 index ba7d074..0000000 --- a/test/orionRequests/entityDelete.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "contextElements": { - "contextElement": { - "type": "T", - "isPattern": "false", - "id": "E1" - } - }, - "updateAction": "DELETE" -} \ No newline at end of file diff --git a/test/orionRequests/entityDelete.xml b/test/orionRequests/entityDelete.xml deleted file mode 100644 index efec6af..0000000 --- a/test/orionRequests/entityDelete.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - E1 - - - - - DELETE - \ No newline at end of file diff --git a/test/orionRequests/entityUpdate.json b/test/orionRequests/entityUpdate.json deleted file mode 100644 index 99bc0d2..0000000 --- a/test/orionRequests/entityUpdate.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "contextElements": [ - { - "type": "Room", - "isPattern": "false", - "id": "Room1", - "attributes": [ - { - "name": "temperature", - "type": "centigrade", - "value": "26.5" - }, - { - "name": "pressure", - "type": "mmHg", - "value": "763" - } - ] - } - ], - "updateAction": "UPDATE" -} \ No newline at end of file diff --git a/test/orionRequests/entityUpdate.xml b/test/orionRequests/entityUpdate.xml deleted file mode 100644 index 0201d32..0000000 --- a/test/orionRequests/entityUpdate.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - Room1 - - - - temperature - centigrade - 26.5 - - - pressure - mmHg - 763 - - - - - UPDATE - \ No newline at end of file diff --git a/test/orionRequests/queryContext.json b/test/orionRequests/v2QueryContext.json similarity index 74% rename from test/orionRequests/queryContext.json rename to test/orionRequests/v2QueryContext.json index 7977af7..aeb53b2 100644 --- a/test/orionRequests/queryContext.json +++ b/test/orionRequests/v2QueryContext.json @@ -2,7 +2,6 @@ "entities": [ { "type": "Room", - "isPattern": "false", "id": "Room1" } ] diff --git a/test/unit/admin_bypass-test.js b/test/unit/admin_bypass-test.js index fdda01a..2dd25d1 100644 --- a/test/unit/admin_bypass-test.js +++ b/test/unit/admin_bypass-test.js @@ -85,7 +85,7 @@ describe('Admin bypass tests', function() { describe('[' + authenticationMechanism.module + '] ' + 'When a request arrives to the PEP and for a user with the admin role', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -94,7 +94,7 @@ describe('Admin bypass tests', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }, currentAuthentication = authenticationMechanism; @@ -107,7 +107,7 @@ describe('Admin bypass tests', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); diff --git a/test/unit/connection-error-tests.js b/test/unit/connection-error-tests.js index 2203a48..d8cbc00 100644 --- a/test/unit/connection-error-tests.js +++ b/test/unit/connection-error-tests.js @@ -85,7 +85,7 @@ describe('Connection error tests', function() { describe('When a request arrives to the PEP and the target app shut down the connection', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -94,7 +94,7 @@ describe('Connection error tests', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }, currentAuthentication = authenticationMechanism; @@ -107,7 +107,7 @@ describe('Connection error tests', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], function(error) { cacheUtils.clean(); done(); diff --git a/test/unit/extract_cb_convenience_test.js b/test/unit/extract_cb_convenience_test.js index 9b1db1d..7a20285 100644 --- a/test/unit/extract_cb_convenience_test.js +++ b/test/unit/extract_cb_convenience_test.js @@ -109,13 +109,9 @@ describe('Extract Context Broker action from convenience operation requests', fu 'Fiware-ServicePath': 'admin_domain', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; - beforeEach(function(done) { - serverMocks.mockPath('/NGSI10/queryContext', mockApp, done); - }); - it('should add the action attribute with value ' + convenienceAction + ' to the request', testAction(convenienceAction, options)); }; diff --git a/test/unit/extract_csb_actions_test.js b/test/unit/extract_csb_actions_test.js index e0ee79c..6d60c77 100644 --- a/test/unit/extract_csb_actions_test.js +++ b/test/unit/extract_csb_actions_test.js @@ -110,9 +110,7 @@ describe('Extract Context Broker action from request', function() { }); var standardOperation = [ - ['/NGSI10/queryContext', 'read'], - ['/v2/op/query', 'read'], - ['/v1/queryContext', 'read'] + ['/v2/op/query', 'read'] ]; function testStandardOperation(url, action) { @@ -127,7 +125,7 @@ describe('Extract Context Broker action from request', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/queryContext.json') + json: utils.readExampleFile('./test/orionRequests/v2QueryContext.json') }; it('should add the action attribute with value "' + action + '" to the request', @@ -142,139 +140,9 @@ describe('Extract Context Broker action from request', function() { )); } - describe('When a create action arrives with JSON payload and the "/NGSI10" prefix', function() { - var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json', - 'fiware-service': 'SmartValencia', - 'fiware-servicepath': 'Electricidad', - 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' - }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') - }; - - beforeEach(function(done) { - serverMocks.mockPath('/NGSI10/queryContext', mockApp, done); - }); - - it('should add the action attribute with value "create" to the request', testAction('create', options)); - }); - - describe('When a create action arrives with JSON payload and the "/v1" prefix', function() { - var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/v1/updateContext', - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json', - 'fiware-service': 'SmartValencia', - 'fiware-servicepath': 'Electricidad', - 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' - }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') - }; - - beforeEach(function(done) { - serverMocks.mockPath('/NGSI10/queryContext', mockApp, done); - }); - - it('should add the action attribute with value "create" to the request', testAction('create', options)); - }); - - describe('When a update action arrives with JSON payload', function() { - var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json', - 'fiware-service': 'SmartValencia', - 'fiware-servicepath': 'Electricidad', - 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' - }, - json: utils.readExampleFile('./test/orionRequests/entityUpdate.json') - }; - - beforeEach(function(done) { - serverMocks.mockPath('/NGSI10/queryContext', mockApp, done); - }); - - it('should add the action attribute with value "update" to the request', testAction('update', options)); - }); - describe('When a delete action arrives with JSON payload', function() { - var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json', - 'fiware-service': 'SmartValencia', - 'fiware-servicepath': 'Electricidad', - 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' - }, - json: utils.readExampleFile('./test/orionRequests/entityDelete.json') - }; - - beforeEach(function(done) { - serverMocks.mockPath('/NGSI10/queryContext', mockApp, done); - }); - - it('should add the action attribute with value "delete" to the request', testAction('delete', options)); - }); - describe('When a delete action arrives with JSON payload', function() { - var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/v1/updateContext?details=on&limit=15&offset=0', - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json', - 'fiware-service': 'SmartValencia', - 'fiware-servicepath': 'Electricidad', - 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' - }, - json: utils.readExampleFile('./test/orionRequests/entityDelete.json') - }; - - beforeEach(function(done) { - serverMocks.mockPath('/NGSI10/queryContext', mockApp, done); - }); - - it('should add the action attribute with value "delete" to the request', testAction('delete', options)); - }); - - describe('When a update action arrives with JSON payload without the \'updateAction\' attribute', function() { - var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json', - 'fiware-service': 'SmartValencia', - 'fiware-servicepath': 'Electricidad', - 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' - }, - json: utils.readExampleFile('./test/orionErrorRequests/entityUpdateNoAttribute.json') - }; - - beforeEach(function(done) { - serverMocks.mockPath('/NGSI10/queryContext', mockApp, done); - }); - - it('should reject the request with an Unauthorized code', function(done) { - request(options, function(error, response, body) { - response.statusCode.should.equal(400 - ); - done(); - }); - }); - }); - describe('When a update action arrives with a URL that it\'s not recognized by the system', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/falsePath', + uri: 'http://localhost:' + config.resource.proxy.port + '/falsePath', method: 'POST', headers: { 'Content-Type': 'application/xml', @@ -283,13 +151,9 @@ describe('Extract Context Broker action from request', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - body: utils.readExampleFile('./test/orionRequests/entityUpdate.xml', true) + body: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json', true) }; - beforeEach(function(done) { - serverMocks.mockPath('/NGSI10/queryContext', mockApp, done); - }); - it('should reject the request with a 400 Bad Request code', function(done) { request(options, function(error, response, body) { response.statusCode.should.equal(400); @@ -298,124 +162,6 @@ describe('Extract Context Broker action from request', function() { }); }); - describe('When an update action comes with an unknown action in a JSON format', function() { - var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json', - 'fiware-service': 'SmartValencia', - 'fiware-servicepath': 'Electricidad', - 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' - }, - json: utils.readExampleFile('./test/orionErrorRequests/entityUnknownOperation.json') - }; - - beforeEach(function(done) { - serverMocks.mockPath('/NGSI10/queryContext', mockApp, done); - }); - - it('should reject the request with a 400', function(done) { - request(options, function(error, response, body) { - response.statusCode.should.equal(400); - done(); - }); - }); - }); - - describe('When a request arrives with an unknown body type', function() { - var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', - method: 'POST', - headers: { - 'Content-Type': 'application/csv', - 'Accept': 'application/csv', - 'fiware-service': 'SmartValencia', - 'fiware-servicepath': 'Electricidad', - 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' - }, - body: utils.readExampleFile('./test/orionErrorRequests/entityUnknownOperation.xml', true) - }; - - beforeEach(function(done) { - serverMocks.mockPath('/NGSI10/queryContext', mockApp, done); - }); - - it('should reject the request with a 415 error', function(done) { - request(options, function(error, response, body) { - response.statusCode.should.equal(415); - done(); - }); - }); - }); - - describe('When a request arrives with a JSON body with a wrong syntax', function() { - var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json', - 'fiware-service': 'SmartValencia', - 'fiware-servicepath': 'Electricidad', - 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' - }, - body: utils.readExampleFile('./test/orionErrorRequests/entitySyntaxError.json', true) - }; - - beforeEach(function(done) { - serverMocks.mockPath('/NGSI10/queryContext', mockApp, done); - }); - - it('should reject the request with a 400 error', function(done) { - request(options, function(error, response, body) { - response.statusCode.should.equal(400); - done(); - }); - }); - }); - - describe('When a request arrives with a valid JSON payload to the proxy', function() { - var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json', - 'fiware-service': 'SmartValencia', - 'fiware-servicepath': 'Electricidad', - 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' - }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') - }; - - beforeEach(function(done) { - async.series([ - async.apply(serverMocks.mockPath, '/v3/role_assignments', mockOAuthApp), - async.apply(serverMocks.mockPath, '/v3/auth/tokens', mockOAuthApp), - async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), - async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockApp) - ], done); - }); - - it('should proxy the request to the target URL', function(done) { - var mockExecuted = false; - - mockApp.handler = function(req, res) { - should.exist(req.body.updateAction); - req.body.updateAction.should.equal('APPEND'); - mockExecuted = true; - res.status(200).json({}); - }; - - request(options, function(error, response, body) { - mockExecuted.should.equal(true); - done(); - }); - }); - }); var v2UpdateOperationMatrix = [ ['append', 'create'], diff --git a/test/unit/extract_info_test.js b/test/unit/extract_info_test.js index 575dc7c..798b552 100644 --- a/test/unit/extract_info_test.js +++ b/test/unit/extract_info_test.js @@ -93,7 +93,7 @@ describe('Extract information from requests', function() { describe('When a request to the CB arrives to the proxy with all the information', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/V2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -102,11 +102,11 @@ describe('Extract information from requests', function() { 'Fiware-ServicePath': 'admin_domain', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { - serverMocks.mockPath('/NGSI10/updateContext', mockApp, done); + serverMocks.mockPath('/v2/op/update', mockApp, done); }); it('should extract the organization to an attribute in the request', function(done) { @@ -162,18 +162,18 @@ describe('Extract information from requests', function() { describe('When a request arrives to the CB without a user token', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Fiware-Service': 'frn:contextbroker:admin_domain:::' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { - serverMocks.mockPath('/NGSI10/updateContext', mockApp, done); + serverMocks.mockPath('/v2/op/update', mockApp, done); }); it('should reject the request with a 400 error code', function(done) { @@ -200,18 +200,18 @@ describe('Extract information from requests', function() { describe('When a request arrives to the CB without a Fiware Service header', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { - serverMocks.mockPath('/NGSI10/updateContext', mockApp, done); + serverMocks.mockPath('/v2/op/update', mockApp, done); }); it('should reject the request with a 400 error code', function(done) { diff --git a/test/unit/headers_test.js b/test/unit/headers_test.js index 40c67da..00b4ce5 100644 --- a/test/unit/headers_test.js +++ b/test/unit/headers_test.js @@ -94,7 +94,7 @@ describe('Control header behavior', function() { describe('When a request to the CB arrives to the proxy without X-Forwarded-For', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -103,13 +103,13 @@ describe('Control header behavior', function() { 'Fiware-ServicePath': 'admin_domain', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { async.series([ async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); @@ -138,7 +138,7 @@ describe('Control header behavior', function() { describe('When a request to the CB arrives to the proxy with the X-Forwarded-For header', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -148,13 +148,13 @@ describe('Control header behavior', function() { 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q', 'X-Forwarded-For': '192.168.2.1' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { async.series([ async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); @@ -181,87 +181,9 @@ describe('Control header behavior', function() { }); }); - describe('When a request to the CB arrives to the proxy with a xml body', function() { - var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', - method: 'POST', - headers: { - 'Accept': 'application/xml', - 'Fiware-Service': 'frn:contextbroker:admin_domain:::', - 'Fiware-ServicePath': 'admin_domain', - 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q', - 'X-Forwarded-For': '192.168.2.1' - }, - body: utils.readExampleFile('./test/orionRequests/entityCreation.xml', true) - }; - beforeEach(function(done) { - async.series([ - async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) - ], done); - }); - - it('should manage content-type: application/xml header', function(done) { - var mockExecuted = false, - expectedBody, - expectedLength; - - options.headers['Content-Type'] = 'application/xml'; - - mockAccessApp.handler = function(req, res) { - res.set('Content-Type', 'application/xml'); - res.send(utils.readExampleFile('./test/accessControlResponses/permitResponse.xml', true)); - }; - - mockTargetApp.handler = function(req, res) { - mockExecuted = true; - expectedBody = req.body; - expectedLength = req.headers['content-length']; - - res.status(200).json({}); - }; - - request(options, function(error, response, body) { - mockExecuted.should.equal(true); - should.exist(expectedBody); - expectedLength.should.be.above(0); - done(); - }); - }); - - it('should manage content-type: text/xml header', function(done) { - var mockExecuted = false, - expectedBody, - expectedLength; - - options.headers['Content-Type'] = 'text/xml'; - - mockAccessApp.handler = function(req, res) { - res.set('Content-Type', 'application/xml'); - res.send(utils.readExampleFile('./test/accessControlResponses/permitResponse.xml', true)); - }; - - mockTargetApp.handler = function(req, res) { - mockExecuted = true; - expectedBody = req.body; - expectedLength = req.headers['content-length']; - - res.status(200).json({}); - }; - - request(options, function(error, response, body) { - mockExecuted.should.equal(true); - should.exist(expectedBody); - expectedLength.should.be.above(0); - done(); - }); - }); - - }); - describe('When a request to the CB arrives to the proxy with a json body', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Accept': 'application/json', @@ -270,12 +192,12 @@ describe('Control header behavior', function() { 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q', 'X-Forwarded-For': '192.168.2.1' }, - body: JSON.stringify(utils.readExampleFile('./test/orionRequests/entityCreation.json')) + body: JSON.stringify(utils.readExampleFile('./test/orionRequests/v2EntityCreation.json')) }; beforeEach(function(done) { async.series([ async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); @@ -338,7 +260,7 @@ describe('Control header behavior', function() { describe('When a request to the CB arrives to the proxy with a json content header but wrong body', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Accept': 'application/json', @@ -352,7 +274,7 @@ describe('Control header behavior', function() { beforeEach(function(done) { async.series([ async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); @@ -388,7 +310,7 @@ describe('Control header behavior', function() { describe('When the PEP Proxy sends a request to the access control', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -397,13 +319,13 @@ describe('Control header behavior', function() { 'Fiware-ServicePath': 'admin_domain', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { async.series([ async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); @@ -436,7 +358,7 @@ describe('Control header behavior', function() { beforeEach(function(done) { options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/v1/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'content-type': 'application/json', @@ -445,13 +367,13 @@ describe('Control header behavior', function() { 'fiware-servicepath': 'admin_domain', 'x-auth-token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; delete options.headers[headerTest]; async.series([ async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); @@ -472,7 +394,7 @@ describe('Control header behavior', function() { beforeEach(function(done) { options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/v1/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'content-type': 'application/json', @@ -481,13 +403,13 @@ describe('Control header behavior', function() { 'fiware-servicepath': 'admin_domain', 'x-auth-token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; options.headers[headerTest] = ''; async.series([ async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); diff --git a/test/unit/httpOptions_test.js b/test/unit/httpOptions_test.js index eb0d655..2236c18 100644 --- a/test/unit/httpOptions_test.js +++ b/test/unit/httpOptions_test.js @@ -100,7 +100,7 @@ describe('HTTPS Options', function() { }); describe('When a request to the CB arrives to the proxy with HTTPS', function() { var options = { - uri: 'https://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'https://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -109,13 +109,13 @@ describe('HTTPS Options', function() { 'Fiware-ServicePath': 'admin_domain', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { async.series([ async.apply(serverMocks.mockPath, '/validate', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); diff --git a/test/unit/keypass_cache-test.js b/test/unit/keypass_cache-test.js index e31ce64..3b85e9f 100644 --- a/test/unit/keypass_cache-test.js +++ b/test/unit/keypass_cache-test.js @@ -91,7 +91,7 @@ describe('Keypass authentication cache', function() { describe('When the keypass cache is activated and multiple requests for a user arrive', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -100,7 +100,7 @@ describe('Keypass authentication cache', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { @@ -111,7 +111,7 @@ describe('Keypass authentication cache', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); diff --git a/test/unit/keystone_cache-test.js b/test/unit/keystone_cache-test.js index 0b5e670..cc17a1e 100644 --- a/test/unit/keystone_cache-test.js +++ b/test/unit/keystone_cache-test.js @@ -92,7 +92,7 @@ describe('Keystone authentication cache', function() { describe('When the keystone cache is activated and multiple requests for a user arrive', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -101,7 +101,7 @@ describe('Keystone authentication cache', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { @@ -112,7 +112,7 @@ describe('Keystone authentication cache', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); @@ -251,7 +251,7 @@ describe('Keystone authentication cache', function() { describe('When multiple requests for a user arrive at the same time', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -260,7 +260,7 @@ describe('Keystone authentication cache', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { @@ -271,7 +271,7 @@ describe('Keystone authentication cache', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); diff --git a/test/unit/reuse_keystone_tokens_test.js b/test/unit/reuse_keystone_tokens_test.js index 4590d06..2b854ab 100644 --- a/test/unit/reuse_keystone_tokens_test.js +++ b/test/unit/reuse_keystone_tokens_test.js @@ -90,7 +90,7 @@ describe('Reuse authentication tokens', function() { describe('When a PEP Proxy has a token and it\'s still valid', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -99,7 +99,7 @@ describe('Reuse authentication tokens', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { @@ -111,7 +111,7 @@ describe('Reuse authentication tokens', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], function() { request(options, function(error, response, body) { done(); @@ -153,7 +153,7 @@ describe('Reuse authentication tokens', function() { describe('When a PEP Proxy has a token and it has expired', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -162,7 +162,7 @@ describe('Reuse authentication tokens', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { @@ -174,7 +174,7 @@ describe('Reuse authentication tokens', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], function() { request(options, function(error, response, body) { cacheUtils.clean(); @@ -229,7 +229,7 @@ describe('Reuse authentication tokens', function() { describe('When a PEP Proxy has an expired token and another request arrives to the proxy', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -238,7 +238,7 @@ describe('Reuse authentication tokens', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { @@ -251,7 +251,7 @@ describe('Reuse authentication tokens', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], function() { request(options, function(error, response, body) { cacheUtils.clean(); diff --git a/test/unit/simultaneous_requests-test.js b/test/unit/simultaneous_requests-test.js index 9bfdb55..7d96953 100644 --- a/test/unit/simultaneous_requests-test.js +++ b/test/unit/simultaneous_requests-test.js @@ -97,7 +97,7 @@ describe('Simultaneous requests', function() { } var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -106,7 +106,7 @@ describe('Simultaneous requests', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; describe('When two requests arrive simultaneusly with successful tokens', function() { @@ -128,7 +128,7 @@ describe('Simultaneous requests', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], function() { cacheUtils.clean(); done(); @@ -213,7 +213,7 @@ describe('Simultaneous requests', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], function() { cacheUtils.clean(); done(); diff --git a/test/unit/slash-in-templates-test.js b/test/unit/slash-in-templates-test.js index 792c3e2..3ad8f89 100644 --- a/test/unit/slash-in-templates-test.js +++ b/test/unit/slash-in-templates-test.js @@ -85,7 +85,7 @@ describe('Slash in Access Control templates', function() { describe('When a request with the value "/" in the "fiware-service-path" header arrives and the user doesn\'t ' + ' have domain roles', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -94,7 +94,7 @@ describe('Slash in Access Control templates', function() { 'fiware-servicepath': '/Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { @@ -105,7 +105,7 @@ describe('Slash in Access Control templates', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); diff --git a/test/unit/top_domain_service_path-test.js b/test/unit/top_domain_service_path-test.js index e4ba2b9..d0d472f 100644 --- a/test/unit/top_domain_service_path-test.js +++ b/test/unit/top_domain_service_path-test.js @@ -90,7 +90,7 @@ describe('Top domain Service-path behavior', function() { describe('When a request with the value "/" in the "fiware-service-path" header arrives and the user doesn\'t ' + ' have domain roles', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -99,7 +99,7 @@ describe('Top domain Service-path behavior', function() { 'fiware-servicepath': '/', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { @@ -110,7 +110,7 @@ describe('Top domain Service-path behavior', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); @@ -152,7 +152,7 @@ describe('Top domain Service-path behavior', function() { describe('When a request with the value "/" in the "fiware-service-path" header arrives and the user ' + ' has domain roles', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -161,7 +161,7 @@ describe('Top domain Service-path behavior', function() { 'fiware-servicepath': '/', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; beforeEach(function(done) { @@ -172,7 +172,7 @@ describe('Top domain Service-path behavior', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); diff --git a/test/unit/unvalidated-mode-test.js b/test/unit/unvalidated-mode-test.js index 1c4f711..13129de 100644 --- a/test/unit/unvalidated-mode-test.js +++ b/test/unit/unvalidated-mode-test.js @@ -97,7 +97,7 @@ describe('Unvalidated mode', function() { async.apply(serverMocks.mockPath, authenticationMechanism.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); @@ -118,7 +118,7 @@ describe('Unvalidated mode', function() { describe('[' + authenticationMechanism.module + '] ' + 'When a request arrives for a user and the access.disable flag is true', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -127,7 +127,7 @@ describe('Unvalidated mode', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; it('shouldn\'t call the Access Control and should not extract the roles', function(done) { @@ -165,13 +165,13 @@ describe('Unvalidated mode', function() { describe('[' + authenticationMechanism.module + '] ' + 'When a request arrives for a user without the X-Auth-Token header and the access control is disabled', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }; it('should return a MISSING_HEADERS error', function(done) { diff --git a/test/unit/validate_user_action_test.js b/test/unit/validate_user_action_test.js index e4b4c29..8b625e7 100644 --- a/test/unit/validate_user_action_test.js +++ b/test/unit/validate_user_action_test.js @@ -113,7 +113,7 @@ describe('Validate action with Access Control', function() { describe('[' + authenticationMechanisms[q].module + '] When a request to the CB arrives to the proxy with appropriate permissions', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -122,7 +122,7 @@ describe('Validate action with Access Control', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }, currentAuthentication = authenticationMechanisms[q]; @@ -134,7 +134,7 @@ describe('Validate action with Access Control', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); @@ -172,7 +172,7 @@ describe('Validate action with Access Control', function() { describe('[' + authenticationMechanisms[q].module + '] When a request to the CB arrives for a user with wrong permissions', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -181,7 +181,7 @@ describe('Validate action with Access Control', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }, currentAuthentication = authenticationMechanisms[q]; @@ -192,7 +192,7 @@ describe('Validate action with Access Control', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); @@ -232,7 +232,7 @@ describe('Validate action with Access Control', function() { describe('[' + authenticationMechanisms[q].module + '] When a request to the CB arrives and the connection to the Access Control is not working', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -241,7 +241,7 @@ describe('Validate action with Access Control', function() { 'Fiware-Servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }, currentAuthentication = authenticationMechanisms[q]; @@ -253,7 +253,7 @@ describe('Validate action with Access Control', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); @@ -287,7 +287,7 @@ describe('Validate action with Access Control', function() { describe('[' + authenticationMechanisms[q].module + '] ' + 'When a request to the CB arrives and the Access Control fails to make a proper decision', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -296,7 +296,7 @@ describe('Validate action with Access Control', function() { 'Fiware-Servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }, currentAuthentication = authenticationMechanisms[q]; @@ -307,7 +307,7 @@ describe('Validate action with Access Control', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); @@ -342,7 +342,7 @@ describe('Validate action with Access Control', function() { describe('[' + authenticationMechanisms[1].module + '] ' + 'When a request arrives and the authentication token has expired', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -351,7 +351,7 @@ describe('Validate action with Access Control', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }, currentAuthentication = authenticationMechanisms[1]; @@ -365,7 +365,7 @@ describe('Validate action with Access Control', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); @@ -399,7 +399,7 @@ describe('Validate action with Access Control', function() { describe('[' + authenticationMechanisms[1].module + '] ' + 'When a request is validated using Keystone', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -408,7 +408,7 @@ describe('Validate action with Access Control', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }, currentAuthentication = authenticationMechanisms[1]; @@ -422,7 +422,7 @@ describe('Validate action with Access Control', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); @@ -557,7 +557,7 @@ describe('Validate action with Access Control', function() { describe('[' + authenticationMechanisms[1].module + '] ' + 'When a request arrives for a user that doesn\'t have a role on the subservice', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -566,7 +566,7 @@ describe('Validate action with Access Control', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }, currentAuthentication = authenticationMechanisms[1]; @@ -578,7 +578,7 @@ describe('Validate action with Access Control', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); @@ -621,7 +621,7 @@ describe('Validate action with Access Control', function() { describe('[' + authenticationMechanisms[1].module + '] ' + 'When a request arrives for a user that has roles in the domain as well as in the project', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -630,7 +630,7 @@ describe('Validate action with Access Control', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }, currentAuthentication = authenticationMechanisms[1]; @@ -642,7 +642,7 @@ describe('Validate action with Access Control', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); @@ -690,7 +690,7 @@ describe('Validate action with Access Control', function() { describe('[' + authenticationMechanisms[1].module + '] ' + 'When a request arrives for a user and the token is not valid', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -699,7 +699,7 @@ describe('Validate action with Access Control', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }, currentAuthentication = authenticationMechanisms[1]; @@ -711,7 +711,7 @@ describe('Validate action with Access Control', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); @@ -755,14 +755,14 @@ describe('Validate action with Access Control', function() { 'When a request arrives and the access.disable flag is true and the authentication.checkHeaders flag is false', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }, currentAuthentication = authenticationMechanisms[1]; @@ -776,7 +776,7 @@ describe('Validate action with Access Control', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); @@ -818,7 +818,7 @@ describe('Validate action with Access Control', function() { describe('[' + authenticationMechanisms[1].module + '] ' + 'When a request with a tenant A tries to access things on tenant B', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -827,7 +827,7 @@ describe('Validate action with Access Control', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }, currentAuthentication = authenticationMechanisms[1]; @@ -839,7 +839,7 @@ describe('Validate action with Access Control', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); @@ -866,7 +866,7 @@ describe('Validate action with Access Control', function() { describe('[' + authenticationMechanisms[1].module + '] ' + 'When a request is validated using a trust token in Keystone', function() { var options = { - uri: 'http://localhost:' + config.resource.proxy.port + '/NGSI10/updateContext', + uri: 'http://localhost:' + config.resource.proxy.port + '/v2/op/update', method: 'POST', headers: { 'Content-Type': 'application/json', @@ -875,7 +875,7 @@ describe('Validate action with Access Control', function() { 'fiware-servicepath': 'Electricidad', 'X-Auth-Token': 'UAidNA9uQJiIVYSCg0IQ8Q' }, - json: utils.readExampleFile('./test/orionRequests/entityCreation.json') + json: utils.readExampleFile('./test/orionRequests/v2EntityCreation.json') }, currentAuthentication = authenticationMechanisms[1]; @@ -889,7 +889,7 @@ describe('Validate action with Access Control', function() { async.apply(serverMocks.mockPath, currentAuthentication.authPath, mockOAuthApp), async.apply(serverMocks.mockPath, '/v3/projects', mockOAuthApp), async.apply(serverMocks.mockPath, '/pdp/v3', mockAccessApp), - async.apply(serverMocks.mockPath, '/NGSI10/updateContext', mockTargetApp) + async.apply(serverMocks.mockPath, '/v2/op/update', mockTargetApp) ], done); }); }); From 491f2abebb85ccec14f20254b1c4d87dbb12d5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Wed, 12 Jun 2024 15:04:22 +0200 Subject: [PATCH 2/3] Update operations.md --- operations.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/operations.md b/operations.md index 26e8f59..5077beb 100644 --- a/operations.md +++ b/operations.md @@ -110,8 +110,6 @@ it is critical: human supervision is highly advisable. Check the Keystone instan the Keystone Operations Manual. ### Orion errors -#### ORION-PLUGIN-001: Wrong XML Payload. Action not found -Indicates that a received request didn't have the appropriate information to determine which action it's going to execute, so the validation process can't proceed. This is a client error and should not require human intervention. Warn the user if the error repeats. #### ORION-PLUGIN-002: Wrong XML Payload. Parsing error: %s An XML payload with syntactic errors has been received. This should be a client error, and it shouldn't require human intervention. Warn the user if the error repeats. #### ORION-PLUGIN-003: Wrong JSON Payload: updateAction element not found From a41c81a5fe7affd728eb012fd7a6a0b5318e1022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Wed, 12 Jun 2024 15:05:46 +0200 Subject: [PATCH 3/3] FIX renumbering ORION-PLUGIN traces --- lib/plugins/orionPlugin.js | 6 +++--- operations.md | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/plugins/orionPlugin.js b/lib/plugins/orionPlugin.js index 69f9661..93a3881 100644 --- a/lib/plugins/orionPlugin.js +++ b/lib/plugins/orionPlugin.js @@ -84,7 +84,7 @@ function inspectBodyJSON(logger, body, field, callback) { callback(new errors.WrongJsonPayload()); } } else { - logger.error('[ORION-PLUGIN-003] Wrong JSON Payload: updateAction element not found'); + logger.error('[ORION-PLUGIN-001] Wrong JSON Payload: updateAction element not found'); callback(new errors.WrongJsonPayload()); } @@ -103,7 +103,7 @@ function inspectBodyV2(req, res, callback) { } else { // TODO: raise error if the type is not recognized. - logger.error('[ORION-PLUGIN-004] Unknown content type: %s', req.headers['content-type']); + logger.error('[ORION-PLUGIN-002] Unknown content type: %s', req.headers['content-type']); actionHandler(new errors.UnexpectedContentType(req.headers['content-type'])); } @@ -147,7 +147,7 @@ function inspectUrl(req, res, callback) { } } - logger.error('[ORION-PLUGIN-005] Action not found'); + logger.error('[ORION-PLUGIN-003] Action not found'); callback(new errors.ActionNotFound(), req, res); } diff --git a/operations.md b/operations.md index 5077beb..3e3b925 100644 --- a/operations.md +++ b/operations.md @@ -110,13 +110,11 @@ it is critical: human supervision is highly advisable. Check the Keystone instan the Keystone Operations Manual. ### Orion errors -#### ORION-PLUGIN-002: Wrong XML Payload. Parsing error: %s -An XML payload with syntactic errors has been received. This should be a client error, and it shouldn't require human intervention. Warn the user if the error repeats. -#### ORION-PLUGIN-003: Wrong JSON Payload: updateAction element not found +#### ORION-PLUGIN-001: Wrong JSON Payload: updateAction element not found Indicates that a received request didn't have the appropriate information to determine which action it's going to execute, so the validation process can't proceed. This is a client error and should not require human intervention. Warn the user if the error repeats. -#### ORION-PLUGIN-004: Unknown content type: %s +#### ORION-PLUGIN-002: Unknown content type: %s The proxy received a request with a content type that is not supported. Currently only JSON ('application/json') and XML ('application/xml' and 'text/xml') are supported. This is a client error and should not require human intervention. This may be a problem with the content headers; if repeated, advice the client to check what headers are being sent and the API for the content payload. -#### ORION-PLUGIN-005: Action not found +#### ORION-PLUGIN-003: Action not found This error is raised when a request action should be identifiable with the information in the URL but the proxy was unavailable to do so. It might happen when the request is trying to access a URL that is not known by the Orion plugin (maybe because the client is trying to access version of the Orion Context Broker different of the one supported by the proxy). This is a client error. The client should check the API he is trying to use is the appropriate one for this version of the proxy and the Context Broker. ## Expected problems and known solutions