]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add test of rest response timeout
authorNick Porter <nick@portercomputing.co.uk>
Wed, 15 Feb 2023 10:41:13 +0000 (10:41 +0000)
committerNick Porter <nick@portercomputing.co.uk>
Wed, 15 Feb 2023 16:11:35 +0000 (16:11 +0000)
scripts/ci/openresty-setup.sh
scripts/ci/openresty/delay-api.lua [new file with mode: 0644]
src/tests/modules/rest/module.conf
src/tests/modules/rest/rest_xlat.unlang

index 6a73ac9df2daac6b919795adc77f961545040c88..44cc28b0613859916474fa87975dba7e9aae213a 100755 (executable)
@@ -83,6 +83,10 @@ http {
        location ~ ^/post(.*)$ {
            content_by_lua_file  ${APIDIR}/post-api.lua;
        }
+
+       location ~ ^/delay(.*)$ {
+           content_by_lua_file  ${APIDIR}/delay-api.lua;
+       }
     }
 
     server {
diff --git a/scripts/ci/openresty/delay-api.lua b/scripts/ci/openresty/delay-api.lua
new file mode 100644 (file)
index 0000000..aa4f61b
--- /dev/null
@@ -0,0 +1,6 @@
+-- Simple API represending a slow response for testing timeouts
+
+local t0 = os.clock()
+while os.clock() - t0 <= 2 do end
+
+ngx.say("Delayed response")
index b3d3580e3221aa5e8282c357a5c33a300032d257..08467681877048e50182c8237f41f1a405bef7bd 100644 (file)
@@ -23,6 +23,7 @@ rest {
 
        xlat {
                tls = ${..tls}
+               timeout = 0.5
        }
 
        authorize {
index 7629791ee6dcb46d38350fe3f89d749753579a17..f2aaaee870e09fc85abf290cb7665552371ecbb6 100644 (file)
@@ -133,4 +133,15 @@ if (!(&Tmp-String-2 == "{\"station\":\"aa:bb:cc:dd:ee:ff\"}\n" )) {
        test_fail
 }
 
+# Test against endpoint which will time out
+&Tmp-String-2 := "%(rest:http://%{Tmp-String-0}:%{Tmp-Integer-0}/delay)"
+
+if (&REST-HTTP-Status-Code) {
+       test_fail
+}
+
+if (!(&Module-Failure-Message == "curl request failed: Timeout was reached (28)")) {
+       test_fail
+}
+
 test_pass