mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 11:45:45 +03:00
parent
7f5db31613
commit
646a8a3356
2 changed files with 102 additions and 104 deletions
|
@ -161,7 +161,7 @@ in {
|
||||||
alice-lg = runTest ./alice-lg.nix;
|
alice-lg = runTest ./alice-lg.nix;
|
||||||
alloy = runTest ./alloy.nix;
|
alloy = runTest ./alloy.nix;
|
||||||
allTerminfo = runTest ./all-terminfo.nix;
|
allTerminfo = runTest ./all-terminfo.nix;
|
||||||
alps = handleTest ./alps.nix {};
|
alps = runTest ./alps.nix;
|
||||||
amazon-cloudwatch-agent = handleTest ./amazon-cloudwatch-agent.nix {};
|
amazon-cloudwatch-agent = handleTest ./amazon-cloudwatch-agent.nix {};
|
||||||
amazon-init-shell = handleTest ./amazon-init-shell.nix {};
|
amazon-init-shell = handleTest ./amazon-init-shell.nix {};
|
||||||
amazon-ssm-agent = handleTest ./amazon-ssm-agent.nix {};
|
amazon-ssm-agent = handleTest ./amazon-ssm-agent.nix {};
|
||||||
|
|
|
@ -2,118 +2,116 @@ let
|
||||||
certs = import ./common/acme/server/snakeoil-certs.nix;
|
certs = import ./common/acme/server/snakeoil-certs.nix;
|
||||||
domain = certs.domain;
|
domain = certs.domain;
|
||||||
in
|
in
|
||||||
import ./make-test-python.nix (
|
{ pkgs, ... }:
|
||||||
{ pkgs, ... }:
|
{
|
||||||
{
|
name = "alps";
|
||||||
name = "alps";
|
meta = with pkgs.lib.maintainers; {
|
||||||
meta = with pkgs.lib.maintainers; {
|
maintainers = [ hmenke ];
|
||||||
maintainers = [ hmenke ];
|
};
|
||||||
|
|
||||||
|
nodes = {
|
||||||
|
server = {
|
||||||
|
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;
|
||||||
|
tlsTrustedAuthorities = "${certs.ca.cert}";
|
||||||
|
sslCert = "${certs.${domain}.cert}";
|
||||||
|
sslKey = "${certs.${domain}.key}";
|
||||||
|
};
|
||||||
|
services.dovecot2 = {
|
||||||
|
enable = true;
|
||||||
|
enableImap = true;
|
||||||
|
sslCACert = "${certs.ca.cert}";
|
||||||
|
sslServerCert = "${certs.${domain}.cert}";
|
||||||
|
sslServerKey = "${certs.${domain}.key}";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
nodes = {
|
client =
|
||||||
server = {
|
{ nodes, config, ... }:
|
||||||
imports = [ ./common/user-account.nix ];
|
{
|
||||||
security.pki.certificateFiles = [
|
security.pki.certificateFiles = [
|
||||||
certs.ca.cert
|
certs.ca.cert
|
||||||
];
|
];
|
||||||
networking.extraHosts = ''
|
networking.extraHosts = ''
|
||||||
127.0.0.1 ${domain}
|
${nodes.server.config.networking.primaryIPAddress} ${domain}
|
||||||
'';
|
'';
|
||||||
networking.firewall.allowedTCPPorts = [
|
services.alps = {
|
||||||
25
|
|
||||||
465
|
|
||||||
993
|
|
||||||
];
|
|
||||||
services.postfix = {
|
|
||||||
enable = true;
|
enable = true;
|
||||||
enableSubmission = true;
|
theme = "alps";
|
||||||
enableSubmissions = true;
|
imaps = {
|
||||||
tlsTrustedAuthorities = "${certs.ca.cert}";
|
host = domain;
|
||||||
sslCert = "${certs.${domain}.cert}";
|
port = 993;
|
||||||
sslKey = "${certs.${domain}.key}";
|
};
|
||||||
};
|
smtps = {
|
||||||
services.dovecot2 = {
|
host = domain;
|
||||||
enable = true;
|
port = 465;
|
||||||
enableImap = true;
|
|
||||||
sslCACert = "${certs.ca.cert}";
|
|
||||||
sslServerCert = "${certs.${domain}.cert}";
|
|
||||||
sslServerKey = "${certs.${domain}.key}";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
client =
|
|
||||||
{ nodes, config, ... }:
|
|
||||||
{
|
|
||||||
security.pki.certificateFiles = [
|
|
||||||
certs.ca.cert
|
|
||||||
];
|
|
||||||
networking.extraHosts = ''
|
|
||||||
${nodes.server.config.networking.primaryIPAddress} ${domain}
|
|
||||||
'';
|
|
||||||
services.alps = {
|
|
||||||
enable = true;
|
|
||||||
theme = "alps";
|
|
||||||
imaps = {
|
|
||||||
host = domain;
|
|
||||||
port = 993;
|
|
||||||
};
|
|
||||||
smtps = {
|
|
||||||
host = domain;
|
|
||||||
port = 465;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
environment.systemPackages = [
|
|
||||||
(pkgs.writers.writePython3Bin "test-alps-login" { } ''
|
|
||||||
from urllib.request import build_opener, HTTPCookieProcessor, Request
|
|
||||||
from urllib.parse import urlencode, urljoin
|
|
||||||
from http.cookiejar import CookieJar
|
|
||||||
|
|
||||||
baseurl = "http://localhost:${toString config.services.alps.port}"
|
|
||||||
username = "alice"
|
|
||||||
password = "${nodes.server.config.users.users.alice.password}"
|
|
||||||
cookiejar = CookieJar()
|
|
||||||
cookieprocessor = HTTPCookieProcessor(cookiejar)
|
|
||||||
opener = build_opener(cookieprocessor)
|
|
||||||
|
|
||||||
data = urlencode({"username": username, "password": password}).encode()
|
|
||||||
req = Request(urljoin(baseurl, "login"), data=data, 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, "mailbox/INBOX")
|
|
||||||
|
|
||||||
req = Request(urljoin(baseurl, "logout"))
|
|
||||||
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)
|
|
||||||
'')
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
};
|
environment.systemPackages = [
|
||||||
|
(pkgs.writers.writePython3Bin "test-alps-login" { } ''
|
||||||
|
from urllib.request import build_opener, HTTPCookieProcessor, Request
|
||||||
|
from urllib.parse import urlencode, urljoin
|
||||||
|
from http.cookiejar import CookieJar
|
||||||
|
|
||||||
testScript =
|
baseurl = "http://localhost:${toString config.services.alps.port}"
|
||||||
{ nodes, ... }:
|
username = "alice"
|
||||||
''
|
password = "${nodes.server.config.users.users.alice.password}"
|
||||||
server.start()
|
cookiejar = CookieJar()
|
||||||
server.wait_for_unit("postfix.service")
|
cookieprocessor = HTTPCookieProcessor(cookiejar)
|
||||||
server.wait_for_unit("dovecot2.service")
|
opener = build_opener(cookieprocessor)
|
||||||
server.wait_for_open_port(465)
|
|
||||||
server.wait_for_open_port(993)
|
|
||||||
|
|
||||||
client.start()
|
data = urlencode({"username": username, "password": password}).encode()
|
||||||
client.wait_for_unit("alps.service")
|
req = Request(urljoin(baseurl, "login"), data=data, method="POST")
|
||||||
client.wait_for_open_port(${toString nodes.client.config.services.alps.port})
|
with opener.open(req) as ret:
|
||||||
client.succeed("test-alps-login")
|
# 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, "mailbox/INBOX")
|
||||||
|
|
||||||
|
req = Request(urljoin(baseurl, "logout"))
|
||||||
|
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 =
|
||||||
|
{ nodes, ... }:
|
||||||
|
''
|
||||||
|
server.start()
|
||||||
|
server.wait_for_unit("postfix.service")
|
||||||
|
server.wait_for_unit("dovecot2.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 nodes.client.config.services.alps.port})
|
||||||
|
client.succeed("test-alps-login")
|
||||||
|
'';
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue