diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 033c046882..4c5c912cb9 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1 +1,2 @@ -- Fix: wrong date values should not allowed in subscription's expires field (#4541) \ No newline at end of file +- Fix: wrong date values should not allowed in subscription's expires field (#4541) +- Fix: do not raise DB alarm in case of wrong GeoJSON in client request \ No newline at end of file diff --git a/src/lib/mongoBackend/MongoCommonUpdate.cpp b/src/lib/mongoBackend/MongoCommonUpdate.cpp index 03617d9d50..3e5b3b28ff 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.cpp +++ b/src/lib/mongoBackend/MongoCommonUpdate.cpp @@ -64,6 +64,7 @@ #include "mongoDriver/safeMongo.h" #include "mongoDriver/BSONObjBuilder.h" #include "mongoDriver/BSONArrayBuilder.h" +#include "mongoDriver/DBErrors.h" /* **************************************************************************** diff --git a/src/lib/mongoBackend/MongoCommonUpdate.h b/src/lib/mongoBackend/MongoCommonUpdate.h index 3873b7a4f8..a3d4266dcc 100644 --- a/src/lib/mongoBackend/MongoCommonUpdate.h +++ b/src/lib/mongoBackend/MongoCommonUpdate.h @@ -32,9 +32,6 @@ #include "orionTypes/UpdateActionType.h" #include "ngsi10/UpdateContextResponse.h" -#define MONGODB_ERROR_DUPLICATE_KEY "duplicate key" -#define MONGODB_ERROR_WRONGJSON "Can't extract geo keys" - /* **************************************************************************** diff --git a/src/lib/mongoDriver/CMakeLists.txt b/src/lib/mongoDriver/CMakeLists.txt index e5153dd283..dc23230ab8 100644 --- a/src/lib/mongoDriver/CMakeLists.txt +++ b/src/lib/mongoDriver/CMakeLists.txt @@ -47,6 +47,7 @@ SET (HEADERS OID.h DBConnection.h DBCursor.h + DBErrors.h safeMongo.h connectionOperations.h mongoConnectionPool.h diff --git a/src/lib/mongoDriver/DBErrors.h b/src/lib/mongoDriver/DBErrors.h new file mode 100644 index 0000000000..b184d13317 --- /dev/null +++ b/src/lib/mongoDriver/DBErrors.h @@ -0,0 +1,34 @@ +#ifndef SRC_LIB_MONGODRIVER_DBERRORS_H_ +#define SRC_LIB_MONGODRIVER_DBERRORS_H_ + +/* +* +* Copyright 2024 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 +* +* Author: Fermín Galán +*/ + + +#define MONGODB_ERROR_DUPLICATE_KEY "duplicate key" +#define MONGODB_ERROR_WRONGJSON "Can't extract geo keys" + + +#endif // SRC_LIB_MONGODRIVER_DBERRORS_H_ \ No newline at end of file diff --git a/src/lib/mongoDriver/connectionOperations.cpp b/src/lib/mongoDriver/connectionOperations.cpp index d0f5ca0b9f..0499f5114c 100644 --- a/src/lib/mongoDriver/connectionOperations.cpp +++ b/src/lib/mongoDriver/connectionOperations.cpp @@ -37,6 +37,7 @@ #include "mongoDriver/BSONArrayBuilder.h" #include "mongoDriver/mongoConnectionPool.h" #include "mongoDriver/safeMongo.h" +#include "mongoDriver/DBErrors.h" @@ -507,7 +508,12 @@ bool orion::collectionInsert " - exception: " + error.message; *err = "Database Error (" + msg + ")"; - alarmMgr.dbError(msg); + + // MONGODB_ERROR_WRONGJSON doesn't raise alarm (responses 400 Bad Request in this situation) + if (!(msg.find(MONGODB_ERROR_WRONGJSON) != std::string::npos)) + { + alarmMgr.dbError(msg); + } } bson_free(bsonStr); diff --git a/test/functionalTest/cases/3347_createEntity_with_wrong_GeoJSON/createEntity_with_wrong_GeoJSON.test b/test/functionalTest/cases/3347_createEntity_with_wrong_GeoJSON/createEntity_with_wrong_GeoJSON.test index 2a6f4ab382..08af1386c5 100644 --- a/test/functionalTest/cases/3347_createEntity_with_wrong_GeoJSON/createEntity_with_wrong_GeoJSON.test +++ b/test/functionalTest/cases/3347_createEntity_with_wrong_GeoJSON/createEntity_with_wrong_GeoJSON.test @@ -34,6 +34,7 @@ brokerStart CB 0 # 02. GET /v2/entities/K # 03. Create entity with WRONG GeoJSON1 # 04. Create entity with WRONG GeoJSON2 +# 05. Ensure no DatabaseError alarm is raised # echo "01. Create entity with correct GeoJSON" @@ -102,6 +103,12 @@ orionCurl --url '/v2/entities' --payload "${payload}" echo echo +echo "05. Ensure no DatabaseError alarm is raised" +echo "===========================================" +cat /tmp/contextBroker.log | grep DatabaseError | wc -l +echo +echo + --REGEXPECT-- 01. Create entity with correct GeoJSON @@ -167,6 +174,11 @@ Content-Length: 52 } +05. Ensure no DatabaseError alarm is raised +=========================================== +0 + + --TEARDOWN-- brokerStop CB dbDrop CB