nixpkgs/nixos/tests/nginx-auth.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.3 KiB
Nix
Raw Permalink Normal View History

{ pkgs, ... }:
{
name = "nginx-auth";
2020-10-20 16:05:41 +00:00
nodes = {
webserver =
{ pkgs, lib, ... }:
{
services.nginx =
let
root = pkgs.runCommand "testdir" { } ''
mkdir "$out"
echo hello world > "$out/index.html"
'';
in
{
enable = true;
2020-10-20 16:05:41 +00:00
virtualHosts.lockedroot = {
inherit root;
basicAuth.alice = "pwofa";
};
2020-10-20 16:05:41 +00:00
virtualHosts.lockedsubdir = {
inherit root;
locations."/sublocation/" = {
alias = "${root}/";
basicAuth.bob = "pwofb";
};
2020-10-20 16:05:41 +00:00
};
};
};
};
2020-10-20 16:05:41 +00:00
testScript = ''
webserver.wait_for_unit("nginx")
webserver.wait_for_open_port(80)
2020-10-20 16:05:41 +00:00
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:pwofa@lockedroot"
)
2020-10-20 16:05:41 +00:00
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:pwofb@lockedsubdir/sublocation/index.html"
)
'';
}