Skip to content

Commit

Permalink
Fixed a crash in the subscription cache for subscriptions with empty …
Browse files Browse the repository at this point in the history
…URL paths in the notification::endpoint::uri field
  • Loading branch information
kzangeli committed Sep 11, 2023
1 parent 271294f commit bf92106
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Fixed issues:
* #280 - Better 501 handling of temporal operations
* #280 - Highly experimental feature for subscriptions: allowing a wildcard as value for entity type, to not filter on entity type
* #280 - Implemented Periodic Notifications (subscriptions with a 'timeInterval')
* #280 - Fixed a crash in the subscription cache for subscriptions with empty URL paths in the notification::endpoint::uri field
2 changes: 1 addition & 1 deletion src/lib/orionld/common/subCacheApiSubscriptionInsert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ static void subCacheItemFill
cSubP->rest));
cSubP->protocolString = strdup(cSubP->protocolString);
cSubP->ip = strdup(cSubP->ip);
cSubP->rest = strdup(cSubP->rest);
cSubP->rest = (cSubP->rest != NULL)? strdup(cSubP->rest) : NULL;
}

if (cSubP->protocol == MQTT)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
# Copyright 2023 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--
Possible error in Subscription Cache

--SHELL-INIT--
dbInit CB
orionldStart CB -experimental

--SHELL--

#
# 01. Create a subscription S1
# 02. Create a subscription S2
# 03. Restart broker
# 04. GET Subscriptions, make sure all is OK
#

echo "01. Create a subscription S1"
echo "============================"
payload='{
"id": "urn:S1",
"type": "Subscription",
"description": "Notify me of all product price changes",
"entities": [
{
"type": "product"
}
],
"watchedAttributes": [ "name" ],
"notification": {
"format": "normalized",
"endpoint": {
"uri": "https://ttttt.free.beeceptor.com",
"accept": "application/json",
"receiverInfo": [
{
"key": "a",
"value": "b"
}
]
}
}
}'
orionCurl --url /ngsi-ld/v1/subscriptions --payload "$payload"
echo
echo


echo "02. Create a subscription S2"
echo "============================"
payload='{
"id": "urn:S2",
"type": "Subscription",
"description": "Notify me of all product price changes",
"entities": [
{
"type": "product"
}
],
"notification": {
"format": "normalized",
"endpoint": {
"uri": "https://ttttt.free.beeceptor.com",
"accept": "application/json",
"receiverInfo": [
{
"key": "a",
"value": "b"
}
]
}
}
}'
orionCurl --url /ngsi-ld/v1/subscriptions --payload "$payload"
echo
echo


echo "03. Restart the broker"
echo "======================"
brokerStop CB
orionldStart CB -experimental
echo
echo



echo "04. GET Subscriptions, make sure all is OK"
echo "=========================================="
orionCurl --url /ngsi-ld/v1/subscriptions
echo
echo


--REGEXPECT--
01. Create a subscription S1
============================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/subscriptions/urn:S1



02. Create a subscription S2
============================
HTTP/1.1 201 Created
Content-Length: 0
Date: REGEX(.*)
Location: /ngsi-ld/v1/subscriptions/urn:S2



03. Restart the broker
======================


04. GET Subscriptions, make sure all is OK
==========================================
HTTP/1.1 200 OK
Content-Length: 900
Content-Type: application/json
Date: REGEX(.*)
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-contextREGEX(.*)

[
{
"description": "Notify me of all product price changes",
"entities": [
{
"type": "product"
}
],
"id": "urn:S1",
"isActive": true,
"jsonldContext": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld",
"notification": {
"endpoint": {
"accept": "application/json",
"receiverInfo": [
{
"key": "a",
"value": "b"
}
],
"uri": "https://ttttt.free.beeceptor.com"
},
"format": "normalized",
"status": "ok"
},
"origin": "cache",
"status": "active",
"type": "Subscription",
"watchedAttributes": [
"name"
]
},
{
"description": "Notify me of all product price changes",
"entities": [
{
"type": "product"
}
],
"id": "urn:S2",
"isActive": true,
"jsonldContext": "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld",
"notification": {
"endpoint": {
"accept": "application/json",
"receiverInfo": [
{
"key": "a",
"value": "b"
}
],
"uri": "https://ttttt.free.beeceptor.com"
},
"format": "normalized",
"status": "ok"
},
"origin": "cache",
"status": "active",
"type": "Subscription"
}
]


--TEARDOWN--
brokerStop CB
dbDrop CB

0 comments on commit bf92106

Please sign in to comment.