Skip to content
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

FIX improve attribute and metadata invalid format dates for DateTime types in logs #4624

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix: improve attribute and metadata invalid format dates for DateTime types in logs (#4616)
24 changes: 15 additions & 9 deletions src/lib/jsonParseV2/parseContextAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ static std::string parseContextAttributeObject
const rapidjson::Value& start,
ContextAttribute* caP,
bool* compoundVector,
bool checkAttrSpecialTypes
bool checkAttrSpecialTypes,
std::string* extraForLog
)
{
// This is NGSIv2 parsing and in NGSIv2, no value means implicit null. Note that
Expand Down Expand Up @@ -229,7 +230,8 @@ static std::string parseContextAttributeObject

if (upOp->numberValue == -1)
{
return "date has invalid format";
*extraForLog = ": " + upOp->stringValue;
return "date has invalid format in attribute value";
}

// Probably reseting stringValue is not needed, but let's do it for cleanliness
Expand All @@ -238,7 +240,8 @@ static std::string parseContextAttributeObject
}
else
{
return "date has invalid format";
*extraForLog = ": must be string or object with max or min operator";
return "date has invalid format in attribute value";
}
}
else
Expand All @@ -247,7 +250,8 @@ static std::string parseContextAttributeObject

if (caP->numberValue == -1)
{
return "date has invalid format";
*extraForLog = ": " + caP->stringValue;
return "date has invalid format in attribute value";
}

// Probably reseting stringValue is not needed, but let's do it for cleanliness
Expand Down Expand Up @@ -383,7 +387,8 @@ std::string parseContextAttribute
// Attribute has a regular structure, in which 'value' is mandatory (except in v2)
if (iter->value.HasMember("value") || ciP->apiVersion == V2)
{
std::string r = parseContextAttributeObject(iter->value, caP, &compoundVector, checkAttrSpecialTypes);
std::string extraForLog = "";
std::string r = parseContextAttributeObject(iter->value, caP, &compoundVector, checkAttrSpecialTypes, &extraForLog);
if (r == "max deep reached")
{
alarmMgr.badInput(clientIp, "max deep reached", "found in ContextAttributeObject::Object");
Expand All @@ -392,7 +397,7 @@ std::string parseContextAttribute
}
else if (r != "OK") // other error cases get a general treatment
{
alarmMgr.badInput(clientIp, "JSON Parse Error in ContextAttribute::Object", r);
alarmMgr.badInput(clientIp, "JSON Parse Error in ContextAttribute::Object", r + extraForLog);
ciP->httpStatusCode = SccBadRequest;
return r;
}
Expand Down Expand Up @@ -455,13 +460,14 @@ std::string parseContextAttribute(ConnectionInfo* ciP, ContextAttribute* caP, bo
}

bool compoundVector = false;
std::string r = parseContextAttributeObject(document, caP, &compoundVector, checkAttrSpecialTypes);
std::string extraForLog = "";
std::string r = parseContextAttributeObject(document, caP, &compoundVector, checkAttrSpecialTypes, &extraForLog);

if (r == "max deep reached")
{
OrionError oe(SccBadRequest, ERROR_DESC_PARSE_MAX_JSON_NESTING, ERROR_PARSE);

alarmMgr.badInput(clientIp, "max deep reached", r);
alarmMgr.badInput(clientIp, "max deep reached", "found in ContextAttributeObject::Object");
ciP->httpStatusCode = SccBadRequest;

return oe.toJson();
Expand All @@ -470,7 +476,7 @@ std::string parseContextAttribute(ConnectionInfo* ciP, ContextAttribute* caP, bo
{
OrionError oe(SccBadRequest, r, ERROR_BAD_REQUEST);

alarmMgr.badInput(clientIp, "JSON Parse Error", r);
alarmMgr.badInput(clientIp, "JSON Parse Error", r + extraForLog);
ciP->httpStatusCode = SccBadRequest;

return oe.toJson();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/jsonParseV2/parseMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ static std::string parseMetadataObject(const rapidjson::Value& start, Metadata*

if (mdP->numberValue == -1)
{
alarmMgr.badInput(clientIp, "date has invalid format", mdP->stringValue);
return "date has invalid format";
alarmMgr.badInput(clientIp, "date has invalid format in metadata value", mdP->stringValue);
return "date has invalid format in metadata value";
}

// Probably reseting stringValue is not needed, but let's do it for cleanliness
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ HTTP/1.1 400 Bad Request
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 62
Content-Length: 81

{
"description": "date has invalid format",
"description": "date has invalid format in attribute value",
"error": "BadRequest"
}

Expand Down Expand Up @@ -188,10 +188,10 @@ HTTP/1.1 400 Bad Request
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 62
Content-Length: 81

{
"description": "date has invalid format",
"description": "date has invalid format in attribute value",
"error": "BadRequest"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ HTTP/1.1 400 Bad Request
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 62
Content-Length: 81

{
"description": "date has invalid format",
"description": "date has invalid format in attribute value",
"error": "BadRequest"
}

Expand Down Expand Up @@ -188,10 +188,10 @@ HTTP/1.1 400 Bad Request
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 62
Content-Length: 81

{
"description": "date has invalid format",
"description": "date has invalid format in attribute value",
"error": "BadRequest"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ HTTP/1.1 400 Bad Request
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 62
Content-Length: 81

{
"description": "date has invalid format",
"description": "date has invalid format in attribute value",
"error": "BadRequest"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ HTTP/1.1 400 Bad Request
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 62
Content-Length: 81

{
"description": "date has invalid format",
"description": "date has invalid format in attribute value",
"error": "BadRequest"
}

Expand All @@ -253,10 +253,10 @@ HTTP/1.1 400 Bad Request
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 62
Content-Length: 81

{
"description": "date has invalid format",
"description": "date has invalid format in attribute value",
"error": "BadRequest"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ HTTP/1.1 400 Bad Request
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 62
Content-Length: 80

{
"description": "date has invalid format",
"description": "date has invalid format in metadata value",
"error": "BadRequest"
}

Expand All @@ -309,10 +309,10 @@ HTTP/1.1 400 Bad Request
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 62
Content-Length: 80

{
"description": "date has invalid format",
"description": "date has invalid format in metadata value",
"error": "BadRequest"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ HTTP/1.1 400 Bad Request
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 62
Content-Length: 81

{
"description": "date has invalid format",
"description": "date has invalid format in attribute value",
"error": "BadRequest"
}

Expand All @@ -145,10 +145,10 @@ HTTP/1.1 400 Bad Request
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 62
Content-Length: 81

{
"description": "date has invalid format",
"description": "date has invalid format in attribute value",
"error": "BadRequest"
}

Expand All @@ -159,10 +159,10 @@ HTTP/1.1 400 Bad Request
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 62
Content-Length: 81

{
"description": "date has invalid format",
"description": "date has invalid format in attribute value",
"error": "BadRequest"
}

Expand All @@ -173,10 +173,10 @@ HTTP/1.1 400 Bad Request
Date: REGEX(.*)
Fiware-Correlator: REGEX([0-9a-f\-]{36})
Content-Type: application/json
Content-Length: 62
Content-Length: 81

{
"description": "date has invalid format",
"description": "date has invalid format in attribute value",
"error": "BadRequest"
}

Expand Down
Loading
Loading