comparison proxy_ssl_conf_command.t @ 1604:4be791074207

Tests: proxy_ssl_conf_command tests.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 23 Oct 2020 13:22:19 +0100
parents
children f6795e2e6a4b
comparison
equal deleted inserted replaced
1603:8d2d37a4b48e 1604:4be791074207
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 ###############################################################################