nixos/alps: test login and cookie

+43 -5
+40 -4
nixos/tests/alps.nix
··· 2 certs = import ./common/acme/server/snakeoil-certs.nix; 3 domain = certs.domain; 4 in 5 - import ./make-test-python.nix { 6 name = "alps"; 7 8 nodes = { ··· 32 }; 33 }; 34 35 - client = { nodes, ... }: { 36 security.pki.certificateFiles = [ 37 certs.ca.cert 38 ]; ··· 51 port = 465; 52 }; 53 }; 54 }; 55 }; 56 ··· 63 64 client.start() 65 client.wait_for_unit("alps.service") 66 - client.wait_until_succeeds("curl -fvvv -s http://127.0.0.1:1323/", timeout=60) 67 ''; 68 - }
··· 2 certs = import ./common/acme/server/snakeoil-certs.nix; 3 domain = certs.domain; 4 in 5 + import ./make-test-python.nix ({ pkgs, ... }: { 6 name = "alps"; 7 8 nodes = { ··· 32 }; 33 }; 34 35 + client = { nodes, config, ... }: { 36 security.pki.certificateFiles = [ 37 certs.ca.cert 38 ]; ··· 51 port = 465; 52 }; 53 }; 54 + environment.systemPackages = [ 55 + (pkgs.writers.writePython3Bin "test-alps-login" { } '' 56 + from urllib.request import build_opener, HTTPCookieProcessor, Request 57 + from urllib.parse import urlencode, urljoin 58 + from http.cookiejar import CookieJar 59 + 60 + baseurl = "http://localhost:${toString config.services.alps.port}" 61 + username = "alice" 62 + password = "${nodes.server.config.users.users.alice.password}" 63 + cookiejar = CookieJar() 64 + cookieprocessor = HTTPCookieProcessor(cookiejar) 65 + opener = build_opener(cookieprocessor) 66 + 67 + data = urlencode({"username": username, "password": password}).encode() 68 + req = Request(urljoin(baseurl, "login"), data=data, method="POST") 69 + with opener.open(req) as ret: 70 + # Check that the alps_session cookie is set 71 + print(cookiejar) 72 + assert any(cookie.name == "alps_session" for cookie in cookiejar) 73 + 74 + req = Request(baseurl) 75 + with opener.open(req) as ret: 76 + # Check that the alps_session cookie is still there... 77 + print(cookiejar) 78 + assert any(cookie.name == "alps_session" for cookie in cookiejar) 79 + # ...and that we have not been redirected back to the login page 80 + print(ret.url) 81 + assert ret.url == urljoin(baseurl, "mailbox/INBOX") 82 + 83 + req = Request(urljoin(baseurl, "logout")) 84 + with opener.open(req) as ret: 85 + # Check that the alps_session cookie is now gone 86 + print(cookiejar) 87 + assert all(cookie.name != "alps_session" for cookie in cookiejar) 88 + '') 89 + ]; 90 }; 91 }; 92 ··· 99 100 client.start() 101 client.wait_for_unit("alps.service") 102 + client.succeed("test-alps-login") 103 ''; 104 + })
+3 -1
pkgs/servers/alps/default.nix
··· 1 - { lib, buildGoModule, fetchFromSourcehut }: 2 3 buildGoModule rec { 4 pname = "alps"; ··· 30 ''; 31 32 proxyVendor = true; 33 34 meta = with lib; { 35 description = "A simple and extensible webmail.";
··· 1 + { lib, buildGoModule, fetchFromSourcehut, nixosTests }: 2 3 buildGoModule rec { 4 pname = "alps"; ··· 30 ''; 31 32 proxyVendor = true; 33 + 34 + passthru.tests = { inherit(nixosTests) alps; }; 35 36 meta = with lib; { 37 description = "A simple and extensible webmail.";