From 9de29daeef864945cb6c943b2a3215f0d2d38492 Mon Sep 17 00:00:00 2001 From: Ken Zangelin Date: Wed, 28 Feb 2024 20:52:17 +0100 Subject: [PATCH 1/5] Fixed a bug about deleting/reloading the core context --- src/lib/orionld/mhd/mhdConnectionInit.cpp | 9 +++- .../ngsild_context-delete-with-url.test | 46 +++++++++++++++++-- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/lib/orionld/mhd/mhdConnectionInit.cpp b/src/lib/orionld/mhd/mhdConnectionInit.cpp index 993673b2e0..1d1474b41d 100644 --- a/src/lib/orionld/mhd/mhdConnectionInit.cpp +++ b/src/lib/orionld/mhd/mhdConnectionInit.cpp @@ -907,8 +907,15 @@ MHD_Result orionldUriArgumentGet(void* cbDataP, MHD_ValueKind kind, const char* } else if (strcmp(key, "reload") == 0) { - orionldState.uriParams.reload = true; orionldState.uriParams.mask |= ORIONLD_URIPARAM_RELOAD; + + if (strcmp(value, "true") == 0) + orionldState.uriParams.reload = true; + else if (strcmp(value, "false") != 0) + { + orionldError(OrionldBadRequestData, "Invalid value for uri parameter /reload/ (not true nor false)", value, 400); + return MHD_YES; + } } else if (strcmp(key, "exist") == 0) { diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_context-delete-with-url.test b/test/functionalTest/cases/0000_ngsild/ngsild_context-delete-with-url.test index c82cb0d17a..d1f4ffa231 100644 --- a/test/functionalTest/cases/0000_ngsild/ngsild_context-delete-with-url.test +++ b/test/functionalTest/cases/0000_ngsild/ngsild_context-delete-with-url.test @@ -34,7 +34,9 @@ orionldStart CB # 01. Create an entity with a context, only to put the context in the context cache # 02. DELETE the context from the cache with the URL # 03. Attempt to GET the context - see 404 Not Found -# 04. Attempt to DELETE the Core Context +# 04. Attempt to DELETE the Core Context without ?reload - see error +# 05. Attempt to DELETE the Core Context, with ?reload=false - see error +# 06. DELETE the Core Context, with ?reload=true - OK # echo "01. Create an entity with a context, only to put the context in the context cache" @@ -66,13 +68,26 @@ echo echo -echo "04. Attempt to DELETE the Core Context" -echo "======================================" +echo "04. Attempt to DELETE the Core Context without ?reload - see error" +echo "==================================================================" orionCurl --url '/ngsi-ld/v1/jsonldContexts/https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld' -X DELETE echo echo +echo "05. Attempt to DELETE the Core Context, with ?reload=false - see error" +echo "======================================================================" +orionCurl --url '/ngsi-ld/v1/jsonldContexts/https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld?reload=false' -X DELETE +echo +echo + +echo "06. DELETE the Core Context, with ?reload=true - OK" +echo "===================================================" +orionCurl --url '/ngsi-ld/v1/jsonldContexts/https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld?reload=true' -X DELETE +echo +echo + + --REGEXPECT-- 01. Create an entity with a context, only to put the context in the context cache ================================================================================= @@ -104,8 +119,22 @@ Date: REGEX(.*) } -04. Attempt to DELETE the Core Context -====================================== +04. Attempt to DELETE the Core Context without ?reload - see error +================================================================== +HTTP/1.1 400 Bad Request +Content-Length: 208 +Content-Type: application/json +Date: REGEX(.*) + +{ + "detail": "The Core Context can be reloaded, please use the URI param '?reload=true' for that", + "title": "The NGSI-LD Core Context cannot be deleted", + "type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData" +} + + +05. Attempt to DELETE the Core Context, with ?reload=false - see error +====================================================================== HTTP/1.1 400 Bad Request Content-Length: 208 Content-Type: application/json @@ -118,6 +147,13 @@ Date: REGEX(.*) } +06. DELETE the Core Context, with ?reload=true - OK +=================================================== +HTTP/1.1 204 No Content +Date: REGEX(.*) + + + --TEARDOWN-- brokerStop CB dbDrop CB From 41efc088c4741f5ff5737bac68541ca9b397f9d6 Mon Sep 17 00:00:00 2001 From: Ken Zangelin Date: Thu, 29 Feb 2024 08:25:35 +0100 Subject: [PATCH 2/5] More traces in functest suite to see what's happening with ngsild_version.test --- test/functionalTest/testHarness.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/functionalTest/testHarness.sh b/test/functionalTest/testHarness.sh index 98c3fdd368..96ef8a4ea7 100755 --- a/test/functionalTest/testHarness.sh +++ b/test/functionalTest/testHarness.sh @@ -1007,7 +1007,8 @@ function partExecute() logMsg "------------------------------------------------------" cat $dirname/$filename.$what.stderr >> $LOG_FILE logMsg "------------------------------------------------------" - echo -n "(ERROR 7 - $what: output on stderr) " + echo -n "(lines in stderr: $linesInStderr) " + echo "(ERROR 7 - $what: output on stderr) " fi partExecuteResult=7 From a2b27d7630a0c036674a546b178fb7baff5b90d0 Mon Sep 17 00:00:00 2001 From: Ken Zangelin Date: Thu, 29 Feb 2024 10:12:00 +0100 Subject: [PATCH 3/5] More traces in functest suite to see what's happening with ngsild_version.test --- test/functionalTest/testHarness.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/functionalTest/testHarness.sh b/test/functionalTest/testHarness.sh index 96ef8a4ea7..47a3760e3c 100755 --- a/test/functionalTest/testHarness.sh +++ b/test/functionalTest/testHarness.sh @@ -996,6 +996,11 @@ function partExecute() # # Check that stderr is empty # + logMsg "==============================================" + logMsg "wc -l $dirname/$filename.$what.stderr:" + wc -l $dirname/$filename.$what.stderr >> $LOG_FILE + logMsg "==============================================" + linesInStderr=$(wc -l $dirname/$filename.$what.stderr | awk '{ print $1}' 2> /dev/null) if [ "$linesInStderr" != "" ] && [ "$linesInStderr" != "0" ] then @@ -1004,9 +1009,9 @@ function partExecute() exitFunction 7 "$what: output on stderr" $path "($path): $what produced output on stderr" $dirname/$filename.$what.stderr $dirname/$filename.$what.stdout "$forcedDie" else logMsg "$what: output on stderr" - logMsg "------------------------------------------------------" + logMsg "******************************************************" cat $dirname/$filename.$what.stderr >> $LOG_FILE - logMsg "------------------------------------------------------" + logMsg "******************************************************" echo -n "(lines in stderr: $linesInStderr) " echo "(ERROR 7 - $what: output on stderr) " fi From 49001e15427142f2869af776471edb606fbc8f6d Mon Sep 17 00:00:00 2001 From: Ken Zangelin Date: Thu, 29 Feb 2024 11:22:17 +0100 Subject: [PATCH 4/5] More traces in functest suite to see what's happening with ngsild_version.test --- test/functionalTest/testHarness.sh | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/test/functionalTest/testHarness.sh b/test/functionalTest/testHarness.sh index 47a3760e3c..0fdecab7dd 100755 --- a/test/functionalTest/testHarness.sh +++ b/test/functionalTest/testHarness.sh @@ -322,10 +322,10 @@ function exitFunction() echo echo "Error $exitCode: $errorText" echo - echo "$stderrFile:" - echo "-------------------------------------------------" + echo "stderrFile: $stderrFile:" + echo "=================================================" cat $stderrFile - echo "-------------------------------------------------" + echo "=================================================" echo echo @@ -772,7 +772,7 @@ then cd $dirOrFile elif [ ! -d "$dir" ] then - exitFunction 1 "$dir is not a directory" "HARNESS" "$dir" "" "" DIE + exitFunction 1 "$dir is not a directory" "HARNESS" "$dir" " " " " DIE " " else cd $dir fi @@ -887,7 +887,7 @@ function fileCreation() NAME=$(sed -n '/--NAME--/,/^--/p' $path | grep -v "^--") if [ "$NAME" == "" ] then - exitFunction 2 "--NAME-- part is missing" "$path" "($path)" "" "" DIE + exitFunction 2 "--NAME-- part is missing" "$path" "($path)" "diffFile" "stdoutFile" DIE "stderrFile" exit 2 # Just in case fi @@ -900,7 +900,7 @@ function fileCreation() logMsg "Creating $TEST_SHELL_INIT at $PWD" sed -n '/--SHELL-INIT--/,/^--/p' $path | grep -v "^--" > $TEST_SHELL_INIT else - exitFunction 3 "--SHELL-INIT-- part is missing" $path "($path)" "" "" DIE + exitFunction 3 "--SHELL-INIT-- part is missing" $path "($path)" "diffFile" "stdoutFile" DIE "stderrFile" fi # @@ -912,7 +912,7 @@ function fileCreation() logMsg "Creating $TEST_SHELL at $PWD" sed -n '/--SHELL--/,/^--/p' $path | grep -v "^--" > $TEST_SHELL else - exitFunction 4 "--SHELL-- part is missing" $path "($path)" "" "" DIE + exitFunction 4 "--SHELL-- part is missing" $path "($path)" "diffFile" "stdoutFile" DIE "stderrFile" fi # @@ -924,7 +924,7 @@ function fileCreation() logMsg "Creating $TEST_REGEXPECT at $PWD" sed -n '/--REGEXPECT--/,/^--/p' $path | grep -v "^--" > $TEST_REGEXPECT else - exitFunction 5 "--REGEXPECT-- part is missing" $path "($path)" "" "" DIE + exitFunction 5 "--REGEXPECT-- part is missing" $path "($path)" "diffFile" "stdoutFile" DIE "stderrFile" fi # @@ -936,7 +936,7 @@ function fileCreation() logMsg "Creating $TEST_TEARDOWN at $PWD" sed -n '/--TEARDOWN--/,/^--/p' $path | grep -v "^--" > $TEST_TEARDOWN else - exitFunction 6 "--TEARDOWN-- part is missing" $path "($path)" "" "" DIE + exitFunction 6 "--TEARDOWN-- part is missing" $path "($path)" "diffFile" "stdoutFile" DIE "stderrFile" fi } @@ -1006,7 +1006,7 @@ function partExecute() then if [ $__tryNo == $MAX_TRIES ] then - exitFunction 7 "$what: output on stderr" $path "($path): $what produced output on stderr" $dirname/$filename.$what.stderr $dirname/$filename.$what.stdout "$forcedDie" + exitFunction 7 "$what: output on stderr" $path "($path): $what produced output on stderr" "no diff" "$dirname/$filename.$what.stdout" "$forcedDie" "$dirname/$filename.$what.stderr" else logMsg "$what: output on stderr" logMsg "******************************************************" @@ -1029,7 +1029,7 @@ function partExecute() logMsg "$what: exit code is $eCode - retry? (try: $__tryNo, MAX_TRIES: $MAX_TRIES)" if [ $__tryNo == $MAX_TRIES ] then - exitFunction 8 $path "$what exited with code $eCode" "($path)" $dirname/$filename.$what.stderr $dirname/$filename.$what.stdout "$forcedDie" + exitFunction 8 "$what exited with code $eCode" "$path" "non-zero exit code" "no diff" "$dirname/$filename.$what.stdout" "$forcedDie" "$dirname/$filename.$what.stderr" else echo -n "(ERROR 8 - $what: exited with code $eCode) " fi @@ -1081,7 +1081,7 @@ function partExecute() logMsg "$what $dirname/$filename: eCode=$eCode" if [ $__tryNo == $MAX_TRIES ] then - exitFunction 9 "output not as expected" $path "($path) output not as expected" $dirname/$filename.diff $dirname/$filename.out "Survive" "$dirname/$filename.$what.stderr" + exitFunction 9 "output not as expected" $path "($path) output not as expected" "$dirname/$filename.diff" "$dirname/$filename.out" "Survive" "$dirname/$filename.$what.stderr" else echo -n "(ERROR 9 - .out and .regexpect differ) " fi @@ -1184,7 +1184,7 @@ function runTest() linesInStderr=$(wc -l $dirname/$filename.shellInit.stderr | awk '{ print $1}' 2> /dev/null) if [ "$linesInStderr" != "" ] && [ "$linesInStderr" != "0" ] then - exitFunction 10 "SHELL-INIT produced output on stderr" $path "($path)" $dirname/$filename.shellInit.stderr $dirname/$filename.shellInit.stdout "Continue" + exitFunction 10 "SHELL-INIT produced output on stderr" $path "stderr not empty" "$dirname/$filename.shellInit.stdout" "Continue" "$dirname/$filename.shellInit.stderr" runTestStatus="shell-init-error" return fi @@ -1222,14 +1222,14 @@ function runTest() if [ "$linesInStderr" != "" ] && [ "$linesInStderr" != "0" ] then - exitFunction 20 "SHELL-INIT II produced output on stderr" $path "($path)" $dirname/$filename.shellInit.stderr $dirname/$filename.shellInit.stdout "Continue" + exitFunction 20 "SHELL-INIT II produced output on stderr" $path "output on stderr" "$dirname/$filename.shellInit.stdout" "Continue" "$dirname/$filename.shellInit.stderr" runTestStatus="shell-init-output-on-stderr" return fi if [ "$eCode" != "0" ] then - exitFunction 11 "SHELL-INIT exited with code $eCode" $path "($path)" $dirname/$filename.shellInit.stderr $dirname/$filename.shellInit.stdout "Continue" + exitFunction 11 "SHELL-INIT exited with code $eCode" $path "output on stderr" "$dirname/$filename.shellInit.stdout" "Continue" "$dirname/$filename.shellInit.stderr" runTestStatus="shell-init-exited-with-"$eCode return fi From e1704b9f916a11a862155662890fa7d6b43d402d Mon Sep 17 00:00:00 2001 From: Ken Zangelin Date: Thu, 29 Feb 2024 13:19:48 +0100 Subject: [PATCH 5/5] Redirecting garbage on stderr to /dev/null for ngsild_version.test --- test/functionalTest/cases/0000_ngsild/ngsild_version.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_version.test b/test/functionalTest/cases/0000_ngsild/ngsild_version.test index 6b539af530..ee66ba1da7 100644 --- a/test/functionalTest/cases/0000_ngsild/ngsild_version.test +++ b/test/functionalTest/cases/0000_ngsild/ngsild_version.test @@ -45,7 +45,7 @@ echo echo "02. Make sure the branch output from Step 01 is the same as current branch" echo "==========================================================================" branchAccordingToBroker=$(echo $_response | awk -F\"branch\" '{ print $2 }' | awk -F\" '{ print $2 }') -branchAccordingToGit=$(git branch | grep ^\* | awk '{ print $2 }') +branchAccordingToGit=$(git branch 2> /dev/null | grep ^\* | awk '{ print $2 }') if [ "$branchAccordingToBroker" != "$branchAccordingToGit" ] then echo "Branch According To Git: $branchAccordingToGit"