nixosTests.nginx-auth: migrate to runTest

Part of #386873
This commit is contained in:
Piotr Kwiecinski 2025-03-29 23:47:25 +01:00
parent 389f2fb908
commit fa5141395f
No known key found for this signature in database
GPG key ID: EC0DE1CB9D5258B4
2 changed files with 45 additions and 47 deletions

View file

@ -798,7 +798,7 @@ in {
nfs4 = handleTest ./nfs { version = 4; }; nfs4 = handleTest ./nfs { version = 4; };
nghttpx = handleTest ./nghttpx.nix {}; nghttpx = handleTest ./nghttpx.nix {};
nginx = runTest ./nginx.nix; nginx = runTest ./nginx.nix;
nginx-auth = handleTest ./nginx-auth.nix {}; nginx-auth = runTest ./nginx-auth.nix;
nginx-etag = handleTest ./nginx-etag.nix {}; nginx-etag = handleTest ./nginx-etag.nix {};
nginx-etag-compression = handleTest ./nginx-etag-compression.nix {}; nginx-etag-compression = handleTest ./nginx-etag-compression.nix {};
nginx-globalredirect = handleTest ./nginx-globalredirect.nix {}; nginx-globalredirect = handleTest ./nginx-globalredirect.nix {};

View file

@ -1,54 +1,52 @@
import ./make-test-python.nix ( { pkgs, ... }:
{ pkgs, ... }: {
{ name = "nginx-auth";
name = "nginx-auth";
nodes = { nodes = {
webserver = webserver =
{ pkgs, lib, ... }: { pkgs, lib, ... }:
{ {
services.nginx = services.nginx =
let let
root = pkgs.runCommand "testdir" { } '' root = pkgs.runCommand "testdir" { } ''
mkdir "$out" mkdir "$out"
echo hello world > "$out/index.html" echo hello world > "$out/index.html"
''; '';
in in
{ {
enable = true; enable = true;
virtualHosts.lockedroot = { virtualHosts.lockedroot = {
inherit root; inherit root;
basicAuth.alice = "pwofa"; basicAuth.alice = "pwofa";
}; };
virtualHosts.lockedsubdir = { virtualHosts.lockedsubdir = {
inherit root; inherit root;
locations."/sublocation/" = { locations."/sublocation/" = {
alias = "${root}/"; alias = "${root}/";
basicAuth.bob = "pwofb"; basicAuth.bob = "pwofb";
};
}; };
}; };
}; };
}; };
};
testScript = '' testScript = ''
webserver.wait_for_unit("nginx") webserver.wait_for_unit("nginx")
webserver.wait_for_open_port(80) webserver.wait_for_open_port(80)
webserver.fail("curl --fail --resolve lockedroot:80:127.0.0.1 http://lockedroot") webserver.fail("curl --fail --resolve lockedroot:80:127.0.0.1 http://lockedroot")
webserver.succeed( webserver.succeed(
"curl --fail --resolve lockedroot:80:127.0.0.1 http://alice:pwofa@lockedroot" "curl --fail --resolve lockedroot:80:127.0.0.1 http://alice:pwofa@lockedroot"
) )
webserver.succeed("curl --fail --resolve lockedsubdir:80:127.0.0.1 http://lockedsubdir") webserver.succeed("curl --fail --resolve lockedsubdir:80:127.0.0.1 http://lockedsubdir")
webserver.fail( webserver.fail(
"curl --fail --resolve lockedsubdir:80:127.0.0.1 http://lockedsubdir/sublocation/index.html" "curl --fail --resolve lockedsubdir:80:127.0.0.1 http://lockedsubdir/sublocation/index.html"
) )
webserver.succeed( webserver.succeed(
"curl --fail --resolve lockedsubdir:80:127.0.0.1 http://bob:pwofb@lockedsubdir/sublocation/index.html" "curl --fail --resolve lockedsubdir:80:127.0.0.1 http://bob:pwofb@lockedsubdir/sublocation/index.html"
) )
''; '';
} }
)