Skip to content

Commit

Permalink
Merge pull request #542 from FIWARE/hardening/avoid-apiv2-regs-for-ng…
Browse files Browse the repository at this point in the history
…sild-ops

hardening/avoid-apiv2-regs-for-ngsild-ops
  • Loading branch information
kzangeli authored Sep 29, 2020
2 parents c685877 + 77f9a06 commit c194f18
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 28 deletions.
25 changes: 14 additions & 11 deletions src/lib/mongoBackend/MongoCommonUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3428,6 +3428,9 @@ static void updateEntity
{
// The entity wasn't actually modified, so we don't need to update it and we can continue with the next one

if (orionldState.apiVersion == NGSI_LD_V1)
return;

//
// FIXME P8: the same three statements are at the end of the while loop. Refactor the code to have this
// in only one place
Expand Down Expand Up @@ -3615,18 +3618,15 @@ static void updateEntity


/* To finish with this entity processing, search for CPrs in not found attributes and
* add the corresponding ContextElementResponse to the global response */
if ((action == ActionTypeUpdate) || (action == ActionTypeReplace))
{
* add the corresponding ContextElementResponse to the global response
*/
if ((orionldState.apiVersion != NGSI_LD_V1) && ((action == ActionTypeUpdate) || (action == ActionTypeReplace)))
searchContextProviders(tenant, servicePathV, *enP, ceP->contextAttributeVector, cerP);
}

// StatusCode may be set already (if so, we keep the existing value)

if (cerP->statusCode.code == SccNone)
{
cerP->statusCode.fill(SccOk);
}

responseP->contextElementResponseVector.push_back(cerP);
}
Expand Down Expand Up @@ -3947,15 +3947,18 @@ void processContextElement

if ((action == ActionTypeUpdate) || (action == ActionTypeReplace))
{
/* In the case of UPDATE or REPLACE we look for context providers */
searchContextProviders(tenant, servicePathV, *enP, ceP->contextAttributeVector, cerP);
cerP->statusCode.fill(SccOk);
responseP->contextElementResponseVector.push_back(cerP);
if (orionldState.apiVersion != NGSI_LD_V1)
{
/* In the case of UPDATE or REPLACE we look for context providers */
searchContextProviders(tenant, servicePathV, *enP, ceP->contextAttributeVector, cerP);
cerP->statusCode.fill(SccOk);
responseP->contextElementResponseVector.push_back(cerP);
}

//
// If no context providers found, then the UPDATE was simply for a non-found entity and an error should be returned
//
if (forwardsPending(responseP) == false)
if ((orionldState.apiVersion == NGSI_LD_V1) || (forwardsPending(responseP) == false))
{
cerP->statusCode.fill(SccContextElementNotFound);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ MongoDB server version: REGEX(.*)
},
"https://fiware=github=io/tutorials=Step-by-Step/schema/statusOfWork" : {
"type" : "Property",
"value" : "https://fiware.github.io/tutorials.Step-by-Step/schema/completed"
"value" : "completed"
}
},
"mdNames" : [
Expand Down Expand Up @@ -263,7 +263,7 @@ bye
05. Get the entity and see the five attributes
==============================================
HTTP/1.1 200 OK
Content-Length: 1108
Content-Length: 1053
Content-Type: application/json
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"
Date: REGEX(.*)
Expand Down Expand Up @@ -298,7 +298,7 @@ Date: REGEX(.*)
},
"https://fiware.github.io/tutorials.Step-by-Step/schema/statusOfWork": {
"type": "Property",
"value": "https://fiware.github.io/tutorials.Step-by-Step/schema/completed"
"value": "completed"
}
},
"https://fiware.github.io/tutorials.Step-by-Step/schema/stocks": {
Expand Down
10 changes: 5 additions & 5 deletions test/functionalTest/cases/0000_ngsild/ngsild_issue_0364.test
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ MongoDB server REGEX(.*)
"type" : "Property",
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"value" : "https://uri.fiware.org/ns/data-models#commercial",
"value" : "commercial",
"mdNames" : [ ]
},
"https://schema=org/address" : {
Expand Down Expand Up @@ -332,10 +332,10 @@ MongoDB server version: REGEX(.*)
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"value" : [
"https://uri.fiware.org/ns/data-models#commercial",
"https://uri.fiware.org/ns/data-models#office",
"https://uri.fiware.org/ns/data-models#industrial",
"https://uri.fiware.org/ns/data-models#retail"
"commercial",
"office",
"industrial",
"retail"
],
"mdNames" : [ ]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Date: REGEX(.*)
04. GET the entity, make sure all metadata of 'locatedIn' are present
=====================================================================
HTTP/1.1 200 OK
Content-Length: 1108
Content-Length: 1053
Content-Type: application/json
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"
Date: REGEX(.*)
Expand Down Expand Up @@ -262,7 +262,7 @@ Date: REGEX(.*)
},
"https://fiware.github.io/tutorials.Step-by-Step/schema/statusOfWork": {
"type": "Property",
"value": "https://fiware.github.io/tutorials.Step-by-Step/schema/completed"
"value": "completed"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ MongoDB server version: REGEX(.*)
"type" : "Property",
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"value" : "https://uri.fiware.org/ns/data-models#commercial",
"value" : "commercial",
"mdNames" : [ ]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ MongoDB server version: REGEX(.*)
"type" : "Property",
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"value" : "https://uri.fiware.org/ns/data-models#commercial",
"value" : "commercial",
"mdNames" : [ ]
},
"https://schema=org/address" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ MongoDB server version: REGEX(.*)
"type" : "Property",
"creDate" : REGEX(.*),
"modDate" : REGEX(.*),
"value" : "https://uri.fiware.org/ns/data-models#industrial",
"value" : "industrial",
"mdNames" : [ ]
}
},
Expand Down Expand Up @@ -135,15 +135,15 @@ Date: REGEX(.*)
04. GET E2 and see the long value of 'category', as the data-model context is NOT used
======================================================================================
HTTP/1.1 200 OK
Content-Length: 183
Content-Length: 145
Content-Type: application/json
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"
Date: REGEX(.*)

{
"https://uri.fiware.org/ns/data-models#category": {
"type": "Property",
"value": "https://uri.fiware.org/ns/data-models#industrial"
"value": "industrial"
},
"id": "urn:ngsi-ld:test:value-expansion:E2",
"type": "T"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,15 @@ Date: REGEX(.*)
08. GET E2 and see the expanded value of 'category'
===================================================
HTTP/1.1 200 OK
Content-Length: 183
Content-Length: 145
Content-Type: application/json
Link: <https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"
Date: REGEX(.*)

{
"https://uri.fiware.org/ns/data-models#category": {
"type": "Property",
"value": "https://uri.fiware.org/ns/data-models#industrial"
"value": "industrial"
},
"id": "urn:ngsi-ld:test:value-expansion:E2",
"type": "T"
Expand Down

0 comments on commit c194f18

Please sign in to comment.