X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fimapd-tls.t;h=44ab350c95b34a7240320e41a88803e3643779e1;hb=d3c6f8e57b15e8d3de0431c8419bdd0497ec3d32;hp=5352d100e4b8517eba4192e894eba0b8337185b7;hpb=29f3d0554f91a7b7aab40130e14179553ee7cb3f;p=public-inbox.git
diff --git a/t/imapd-tls.t b/t/imapd-tls.t
index 5352d100..44ab350c 100644
--- a/t/imapd-tls.t
+++ b/t/imapd-tls.t
@@ -1,12 +1,12 @@
-# Copyright (C) 2020 all contributors
+#!perl -w
+# Copyright (C) 2020-2021 all contributors
# License: AGPL-3.0+
use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
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));
+require_mods(qw(-imapd IO::Socket::SSL Mail::IMAPClient IO::Poll));
my $imap_client = 'Mail::IMAPClient';
$imap_client->can('starttls') or
plan skip_all => 'Mail::IMAPClient does not support TLS';
@@ -24,53 +24,35 @@ unless (-r $key && -r $cert) {
}
use_ok 'PublicInbox::TLS';
use_ok 'IO::Socket::SSL';
-use PublicInbox::InboxWritable;
-require PublicInbox::SearchIdx;
my $version = 1; # v2 needs newer git
require_git('2.6') if $version >= 2;
my ($tmpdir, $for_destroy) = tmpdir();
my $err = "$tmpdir/stderr.log";
my $out = "$tmpdir/stdout.log";
-my $inboxdir = "$tmpdir";
-my $pi_config = "$tmpdir/pi_config";
+my $pi_config;
my $group = 'test-imapd-tls';
my $addr = $group . '@example.com';
my $starttls = tcp_server();
my $imaps = tcp_server();
-my $ibx = PublicInbox::Inbox->new({
- inboxdir => $inboxdir,
- name => 'imapd-tls',
- version => $version,
- -primary_address => $addr,
- indexlevel => 'basic',
-});
-$ibx = PublicInbox::InboxWritable->new($ibx, {nproc=>1});
-$ibx->init_inbox(0);
-{
+my $ibx = create_inbox 'imapd-tls', version => $version,
+ -primary_address => $addr, indexlevel => 'basic', sub {
+ my ($im, $ibx) = @_;
+ $im->add(eml_load('t/data/0001.patch')) or BAIL_OUT '->add';
+ $pi_config = "$ibx->{inboxdir}/pi_config";
open my $fh, '>', $pi_config or BAIL_OUT "open: $!";
- print $fh <{inboxdir}
address = $addr
indexlevel = basic
newsgroup = $group
EOF
- ;
close $fh or BAIL_OUT "close: $!\n";
-}
+};
+$pi_config //= "$ibx->{inboxdir}/pi_config";
-{
- my $im = $ibx->importer(0);
- ok($im->add(eml_load('t/data/0001.patch')), 'message added');
- $im->done;
- if ($version == 1) {
- my $s = PublicInbox::SearchIdx->new($ibx, 1);
- $s->index_sync;
- }
-}
-
-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;
@@ -113,7 +95,9 @@ for my $args (
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');
@@ -171,6 +155,13 @@ for my $args (
ok(sysread($slow, my $end, 4096) > 0, 'got end');
is(sysread($slow, my $eof, 4096), 0, 'got EOF');
+ test_lei(sub {
+ lei_ok qw(ls-mail-source), "imap://$starttls_addr",
+ \'STARTTLS not used by default';
+ ok(!lei(qw(ls-mail-source -c imap.starttls=true),
+ "imap://$starttls_addr"), 'STARTTLS verify fails');
+ });
+
SKIP: {
skip 'TCP_DEFER_ACCEPT is Linux-only', 2 if $^O ne 'linux';
my $var = eval { Socket::TCP_DEFER_ACCEPT() } // 9;
@@ -185,10 +176,11 @@ for my $args (
skip 'accf_data not loaded? kldload accf_data', 2;
}
require PublicInbox::Daemon;
- my $var = PublicInbox::Daemon::SO_ACCEPTFILTER();
- my $x = getsockopt($imaps, SOL_SOCKET, $var);
+ my $x = getsockopt($imaps, SOL_SOCKET,
+ $PublicInbox::Daemon::SO_ACCEPTFILTER);
like($x, qr/\Adataready\0+\z/, 'got dataready accf for IMAPS');
- $x = getsockopt($starttls, IPPROTO_TCP, $var);
+ $x = getsockopt($starttls, IPPROTO_TCP,
+ $PublicInbox::Daemon::SO_ACCEPTFILTER);
is($x, undef, 'no BSD accept filter for plain IMAP');
};