Skip to content

Commit 9bb8643

Browse files
committed
Tests: test external account binding support.
1 parent 1106471 commit 9bb8643

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed

t/acme_external_account.t

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
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: External Account Binding support.
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 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+
external_account_key eab-kid eab-secret;
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:8080;
56+
server_name example.test;
57+
}
58+
59+
server {
60+
listen 127.0.0.1:8443 ssl;
61+
server_name example.test;
62+
63+
acme_certificate default;
64+
65+
ssl_certificate $acme_certificate;
66+
ssl_certificate_key $acme_certificate_key;
67+
}
68+
}
69+
70+
EOF
71+
72+
$t->write_file('openssl.conf', <<EOF);
73+
[ req ]
74+
default_bits = 2048
75+
encrypt_key = no
76+
distinguished_name = req_distinguished_name
77+
[ req_distinguished_name ]
78+
EOF
79+
80+
my $d = $t->testdir();
81+
82+
foreach my $name ('acme.test') {
83+
system('openssl req -x509 -new '
84+
. "-config $d/openssl.conf -subj /CN=$name/ "
85+
. "-out $d/$name.crt -keyout $d/$name.key "
86+
. ">>$d/openssl.out 2>&1") == 0
87+
or die "Can't create certificate for $name: $!\n";
88+
}
89+
90+
my $dp = port(8980, udp=>1);
91+
my @dc = (
92+
{ name => 'acme.test', A => '127.0.0.1' },
93+
{ name => 'example.test', A => '127.0.0.1' }
94+
);
95+
96+
my $eab_key = 'zWNDZM6eQGHWpSRTPal5eIUYFTu7EajVIoguysqZ9wG44nMEtx3MUAsUDkMTQ12W';
97+
98+
my $acme = Test::Nginx::ACME->new($t, port(9000), port(9001),
99+
$t->testdir . '/acme.test.crt',
100+
$t->testdir . '/acme.test.key',
101+
http_port => port(8080),
102+
tls_port => port(8443),
103+
dns_port => $dp,
104+
conf => {
105+
externalAccountBindingRequired => \1,
106+
externalAccountMACKeys => { 'eab-kid' => $eab_key },
107+
}
108+
)->has(qw/eab/);
109+
110+
$t->run_daemon(\&Test::Nginx::DNS::dns_test_daemon, $t, $dp, \@dc);
111+
$t->waitforfile($t->testdir . '/' . $dp);
112+
113+
$t->run_daemon(\&Test::Nginx::ACME::acme_test_daemon, $t, $acme);
114+
$t->waitforsocket('127.0.0.1:' . $acme->port());
115+
$t->write_file('acme-root.crt', $acme->trusted_ca());
116+
$t->write_file('eab-secret', $eab_key);
117+
118+
$t->write_file('index.html', 'SUCCESS');
119+
$t->plan(1)->run();
120+
121+
###############################################################################
122+
123+
$acme->wait_certificate('example.test') or die "no certificate";
124+
125+
like(get(8443, 'example.test', 'acme-root'), qr/SUCCESS/, 'tls request');
126+
127+
###############################################################################
128+
129+
sub get {
130+
my ($port, $host, $ca) = @_;
131+
132+
$ca = undef if $IO::Socket::SSL::VERSION < 2.062
133+
|| !eval { Net::SSLeay::X509_V_FLAG_PARTIAL_CHAIN() };
134+
135+
http_get('/',
136+
PeerAddr => '127.0.0.1:' . port($port),
137+
SSL => 1,
138+
$ca ? (
139+
SSL_ca_file => "$d/$ca.crt",
140+
SSL_verifycn_name => $host,
141+
SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
142+
) : ()
143+
);
144+
}
145+
146+
###############################################################################

0 commit comments

Comments
 (0)