From 18136f6de321567f640bc7cedfcd99de9a32b5f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Fri, 22 Dec 2023 11:28:44 +0100 Subject: [PATCH 1/4] ADD test case for 4460 working aligned with the current faulty behaviour --- .../overloging_runtime_error_fwd_update.test | 189 ++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 test/functionalTest/cases/4460_overloging_runtime_error_fwd_update/overloging_runtime_error_fwd_update.test diff --git a/test/functionalTest/cases/4460_overloging_runtime_error_fwd_update/overloging_runtime_error_fwd_update.test b/test/functionalTest/cases/4460_overloging_runtime_error_fwd_update/overloging_runtime_error_fwd_update.test new file mode 100644 index 0000000000..783003bac7 --- /dev/null +++ b/test/functionalTest/cases/4460_overloging_runtime_error_fwd_update/overloging_runtime_error_fwd_update.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-- +Overloging Runtime Error on forwarding update request case + +--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 +================================ +1 + + +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: 98 + +{ + "id": "device:wt:13", + "profile_config": { + "metadata": {}, + "type": "command", + "value": "" + }, + "type": "Device" +} + + +--TEARDOWN-- +brokerStop CB +brokerStop CP1 +dbDrop CB +dbDrop CP1 From 0512f650719822452d831b0cdfd264b564f3701d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Fri, 22 Dec 2023 11:33:58 +0100 Subject: [PATCH 2/4] FIX overloging runtime error problem and forwarding update case --- src/lib/ngsi10/UpdateContextRequest.cpp | 4 +++- .../overloging_runtime_error_fwd_update.test | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib/ngsi10/UpdateContextRequest.cpp b/src/lib/ngsi10/UpdateContextRequest.cpp index 2959a8e743..ca55df1790 100644 --- a/src/lib/ngsi10/UpdateContextRequest.cpp +++ b/src/lib/ngsi10/UpdateContextRequest.cpp @@ -332,11 +332,13 @@ 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; } + // FIXME PR: eP is overriden here. Remove eP from function signature Entity* eP = entityVector[ceIx]; for (unsigned int aIx = 0; aIx < eP->attributeVector.size(); ++aIx) diff --git a/test/functionalTest/cases/4460_overloging_runtime_error_fwd_update/overloging_runtime_error_fwd_update.test b/test/functionalTest/cases/4460_overloging_runtime_error_fwd_update/overloging_runtime_error_fwd_update.test index 783003bac7..a7331870c4 100644 --- a/test/functionalTest/cases/4460_overloging_runtime_error_fwd_update/overloging_runtime_error_fwd_update.test +++ b/test/functionalTest/cases/4460_overloging_runtime_error_fwd_update/overloging_runtime_error_fwd_update.test @@ -160,7 +160,7 @@ Fiware-Correlator: REGEX([0-9a-f\-]{36}) 05. Check no Runtime Error occur ================================ -1 +0 06. Query device:wt:13 attribute profile_config in CP1 and see foobar @@ -169,14 +169,14 @@ HTTP/1.1 200 OK Date: REGEX(.*) Fiware-Correlator: REGEX([0-9a-f\-]{36}) Content-Type: application/json -Content-Length: 98 +Content-Length: 104 { "id": "device:wt:13", "profile_config": { "metadata": {}, "type": "command", - "value": "" + "value": "foobar" }, "type": "Device" } From a885d5627bbef211ff9d6ab1a31eed5bf50398e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Fri, 22 Dec 2023 11:51:08 +0100 Subject: [PATCH 3/4] FIX cleanup and CNR --- CHANGES_NEXT_RELEASE | 1 + src/lib/ngsi10/UpdateContextRequest.cpp | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) 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 ca55df1790..db3a910e75 100644 --- a/src/lib/ngsi10/UpdateContextRequest.cpp +++ b/src/lib/ngsi10/UpdateContextRequest.cpp @@ -338,12 +338,11 @@ ContextAttribute* UpdateContextRequest::attributeLookup(Entity* eP, const std::s continue; } - // FIXME PR: eP is overriden here. Remove eP from function signature - 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) { From 7e3d43bb8b0f27a12e4dbc15c70117b0db5693c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Gal=C3=A1n=20M=C3=A1rquez?= Date: Fri, 22 Dec 2023 12:09:20 +0100 Subject: [PATCH 4/4] RENAME case 4460 ftest --- ...d_not_working_when_entity_type_not_included_in_request.test} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename test/functionalTest/cases/{4460_overloging_runtime_error_fwd_update/overloging_runtime_error_fwd_update.test => 4460_update_fwd_not_working_when_entity_type_not_included_in_request/update_fwd_not_working_when_entity_type_not_included_in_request.test} (98%) diff --git a/test/functionalTest/cases/4460_overloging_runtime_error_fwd_update/overloging_runtime_error_fwd_update.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 similarity index 98% rename from test/functionalTest/cases/4460_overloging_runtime_error_fwd_update/overloging_runtime_error_fwd_update.test rename to 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 index a7331870c4..c1dba621db 100644 --- a/test/functionalTest/cases/4460_overloging_runtime_error_fwd_update/overloging_runtime_error_fwd_update.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 @@ -21,7 +21,7 @@ # VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh --NAME-- -Overloging Runtime Error on forwarding update request case +Update forwarding was not working when entity type is not included in the request --SHELL-INIT-- dbInit CB