File: snihostcheck.t

package info (click to toggle)
apache2 2.4.66-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 59,884 kB
  • sloc: ansic: 212,340; python: 13,830; perl: 11,307; sh: 7,266; php: 1,320; javascript: 1,314; awk: 749; makefile: 715; lex: 374; yacc: 161; xml: 2
file content (56 lines) | stat: -rw-r--r-- 1,341 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestRequest;
use Apache::TestUtil;
use MIME::Base64;
use Data::Dumper;
use HTTP::Response;
use Socket;

Apache::TestRequest::scheme('https');
my $vars = Apache::Test::vars();

my @ssl_test_cases = (
  [ "unmatched"      => 200, "no hop, stays on default vhost"],
  # To run without SSLVHostSNIPolicy, prefix t/TEST with env NO_TEST_SNIPOLICY=/tmp (any file or dir)
  [ "nvh"            => defined($ENV{'NO_TEST_SNIPOLICY'}) ? 421 : 200, "hop allowed by global directive"],
);

plan tests => scalar(@ssl_test_cases);


foreach my $vhosts (([$vars->{ssl_module_name} => 1])) {
  my $vhost = $vhosts->[0];

  foreach my $t (@ssl_test_cases) {
    my $host = $t->[0];
    my $expect = $t->[1];
    my $desc = $t->[2];

    my $r = GET("/", 'Host' => $host);
    ok t_cmp($r->code, $expect, $desc);
  }
}

sub escape
{
    my $in = shift;
    $in =~ s{\\}{\\\\}g;
    $in =~ s{\r}{\\r}g;
    $in =~ s{\n}{\\n}g;
    $in =~ s{\t}{\\t}g;
    $in =~ s{([\x00-\x1f])}{sprintf("\\x%02x", ord($1))}ge;
    return $in;
}

sub peer
{
   my $sock = shift;
   my $hersockaddr    = getpeername($sock);
   my ($port, $iaddr) = sockaddr_in($hersockaddr);
   my $herhostname    = gethostbyaddr($iaddr, AF_INET);
   my $herstraddr     = inet_ntoa($iaddr);
   return "$herstraddr:$port";
}