Skip to content

Commit 689608c

Browse files
committed
Tests: ACME configuration parsing test.
1 parent e2f55b2 commit 689608c

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed

t/acme_conf_issuer.t

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
#!/usr/bin/perl
2+
3+
# (C) Aleksei Bavshin
4+
# (C) Nginx, Inc.
5+
6+
# Tests for ACME client: configuration parsing and validation.
7+
8+
###############################################################################
9+
10+
use warnings;
11+
use strict;
12+
13+
use Test::More;
14+
15+
use IO::Select;
16+
17+
BEGIN { use FindBin; chdir($FindBin::Bin); }
18+
19+
use lib 'lib';
20+
use Test::Nginx;
21+
22+
###############################################################################
23+
24+
select STDERR; $| = 1;
25+
select STDOUT; $| = 1;
26+
27+
my $t = Test::Nginx->new()->has(qw/http socket_ssl/)->plan(8);
28+
29+
use constant TEMPLATE_CONF => <<'EOF';
30+
31+
%%TEST_GLOBALS%%
32+
33+
daemon off;
34+
35+
events {
36+
}
37+
38+
http {
39+
%%TEST_GLOBALS_HTTP%%
40+
41+
server {
42+
listen 127.0.0.1:8080;
43+
server_name example.test;
44+
}
45+
46+
server {
47+
listen 127.0.0.1:8443 ssl;
48+
server_name example.test;
49+
50+
acme_certificate example.test
51+
issuer=example;
52+
53+
ssl_certificate $acme_certificate;
54+
ssl_certificate_key $acme_certificate_key;
55+
}
56+
57+
%%ACME_ISSUER%%
58+
}
59+
60+
EOF
61+
62+
###############################################################################
63+
64+
is(check($t, <<'EOF' ), undef, 'valid');
65+
66+
acme_shared_zone 1M;
67+
68+
acme_issuer example {
69+
uri https://localhost:%%PORT_9000%%/dir;
70+
account_key ecdsa:256;
71+
contact mailto:[email protected];
72+
resolver 127.0.0.1:%%PORT_8980_UDP%%;
73+
resolver_timeout 5s;
74+
state_path %%TESTDIR%%;
75+
}
76+
77+
EOF
78+
79+
80+
is(check($t, <<'EOF' ), undef, 'valid - resolver in server');
81+
82+
acme_issuer example {
83+
uri https://localhost:%%PORT_9000%%/dir;
84+
}
85+
86+
resolver 127.0.0.1:%%PORT_8980_UDP%%;
87+
88+
EOF
89+
90+
91+
like(check($t, <<'EOF' ), qr/\[emerg].*resolver is not/, 'no resolver');
92+
93+
acme_issuer example {
94+
uri https://localhost:%%PORT_9000%%/dir;
95+
}
96+
97+
EOF
98+
99+
like(check($t, <<'EOF' ), qr/\[emerg].*invalid zone size/, 'bad zone size');
100+
101+
acme_shared_zone bad-value;
102+
103+
acme_issuer example {
104+
uri https://localhost:%%PORT_9000%%/dir;
105+
resolver 127.0.0.1:%%PORT_8980_UDP%%;
106+
}
107+
108+
EOF
109+
110+
111+
like(check($t, <<'EOF' ), qr/\[emerg].*bad account key/, 'bad key file');
112+
113+
acme_issuer example {
114+
uri https://localhost:%%PORT_9000%%/dir;
115+
account_key no-such-file.key;
116+
resolver 127.0.0.1:%%PORT_8980_UDP%%;
117+
}
118+
119+
EOF
120+
121+
122+
like(check($t, <<'EOF' ), qr/\[emerg].*unsupported curve/, 'bad key curve');
123+
124+
acme_issuer example {
125+
uri https://localhost:%%PORT_9000%%/dir;
126+
account_key ecdsa:234;
127+
resolver 127.0.0.1:%%PORT_8980_UDP%%;
128+
}
129+
130+
EOF
131+
132+
133+
like(check($t, <<'EOF' ), qr/\[emerg].*unsupported key size/, 'bad key size');
134+
135+
acme_issuer example {
136+
uri https://localhost:%%PORT_9000%%/dir;
137+
account_key rsa:1024;
138+
resolver 127.0.0.1:%%PORT_8980_UDP%%;
139+
}
140+
141+
EOF
142+
143+
144+
like(check($t, ''), qr/\[emerg].*issuer "[^"]+" is missing/, 'no issuer');
145+
146+
###############################################################################
147+
148+
sub check {
149+
my ($t, $issuer) = @_;
150+
151+
$t->write_file_expand('nginx.conf',
152+
TEMPLATE_CONF =~ s/%%ACME_ISSUER%%/$issuer/r);
153+
154+
return try_run($t);
155+
}
156+
157+
sub try_run {
158+
my $t = shift;
159+
160+
# clean up after a successfull try
161+
162+
$t->stop();
163+
unlink $t->testdir() . '/error.log';
164+
165+
eval {
166+
open OLDERR, ">&", \*STDERR; close STDERR;
167+
$t->run();
168+
open STDERR, ">&", \*OLDERR;
169+
};
170+
171+
return unless $@;
172+
173+
return $t->read_file('error.log');
174+
}

0 commit comments

Comments
 (0)