diff --git a/src/lib/orionld/context/orionldContextFromBuffer.cpp b/src/lib/orionld/context/orionldContextFromBuffer.cpp index a0b9885180..17014a8f86 100644 --- a/src/lib/orionld/context/orionldContextFromBuffer.cpp +++ b/src/lib/orionld/context/orionldContextFromBuffer.cpp @@ -67,7 +67,7 @@ OrionldContext* orionldContextFromBuffer(char* url, OrionldContextOrigin origin, KjNode* contextNodeP = kjLookup(tree, "@context"); if (contextNodeP == NULL) { - orionldError(OrionldBadRequestData, "Invalid context - @context field missing", url, 400); + orionldError(OrionldInvalidRequest, "Invalid context - @context field missing", url, 400); return NULL; } diff --git a/src/lib/orionld/serviceRoutines/orionldDeleteContext.cpp b/src/lib/orionld/serviceRoutines/orionldDeleteContext.cpp index 9c674ba4e9..131d503deb 100644 --- a/src/lib/orionld/serviceRoutines/orionldDeleteContext.cpp +++ b/src/lib/orionld/serviceRoutines/orionldDeleteContext.cpp @@ -59,7 +59,10 @@ bool orionldDeleteContext(void) if (orionldState.uriParams.reload == true) { - if (oldContextP->origin != OrionldContextDownloaded) + // + // Only contexts of type Cached (indirect download) can be reloaded + // + if (oldContextP->kind != OrionldContextCached) { orionldError(OrionldBadRequestData, "Wrong type of context", "only cached contexts are subject for reload", 400); return false; @@ -93,6 +96,7 @@ bool orionldDeleteContext(void) if (contextP == NULL) { orionldContextCacheInsert(oldContextP); + // orionldError(OrionldLdContextNotAvailable, "Unable to reload the @context", oldContextP->url, 504); return false; } diff --git a/src/lib/orionld/serviceRoutines/orionldGetContext.cpp b/src/lib/orionld/serviceRoutines/orionldGetContext.cpp index a50e525ae2..268c90e4de 100644 --- a/src/lib/orionld/serviceRoutines/orionldGetContext.cpp +++ b/src/lib/orionld/serviceRoutines/orionldGetContext.cpp @@ -55,6 +55,16 @@ bool orionldGetContext(void) return false; } + // + // Contexts of type Cached (indirect download) are not served. + // The broker is not a context server. + // See 5.13.4.4 of the NGSI-LD API Specification + // + if ((contextP->kind == OrionldContextCached) && (orionldState.uriParams.details == false)) + { + orionldError(OrionldOperationNotSupported, "Not serving cached JSON-LD @context", orionldState.wildcard[0], 422); + return false; + } if (orionldState.uriParams.details == true) orionldState.responseTree = orionldContextWithDetails(contextP); diff --git a/src/lib/orionld/serviceRoutines/orionldPostContexts.cpp b/src/lib/orionld/serviceRoutines/orionldPostContexts.cpp index 1a3984b5f8..b58f4381d6 100644 --- a/src/lib/orionld/serviceRoutines/orionldPostContexts.cpp +++ b/src/lib/orionld/serviceRoutines/orionldPostContexts.cpp @@ -71,7 +71,7 @@ bool orionldPostContexts(void) if (orionldState.payloadContextNode == NULL) { - orionldError(OrionldAlreadyExists, "Invalid @context", "@context field missing", 400); + orionldError(OrionldInvalidRequest, "Invalid @context", "@context field missing", 400); return false; } diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_context-delete-and-reload.test b/test/functionalTest/cases/0000_ngsild/ngsild_context-delete-and-reload.test index a2b3aadabf..b959526cdd 100644 --- a/test/functionalTest/cases/0000_ngsild/ngsild_context-delete-and-reload.test +++ b/test/functionalTest/cases/0000_ngsild/ngsild_context-delete-and-reload.test @@ -34,7 +34,8 @@ orionldStart CB # # 01. Create a context in the context server # 02. Create an entity using the context from step 01, just to get the context inside the context cache of the broker -# 03. GET the context (from step 01) from the broker +# 03. GET the context (from step 01) from the broker - without details - see 422 +# 03. GET the context (from step 01) from the broker - with details - see metadata of the context # 04. Update the context in the context server # 05. DELETE and RELOAD the context in the broker's context cache # 06. GET the context (from step 05) from the broker and make sure it's been updated @@ -72,13 +73,20 @@ echo echo -echo "03. GET the context (from step 01) from the broker" -echo "==================================================" +echo "03. GET the context (from step 01) from the broker - without details - see 422" +echo "==============================================================================" orionCurl --url '/ngsi-ld/v1/jsonldContexts/http://localhost:7080/jsonldContexts/testContext2' echo echo +echo "03. GET the context (from step 01) from the broker - with details - see metadata of the context" +echo "===============================================================================================" +orionCurl --url '/ngsi-ld/v1/jsonldContexts/http://localhost:7080/jsonldContexts/testContext2?details=true' +echo +echo + + echo "04. Update the context in the context server" echo "============================================" cServerCurl --url /jsonldContexts/testContext2 --verb DELETE @@ -103,7 +111,7 @@ echo echo "06. GET the context (from step 05) from the broker and make sure it's been updated" echo "==================================================================================" -orionCurl --url '/ngsi-ld/v1/jsonldContexts/http://localhost:7080/jsonldContexts/testContext2' +orionCurl --url '/ngsi-ld/v1/jsonldContexts/http://localhost:7080/jsonldContexts/testContext2?details=true' echo echo @@ -131,7 +139,7 @@ echo echo "10. GET the context from the broker and make sure it exists in the broker's context cache and is the same as in step 06" echo "=======================================================================================================================" -orionCurl --url '/ngsi-ld/v1/jsonldContexts/http://localhost:7080/jsonldContexts/testContext2' +orionCurl --url '/ngsi-ld/v1/jsonldContexts/http://localhost:7080/jsonldContexts/testContext2?details=true' echo echo @@ -156,18 +164,44 @@ Location: /ngsi-ld/v1/entities/urn:ngsi-ld:entities:E1 -03. GET the context (from step 01) from the broker -================================================== +03. GET the context (from step 01) from the broker - without details - see 422 +============================================================================== +HTTP/1.1 422 Unprocessable Content +Content-Length: 175 +Content-Type: application/json +Date: REGEX(.*) + +{ + "detail": "http://localhost:7080/jsonldContexts/testContext2", + "title": "Not serving cached JSON-LD @context", + "type": "https://uri.etsi.org/ngsi-ld/errors/OperationNotSupported" +} + + +03. GET the context (from step 01) from the broker - with details - see metadata of the context +=============================================================================================== HTTP/1.1 200 OK -Content-Length: 42 +Content-Length: 349 Content-Type: application/json Date: REGEX(.*) { - "@context": { - "p1": "urn:p1", - "p2": "urn:p2" - } + "URL": "http://localhost:7080/jsonldContexts/testContext2", + "createdAt": "202REGEX(.*)", + "extraInfo": { + "compactions": 0, + "expansions": 0, + "hash-table": { + "p1": "urn:p1", + "p2": "urn:p2" + }, + "origin": "Downloaded", + "type": "hash-table" + }, + "kind": "Cached", + "lastUsage": "202REGEX(.*)", + "localId": "REGEX(.*)", + "numberOfHits": 1 } @@ -196,15 +230,27 @@ Date: REGEX(.*) 06. GET the context (from step 05) from the broker and make sure it's been updated ================================================================================== HTTP/1.1 200 OK -Content-Length: 56 +Content-Length: 363 Content-Type: application/json Date: REGEX(.*) { - "@context": { - "p1": "urn:step04:p1", - "p2": "urn:step04:p2" - } + "URL": "http://localhost:7080/jsonldContexts/testContext2", + "createdAt": "202REGEX(.*)", + "extraInfo": { + "compactions": 0, + "expansions": 0, + "hash-table": { + "p1": "urn:step04:p1", + "p2": "urn:step04:p2" + }, + "origin": "Downloaded", + "type": "hash-table" + }, + "kind": "Cached", + "lastUsage": "202REGEX(.*)", + "localId": "REGEX(.*)", + "numberOfHits": 1 } @@ -242,15 +288,27 @@ Date: REGEX(.*) 10. GET the context from the broker and make sure it exists in the broker's context cache and is the same as in step 06 ======================================================================================================================= HTTP/1.1 200 OK -Content-Length: 56 +Content-Length: 363 Content-Type: application/json Date: REGEX(.*) { - "@context": { - "p1": "urn:step04:p1", - "p2": "urn:step04:p2" - } + "URL": "http://localhost:7080/jsonldContexts/testContext2", + "createdAt": "202REGEX(.*)", + "extraInfo": { + "compactions": 0, + "expansions": 0, + "hash-table": { + "p1": "urn:step04:p1", + "p2": "urn:step04:p2" + }, + "origin": "Downloaded", + "type": "hash-table" + }, + "kind": "Cached", + "lastUsage": "202REGEX(.*)", + "localId": "REGEX(.*)", + "numberOfHits": 1 }