Move server certificate to server module

This commit is contained in:
Wolf-Martell Montwé 2023-09-05 17:10:44 +02:00
parent 6acdf48e2d
commit dcad7a95b6
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
22 changed files with 91 additions and 87 deletions

View file

@ -61,8 +61,12 @@ class DependencyInjectionTest : AutoCloseKoinTest() {
withParameters(clazz = Class.forName("com.fsck.k9.view.K9WebViewClient").kotlin) {
parametersOf(null, null)
}
withParameter<ServerValidationContract.ViewModel>(named(KOIN_NAME_INCOMING_SERVER_VALIDATION)) { authStateStorage }
withParameter<ServerValidationContract.ViewModel>(named(KOIN_NAME_OUTGOING_SERVER_VALIDATION)) { authStateStorage }
withParameter<ServerValidationContract.ViewModel>(
named(KOIN_NAME_INCOMING_SERVER_VALIDATION),
) { authStateStorage }
withParameter<ServerValidationContract.ViewModel>(
named(KOIN_NAME_OUTGOING_SERVER_VALIDATION),
) { authStateStorage }
withParameter<ServerValidationDomainContract.UseCase.ValidateServerSettings> { authStateStorage }
withParameter<AccountRemoverWorker> { mock<WorkerParameters>() }
}

View file

@ -3,8 +3,8 @@ plugins {
}
android {
namespace = "app.k9mail.feature.account.servercertificate"
resourcePrefix = "account_servercertificate_"
namespace = "app.k9mail.feature.account.server.certificate"
resourcePrefix = "account_server_certificate_"
}
dependencies {

View file

@ -0,0 +1,29 @@
package app.k9mail.feature.account.server.certificate
import app.k9mail.feature.account.server.certificate.data.InMemoryServerCertificateErrorRepository
import app.k9mail.feature.account.server.certificate.domain.ServerCertificateDomainContract
import app.k9mail.feature.account.server.certificate.domain.usecase.AddServerCertificateException
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.module.Module
import org.koin.dsl.module
val featureAccountServerCertificateModule: Module = module {
single<ServerCertificateDomainContract.ServerCertificateErrorRepository> {
InMemoryServerCertificateErrorRepository()
}
factory<ServerCertificateDomainContract.UseCase.AddServerCertificateException> {
AddServerCertificateException(
localKeyStore = get(),
)
}
viewModel {
ServerCertificateErrorViewModel(
certificateErrorRepository = get(),
addServerCertificateException = get(),
)
}
}

View file

@ -1,11 +1,11 @@
package app.k9mail.feature.account.servercertificate.data
package app.k9mail.feature.account.server.certificate.data
import app.k9mail.feature.account.servercertificate.domain.AccountServerCertificateDomainContract
import app.k9mail.feature.account.servercertificate.domain.entity.ServerCertificateError
import app.k9mail.feature.account.server.certificate.domain.ServerCertificateDomainContract
import app.k9mail.feature.account.server.certificate.domain.entity.ServerCertificateError
class InMemoryServerCertificateErrorRepository(
private var serverCertificateError: ServerCertificateError? = null,
) : AccountServerCertificateDomainContract.ServerCertificateErrorRepository {
) : ServerCertificateDomainContract.ServerCertificateErrorRepository {
override fun getCertificateError(): ServerCertificateError? {
return serverCertificateError

View file

@ -1,9 +1,9 @@
package app.k9mail.feature.account.servercertificate.domain
package app.k9mail.feature.account.server.certificate.domain
import app.k9mail.feature.account.servercertificate.domain.entity.ServerCertificateError
import app.k9mail.feature.account.server.certificate.domain.entity.ServerCertificateError
import java.security.cert.X509Certificate
interface AccountServerCertificateDomainContract {
interface ServerCertificateDomainContract {
interface ServerCertificateErrorRepository {
fun getCertificateError(): ServerCertificateError?

View file

@ -1,4 +1,4 @@
package app.k9mail.feature.account.servercertificate.domain.entity
package app.k9mail.feature.account.server.certificate.domain.entity
import java.security.cert.X509Certificate

View file

@ -1,6 +1,6 @@
package app.k9mail.feature.account.servercertificate.domain.usecase
package app.k9mail.feature.account.server.certificate.domain.usecase
import app.k9mail.feature.account.servercertificate.domain.AccountServerCertificateDomainContract.UseCase
import app.k9mail.feature.account.server.certificate.domain.ServerCertificateDomainContract.UseCase
import com.fsck.k9.mail.ssl.LocalKeyStore
import java.security.cert.X509Certificate
import kotlinx.coroutines.CoroutineDispatcher

View file

@ -1,8 +1,8 @@
package app.k9mail.feature.account.servercertificate.ui
package app.k9mail.feature.account.server.certificate.ui
import app.k9mail.core.ui.compose.common.mvi.UnidirectionalViewModel
interface AccountServerCertificateErrorContract {
interface ServerCertificateErrorContract {
interface ViewModel : UnidirectionalViewModel<State, Event, Effect>

View file

@ -1,4 +1,4 @@
package app.k9mail.feature.account.servercertificate.ui
package app.k9mail.feature.account.server.certificate.ui
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Column
@ -21,11 +21,11 @@ import app.k9mail.core.ui.compose.designsystem.template.ResponsiveWidthContainer
import app.k9mail.core.ui.compose.designsystem.template.Scaffold
import app.k9mail.core.ui.compose.theme.K9Theme
import app.k9mail.core.ui.compose.theme.MainTheme
import app.k9mail.feature.account.servercertificate.data.InMemoryServerCertificateErrorRepository
import app.k9mail.feature.account.servercertificate.domain.entity.ServerCertificateError
import app.k9mail.feature.account.servercertificate.ui.AccountServerCertificateErrorContract.Effect
import app.k9mail.feature.account.servercertificate.ui.AccountServerCertificateErrorContract.Event
import app.k9mail.feature.account.servercertificate.ui.AccountServerCertificateErrorContract.ViewModel
import app.k9mail.feature.account.server.certificate.data.InMemoryServerCertificateErrorRepository
import app.k9mail.feature.account.server.certificate.domain.entity.ServerCertificateError
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorContract.Effect
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorContract.Event
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorContract.ViewModel
import java.security.cert.CertificateFactory
import java.security.cert.X509Certificate
import org.koin.androidx.compose.koinViewModel
@ -33,11 +33,11 @@ import org.koin.androidx.compose.koinViewModel
// Note: This is a placeholder with mostly hardcoded text.
// TODO: Replace with final design.
@Composable
fun CertificateErrorScreen(
fun ServerCertificateErrorScreen(
onCertificateAccepted: () -> Unit,
onBack: () -> Unit,
modifier: Modifier = Modifier,
viewModel: ViewModel = koinViewModel<AccountServerCertificateErrorViewModel>(),
viewModel: ViewModel = koinViewModel<ServerCertificateErrorViewModel>(),
) {
val (state, dispatch) = viewModel.observe { effect ->
when (effect) {
@ -102,7 +102,7 @@ fun CertificateErrorScreen(
@Composable
@DevicePreviews
internal fun CertificateErrorScreenK9Preview() {
internal fun ServerCertificateErrorScreenK9Preview() {
val inputStream = """
-----BEGIN CERTIFICATE-----
MIIE8jCCA9qgAwIBAgISA3bsPKY1eoe/RiBO2t8fUvh1MA0GCSqGSIb3DQEBCwUA
@ -145,10 +145,10 @@ internal fun CertificateErrorScreenK9Preview() {
)
K9Theme {
CertificateErrorScreen(
ServerCertificateErrorScreen(
onCertificateAccepted = {},
onBack = {},
viewModel = AccountServerCertificateErrorViewModel(
viewModel = ServerCertificateErrorViewModel(
addServerCertificateException = { _, _, _ -> },
certificateErrorRepository = InMemoryServerCertificateErrorRepository(serverCertificateError),
),

View file

@ -1,13 +1,13 @@
package app.k9mail.feature.account.servercertificate.ui
package app.k9mail.feature.account.server.certificate.ui
import androidx.lifecycle.viewModelScope
import app.k9mail.core.ui.compose.common.mvi.BaseViewModel
import app.k9mail.feature.account.servercertificate.domain.AccountServerCertificateDomainContract
import app.k9mail.feature.account.servercertificate.domain.AccountServerCertificateDomainContract.UseCase
import app.k9mail.feature.account.servercertificate.domain.entity.ServerCertificateError
import app.k9mail.feature.account.servercertificate.ui.AccountServerCertificateErrorContract.Effect
import app.k9mail.feature.account.servercertificate.ui.AccountServerCertificateErrorContract.Event
import app.k9mail.feature.account.servercertificate.ui.AccountServerCertificateErrorContract.State
import app.k9mail.feature.account.server.certificate.domain.ServerCertificateDomainContract
import app.k9mail.feature.account.server.certificate.domain.ServerCertificateDomainContract.UseCase
import app.k9mail.feature.account.server.certificate.domain.entity.ServerCertificateError
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorContract.Effect
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorContract.Event
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorContract.State
import com.fsck.k9.logging.Timber
import com.fsck.k9.mail.filter.Hex
import java.security.MessageDigest
@ -15,11 +15,11 @@ import java.security.NoSuchAlgorithmException
import java.security.cert.CertificateEncodingException
import kotlinx.coroutines.launch
class AccountServerCertificateErrorViewModel(
private val certificateErrorRepository: AccountServerCertificateDomainContract.ServerCertificateErrorRepository,
class ServerCertificateErrorViewModel(
private val certificateErrorRepository: ServerCertificateDomainContract.ServerCertificateErrorRepository,
private val addServerCertificateException: UseCase.AddServerCertificateException,
initialState: State = State(),
) : BaseViewModel<State, Event, Effect>(initialState), AccountServerCertificateErrorContract.ViewModel {
) : BaseViewModel<State, Event, Effect>(initialState), ServerCertificateErrorContract.ViewModel {
private val serverCertificateError: ServerCertificateError? = certificateErrorRepository.getCertificateError()
init {

View file

@ -1,6 +1,6 @@
package app.k9mail.feature.account.servercertificate
package app.k9mail.feature.account.server.certificate
import app.k9mail.feature.account.servercertificate.ui.AccountServerCertificateErrorContract
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorContract
import com.fsck.k9.mail.ssl.LocalKeyStore
import org.junit.Test
import org.koin.core.annotation.KoinExperimentalAPI
@ -12,7 +12,7 @@ import org.koin.test.check.checkModules
import org.koin.test.verify.verify
import org.mockito.Mockito
class AccountServerCertificateModuleKtTest : KoinTest {
class ServerCertificateModuleKtTest : KoinTest {
private val externalModule: Module = module {
single<LocalKeyStore> { Mockito.mock() }
@ -23,7 +23,7 @@ class AccountServerCertificateModuleKtTest : KoinTest {
fun `should have a valid di module`() {
featureAccountServerCertificateModule.verify(
extraTypes = listOf(
AccountServerCertificateErrorContract.State::class,
ServerCertificateErrorContract.State::class,
),
)

View file

@ -27,7 +27,7 @@ dependencies {
implementation(projects.feature.account.common)
implementation(projects.feature.account.oauth)
implementation(projects.feature.account.servercertificate)
implementation(projects.feature.account.server.certificate)
testImplementation(projects.core.ui.compose.testing)
}

View file

@ -3,10 +3,10 @@ package app.k9mail.feature.account.server.validation
import app.k9mail.core.common.coreCommonModule
import app.k9mail.feature.account.common.featureAccountCommonModule
import app.k9mail.feature.account.oauth.featureAccountOAuthModule
import app.k9mail.feature.account.server.certificate.featureAccountServerCertificateModule
import app.k9mail.feature.account.server.validation.domain.ServerValidationDomainContract
import app.k9mail.feature.account.server.validation.domain.usecase.ValidateServerSettings
import app.k9mail.feature.account.server.validation.ui.ServerValidationViewModel
import app.k9mail.feature.account.servercertificate.featureAccountServerCertificateModule
import com.fsck.k9.mail.store.imap.ImapServerSettingsValidator
import com.fsck.k9.mail.store.pop3.Pop3ServerSettingsValidator
import com.fsck.k9.mail.transport.smtp.SmtpServerSettingsValidator

View file

@ -12,9 +12,9 @@ import app.k9mail.feature.account.common.ui.WizardNavigationBar
import app.k9mail.feature.account.common.ui.WizardNavigationBarState
import app.k9mail.feature.account.common.ui.preview.PreviewAccountStateRepository
import app.k9mail.feature.account.oauth.ui.preview.PreviewAccountOAuthViewModel
import app.k9mail.feature.account.server.certificate.data.InMemoryServerCertificateErrorRepository
import app.k9mail.feature.account.server.validation.ui.ServerValidationContract.Event
import app.k9mail.feature.account.server.validation.ui.ServerValidationContract.ViewModel
import app.k9mail.feature.account.servercertificate.data.InMemoryServerCertificateErrorRepository
import com.fsck.k9.mail.server.ServerSettingsValidationResult
@Composable

View file

@ -5,10 +5,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import app.k9mail.core.ui.compose.common.mvi.observe
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorScreen
import app.k9mail.feature.account.server.validation.ui.ServerValidationContract.Effect
import app.k9mail.feature.account.server.validation.ui.ServerValidationContract.Event
import app.k9mail.feature.account.server.validation.ui.ServerValidationContract.ViewModel
import app.k9mail.feature.account.servercertificate.ui.CertificateErrorScreen
@Composable
fun ServerValidationScreen(
@ -33,7 +33,7 @@ fun ServerValidationScreen(
}
if (state.value.error is ServerValidationContract.Error.CertificateError) {
CertificateErrorScreen(
ServerCertificateErrorScreen(
onCertificateAccepted = { dispatch(Event.OnCertificateAccepted) },
onBack = { dispatch(Event.OnBackClicked) },
modifier = modifier,

View file

@ -7,13 +7,13 @@ import app.k9mail.feature.account.oauth.domain.AccountOAuthDomainContract
import app.k9mail.feature.account.oauth.domain.entity.OAuthResult
import app.k9mail.feature.account.oauth.domain.entity.isOAuth
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract
import app.k9mail.feature.account.server.certificate.domain.ServerCertificateDomainContract
import app.k9mail.feature.account.server.certificate.domain.entity.ServerCertificateError
import app.k9mail.feature.account.server.validation.domain.ServerValidationDomainContract
import app.k9mail.feature.account.server.validation.ui.ServerValidationContract.Effect
import app.k9mail.feature.account.server.validation.ui.ServerValidationContract.Error
import app.k9mail.feature.account.server.validation.ui.ServerValidationContract.Event
import app.k9mail.feature.account.server.validation.ui.ServerValidationContract.State
import app.k9mail.feature.account.servercertificate.domain.AccountServerCertificateDomainContract
import app.k9mail.feature.account.servercertificate.domain.entity.ServerCertificateError
import com.fsck.k9.mail.server.ServerSettingsValidationResult
import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.delay
@ -26,7 +26,7 @@ class ServerValidationViewModel(
private val accountStateRepository: AccountDomainContract.AccountStateRepository,
private val validateServerSettings: ServerValidationDomainContract.UseCase.ValidateServerSettings,
private val authorizationStateRepository: AccountOAuthDomainContract.AuthorizationStateRepository,
private val certificateErrorRepository: AccountServerCertificateDomainContract.ServerCertificateErrorRepository,
private val certificateErrorRepository: ServerCertificateDomainContract.ServerCertificateErrorRepository,
override val oAuthViewModel: AccountOAuthContract.ViewModel,
override val isIncomingValidation: Boolean = true,
initialState: State? = null,

View file

@ -4,9 +4,9 @@ import android.content.Context
import app.k9mail.core.common.oauth.OAuthConfigurationFactory
import app.k9mail.feature.account.common.domain.AccountDomainContract
import app.k9mail.feature.account.common.domain.entity.AccountState
import app.k9mail.feature.account.server.certificate.domain.ServerCertificateDomainContract
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorContract
import app.k9mail.feature.account.server.validation.ui.ServerValidationContract
import app.k9mail.feature.account.servercertificate.domain.AccountServerCertificateDomainContract
import app.k9mail.feature.account.servercertificate.ui.AccountServerCertificateErrorContract
import com.fsck.k9.mail.oauth.OAuth2TokenProvider
import com.fsck.k9.mail.oauth.OAuth2TokenProviderFactory
import com.fsck.k9.mail.ssl.LocalKeyStore
@ -51,8 +51,8 @@ class ServerValidationModuleKtTest : KoinTest {
extraTypes = listOf(
ServerValidationContract.State::class,
AccountDomainContract.AccountStateRepository::class,
AccountServerCertificateDomainContract.ServerCertificateErrorRepository::class,
AccountServerCertificateErrorContract.State::class,
ServerCertificateDomainContract.ServerCertificateErrorRepository::class,
ServerCertificateErrorContract.State::class,
AccountState::class,
Context::class,
Boolean::class,

View file

@ -6,11 +6,11 @@ import app.k9mail.core.ui.compose.testing.mvi.turbinesWithInitialStateCheck
import app.k9mail.feature.account.common.data.InMemoryAccountStateRepository
import app.k9mail.feature.account.common.domain.entity.AccountState
import app.k9mail.feature.account.oauth.ui.fake.FakeAccountOAuthViewModel
import app.k9mail.feature.account.server.certificate.data.InMemoryServerCertificateErrorRepository
import app.k9mail.feature.account.server.validation.ui.ServerValidationContract.Effect
import app.k9mail.feature.account.server.validation.ui.ServerValidationContract.Error
import app.k9mail.feature.account.server.validation.ui.ServerValidationContract.Event
import app.k9mail.feature.account.server.validation.ui.ServerValidationContract.State
import app.k9mail.feature.account.servercertificate.data.InMemoryServerCertificateErrorRepository
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isTrue

View file

@ -1,29 +0,0 @@
package app.k9mail.feature.account.servercertificate
import app.k9mail.feature.account.servercertificate.data.InMemoryServerCertificateErrorRepository
import app.k9mail.feature.account.servercertificate.domain.AccountServerCertificateDomainContract
import app.k9mail.feature.account.servercertificate.domain.usecase.AddServerCertificateException
import app.k9mail.feature.account.servercertificate.ui.AccountServerCertificateErrorViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.core.module.Module
import org.koin.dsl.module
val featureAccountServerCertificateModule: Module = module {
single<AccountServerCertificateDomainContract.ServerCertificateErrorRepository> {
InMemoryServerCertificateErrorRepository()
}
factory<AccountServerCertificateDomainContract.UseCase.AddServerCertificateException> {
AddServerCertificateException(
localKeyStore = get(),
)
}
viewModel {
AccountServerCertificateErrorViewModel(
certificateErrorRepository = get(),
addServerCertificateException = get(),
)
}
}

View file

@ -29,7 +29,7 @@ dependencies {
api(projects.feature.account.common)
implementation(projects.feature.account.oauth)
implementation(projects.feature.account.servercertificate)
implementation(projects.feature.account.server.certificate)
api(projects.feature.account.server.validation)
testImplementation(projects.core.ui.compose.testing)

View file

@ -4,8 +4,8 @@ import android.content.Context
import app.k9mail.core.common.oauth.OAuthConfigurationFactory
import app.k9mail.feature.account.common.domain.entity.AccountState
import app.k9mail.feature.account.oauth.ui.AccountOAuthContract
import app.k9mail.feature.account.server.certificate.ui.ServerCertificateErrorContract
import app.k9mail.feature.account.server.validation.ui.ServerValidationContract
import app.k9mail.feature.account.servercertificate.ui.AccountServerCertificateErrorContract
import app.k9mail.feature.account.setup.AccountSetupExternalContract.AccountCreator
import app.k9mail.feature.account.setup.AccountSetupExternalContract.AccountCreator.AccountCreatorResult
import app.k9mail.feature.account.setup.ui.AccountSetupContract
@ -69,7 +69,7 @@ class AccountSetupModuleKtTest : KoinTest {
AccountOutgoingConfigContract.State::class,
AccountOptionsContract.State::class,
AccountState::class,
AccountServerCertificateErrorContract.State::class,
ServerCertificateErrorContract.State::class,
AuthStateStorage::class,
Context::class,
Boolean::class,

View file

@ -46,8 +46,8 @@ include(
include(
":feature:account:common",
":feature:account:oauth",
":feature:account:servercertificate",
":feature:account:setup",
":feature:account:server:certificate",
":feature:account:server:validation",
)