nginx: test basic auth
This commit is contained in:
parent
c7bf3828f0
commit
a4b86b2bf5
@ -242,6 +242,7 @@ in
|
||||
nfs4 = handleTest ./nfs { version = 4; };
|
||||
nghttpx = handleTest ./nghttpx.nix {};
|
||||
nginx = handleTest ./nginx.nix {};
|
||||
nginx-auth = handleTest ./nginx-auth.nix {};
|
||||
nginx-etag = handleTest ./nginx-etag.nix {};
|
||||
nginx-pubhtml = handleTest ./nginx-pubhtml.nix {};
|
||||
nginx-sandbox = handleTestOn ["x86_64-linux"] ./nginx-sandbox.nix {};
|
||||
|
47
nixos/tests/nginx-auth.nix
Normal file
47
nixos/tests/nginx-auth.nix
Normal file
@ -0,0 +1,47 @@
|
||||
import ./make-test-python.nix ({ pkgs, ... }: {
|
||||
name = "nginx-auth";
|
||||
|
||||
nodes = {
|
||||
webserver = { pkgs, lib, ... }: {
|
||||
services.nginx = let
|
||||
root = pkgs.runCommand "testdir" {} ''
|
||||
mkdir "$out"
|
||||
echo hello world > "$out/index.html"
|
||||
'';
|
||||
in {
|
||||
enable = true;
|
||||
|
||||
virtualHosts.lockedroot = {
|
||||
inherit root;
|
||||
basicAuth.alice = "jane";
|
||||
};
|
||||
|
||||
virtualHosts.lockedsubdir = {
|
||||
inherit root;
|
||||
locations."/sublocation/" = {
|
||||
alias = "${root}/";
|
||||
basicAuth.bob = "john";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
webserver.wait_for_unit("nginx")
|
||||
webserver.wait_for_open_port(80)
|
||||
|
||||
webserver.fail("curl --fail --resolve lockedroot:80:127.0.0.1 http://lockedroot")
|
||||
webserver.succeed(
|
||||
"curl --fail --resolve lockedroot:80:127.0.0.1 http://alice:jane@lockedroot"
|
||||
)
|
||||
|
||||
webserver.succeed("curl --fail --resolve lockedsubdir:80:127.0.0.1 http://lockedsubdir")
|
||||
webserver.fail(
|
||||
"curl --fail --resolve lockedsubdir:80:127.0.0.1 http://lockedsubdir/sublocation/index.html"
|
||||
)
|
||||
webserver.succeed(
|
||||
"curl --fail --resolve lockedsubdir:80:127.0.0.1 http://bob:john@lockedsubdir/sublocation/index.html"
|
||||
)
|
||||
'';
|
||||
})
|
Loading…
Reference in New Issue
Block a user