]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: check for IMAP auth errors
authorEric Wong <e@80x24.org>
Thu, 18 Feb 2021 20:22:25 +0000 (23:22 +0300)
committerEric Wong <e@80x24.org>
Fri, 19 Feb 2021 00:02:22 +0000 (20:02 -0400)
We need to ensure authentication failures and error codes get
propagated to the parent process(es) properly.

v2: update MANIFEST
v3: LeiAuth.pm ->_lei_cfg bit moved to a previous commit

MANIFEST
lib/PublicInbox/NetReader.pm
xt/lei-auth-fail.t [new file with mode: 0644]

index 19f733568648de1f342cbc2eb1d197c540187e20..3d9ad616cd488b9daaa240c8bcdbc0a09f90863f 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -466,6 +466,7 @@ xt/git_async_cmp.t
 xt/httpd-async-stream.t
 xt/imapd-mbsync-oimap.t
 xt/imapd-validate.t
+xt/lei-auth-fail.t
 xt/lei-sigpipe.t
 xt/mem-imapd-tls.t
 xt/mem-msgview.t
index ad8c18d0df132c4687ec167c1224d67ddd55d1e8..61ea538b75cbcda7e8fdbf09df5bf3f498208a96 100644 (file)
@@ -89,6 +89,9 @@ sub mic_for { # mic = Mail::IMAPClient
                $self->{mic_arg}->{uri_section($uri)} = $mic_arg;
        } else {
                $err = "E: <$url> LOGIN: $@\n";
+               if ($cred && defined($cred->{password})) {
+                       $err =~ s/\Q$cred->{password}\E/*******/g;
+               }
                $mic = undef;
        }
        $cred->run($mic ? 'approve' : 'reject') if $cred;
diff --git a/xt/lei-auth-fail.t b/xt/lei-auth-fail.t
new file mode 100644 (file)
index 0000000..5308d0f
--- /dev/null
@@ -0,0 +1,20 @@
+#!perl -w
+# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict; use v5.10.1; use PublicInbox::TestCommon;
+
+# TODO: mock IMAP server which fails at authentication so we don't
+# have to make external connections to test this:
+my $imap_fail = $ENV{TEST_LEI_IMAP_FAIL_URL} //
+       'imaps://AzureDiamond:Hunter2@public-inbox.org:994/INBOX';
+test_lei(sub {
+       ok(!lei(qw(convert -o mboxrd:/dev/stdout), $imap_fail),
+               'IMAP auth failure on convert');
+       like($lei_err, qr!\bE:.*?imaps://.*?!sm, 'error shown');
+       unlike($lei_err, qr!Hunter2!s, 'password not shown');
+       is($lei_out, '', 'nothing output');
+       ok(!lei(qw(import), $imap_fail), 'IMAP auth failure on import');
+       like($lei_err, qr!\bE:.*?imaps://.*?!sm, 'error shown');
+       unlike($lei_err, qr!Hunter2!s, 'password not shown');
+});
+done_testing;