"Fossies" - the Fresh Open Source Software Archive 
Member "memcached-1.6.15/t/ssl_session_resumption.t" (21 Feb 2022, 2010 Bytes) of package /linux/www/memcached-1.6.15.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 #!/usr/bin/perl
2
3 use warnings;
4 use Test::More;
5 use FindBin qw($Bin);
6 use lib "$Bin/lib";
7 use MemcachedTest;
8
9 if (!enabled_tls_testing()) {
10 plan skip_all => 'SSL testing is not enabled';
11 exit 0;
12 }
13
14 my $server;
15 my $sock;
16 my $stats;
17
18 my $session_cache = eval qq{ IO::Socket::SSL::Session_Cache->new(1); };
19
20 ### Disabled SSL session cache
21
22 $server = new_memcached();
23 $stats = mem_stats($server->sock);
24 is($stats->{ssl_new_sessions}, undef,
25 "new SSL sessions not recorded when session cache is disabled");
26 my $disabled_initial_total_conns = $stats->{total_connections};
27
28 $sock = $server->new_sock($session_cache, 'TLSv1_2');
29 $stats = mem_stats($sock);
30 cmp_ok($stats->{total_connections}, '>', $disabled_initial_total_conns,
31 "client-side session cache is noop in establishing a new connection");
32 is($sock->get_session_reused(), 0, "client-side session cache is unused");
33
34 ### Enabled SSL session cache
35
36 $server = new_memcached("-o ssl_session_cache");
37 # Support for session caching in IO::Socket::SSL for TLS v1.3 is incomplete.
38 # Here, we will deliberately force TLS v1.2 to test session caching.
39 $sock = $server->new_sock($session_cache, 'TLSv1_2');
40 $stats = mem_stats($sock);
41 cmp_ok($stats->{total_connections}, '>', 0, "initial connection is established");
42 SKIP: {
43 skip "sessions counter accuracy requires OpenSSL 1.1.1 or newer", 1;
44 cmp_ok($stats->{ssl_new_sessions}, '>', 0, "successful new SSL session");
45 }
46 my $enabled_initial_ssl_sessions = $stats->{ssl_new_sessions};
47 my $enabled_initial_total_conns = $stats->{total_connections};
48
49 # Create a new client with the same session cache
50 $sock = $server->new_sock($session_cache, 'TLSv1_2');
51 $stats = mem_stats($sock);
52 cmp_ok($stats->{total_connections}, '>', $enabled_initial_total_conns,
53 "new connection is established");
54 is($stats->{ssl_new_sessions}, $enabled_initial_ssl_sessions,
55 "no new SSL sessions are created on the server");
56 is($sock->get_session_reused(), 1,
57 "client-persisted session is reused");
58
59 done_testing();