user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCHv3 4/4] lei: check for IMAP auth errors
Date: Thu, 18 Feb 2021 23:22:25 +0300	[thread overview]
Message-ID: <20210218202225.85440-5-e@80x24.org> (raw)
In-Reply-To: <20210218110647.9822-2-e@80x24.org>

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                     |  1 +
 lib/PublicInbox/NetReader.pm |  3 +++
 xt/lei-auth-fail.t           | 20 ++++++++++++++++++++
 3 files changed, 24 insertions(+)
 create mode 100644 xt/lei-auth-fail.t

diff --git a/MANIFEST b/MANIFEST
index 19f73356..3d9ad616 100644
--- 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
diff --git a/lib/PublicInbox/NetReader.pm b/lib/PublicInbox/NetReader.pm
index ad8c18d0..61ea538b 100644
--- a/lib/PublicInbox/NetReader.pm
+++ b/lib/PublicInbox/NetReader.pm
@@ -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
index 00000000..5308d0f9
--- /dev/null
+++ b/xt/lei-auth-fail.t
@@ -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;

  parent reply	other threads:[~2021-02-18 20:22 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-17 10:06 [PATCH 00/11] lei IMAP read support Eric Wong
2021-02-17 10:06 ` [PATCH 01/11] lei: bless config Eric Wong
2021-02-17 10:06 ` [PATCH 02/11] watch: move imap_common_init to NetReader Eric Wong
2021-02-17 10:06 ` [PATCH 03/11] watch: connect to NNTP and IMAP in config order Eric Wong
2021-02-17 10:07 ` [PATCH 04/11] lei import: start rearranging code for IMAP support Eric Wong
2021-02-17 10:07 ` [PATCH 05/11] lei import: move check_input_format to lei Eric Wong
2021-02-17 10:07 ` [PATCH 06/11] tests: setup_public_inboxes: use IMAP-friendly newsgroups Eric Wong
2021-02-17 10:07 ` [PATCH 07/11] t/lei_to_mail: remove unnecessary arg passing Eric Wong
2021-02-17 10:07 ` [PATCH 08/11] lei convert: mail format conversion sub-command Eric Wong
2021-02-17 10:53   ` Eric Wong
2021-02-18 11:06     ` [PATCHv2 0/4] lei IMAP support take #2 Eric Wong
2021-02-18 11:06       ` [PATCHv2 1/4] lei convert: mail format conversion sub-command Eric Wong
2021-02-18 20:22         ` [PATCHv3 0/4] lei convert IMAP support Eric Wong
2021-02-18 20:22         ` [PATCHv3 1/4] lei convert: mail format conversion sub-command Eric Wong
2021-02-18 20:22         ` [PATCHv3 2/4] lei import: add IMAP and (maildir|mbox*):$PATHNAME support Eric Wong
2021-02-18 20:22         ` [PATCHv3 3/4] lei: consolidate the bulk of the IPC code Eric Wong
2021-02-18 20:22         ` Eric Wong [this message]
2021-02-18 11:06       ` [PATCHv2 2/4] lei import: add IMAP and (maildir|mbox*):$PATHNAME support Eric Wong
2021-02-18 11:06       ` [PATCH (resend) 3/4] lei: consolidate the bulk of the IPC code Eric Wong
2021-02-18 11:06       ` [PATCHv2 4/4] lei: check for IMAP auth errors Eric Wong
2021-02-17 10:07 ` [PATCH 09/11] lei import: add IMAP, (maildir|mbox*):$PATHNAME support Eric Wong
2021-02-17 10:07 ` [PATCH 10/11] lei: consolidate the bulk of the IPC code Eric Wong
2021-02-17 10:07 ` [PATCH 11/11] lei: check for IMAP auth errors Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210218202225.85440-5-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    --subject='Re: [PATCHv3 4/4] lei: check for IMAP auth errors' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).