1 import ./make-test-python.nix ({ pkgs, lib, ... }: {
3 meta = with lib.maintainers; {
4 maintainers = [ lukegb ];
7 nodes = let base = myIP: { pkgs, lib, ... }: {
8 virtualisation.vlans = [ 1 ];
10 dhcpcd.enable = false;
11 firewall.allowedTCPPorts = [ 80 443 ];
13 "192.168.1.1" = [ "pomerium" "pom-auth" ];
14 "192.168.1.2" = [ "backend" "dummy-oidc" ];
16 interfaces.eth1.ipv4.addresses = pkgs.lib.mkOverride 0 [
17 { address = myIP; prefixLength = 24; }
21 pomerium = { pkgs, lib, ... }: {
22 imports = [ (base "192.168.1.1") ];
27 insecure_server = true;
28 authenticate_service_url = "http://pom-auth";
30 idp_provider = "oidc";
31 idp_scopes = [ "oidc" ];
32 idp_client_id = "dummy";
33 idp_provider_url = "http://dummy-oidc";
36 from = "https://my.website";
37 to = "http://192.168.1.2";
38 allow_public_unauthenticated_access = true;
39 preserve_host_header = true;
41 from = "https://login.required";
42 to = "http://192.168.1.2";
43 allowed_domains = [ "my.domain" ];
44 preserve_host_header = true;
47 secretsFile = pkgs.writeText "pomerium-secrets" ''
48 # 12345678901234567890123456789012 in base64
49 COOKIE_SECRET=MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=
50 IDP_CLIENT_SECRET=dummy
54 backend = { pkgs, lib, ... }: {
55 imports = [ (base "192.168.1.2") ];
56 services.nginx.enable = true;
57 services.nginx.virtualHosts."my.website" = {
58 root = pkgs.runCommand "testdir" {} ''
60 echo hello world > "$out/index.html"
63 services.nginx.virtualHosts."dummy-oidc" = {
64 root = pkgs.runCommand "testdir" {} ''
65 mkdir -p "$out/.well-known"
66 cat <<EOF >"$out/.well-known/openid-configuration"
68 "issuer": "http://dummy-oidc",
69 "authorization_endpoint": "http://dummy-oidc/auth.txt",
70 "token_endpoint": "http://dummy-oidc/token",
71 "jwks_uri": "http://dummy-oidc/jwks.json",
72 "userinfo_endpoint": "http://dummy-oidc/userinfo",
73 "id_token_signing_alg_values_supported": ["RS256"]
76 echo hello I am login page >"$out/auth.txt"
82 testScript = { ... }: ''
83 backend.wait_for_unit("nginx")
84 backend.wait_for_open_port(80)
86 pomerium.wait_for_unit("pomerium")
87 pomerium.wait_for_open_port(80)
89 with subtest("no authentication required"):
91 "curl --resolve my.website:80:127.0.0.1 http://my.website | grep 'hello world'"
94 with subtest("login required"):
96 "curl -I --resolve login.required:80:127.0.0.1 http://login.required | grep pom-auth"
99 "curl -L --resolve login.required:80:127.0.0.1 http://login.required | grep 'hello I am login page'"