Skip to content

Commit fbc053f

Browse files
committed
Tests: tls-alpn-01 challenge tests.
1 parent 426903f commit fbc053f

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

t/acme_tls_alpn.t

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/usr/bin/perl
2+
3+
# Copyright (c) F5, Inc.
4+
#
5+
# This source code is licensed under the Apache License, Version 2.0 license
6+
# found in the LICENSE file in the root directory of this source tree.
7+
8+
# Tests for ACME client: TLS-ALPN-01 challenge.
9+
10+
###############################################################################
11+
12+
use warnings;
13+
use strict;
14+
15+
use Test::More;
16+
17+
BEGIN { use FindBin; chdir($FindBin::Bin); }
18+
19+
use lib 'lib';
20+
use Test::Nginx;
21+
use Test::Nginx::ACME;
22+
use Test::Nginx::DNS;
23+
24+
###############################################################################
25+
26+
select STDERR; $| = 1;
27+
select STDOUT; $| = 1;
28+
29+
my $t = Test::Nginx->new()->has(qw/http http_ssl sni socket_ssl/)
30+
->has_daemon('openssl');
31+
32+
$t->write_file_expand('nginx.conf', <<'EOF');
33+
34+
%%TEST_GLOBALS%%
35+
36+
daemon off;
37+
38+
events {
39+
}
40+
41+
http {
42+
%%TEST_GLOBALS_HTTP%%
43+
44+
resolver 127.0.0.1:%%PORT_8980_UDP%%;
45+
46+
acme_issuer default {
47+
uri https://acme.test:%%PORT_9000%%/dir;
48+
challenge tls-alpn-01;
49+
ssl_trusted_certificate acme.test.crt;
50+
state_path %%TESTDIR%%;
51+
accept_terms_of_service;
52+
}
53+
54+
server {
55+
listen 127.0.0.1:8443 ssl;
56+
server_name .example.test;
57+
58+
acme_certificate default;
59+
60+
ssl_certificate $acme_certificate;
61+
ssl_certificate_key $acme_certificate_key;
62+
}
63+
}
64+
65+
EOF
66+
67+
$t->write_file('openssl.conf', <<EOF);
68+
[ req ]
69+
default_bits = 2048
70+
encrypt_key = no
71+
distinguished_name = req_distinguished_name
72+
[ req_distinguished_name ]
73+
EOF
74+
75+
my $d = $t->testdir();
76+
77+
foreach my $name ('acme.test') {
78+
system('openssl req -x509 -new '
79+
. "-config $d/openssl.conf -subj /CN=$name/ "
80+
. "-out $d/$name.crt -keyout $d/$name.key "
81+
. ">>$d/openssl.out 2>&1") == 0
82+
or die "Can't create certificate for $name: $!\n";
83+
}
84+
85+
my $dp = port(8980, udp=>1);
86+
my @dc = (
87+
{ name => 'acme.test', A => '127.0.0.1' },
88+
{ match => qr/^(\w+\.)?example.test$/, A => '127.0.0.1' }
89+
);
90+
91+
my $acme = Test::Nginx::ACME->new($t, port(9000), port(9001),
92+
$t->testdir . '/acme.test.crt',
93+
$t->testdir . '/acme.test.key',
94+
tls_port => port(8443),
95+
dns_port => $dp,
96+
nosleep => 1,
97+
);
98+
99+
$t->run_daemon(\&Test::Nginx::DNS::dns_test_daemon, $t, $dp, \@dc);
100+
$t->waitforfile($t->testdir . '/' . $dp);
101+
102+
$t->run_daemon(\&Test::Nginx::ACME::acme_test_daemon, $t, $acme);
103+
$t->waitforsocket('127.0.0.1:' . $acme->port());
104+
$t->write_file('acme-root.crt', $acme->trusted_ca());
105+
106+
$t->write_file('index.html', 'SUCCESS');
107+
$t->plan(1)->run();
108+
109+
###############################################################################
110+
111+
$acme->wait_certificate('example.test') or die "no certificate";
112+
113+
like(get(8443, 'example.test', 'acme-root'), qr/SUCCESS/, 'tls request');
114+
115+
###############################################################################
116+
117+
sub get {
118+
my ($port, $host, $ca) = @_;
119+
120+
$ca = undef if $IO::Socket::SSL::VERSION < 2.062
121+
|| !eval { Net::SSLeay::X509_V_FLAG_PARTIAL_CHAIN() };
122+
123+
http_get('/',
124+
PeerAddr => '127.0.0.1:' . port($port),
125+
SSL => 1,
126+
$ca ? (
127+
SSL_ca_file => "$d/$ca.crt",
128+
SSL_verifycn_name => $host,
129+
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
130+
) : ()
131+
);
132+
}
133+
134+
###############################################################################

0 commit comments

Comments
 (0)