]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add test of %rest() receiving a failure HTTP status code
authorNick Porter <nick@portercomputing.co.uk>
Wed, 30 Jul 2025 13:15:16 +0000 (14:15 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Wed, 30 Jul 2025 13:15:16 +0000 (14:15 +0100)
scripts/ci/openresty-setup.sh
scripts/ci/openresty/fail.lua [new file with mode: 0644]
src/tests/modules/rest/rest_xlat.unlang

index c97d81f4eb03933ef757b194267380eb595de917..c86783ddfe9c9cee014ae8ab4d0dfcc5603c37dc 100755 (executable)
@@ -102,6 +102,10 @@ http {
        location ~ ^/delay(.*)$ {
            content_by_lua_file  ${APIDIR}/delay-api.lua;
        }
+
+       location ~ ^/fail(.*)$ {
+           content_by_lua_file  ${APIDIR}/fail.lua;
+       }
     }
 
     server {
diff --git a/scripts/ci/openresty/fail.lua b/scripts/ci/openresty/fail.lua
new file mode 100644 (file)
index 0000000..76a5025
--- /dev/null
@@ -0,0 +1,5 @@
+-- API which will return code 400 with a JSON formatted error message
+
+ngx.status = ngx.HTTP_BAD_REQUEST
+ngx.say('{"error": "Invalid request"}')
+return ngx.exit(ngx.HTTP_BAD_REQUEST)
index e96b7689c51821892f2063a0ef6d734a3b06350a..ca452b05028142c2c01d603de5952e4bab1e8a2d 100644 (file)
@@ -212,4 +212,25 @@ if (!(Module-Failure-Message == "curl request failed: Timeout was reached (28)")
        test_fail
 }
 
+# Call an endpoint which will return a "failure" status code
+result_string := %rest('GET', "http://%{server_host}:%uri.safe(%{server_port})/fail")
+
+if (REST-HTTP-Status-Code != 400) {
+       test_fail
+}
+
+# The output should not be returned
+if (result_string) {
+       test_fail
+}
+
+# Server output will be in REST-HTTP-Body (this endpoint returns JSON)
+map json REST-HTTP-Body {
+       test_string := '$.error'
+}
+
+if (test_string != 'Invalid request') {
+       test_fail
+}
+
 test_pass