-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug/2763 bug fix not refactor #2821
Changes from all commits
b582c86
493d873
4adda71
8fa9c69
159bd5f
f422157
a93291f
f1ac202
b9eb33a
a2e549b
a6faae9
f0be43b
bc960d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
#include "jsonParseV2/jsonParseTypeNames.h" | ||
#include "jsonParseV2/parseEntity.h" | ||
#include "jsonParseV2/parseContextAttribute.h" | ||
#include "parse/forbiddenChars.h" | ||
#include "alarmMgr/alarmMgr.h" | ||
|
||
using namespace rapidjson; | ||
|
@@ -139,34 +140,68 @@ std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL) | |
{ | ||
if (type != "String") | ||
{ | ||
alarmMgr.badInput(clientIp, "invalid JSON type for entity id"); | ||
ciP->httpStatusCode = SccBadRequest;; | ||
OrionError oe(SccBadRequest, "invalid JSON type for entity id", "BadRequest"); | ||
alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTID); | ||
ciP->httpStatusCode = SccBadRequest; | ||
OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTID, "BadRequest"); | ||
|
||
return oe.toJson(); | ||
} | ||
|
||
eP->id = iter->value.GetString(); | ||
|
||
if (forbiddenIdChars(ciP->apiVersion, eP->id.c_str(), "")) | ||
{ | ||
alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID); | ||
ciP->httpStatusCode = SccBadRequest; | ||
OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID, "BadRequest"); | ||
|
||
return oe.toJson(); | ||
} | ||
} | ||
else // "id" is present in payload for /v2/entities/<eid> - not a valid payload | ||
{ | ||
alarmMgr.badInput(clientIp, "'id' is not a valid attribute"); | ||
ciP->httpStatusCode = SccBadRequest;; | ||
OrionError oe(SccBadRequest, "invalid input, 'id' as attribute", "BadRequest"); | ||
const char* errorText = "invalid input, 'id' as attribute"; | ||
|
||
alarmMgr.badInput(clientIp, errorText); | ||
ciP->httpStatusCode = SccBadRequest; | ||
OrionError oe(SccBadRequest, errorText, "BadRequest"); | ||
|
||
return oe.toJson(); | ||
} | ||
} | ||
else if (name == "type") | ||
{ | ||
if (type != "String") | ||
{ | ||
alarmMgr.badInput(clientIp, "invalid JSON type for entity type"); | ||
alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTTYPE); | ||
ciP->httpStatusCode = SccBadRequest; | ||
OrionError oe(SccBadRequest, "invalid JSON type for entity type", "BadRequest"); | ||
OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTTYPE, "BadRequest"); | ||
|
||
return oe.toJson(); | ||
} | ||
|
||
eP->type = iter->value.GetString(); | ||
eP->typeGiven = true; | ||
|
||
if (eP->type.empty()) | ||
{ | ||
const char* errorText = "entity type length: 0, min length supported: 1"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move to errorMessages.h (in fact, I think the text is already there in a previous define) |
||
|
||
alarmMgr.badInput(clientIp, errorText); | ||
ciP->httpStatusCode = SccBadRequest; | ||
OrionError oe(SccBadRequest, errorText, "BadRequest"); | ||
|
||
return oe.toJson(); | ||
} | ||
|
||
if (forbiddenIdChars(ciP->apiVersion, eP->type.c_str(), "")) | ||
{ | ||
alarmMgr.badInput(clientIp, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE); | ||
ciP->httpStatusCode = SccBadRequest; | ||
OrionError oe(SccBadRequest, ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE, "BadRequest"); | ||
|
||
return oe.toJson(); | ||
} | ||
} | ||
else // attribute | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
*/ | ||
#include "rapidjson/document.h" | ||
|
||
#include "common/errorMessages.h" | ||
#include "rest/ConnectionInfo.h" | ||
#include "ngsi/ParseData.h" | ||
#include "ngsi/Request.h" | ||
|
@@ -68,27 +69,27 @@ std::string parseEntityObject(ConnectionInfo* ciP, Value::ConstValueIterator val | |
{ | ||
if (type != "String") | ||
{ | ||
return "invalid JSON type for entity id"; | ||
return ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTID; | ||
} | ||
|
||
eP->id = iter->value.GetString(); | ||
|
||
if (forbiddenChars(eP->id.c_str(), "")) | ||
if (forbiddenIdChars(ciP->apiVersion, eP->id.c_str(), "")) | ||
{ | ||
return "Invalid characters in entity id"; | ||
return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTID; | ||
} | ||
} | ||
else if (name == "idPattern") | ||
{ | ||
if (type != "String") | ||
{ | ||
return "invalid JSON type for entity idPattern"; | ||
return ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTIDPATTERN; | ||
} | ||
|
||
regex_t re; | ||
if (regcomp(&re, iter->value.GetString(), REG_EXTENDED) != 0) | ||
{ | ||
return "invalid regex for entity id pattern"; | ||
return ERROR_DESC_BAD_REQUEST_INVALID_REGEX_ENTIDPATTERN; | ||
} | ||
regfree(&re); // If regcomp fails it frees up itself (see glibc sources for details) | ||
|
||
|
@@ -99,28 +100,33 @@ std::string parseEntityObject(ConnectionInfo* ciP, Value::ConstValueIterator val | |
{ | ||
if (type != "String") | ||
{ | ||
return "invalid JSON type for entity type"; | ||
return ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTTYPE; | ||
} | ||
|
||
eP->type = iter->value.GetString(); | ||
eP->typeGiven = true; | ||
|
||
if (forbiddenChars(eP->type.c_str(), "")) | ||
if (eP->type.empty()) | ||
{ | ||
return "Invalid characters in entity type"; | ||
return "entity type length: 0, min length supported: 1"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move to errorMessages.h |
||
} | ||
|
||
if (forbiddenIdChars(ciP->apiVersion, eP->type.c_str(), "")) | ||
{ | ||
return ERROR_DESC_BAD_REQUEST_INVALID_CHAR_ENTTYPE; | ||
} | ||
} | ||
else if (name == "typePattern") | ||
{ | ||
if (type != "String") | ||
{ | ||
return "invalid JSON type for entity typePattern"; | ||
return ERROR_DESC_BAD_REQUEST_INVALID_JTYPE_ENTTYPEPATTERN; | ||
} | ||
|
||
regex_t re; | ||
if (regcomp(&re, iter->value.GetString(), REG_EXTENDED) != 0) | ||
{ | ||
return "invalid regex for entity type pattern"; | ||
return ERROR_DESC_BAD_REQUEST_INVALID_REGEX_ENTTYPEPATTERN; | ||
} | ||
regfree(&re); // If regcomp fails it frees up itself (see glibc sources for details) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -362,7 +362,7 @@ static std::string parseEntitiesVector(ConnectionInfo* ciP, std::vector<EntID>* | |
regex_t re; | ||
if (regcomp(&re, idPattern.c_str(), REG_EXTENDED) != 0) | ||
{ | ||
return badInput(ciP, "Invalid regex for entity id pattern"); | ||
return badInput(ciP, ERROR_DESC_BAD_REQUEST_INVALID_REGEX_ENTIDPATTERN); | ||
} | ||
regfree(&re); // If regcomp fails it frees up itself | ||
} | ||
|
@@ -384,6 +384,10 @@ static std::string parseEntitiesVector(ConnectionInfo* ciP, std::vector<EntID>* | |
{ | ||
return badInput(ciP, "max type length exceeded"); | ||
} | ||
if (typeOpt.value.empty()) | ||
{ | ||
return badInput(ciP, "entity type length: 0, min length supported: 1"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move to errorMessages.h |
||
} | ||
type = typeOpt.value; | ||
} | ||
} | ||
|
@@ -407,7 +411,7 @@ static std::string parseEntitiesVector(ConnectionInfo* ciP, std::vector<EntID>* | |
regex_t re; | ||
if (regcomp(&re, typePattern.c_str(), REG_EXTENDED) != 0) | ||
{ | ||
return badInput(ciP, "Invalid regex for entity id pattern"); | ||
return badInput(ciP, ERROR_DESC_BAD_REQUEST_INVALID_REGEX_ENTTYPEPATTERN); | ||
} | ||
regfree(&re); // If regcomp fails it frees up itself | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,7 +109,7 @@ std::string OrionError::smartRender(ApiVersion apiVersion) | |
*/ | ||
std::string OrionError::setStatusCodeAndSmartRender(ApiVersion apiVersion, HttpStatusCode* scP) | ||
{ | ||
if (apiVersion == V2) | ||
if ((apiVersion == V2) || (apiVersion == ADMIN_API)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great to see that the addition has not broken anything... setStatusCodeAndSmartRender() modifyication were hard in the past (at least to me...) NTC There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I am not so sure. Seeing a few really strange errors in functests ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Errors under control again, fixed in f422157 (this line is intact, the problem was elsewhere) |
||
{ | ||
*scP = code; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to errorMessages.h