diff options
author | Gabriel Fontes <hi@m7.rs> | 2023-12-01 15:42:46 -0300 |
---|---|---|
committer | Gabriel Fontes <hi@m7.rs> | 2023-12-11 11:09:02 -0300 |
commit | a3c60d2ddc9f70dca3fa5c5926aefc9a74bd2519 (patch) | |
tree | 3e417cec2c0236f2c79e7e43069e92738bccb15f /nixos/tests | |
parent | 72061433dd3711fe9a06b177323e4ffd4a81847a (diff) | |
download | nixlib-a3c60d2ddc9f70dca3fa5c5926aefc9a74bd2519.tar nixlib-a3c60d2ddc9f70dca3fa5c5926aefc9a74bd2519.tar.gz nixlib-a3c60d2ddc9f70dca3fa5c5926aefc9a74bd2519.tar.bz2 nixlib-a3c60d2ddc9f70dca3fa5c5926aefc9a74bd2519.tar.lz nixlib-a3c60d2ddc9f70dca3fa5c5926aefc9a74bd2519.tar.xz nixlib-a3c60d2ddc9f70dca3fa5c5926aefc9a74bd2519.tar.zst nixlib-a3c60d2ddc9f70dca3fa5c5926aefc9a74bd2519.zip |
nixos/nginx: make redirect status code configurable
Add an option to configure which code globalRedirect and forceSSL use. It previously was always 301 with no easy way to override.
Diffstat (limited to 'nixos/tests')
-rw-r--r-- | nixos/tests/all-tests.nix | 1 | ||||
-rw-r--r-- | nixos/tests/nginx-redirectcode.nix | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index e0572e3bed9c..9f3bf284da02 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -583,6 +583,7 @@ in { nginx-njs = handleTest ./nginx-njs.nix {}; nginx-proxyprotocol = handleTest ./nginx-proxyprotocol {}; nginx-pubhtml = handleTest ./nginx-pubhtml.nix {}; + nginx-redirectcode = handleTest ./nginx-redirectcode.nix {}; nginx-sso = handleTest ./nginx-sso.nix {}; nginx-status-page = handleTest ./nginx-status-page.nix {}; nginx-tmpdir = handleTest ./nginx-tmpdir.nix {}; diff --git a/nixos/tests/nginx-redirectcode.nix b/nixos/tests/nginx-redirectcode.nix new file mode 100644 index 000000000000..f60434a21a85 --- /dev/null +++ b/nixos/tests/nginx-redirectcode.nix @@ -0,0 +1,25 @@ +import ./make-test-python.nix ({ pkgs, lib, ... }: { + name = "nginx-redirectcode"; + meta.maintainers = with lib.maintainers; [ misterio77 ]; + + nodes = { + webserver = { pkgs, lib, ... }: { + services.nginx = { + enable = true; + virtualHosts.localhost = { + globalRedirect = "example.com/foo"; + # With 308 (and 307), the method and body are to be kept when following it + redirectCode = 308; + }; + }; + }; + }; + + testScript = '' + webserver.wait_for_unit("nginx") + webserver.wait_for_open_port(80) + + # Check the status code + webserver.succeed("curl -si http://localhost | grep '^HTTP/[0-9.]\+ 308 Permanent Redirect'") + ''; +}) |