1{ pkgs, ... }:
2{
3 name = "nginx-auth";
4
5 nodes = {
6 webserver =
7 { pkgs, lib, ... }:
8 {
9 services.nginx =
10 let
11 root = pkgs.runCommand "testdir" { } ''
12 mkdir "$out"
13 echo hello world > "$out/index.html"
14 '';
15 in
16 {
17 enable = true;
18
19 virtualHosts.lockedroot = {
20 inherit root;
21 basicAuth.alice = "pwofa";
22 };
23
24 virtualHosts.lockedsubdir = {
25 inherit root;
26 locations."/sublocation/" = {
27 alias = "${root}/";
28 basicAuth.bob = "pwofb";
29 };
30 };
31 };
32 };
33 };
34
35 testScript = ''
36 webserver.wait_for_unit("nginx")
37 webserver.wait_for_open_port(80)
38
39 webserver.fail("curl --fail --resolve lockedroot:80:127.0.0.1 http://lockedroot")
40 webserver.succeed(
41 "curl --fail --resolve lockedroot:80:127.0.0.1 http://alice:pwofa@lockedroot"
42 )
43
44 webserver.succeed("curl --fail --resolve lockedsubdir:80:127.0.0.1 http://lockedsubdir")
45 webserver.fail(
46 "curl --fail --resolve lockedsubdir:80:127.0.0.1 http://lockedsubdir/sublocation/index.html"
47 )
48 webserver.succeed(
49 "curl --fail --resolve lockedsubdir:80:127.0.0.1 http://bob:pwofb@lockedsubdir/sublocation/index.html"
50 )
51 '';
52}