Skip to content

Commit df55728

Browse files
committed
Tests: proxy_ssl_conf_command tests.
1 parent 8e41c46 commit df55728

File tree

2 files changed

+181
-0
lines changed

2 files changed

+181
-0
lines changed

proxy_ssl_conf_command.t

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/perl
2+
3+
# (C) Sergey Kandaurov
4+
# (C) Nginx, Inc.
5+
6+
# Tests for http proxy to ssl backend, proxy_ssl_conf_command.
7+
8+
###############################################################################
9+
10+
use warnings;
11+
use strict;
12+
13+
use Test::More;
14+
15+
BEGIN { use FindBin; chdir($FindBin::Bin); }
16+
17+
use lib 'lib';
18+
use Test::Nginx;
19+
20+
###############################################################################
21+
22+
select STDERR; $| = 1;
23+
select STDOUT; $| = 1;
24+
25+
my $t = Test::Nginx->new()->has(qw/http http_ssl proxy/)
26+
->has_daemon('openssl');
27+
28+
$t->write_file_expand('nginx.conf', <<'EOF');
29+
30+
%%TEST_GLOBALS%%
31+
32+
daemon off;
33+
34+
events {
35+
}
36+
37+
http {
38+
%%TEST_GLOBALS_HTTP%%
39+
40+
server {
41+
listen 127.0.0.1:8080;
42+
server_name localhost;
43+
44+
proxy_ssl_certificate localhost.crt;
45+
proxy_ssl_certificate_key localhost.key;
46+
proxy_ssl_conf_command Certificate override.crt;
47+
proxy_ssl_conf_command PrivateKey override.key;
48+
49+
location / {
50+
proxy_pass https://127.0.0.1:8081/;
51+
}
52+
}
53+
54+
server {
55+
listen 127.0.0.1:8081 ssl;
56+
server_name localhost;
57+
58+
ssl_certificate localhost.crt;
59+
ssl_certificate_key localhost.key;
60+
ssl_verify_client optional_no_ca;
61+
62+
location / {
63+
add_header X-Cert $ssl_client_s_dn;
64+
}
65+
}
66+
}
67+
68+
EOF
69+
70+
$t->write_file('openssl.conf', <<EOF);
71+
[ req ]
72+
default_bits = 2048
73+
encrypt_key = no
74+
distinguished_name = req_distinguished_name
75+
[ req_distinguished_name ]
76+
EOF
77+
78+
my $d = $t->testdir();
79+
80+
foreach my $name ('localhost', 'override') {
81+
system('openssl req -x509 -new '
82+
. "-config $d/openssl.conf -subj /CN=$name/ "
83+
. "-out $d/$name.crt -keyout $d/$name.key "
84+
. ">>$d/openssl.out 2>&1") == 0
85+
or die "Can't create certificate for $name: $!\n";
86+
}
87+
88+
$t->write_file('index.html', '');
89+
$t->try_run('no proxy_ssl_conf_command')->plan(1);
90+
91+
###############################################################################
92+
93+
like(http_get('/'), qr/CN=override/, 'Certificate');
94+
95+
###############################################################################

stream_proxy_ssl_conf_command.t

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/perl
2+
3+
# (C) Sergey Kandaurov
4+
# (C) Nginx, Inc.
5+
6+
# Tests for stream proxy to ssl backend, proxy_ssl_conf_command.
7+
8+
###############################################################################
9+
10+
use warnings;
11+
use strict;
12+
13+
use Test::More;
14+
15+
BEGIN { use FindBin; chdir($FindBin::Bin); }
16+
17+
use lib 'lib';
18+
use Test::Nginx;
19+
20+
###############################################################################
21+
22+
select STDERR; $| = 1;
23+
select STDOUT; $| = 1;
24+
25+
my $t = Test::Nginx->new()->has(qw/stream stream_ssl stream_return/)
26+
->has_daemon('openssl');
27+
28+
$t->write_file_expand('nginx.conf', <<'EOF');
29+
30+
%%TEST_GLOBALS%%
31+
32+
daemon off;
33+
34+
events {
35+
}
36+
37+
stream {
38+
server {
39+
listen 127.0.0.1:8080;
40+
proxy_pass 127.0.0.1:8081;
41+
proxy_ssl on;
42+
43+
proxy_ssl_certificate localhost.crt;
44+
proxy_ssl_certificate_key localhost.key;
45+
proxy_ssl_conf_command Certificate override.crt;
46+
proxy_ssl_conf_command PrivateKey override.key;
47+
}
48+
49+
server {
50+
listen 127.0.0.1:8081 ssl;
51+
return $ssl_client_s_dn;
52+
53+
ssl_certificate localhost.crt;
54+
ssl_certificate_key localhost.key;
55+
ssl_verify_client optional_no_ca;
56+
}
57+
}
58+
59+
EOF
60+
61+
$t->write_file('openssl.conf', <<EOF);
62+
[ req ]
63+
default_bits = 2048
64+
encrypt_key = no
65+
distinguished_name = req_distinguished_name
66+
[ req_distinguished_name ]
67+
EOF
68+
69+
my $d = $t->testdir();
70+
71+
foreach my $name ('localhost', 'override') {
72+
system('openssl req -x509 -new '
73+
. "-config $d/openssl.conf -subj /CN=$name/ "
74+
. "-out $d/$name.crt -keyout $d/$name.key "
75+
. ">>$d/openssl.out 2>&1") == 0
76+
or die "Can't create certificate for $name: $!\n";
77+
}
78+
79+
$t->write_file('index.html', '');
80+
$t->try_run('no proxy_ssl_conf_command')->plan(1);
81+
82+
###############################################################################
83+
84+
like(http_get('/'), qr/CN=override/, 'Certificate');
85+
86+
###############################################################################

0 commit comments

Comments
 (0)