Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 76b52d17 authored by cketti's avatar cketti Committed by cketti
Browse files

IMAP: Ignore errors during LOGIN fallback and throw original exception

parent faf3a0b6
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -449,7 +449,22 @@ internal class RealImapConnection(
                throw e
            }

            loginOrThrow(e)
        }
    }

    @Suppress("ThrowsCount")
    private fun loginOrThrow(originalException: AuthenticationFailedException): List<ImapResponse> {
        return try {
            login()
        } catch (e: AuthenticationFailedException) {
            throw e
        } catch (e: IOException) {
            Timber.d(e, "LOGIN fallback failed")
            throw originalException
        } catch (e: MessagingException) {
            Timber.d(e, "LOGIN fallback failed")
            throw originalException
        }
    }

+27 −0
Original line number Diff line number Diff line
@@ -990,6 +990,33 @@ class RealImapConnectionTest {
        server.verifyInteractionCompleted()
    }

    @Test
    fun `disconnect during LOGIN fallback should throw AuthenticationFailedException`() {
        val server = MockImapServer().apply {
            output("* OK example.org server")
            expect("1 CAPABILITY")
            output("* CAPABILITY IMAP4 IMAP4REV1 AUTH=PLAIN")
            output("1 OK CAPABILITY Completed")
            expect("2 AUTHENTICATE PLAIN")
            output("+")
            expect("\u0000$USERNAME\u0000$PASSWORD".base64())
            output("2 NO AUTHENTICATE failed")
            expect("3 LOGIN \"$USERNAME\" \"$PASSWORD\"")
            output("* BYE IMAP server terminating connection")
            closeConnection()
        }
        val imapConnection = startServerAndCreateImapConnection(server)

        try {
            imapConnection.open()
            fail("Expected exception")
        } catch (e: AuthenticationFailedException) {
            assertThat(e.messageFromServer).isEqualTo("AUTHENTICATE failed")
        }

        server.verifyInteractionCompleted()
    }

    private fun createImapConnection(
        settings: ImapSettings,
        socketFactory: TrustedSocketFactory,