mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-09-01 13:14:42 +00:00
146 lines
4.3 KiB
Nix
146 lines
4.3 KiB
Nix
{ lib, ... }:
|
|
let
|
|
certs = import ./common/acme/server/snakeoil-certs.nix;
|
|
domain = certs.domain;
|
|
port = 1323;
|
|
in
|
|
{
|
|
name = "alps";
|
|
meta = {
|
|
maintainers = with lib.maintainers; [
|
|
hmenke
|
|
prince213
|
|
];
|
|
};
|
|
|
|
nodes = {
|
|
server =
|
|
{ config, ... }:
|
|
{
|
|
imports = [ ./common/user-account.nix ];
|
|
security.pki.certificateFiles = [
|
|
certs.ca.cert
|
|
];
|
|
networking.extraHosts = ''
|
|
127.0.0.1 ${domain}
|
|
'';
|
|
networking.firewall.allowedTCPPorts = [
|
|
25
|
|
465
|
|
993
|
|
];
|
|
services.postfix = {
|
|
enable = true;
|
|
enableSubmission = true;
|
|
enableSubmissions = true;
|
|
|
|
settings.main = {
|
|
smtp_tls_CAfile = "${certs.ca.cert}";
|
|
smtpd_tls_chain_files = [
|
|
"${certs.${domain}.key}"
|
|
"${certs.${domain}.cert}"
|
|
];
|
|
};
|
|
};
|
|
services.dovecot2 = {
|
|
enable = true;
|
|
enablePAM = true;
|
|
settings = {
|
|
dovecot_config_version = "2.4.3";
|
|
dovecot_storage_version = config.services.dovecot2.package.version;
|
|
mail_driver = "maildir";
|
|
mail_path = "~/mail";
|
|
protocols.imap = true;
|
|
ssl_server_ca_file = "${certs.ca.cert}";
|
|
ssl_server_cert_file = "${certs.${domain}.cert}";
|
|
ssl_server_key_file = "${certs.${domain}.key}";
|
|
};
|
|
};
|
|
};
|
|
client =
|
|
{ nodes, pkgs, ... }:
|
|
{
|
|
security.pki.certificateFiles = [
|
|
certs.ca.cert
|
|
];
|
|
networking.extraHosts = ''
|
|
${nodes.server.networking.primaryIPAddress} ${domain}
|
|
'';
|
|
services.alps = {
|
|
enable = true;
|
|
settings = {
|
|
server = {
|
|
addr = ":${toString port}";
|
|
};
|
|
provider = {
|
|
type = "imap";
|
|
imap = {
|
|
server = "imaps://${domain}:993";
|
|
};
|
|
};
|
|
smtp = {
|
|
server = "smtps://${domain}:465";
|
|
};
|
|
};
|
|
};
|
|
environment.systemPackages = [
|
|
(pkgs.writers.writePython3Bin "test-alps-login" { } ''
|
|
from urllib.request import build_opener, HTTPCookieProcessor, Request
|
|
from urllib.parse import urljoin
|
|
from http.cookiejar import CookieJar
|
|
import json
|
|
|
|
baseurl = "http://localhost:${toString port}"
|
|
username = "alice"
|
|
password = "${nodes.server.users.users.alice.password}"
|
|
cookiejar = CookieJar()
|
|
cookieprocessor = HTTPCookieProcessor(cookiejar)
|
|
opener = build_opener(cookieprocessor)
|
|
|
|
data = json.dumps(
|
|
{"username": username, "password": password, "remember-me": ""}
|
|
).encode()
|
|
req = Request(
|
|
urljoin(baseurl, "session"),
|
|
data=data,
|
|
headers={"Content-Type": "application/json"},
|
|
method="POST",
|
|
)
|
|
with opener.open(req) as ret:
|
|
# Check that the alps_session cookie is set
|
|
print(cookiejar)
|
|
assert any(cookie.name == "alps_session" for cookie in cookiejar)
|
|
|
|
req = Request(baseurl)
|
|
with opener.open(req) as ret:
|
|
# Check that the alps_session cookie is still there...
|
|
print(cookiejar)
|
|
assert any(cookie.name == "alps_session" for cookie in cookiejar)
|
|
# ...and that we have not been redirected back to the login page
|
|
print(ret.url)
|
|
assert ret.url != urljoin(baseurl, "#/login")
|
|
|
|
req = Request(urljoin(baseurl, "session"), method="DELETE")
|
|
with opener.open(req) as ret:
|
|
# Check that the alps_session cookie is now gone
|
|
print(cookiejar)
|
|
assert all(cookie.name != "alps_session" for cookie in cookiejar)
|
|
'')
|
|
];
|
|
};
|
|
};
|
|
|
|
testScript = ''
|
|
server.start()
|
|
server.wait_for_unit("postfix.service")
|
|
server.wait_for_unit("dovecot.service")
|
|
server.wait_for_open_port(465)
|
|
server.wait_for_open_port(993)
|
|
|
|
client.start()
|
|
client.wait_for_unit("alps.service")
|
|
client.wait_for_open_port(${toString port})
|
|
client.succeed("test-alps-login")
|
|
'';
|
|
}
|