X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fimapd-tls.t;h=ab90ddec4738fb54fae016a6bd2518ac7956fe32;hb=860169adcd29341142b7c4a369c09b4ac492bd1e;hp=9f5abfe048ef339bca707ab077ea203ca88cd9b3;hpb=90f11ce471c53365a77896c847d0a39b0995b5b5;p=public-inbox.git
diff --git a/t/imapd-tls.t b/t/imapd-tls.t
index 9f5abfe0..ab90ddec 100644
--- a/t/imapd-tls.t
+++ b/t/imapd-tls.t
@@ -1,4 +1,4 @@
-# Copyright (C) 2020 all contributors
+# Copyright (C) 2020-2021 all contributors
# License: AGPL-3.0+
use strict;
use warnings;
@@ -6,9 +6,17 @@ use Test::More;
use Socket qw(IPPROTO_TCP SOL_SOCKET);
use PublicInbox::TestCommon;
# IO::Poll is part of the standard library, but distros may split it off...
-require_mods(qw(DBD::SQLite IO::Socket::SSL Mail::IMAPClient IO::Poll));
-Mail::IMAPClient->can('starttls') or
+require_mods(qw(DBD::SQLite IO::Socket::SSL Mail::IMAPClient IO::Poll
+ Email::Address::XS||Mail::Address Parse::RecDescent));
+my $imap_client = 'Mail::IMAPClient';
+$imap_client->can('starttls') or
plan skip_all => 'Mail::IMAPClient does not support TLS';
+my $can_compress = $imap_client->can('compress');
+if ($can_compress) { # hope this gets fixed upstream, soon
+ require PublicInbox::IMAPClient;
+ $imap_client = 'PublicInbox::IMAPClient';
+}
+
my $cert = 'certs/server-cert.pem';
my $key = 'certs/server-key.pem';
unless (-r $key && -r $cert) {
@@ -62,23 +70,11 @@ EOF
}
}
-my $imaps_addr = $imaps->sockhost . ':' . $imaps->sockport;
-my $starttls_addr = $starttls->sockhost . ':' . $starttls->sockport;
+my $imaps_addr = tcp_host_port($imaps);
+my $starttls_addr = tcp_host_port($starttls);
my $env = { PI_CONFIG => $pi_config };
my $td;
-# Mail::IMAPClient ->compress creates cyclic reference:
-# https://rt.cpan.org/Ticket/Display.html?id=132654
-my $compress_logout = sub {
- my ($c) = @_;
- ok($c->logout, 'logout ok after ->compress');
- # all documented in Mail::IMAPClient manpage:
- for (qw(Readmoremethod Readmethod Prewritemethod)) {
- $c->$_(undef);
- }
-};
-
-
for my $args (
[ "--cert=$cert", "--key=$key",
"-limaps://$imaps_addr",
@@ -112,22 +108,24 @@ for my $args (
Server => $imaps->sockhost,
Port => $imaps->sockport);
# IMAPS
- my $c = Mail::IMAPClient->new(%imaps_opt, Ssl => [ %o ]);
+ my $c = $imap_client->new(%imaps_opt, Ssl => [ %o ]);
ok($c && $c->IsAuthenticated, 'authenticated');
ok($c->select($group), 'SELECT works');
ok(!(scalar $c->has_capability('STARTTLS')),
'starttls not advertised with IMAPS');
ok(!$c->starttls, "starttls fails");
- ok($c->has_capability('COMPRESS'), 'compress advertised');
+ ok($c->has_capability('COMPRESS') ||
+ $c->has_capability('COMPRESS=DEFLATE'),
+ 'compress advertised');
ok($c->compress, 'compression enabled with IMAPS');
ok(!$c->starttls, 'starttls still fails');
ok($c->noop, 'noop succeeds');
- $compress_logout->($c);
+ ok($c->logout, 'logout succeeds');
# STARTTLS
my %imap_opt = (Server => $starttls->sockhost,
Port => $starttls->sockport);
- $c = Mail::IMAPClient->new(%imap_opt);
+ $c = $imap_client->new(%imap_opt);
ok(scalar $c->has_capability('STARTTLS'),
'starttls advertised');
ok($c->Starttls([ %o ]), 'set starttls options');
@@ -141,25 +139,25 @@ for my $args (
ok($c->noop, 'NOOP works');
ok($c->compress, 'compression enabled with IMAPS');
ok($c->noop, 'NOOP works after compress');
- $compress_logout->($c);
+ ok($c->logout, 'logout succeeds after compress');
# STARTTLS with bad hostname
$o{SSL_hostname} = $o{SSL_verifycn_name} = 'server.invalid';
- $c = Mail::IMAPClient->new(%imap_opt);
+ $c = $imap_client->new(%imap_opt);
ok(scalar $c->has_capability('STARTTLS'), 'starttls advertised');
ok($c->Starttls([ %o ]), 'set starttls options');
ok(!$c->starttls, '->starttls fails with bad hostname');
- $c = Mail::IMAPClient->new(%imap_opt);
+ $c = $imap_client->new(%imap_opt);
ok($c->noop, 'NOOP still works from plain IMAP');
# IMAPS with bad hostname
- $c = Mail::IMAPClient->new(%imaps_opt, Ssl => [ %o ]);
+ $c = $imap_client->new(%imaps_opt, Ssl => [ %o ]);
is($c, undef, 'IMAPS fails with bad hostname');
# make hostname valid
$o{SSL_hostname} = $o{SSL_verifycn_name} = 'server.local';
- $c = Mail::IMAPClient->new(%imaps_opt, Ssl => [ %o ]);
+ $c = $imap_client->new(%imaps_opt, Ssl => [ %o ]);
ok($c, 'IMAPS succeeds again with valid hostname');
# slow TLS connection did not block the other fast clients while