diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index fe97d8c1f3..0cfc39e90e 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -2,6 +2,7 @@ - Add: notification.mqtt.retain and notification.mqttCustom.retain flag for MQTT retain in notifications (#4388) - Add: notification payload in INFO log traces (#4449) - Fix: correctly detect JSON attribute and metadata value changes in subscription triggering logic (#4211, #4434, #643) +- Fix: update forwarding was not working when entity type is not included in the request (#4460) - Fix: DateTime and geo:json types were not supported in custom notifications using ngsi patching (#4435) - Fix: logDeprecate not working correctly (`geo:json` wrongly considered as deprecated) - Fix: improve error traces (#4387) diff --git a/src/lib/ngsi10/UpdateContextRequest.cpp b/src/lib/ngsi10/UpdateContextRequest.cpp index 2959a8e743..db3a910e75 100644 --- a/src/lib/ngsi10/UpdateContextRequest.cpp +++ b/src/lib/ngsi10/UpdateContextRequest.cpp @@ -332,16 +332,17 @@ ContextAttribute* UpdateContextRequest::attributeLookup(Entity* eP, const std::s { Entity* enP = entityVector[ceIx]; - if ((enP->id != eP->id) || (enP->type != eP->type)) + // empty type in request (enP) is always a match + if ((enP->id != eP->id) || ((enP->type != "") && (enP->type != eP->type))) { continue; } - Entity* eP = entityVector[ceIx]; + Entity* eVItemP = entityVector[ceIx]; - for (unsigned int aIx = 0; aIx < eP->attributeVector.size(); ++aIx) + for (unsigned int aIx = 0; aIx < eVItemP->attributeVector.size(); ++aIx) { - ContextAttribute* aP = eP->attributeVector[aIx]; + ContextAttribute* aP = eVItemP->attributeVector[aIx]; if (aP->name == attributeName) { diff --git a/test/functionalTest/cases/4460_update_fwd_not_working_when_entity_type_not_included_in_request/update_fwd_not_working_when_entity_type_not_included_in_request.test b/test/functionalTest/cases/4460_update_fwd_not_working_when_entity_type_not_included_in_request/update_fwd_not_working_when_entity_type_not_included_in_request.test new file mode 100644 index 0000000000..c1dba621db --- /dev/null +++ b/test/functionalTest/cases/4460_update_fwd_not_working_when_entity_type_not_included_in_request/update_fwd_not_working_when_entity_type_not_included_in_request.test @@ -0,0 +1,189 @@ +# Copyright 2023 Telefonica Investigacion y Desarrollo, S.A.U +# +# This file is part of Orion Context Broker. +# +# Orion Context Broker 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. +# +# Orion Context Broker 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 Orion Context Broker. If not, see http://www.gnu.org/licenses/. +# +# For those usages not covered by this license please contact with +# iot_support at tid dot es + +# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh + +--NAME-- +Update forwarding was not working when entity type is not included in the request + +--SHELL-INIT-- +dbInit CB +dbInit CP1 +brokerStart CB +brokerStart CP1 + +--SHELL-- + +# +# 01. Create device:wt:13 attribute profile_config in CP1 +# 02. Create device:wt:13 attribute profile in CB +# 03. Register device:wt:13 attribute profile_config in CB, provApp: CP1 +# 04. Update device:wt:13 attribute profile_config in CB +# 05. Check no Runtime Error occur +# 06. Query device:wt:13 attribute profile_config in CP1 +# + +echo "01. Create device:wt:13 attribute profile_config in CP1" +echo "=======================================================" +payload='{ + "id": "device:wt:13", + "type": "Device", + "profile_config": { + "type": "command", + "value": "init" + } +}' +orionCurl --url /v2/entities --payload "$payload" --port $CP1_PORT +echo +echo + + +echo "02. Create device:wt:13 attribute profile in CB" +echo "===============================================" +payload='{ + "id": "device:wt:13", + "type": "Device", + "profile": { + "type": "Text", + "value": "prof01" + } +}' +orionCurl --url /v2/entities --payload "$payload" +echo +echo + + +echo "03. Register device:wt:13 attribute profile_config in CB, provApp: CP1" +echo "======================================================================" +payload='{ + "dataProvided": { + "entities": [ + { + "type": "Device", + "id": "device:wt:13" + } + ], + "attrs": [ "profile_config" ] + }, + "provider": { + "http": { + "url": "http://localhost:'${CP1_PORT}'/v2" + } + } +}' +orionCurl --url /v2/registrations --payload "$payload" +echo +echo + + +echo "04. Update device:wt:13 attribute profile_config in CB" +echo "======================================================" +payload='{ + "type": "command", + "value": "foobar" +}' +orionCurl --url /v2/entities/device:wt:13/attrs/profile_config --payload "$payload" -X PUT +echo +echo + + +echo "05. Check no Runtime Error occur" +echo "================================" +cat /tmp/contextBroker.log | grep "Runtime Error" | wc -l +echo +echo + + +echo "06. Query device:wt:13 attribute profile_config in CP1 and see foobar" +echo "=====================================================================" +orionCurl --url /v2/entities/device:wt:13 --port $CP1_PORT +echo +echo + + + +--REGEXPECT-- +01. Create device:wt:13 attribute profile_config in CP1 +======================================================= +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/entities/device:wt:13?type=Device +Content-Length: 0 + + + +02. Create device:wt:13 attribute profile in CB +=============================================== +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/entities/device:wt:13?type=Device +Content-Length: 0 + + + +03. Register device:wt:13 attribute profile_config in CB, provApp: CP1 +====================================================================== +HTTP/1.1 201 Created +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Location: /v2/registrations/REGEX([0-9a-f\-]{24}) +Content-Length: 0 + + + +04. Update device:wt:13 attribute profile_config in CB +====================================================== +HTTP/1.1 204 No Content +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) + + + +05. Check no Runtime Error occur +================================ +0 + + +06. Query device:wt:13 attribute profile_config in CP1 and see foobar +===================================================================== +HTTP/1.1 200 OK +Date: REGEX(.*) +Fiware-Correlator: REGEX([0-9a-f\-]{36}) +Content-Type: application/json +Content-Length: 104 + +{ + "id": "device:wt:13", + "profile_config": { + "metadata": {}, + "type": "command", + "value": "foobar" + }, + "type": "Device" +} + + +--TEARDOWN-- +brokerStop CB +brokerStop CP1 +dbDrop CB +dbDrop CP1