Fix missing outgoing check

This commit is contained in:
Wolf-Martell Montwé 2024-02-09 13:31:35 +01:00
parent 3a121f335b
commit 208e4fd8df
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
2 changed files with 36 additions and 6 deletions

View file

@ -26,7 +26,9 @@ internal class GetAutoDiscovery(
}
private fun validateOAuthSupport(settings: AutoDiscoveryResult.Settings): AutoDiscoveryResult {
if (settings.incomingServerSettings !is ImapServerSettings) {
if (settings.incomingServerSettings !is ImapServerSettings ||
settings.outgoingServerSettings !is SmtpServerSettings
) {
return AutoDiscoveryResult.NoUsableSettingsFound
}

View file

@ -6,6 +6,7 @@ import app.k9mail.autodiscovery.api.AutoDiscoveryService
import app.k9mail.autodiscovery.api.ConnectionSecurity
import app.k9mail.autodiscovery.api.ImapServerSettings
import app.k9mail.autodiscovery.api.IncomingServerSettings
import app.k9mail.autodiscovery.api.OutgoingServerSettings
import app.k9mail.autodiscovery.api.SmtpServerSettings
import app.k9mail.core.common.mail.EmailAddress
import app.k9mail.core.common.net.toHostname
@ -48,9 +49,22 @@ class GetAutoDiscoveryTest {
}
@Test
fun `should return NoUsableSettingsFound result when server settings not supported`() = runTest {
fun `should return NoUsableSettingsFound result when incoming server settings not supported`() = runTest {
val useCase = GetAutoDiscovery(
service = FakeAutoDiscoveryService(SETTINGS_WITH_UNSUPPORTED_SERVER),
service = FakeAutoDiscoveryService(SETTINGS_WITH_UNSUPPORTED_INCOMING_SERVER),
oauthProvider = FakeOAuthConfigurationProvider(),
)
val result = useCase.execute("user@example.com")
assertThat(result)
.isInstanceOf<AutoDiscoveryResult.NoUsableSettingsFound>()
}
@Test
fun `should return NoUsableSettingsFound result when server outgoing settings not supported`() = runTest {
val useCase = GetAutoDiscovery(
service = FakeAutoDiscoveryService(SETTINGS_WITH_UNSUPPORTED_OUTGOING_SERVER),
oauthProvider = FakeOAuthConfigurationProvider(),
)
@ -124,7 +138,8 @@ class GetAutoDiscoveryTest {
override fun getConfiguration(hostname: String): OAuthConfiguration? = answer
}
private class UnsupportedServerSettings : IncomingServerSettings
private class UnsupportedIncomingServerSettings : IncomingServerSettings
private class UnsupportedOutgoingServerSettings : OutgoingServerSettings
private companion object {
private val SETTINGS_WITH_OAUTH = AutoDiscoveryResult.Settings(
@ -146,8 +161,8 @@ class GetAutoDiscoveryTest {
source = "source",
)
private val SETTINGS_WITH_UNSUPPORTED_SERVER = AutoDiscoveryResult.Settings(
incomingServerSettings = UnsupportedServerSettings(),
private val SETTINGS_WITH_UNSUPPORTED_INCOMING_SERVER = AutoDiscoveryResult.Settings(
incomingServerSettings = UnsupportedIncomingServerSettings(),
outgoingServerSettings = SmtpServerSettings(
hostname = "smtp.example.com".toHostname(),
port = 465.toPort(),
@ -159,6 +174,19 @@ class GetAutoDiscoveryTest {
source = "source",
)
private val SETTINGS_WITH_UNSUPPORTED_OUTGOING_SERVER = AutoDiscoveryResult.Settings(
incomingServerSettings = ImapServerSettings(
hostname = "imap.example.com".toHostname(),
port = 993.toPort(),
connectionSecurity = ConnectionSecurity.TLS,
authenticationTypes = listOf(AuthenticationType.OAuth2, AuthenticationType.PasswordCleartext),
username = "user",
),
outgoingServerSettings = UnsupportedOutgoingServerSettings(),
isTrusted = true,
source = "source",
)
private val SETTINGS_WITH_PASSWORD = AutoDiscoveryResult.Settings(
incomingServerSettings = ImapServerSettings(
hostname = "imap.example.com".toHostname(),