From b42458b20a28877ad6c4171a70e77355ae06a30c Mon Sep 17 00:00:00 2001 From: Ken Zangelin Date: Mon, 7 Oct 2024 16:03:26 +0200 Subject: [PATCH] Adding idPattern to forwarded requests --- CHANGES_NEXT_RELEASE | 1 + src/lib/orionld/distOp/distOpSend.cpp | 2 + .../ngsild_forward_with_idPattern.test | 189 ++++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 test/functionalTest/cases/0000_ngsild/ngsild_forward_with_idPattern.test diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 8e1bbf823e..6e79326a90 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -2,6 +2,7 @@ #1621: URL-Encoding single quote in attribute values in TRoE DB #1649: Crash when using subscriptions in a mixed environment (LD and V2) #1682: Default User Context + #1688: Forward of idPattern URL parameter ## New Features: * Distributed subscriptions: subordinate subscriptions are DELETED when their "father" is deleted. diff --git a/src/lib/orionld/distOp/distOpSend.cpp b/src/lib/orionld/distOp/distOpSend.cpp index d54cb048e5..0170a9113d 100644 --- a/src/lib/orionld/distOp/distOpSend.cpp +++ b/src/lib/orionld/distOp/distOpSend.cpp @@ -496,6 +496,8 @@ bool distOpSend(DistOp* distOpP, const char* dateHeader, const char* xForwardedF uriParamAdd(&urlParts, "id", entityIds, -1); else if (distOpP->entityId != NULL) uriParamAdd(&urlParts, "id", distOpP->entityId, -1); + else if (orionldState.uriParams.idPattern != NULL) + uriParamAdd(&urlParts, "idPattern", orionldState.uriParams.idPattern, -1); } if (distOpP->qNode != NULL) diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_forward_with_idPattern.test b/test/functionalTest/cases/0000_ngsild/ngsild_forward_with_idPattern.test new file mode 100644 index 0000000000..a2fb2371e6 --- /dev/null +++ b/test/functionalTest/cases/0000_ngsild/ngsild_forward_with_idPattern.test @@ -0,0 +1,189 @@ +# Copyright 2024 FIWARE Foundation e.V. +# +# This file is part of Orion-LD Context Broker. +# +# Orion-LD 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-LD 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-LD Context Broker. If not, see http://www.gnu.org/licenses/. +# +# For those usages not covered by this license please contact with +# orionld at fiware dot org + +# VALGRIND_READY - to mark the test ready for valgrindTestSuite.sh + +--NAME-- +GET /entities with two brokers all connected via registrations + +--SHELL-INIT-- +dbInit CB +dbInit CP1 +orionldStart CB -experimental -forwarding -wip entityMaps +orionldStart CP1 -experimental + +--SHELL-- + +# +# 01. In CP1, create an entity urn:E1 with attributes P1+R1 +# 02. In CP1, create an entity urn:E2 with attributes P1+R1 +# 03. In CP1, create an entity urn:F1 with attributes P1+R1 +# 04. Create an inclusive registration R1 in CB on entities of type T pointing to CP1 +# 05. GET entities in CB with idPattern urn:E.* - see E1 and E2, not urn:F1 +# + +echo "01. In CP1, create an entity urn:E1 with attributes P1+R1" +echo "=========================================================" +payload='{ + "id": "urn:E1", + "type": "T", + "P1": "Entity E1 in CP1", + "R1": { "object": "urn:E2" } +}' +orionCurl --url /ngsi-ld/v1/entities --payload "$payload" --port $CP1_PORT +echo +echo + + +echo "02. In CP1, create an entity urn:E2 with attributes P1+R1" +echo "=========================================================" +payload='{ + "id": "urn:E2", + "type": "T", + "P1": "Entity E2 in CP1", + "R1": { "object": "urn:E2" } +}' +orionCurl --url /ngsi-ld/v1/entities --payload "$payload" --port $CP1_PORT +echo +echo + + +echo "03. In CP1, create an entity urn:F1 with attributes P1+R1" +echo "=========================================================" +payload='{ + "id": "urn:F1", + "type": "T", + "P1": "Entity F1 in CP1", + "R1": { "object": "urn:E2" } +}' +orionCurl --url /ngsi-ld/v1/entities --payload "$payload" --port $CP1_PORT +echo +echo + + +echo "04. Create an inclusive registration R1 in CB on entities of type T pointing to CP1" +echo "===================================================================================" +payload='{ + "id": "urn:R1", + "type": "ContextSourceRegistration", + "information": [ + { + "entities": [ + { + "type": "T" + } + ] + } + ], + "mode": "inclusive", + "operations": [ "retrieveOps" ], + "endpoint": "http://'$(hostname)':'$CP1_PORT'" +}' +orionCurl --url /ngsi-ld/v1/csourceRegistrations --payload "$payload" +echo +echo + + +echo "05. GET entities in CB with idPattern urn:E.* - see E1 and E2" +echo "=============================================================" +orionCurl --url "/ngsi-ld/v1/entities?idPattern=urn:E.*" +echo +echo + + +--REGEXPECT-- +01. In CP1, create an entity urn:E1 with attributes P1+R1 +========================================================= +HTTP/1.1 201 Created +Content-Length: 0 +Date: REGEX(.*) +Location: /ngsi-ld/v1/entities/urn:E1 + + + +02. In CP1, create an entity urn:E2 with attributes P1+R1 +========================================================= +HTTP/1.1 201 Created +Content-Length: 0 +Date: REGEX(.*) +Location: /ngsi-ld/v1/entities/urn:E2 + + + +03. In CP1, create an entity urn:F1 with attributes P1+R1 +========================================================= +HTTP/1.1 201 Created +Content-Length: 0 +Date: REGEX(.*) +Location: /ngsi-ld/v1/entities/urn:F1 + + + +04. Create an inclusive registration R1 in CB on entities of type T pointing to CP1 +=================================================================================== +HTTP/1.1 201 Created +Content-Length: 0 +Date: REGEX(.*) +Location: /ngsi-ld/v1/csourceRegistrations/urn:R1 + + + +05. GET entities in CB with idPattern urn:E.* - see E1 and E2 +============================================================= +HTTP/1.1 200 OK +Content-Length: 253 +Content-Type: application/json +Date: REGEX(.*) +Link: