From 73fbb64c37785d8461ad3103a1663fbef740c0b5 Mon Sep 17 00:00:00 2001 From: brox Date: Wed, 10 Feb 2016 10:06:27 +0100 Subject: [PATCH] Fix error with long servicepath component --- CHANGES_NEXT_RELEASE | 2 +- src/lib/mongoBackend/MongoCommonUpdate.cpp | 4 +- .../1764_long_servicepath_component.test | 161 ++++++++++++++++++ 3 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 test/functionalTest/cases/1764_long_servicepath_component/1764_long_servicepath_component.test diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 8c16de12d4..1f5b13440a 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -3,7 +3,7 @@ - Fix: '+' supported in entity ids and names in URLs (Issue #1675) - Fix: libmicrohttpd 0.9.48 included in contextBroker as static lib (previous Orion versions used 0.9.22 as dynamic library) (Issue #1675) - Fix: list of attribute names in URI param 'type' (Issue #1749) -- Fix: long servicepath when getting in NGSIv2 (#1423) +- Fix: long servicepath component in NGSIv2 (Issue #1423, #1764, #1774) - Fix: syntax change in string query 'q' for exist and not-exist (Issue #1751) - Fix: sanity check for string query 'q' - detect 'left-hand-side missing' (Issue #1754) - Fix: more sanity checks for string query 'q' (q empty, parts of 'q' empty - parts of 'q' are separated by ';') diff --git a/src/lib/mongoBackend/MongoCommonUpdate.cpp b/src/lib/mongoBackend/MongoCommonUpdate.cpp index 6212f3cf1c..118897b7ec 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.cpp +++ b/src/lib/mongoBackend/MongoCommonUpdate.cpp @@ -2941,7 +2941,7 @@ static void updateEntity } // The servicePath of THIS object is entitySPath - char espath[SERVICE_NAME_MAX_LEN]; + char espath[SERVICE_PATH_MAX_TOTAL]; slashEscape(entitySPath.c_str(), espath, sizeof(espath)); // servicePathString from earlier in this function @@ -3126,7 +3126,7 @@ void processContextElement servicePathV[0].c_str(), action.c_str())); - char path[SERVICE_NAME_MAX_LEN]; + char path[SERVICE_PATH_MAX_TOTAL]; slashEscape(servicePathV[0].c_str(), path, sizeof(path)); const std::string servicePathValue = std::string("^") + path + "$"; diff --git a/test/functionalTest/cases/1764_long_servicepath_component/1764_long_servicepath_component.test b/test/functionalTest/cases/1764_long_servicepath_component/1764_long_servicepath_component.test new file mode 100644 index 0000000000..8c3f0b904a --- /dev/null +++ b/test/functionalTest/cases/1764_long_servicepath_component/1764_long_servicepath_component.test @@ -0,0 +1,161 @@ +# Copyright 2016 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-- +Bug long servicepath component created, but not accesible + +--SHELL-INIT-- +dbInit CB +brokerStart CB + +--SHELL-- + +# +# 01. POST /v2/entities to create entity +# 02. GET /v2/entities +# 03. PUT /v2/entities +# 04. DELETE /v2/entities +# + +SP_LONG=/F_n_F4elhADVuCbEK4DDXlmi8lcV1b81OIhOpiubSD2jO6BZGM/9WNRpTC7Citc4c3qPbrHBUB7YhMxr1jenFM3JMhBHshBT5PcKl/2UAwWWAKBHI_0zU7sLfjozmcyhEcVle2c6mHQFZFkvswiyH2nb/6QaTP24vcPf4GozreIJnqZUN7WHYoOoCLz2dcgdVUOJ3sdiIh3/uf8uPlJanFCgkSiYnPwzTbIMc637zTK2ND_MsBK9BwMcEbQ9Xr/au_RXEqbjEMNRIelgPjosLpV_ZZ_JZqBg0UC1L8wlbsgYPLQEc/knywh8I1Ke41Cs1rcT4AZfoI0F6EsGyuVcgJTP3VJRqpRfTv7j/HTbaBPgyw4Z94_kzb40tCMzAWzYnerChJQmMeGND_kX6zXnBAO/QjyQLjX3OPyApIg0s4nwAqFGIoGmytUVOt2k4o0qpWNqvwxufg/RtEgL9yEQBp1wSX4bYwze7kf_BMh0sISAJBPNFnH5c9r6ydxsX + +echo "01. POST /v2/entities to create entity" +echo "======================================" +payload='{ + "id": "8787GHY", + "type": "Car", + "brand":{ + "type": "string", + "value": "Mercedes Benz" + }, + "speed":{ + "type": "number", + "value" : "150" + }, + "plateCountry": { + "value" : "ES" + }, + "madeInCountry": { + "value" : "DE", + "type" : "" + }, + "model" : { + "type": "myString", + "value" : "Klasse C" + } +}' +orionCurl --url /v2/entities --payload "$payload" --servicePath "$SP_LONG" --json +echo +echo + + +echo "02. GET /v2/entities/8787GHY" +echo "============================" +orionCurl --url "/v2/entities/8787GHY" --servicePath "$SP_LONG" --json +echo +echo + + +echo "03. PUT /v2/entities/8787GHY/attrs/speed" +echo "========================================" +payload='{ + "value" : "999" +}' +orionCurl --url "/v2/entities/8787GHY/attrs/speed" --payload "$payload" --servicePath "$SP_LONG" --json -X PUT +echo +echo + + +echo "04. DELETE /v2/entities/8787GHY" +echo "===============================" +orionCurl --url "/v2/entities/8787GHY" --servicePath "$SP_LONG" --json -X DELETE +echo +echo + + +--REGEXPECT-- +01. POST /v2/entities to create entity +====================================== +HTTP/1.1 201 Created +Content-Length: 0 +Location: /v2/entities/8787GHY +Date: REGEX(.*) + + + +02. GET /v2/entities/8787GHY +============================ +HTTP/1.1 200 OK +Content-Length: 321 +Content-Type: application/json +Date: REGEX(.*) + +{ + "brand": { + "metadata": {}, + "type": "string", + "value": "Mercedes Benz" + }, + "id": "8787GHY", + "madeInCountry": { + "metadata": {}, + "type": null, + "value": "DE" + }, + "model": { + "metadata": {}, + "type": "myString", + "value": "Klasse C" + }, + "plateCountry": { + "metadata": {}, + "type": null, + "value": "ES" + }, + "speed": { + "metadata": {}, + "type": "number", + "value": "150" + }, + "type": "Car" +} + + +03. PUT /v2/entities/8787GHY/attrs/speed +======================================== +HTTP/1.1 204 No Content +Content-Length: 0 +Date: REGEX(.*) + + + +04. DELETE /v2/entities/8787GHY +=============================== +HTTP/1.1 204 No Content +Content-Length: 0 +Date: REGEX(.*) + + + +--TEARDOWN-- +brokerStop CB +dbDrop CB