summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/t/90live-sni.t
blob: eb5bb5d8d5cf26b08337a998fad8db6b9f2f42eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
use Test::More;
use t::Util;

our $CA_CERT = "misc/test-ca/ca.crt";

# using wget since curl of OS X 10.9.5 returns invalid certificate chain error with the test
plan skip_all => 'wget not found'
    unless prog_exists('wget');

plan skip_all => 'only wget >= 1.14 supports SNI'
    unless `wget --version` =~ /^GNU Wget 1\.([0-9]+)/ && $1 >= 14;

plan skip_all => "skipping live tests (setenv LIVE_TESTS=1 to run them)"
    unless $ENV{LIVE_TESTS};

subtest "basic" => sub {
    my $server = spawn_h2o(sub {
        my ($port, $tls_port) = @_;
        return << "EOT";
hosts:
  "127.0.0.1.xip.io:$tls_port":
    paths:
      /:
        file.dir: examples/doc_root
  "alternate.127.0.0.1.xip.io:$tls_port":
    listen:
      port: $tls_port
      ssl:
        key-file: examples/h2o/alternate.key
        certificate-file: examples/h2o/alternate.crt
    paths:
      /:
        file.dir: examples/doc_root.alternate
EOT
    });

    do_test(
        "127.0.0.1.xip.io:$server->{tls_port}",
        md5_file("examples/doc_root/index.html"),
    );

    do_test(
        "alternate.127.0.0.1.xip.io:$server->{tls_port}",
        md5_file("examples/doc_root.alternate/index.txt"),
    );
};

subtest "wildcard" => sub {
    my $server = spawn_h2o(sub {
        my ($port, $tls_port) = @_;
        return << "EOT";
hosts:
  "127.0.0.1.xip.io:$tls_port":
    paths:
      /:
        file.dir: examples/doc_root
  "*.127.0.0.1.xip.io:$tls_port":
    listen:
      port: $tls_port
      ssl:
        key-file: examples/h2o/alternate.key
        certificate-file: examples/h2o/alternate.crt
    paths:
      /:
        file.dir: examples/doc_root.alternate
EOT
    });

    do_test(
        "127.0.0.1.xip.io:$server->{tls_port}",
        md5_file("examples/doc_root/index.html"),
    );

    do_test(
        "alternate.127.0.0.1.xip.io:$server->{tls_port}",
        md5_file("examples/doc_root.alternate/index.txt"),
    );
};


done_testing();

sub do_test {
    my ($authority, $md5_expected) = @_;
    my $content = `wget -nv --ca-certificate=$CA_CERT -O - https://$authority/`;
    is $?, 0, "wget returns success";
    is md5_hex($content), $md5_expected, "content is as expected";
}