summaryrefslogtreecommitdiffstats
path: root/tests/SSLTest.pm
blob: 60f8188e700cb0c332bdef1e063177224a07ce7b (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
package SSLTest;

use strict;
use warnings;

use SSLServer;
use WgetTests;
use HTTPTest;

our @ISA = qw(WgetTest HTTPTest);
my $VERSION = 0.01;

my $srcdir;
if (defined $ENV{srcdir}) {
    $srcdir = Cwd::abs_path($ENV{srcdir});
} else {
    $srcdir = ".";
}

my %ssl_defaults = (
    _certfile  => "$srcdir/certs/server-cert.pem",
    _keyfile   => "$srcdir/certs/server-key.pem",
    _cafile    => "$srcdir/certs/test-ca-cert.pem",
    _ciphers   => 'ALL',
    _lhostname => 'wgettestingserver',
    _sslport   => 55443,
);

{
    my %_attr_data = %ssl_defaults;

    sub _default_for
    {
        my ($self, $attr) = @_;
        return $_attr_data{$attr} if exists $_attr_data{$attr};
        return $self->SUPER::_default_for($attr);
    }

    sub _standard_keys
    {
        my ($self) = @_;
        ($self->SUPER::_standard_keys(), keys %_attr_data);
    }
}

sub _setup_server
{
    my $self = shift;
    my %ssl_config = %ssl_defaults;

    $self->{_server} = SSLServer->new()
        or die "Cannot create SSL server!!!";

    for my $attrname ($self->_standard_keys())
    {
        my ($argname) = ($attrname =~ m/^_(.*)/msx);
        $ssl_config{$argname} = $self->{$attrname};
    }
#    for my $attrname (keys %ssl_config)
#    {
#        if ($attrname =~ m/file$/ && !$attrname =~ m/^\//)
#        {
#            my $cwd = $self->SUPER::_default_for('_workdir');
#            my $cfile = $ssl_config{$attrname};
#            $ssl_config{$attrname} = "$cwd/$cfile";
#        }
#    }
    $self->{_server}->init(%ssl_config);
}

1;

# vim: et ts=4 sw=4