Skip to content

Commit eeaa42f

Browse files
m1cr0manmweinelt
authored andcommitted
nixos/tests/acme: Add CSR test
1 parent 754412b commit eeaa42f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

nixos/tests/acme/http01-builtin.nix

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,45 @@ in
9999
"builtin-3.${domain}".listenHTTP = ":80";
100100
};
101101
};
102+
103+
csr.configuration =
104+
let
105+
conf = pkgs.writeText "openssl.csr.conf" ''
106+
[req]
107+
default_bits = 2048
108+
prompt = no
109+
default_md = sha256
110+
req_extensions = req_ext
111+
distinguished_name = dn
112+
113+
[ dn ]
114+
CN = ${config.networking.fqdn}
115+
116+
[ req_ext ]
117+
subjectAltName = @alt_names
118+
119+
[ alt_names ]
120+
DNS.1 = ${config.networking.fqdn}
121+
'';
122+
csrData =
123+
pkgs.runCommandNoCC "csr-and-key"
124+
{
125+
buildInputs = [ pkgs.openssl ];
126+
}
127+
''
128+
mkdir -p $out
129+
openssl req -new -newkey rsa:2048 -nodes \
130+
-keyout $out/key.pem \
131+
-out $out/request.csr \
132+
-config ${conf}
133+
'';
134+
in
135+
{
136+
security.acme.certs."${config.networking.fqdn}" = {
137+
csr = "${csrData}/request.csr";
138+
csrKey = "${csrData}/key.pem";
139+
};
140+
};
102141
};
103142
};
104143
};
@@ -211,5 +250,10 @@ in
211250
212251
with subtest("Validate permissions (self-signed)"):
213252
check_permissions(builtin, cert, "acme")
253+
254+
with subtest("Can renew using a CSR"):
255+
builtin.succeed(f"systemctl clean acme-{cert}.service --what=state")
256+
switch_to(builtin, "csr")
257+
check_issuer(builtin, cert, "pebble")
214258
'';
215259
}

0 commit comments

Comments
 (0)