@@ -29,20 +29,20 @@ subtest 'Web server with valid certificates' => sub {
29
29
30
30
subtest ' No certificate' => sub {
31
31
my $ua = Mojo::UserAgent-> new(ioloop => Mojo::IOLoop-> singleton);
32
- my $tx = $ua -> get(" https://127.0.0.1 :$port " );
32
+ my $tx = $ua -> get(" https://localhost :$port " );
33
33
ok $tx -> error, ' has error' ;
34
- $tx = $ua -> get(" https://127.0.0.1 :$port " );
34
+ $tx = $ua -> get(" https://localhost :$port " );
35
35
ok $tx -> error, ' has error' ;
36
- $tx = $ua -> ca(' t/mojo/certs/ca.crt' )-> get(" https://127.0.0.1 :$port " );
36
+ $tx = $ua -> ca(' t/mojo/certs/ca.crt' )-> get(" https://localhost :$port " );
37
37
ok $tx -> error, ' has error' ;
38
- $tx = $ua -> get(" https://127.0.0.1 :$port " );
38
+ $tx = $ua -> get(" https://localhost :$port " );
39
39
ok $tx -> error, ' has error' ;
40
40
};
41
41
42
42
subtest ' Valid certificates' => sub {
43
43
my $ua = Mojo::UserAgent-> new(ioloop => Mojo::IOLoop-> singleton);
44
44
$ua -> ca(' t/mojo/certs/ca.crt' )-> cert(' t/mojo/certs/client.crt' )-> key(' t/mojo/certs/client.key' );
45
- my $tx = $ua -> get(" https://127.0.0.1 :$port " );
45
+ my $tx = $ua -> get(" https://localhost :$port " );
46
46
ok !$tx -> error, ' no error' ;
47
47
is $tx -> res-> code, 200, ' right status' ;
48
48
is $tx -> res-> body, ' works!' , ' right content' ;
@@ -54,7 +54,7 @@ subtest 'Web server with valid certificates' => sub {
54
54
local $ENV {MOJO_CERT_FILE } = ' t/mojo/certs/client.crt' ;
55
55
local $ENV {MOJO_KEY_FILE } = ' t/mojo/certs/client.key' ;
56
56
local $ENV {MOJO_INSECURE } = 0;
57
- my $tx = $ua -> get(" https://127.0.0.1 :$port " );
57
+ my $tx = $ua -> get(" https://localhost :$port " );
58
58
is $ua -> ca, ' t/mojo/certs/ca.crt' , ' right path' ;
59
59
is $ua -> cert, ' t/mojo/certs/client.crt' , ' right path' ;
60
60
is $ua -> key, ' t/mojo/certs/client.key' , ' right path' ;
@@ -67,7 +67,7 @@ subtest 'Web server with valid certificates' => sub {
67
67
subtest ' Invalid certificate' => sub {
68
68
my $ua = Mojo::UserAgent-> new(ioloop => Mojo::IOLoop-> singleton);
69
69
$ua -> cert(' t/mojo/certs/bad.crt' )-> key(' t/mojo/certs/bad.key' );
70
- my $tx = $ua -> get(" https://127.0.0.1 :$port " );
70
+ my $tx = $ua -> get(" https://localhost :$port " );
71
71
ok $tx -> error, ' has error' ;
72
72
};
73
73
};
@@ -82,43 +82,48 @@ subtest 'Web server with valid certificates and no verification' => sub {
82
82
. ' &ca=t/mojo/certs/ca.crt'
83
83
. ' &ciphers=AES256-SHA:ALL'
84
84
. ' &verify=0x00'
85
- . ' &version=TLSv1 ' ;
85
+ . ' &version=TLSv1_2 ' ;
86
86
my $port = $daemon -> listen ([$listen ])-> start-> ports-> [0];
87
87
88
88
# Invalid certificate
89
89
my $ua = Mojo::UserAgent-> new(ioloop => Mojo::IOLoop-> singleton);
90
90
$ua -> cert(' t/mojo/certs/bad.crt' )-> key(' t/mojo/certs/bad.key' );
91
- my $tx = $ua -> get(" https://127.0.0.1 :$port " );
91
+ my $tx = $ua -> get(" https://localhost :$port " );
92
92
ok $tx -> error, ' has error' ;
93
93
$ua = Mojo::UserAgent-> new(ioloop => $ua -> ioloop, insecure => 1);
94
94
$ua -> cert(' t/mojo/certs/bad.crt' )-> key(' t/mojo/certs/bad.key' );
95
- $tx = $ua -> get(" https://127.0.0.1 :$port " );
95
+ $tx = $ua -> get(" https://localhost :$port " );
96
96
ok !$tx -> error, ' no error' ;
97
97
is $ua -> ioloop-> stream($tx -> connection)-> handle-> get_cipher, ' AES256-SHA' , ' AES256-SHA has been negotiatied' ;
98
- is $ua -> ioloop-> stream($tx -> connection)-> handle-> get_sslversion, ' TLSv1 ' , ' TLSv1 has been negotiatied' ;
98
+ is $ua -> ioloop-> stream($tx -> connection)-> handle-> get_sslversion, ' TLSv1_2 ' , ' TLSv1.2 has been negotiatied' ;
99
99
};
100
100
101
101
subtest ' Client side TLS options' => sub {
102
102
my $daemon = Mojo::Server::Daemon-> new(app => app, ioloop => Mojo::IOLoop-> singleton, silent => 1);
103
- my $listen = ' https://127.0.0.1/?version=TLSv1_1' ;
104
- my $port = $daemon -> listen ([$listen ])-> start-> ports-> [0];
103
+ my $listen
104
+ = ' https://127.0.0.1'
105
+ . ' ?cert=t/mojo/certs/server.crt'
106
+ . ' &key=t/mojo/certs/server.key'
107
+ . ' &ca=t/mojo/certs/ca.crt'
108
+ . ' &version=TLSv1_2' ;
109
+ my $port = $daemon -> listen ([$listen ])-> start-> ports-> [0];
105
110
106
111
subtest ' (Not) setting verification mode' => sub {
107
112
my $ua = Mojo::UserAgent-> new(ioloop => Mojo::IOLoop-> singleton);
108
- my $tx = $ua -> get(" https://127.0.0.1 :$port " );
113
+ my $tx = $ua -> get(" https://localhost :$port " );
109
114
like $tx -> error-> {message }, qr / certificate verify failed/ , ' has error' ;
110
115
111
116
$ua = Mojo::UserAgent-> new(ioloop => Mojo::IOLoop-> singleton);
112
117
$ua -> tls_options({SSL_verify_mode => 0x00});
113
- $tx = $ua -> get(" https://127.0.0.1 :$port " );
118
+ $tx = $ua -> get(" https://localhost :$port " );
114
119
ok !$tx -> error, ' no error' ;
115
120
};
116
121
117
122
subtest ' Setting acceptable protocol version' => sub {
118
123
my $ua = Mojo::UserAgent-> new(ioloop => Mojo::IOLoop-> singleton);
119
- $ua -> tls_options({SSL_version => ' TLSv1_2 ' });
120
- my $tx = $ua -> get(" https://127.0.0.1 :$port " );
121
- like $tx -> error-> {message }, qr /wrong ssl version/ , ' has error' ;
124
+ $ua -> tls_options({SSL_version => ' TLSv1_3 ' });
125
+ my $tx = $ua -> get(" https://localhost :$port " );
126
+ like $tx -> error-> {message }, qr /tlsv1 alert protocol version/ , ' has error' ;
122
127
};
123
128
};
124
129
0 commit comments