Skip to content

Commit

Permalink
Merge pull request #4582 from telefonicaid/hardening/no-db-alarm-with…
Browse files Browse the repository at this point in the history
…-wrong-geojson

FIX do not raise DB alarm in case of wrong GeoJSON
  • Loading branch information
danielvillalbamota authored Jun 11, 2024
2 parents 0c9a6b9 + bf84f69 commit 137e456
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Fix: wrong date values should not allowed in subscription's expires field (#4541)
- 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
1 change: 1 addition & 0 deletions src/lib/mongoBackend/MongoCommonUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
#include "mongoDriver/safeMongo.h"
#include "mongoDriver/BSONObjBuilder.h"
#include "mongoDriver/BSONArrayBuilder.h"
#include "mongoDriver/DBErrors.h"


/* ****************************************************************************
Expand Down
3 changes: 0 additions & 3 deletions src/lib/mongoBackend/MongoCommonUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"



/* ****************************************************************************
Expand Down
1 change: 1 addition & 0 deletions src/lib/mongoDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ SET (HEADERS
OID.h
DBConnection.h
DBCursor.h
DBErrors.h
safeMongo.h
connectionOperations.h
mongoConnectionPool.h
Expand Down
34 changes: 34 additions & 0 deletions src/lib/mongoDriver/DBErrors.h
Original file line number Diff line number Diff line change
@@ -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_
8 changes: 7 additions & 1 deletion src/lib/mongoDriver/connectionOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "mongoDriver/BSONArrayBuilder.h"
#include "mongoDriver/mongoConnectionPool.h"
#include "mongoDriver/safeMongo.h"
#include "mongoDriver/DBErrors.h"



Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -167,6 +174,11 @@ Content-Length: 52
}


05. Ensure no DatabaseError alarm is raised
===========================================
0


--TEARDOWN--
brokerStop CB
dbDrop CB

0 comments on commit 137e456

Please sign in to comment.