diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/WkdClientTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/WkdClientTest.kt index b55144aaff..dd2f74f875 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/WkdClientTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/WkdClientTest.kt @@ -24,7 +24,6 @@ import org.apache.commons.codec.binary.ZBase32 import org.apache.commons.codec.digest.DigestUtils import org.junit.Assert.assertNull import org.junit.Assert.assertTrue -import org.junit.ClassRule import org.junit.Rule import org.junit.Test import org.junit.rules.RuleChain @@ -38,10 +37,46 @@ import java.net.HttpURLConnection class WkdClientTest { private val context: Context = ApplicationProvider.getApplicationContext() + private val mockWebServerRule = FlowCryptMockWebServerRule( + TestConstants.MOCK_WEB_SERVER_PORT, + object : Dispatcher() { + override fun dispatch(request: RecordedRequest): MockResponse { + val gson = ApiHelper.getInstance(ApplicationProvider.getApplicationContext()).gson + + when (request.path) { + "/.well-known/openpgpkey/policy" -> { + return MockResponse().setResponseCode(HttpURLConnection.HTTP_OK) + } + + genLookupUrlPath(EXISTING_EMAIL) -> { + return MockResponse().setResponseCode(HttpURLConnection.HTTP_OK) + .setBody( + PGPainless.generateKeyRing().simpleEcKeyRing(EXISTING_EMAIL).publicKey.armor() + ) + } + + genLookupUrlPath(NOT_EXISTING_EMAIL) -> { + return MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND) + .setBody( + gson.toJson( + ApiError( + code = HttpURLConnection.HTTP_NOT_FOUND, + message = "Public key not found" + ) + ) + ) + } + } + + return MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND) + } + }) + @get:Rule var ruleChain: TestRule = RuleChain .outerRule(ClearAppSettingsRule()) .around(GrantPermissionRuleChooser.grant(android.Manifest.permission.POST_NOTIFICATIONS)) + .around(mockWebServerRule) @Test fun existingEmailFlowCryptDomainTest() = runBlocking { @@ -75,42 +110,6 @@ class WkdClientTest { const val EXISTING_EMAIL = "existing@flowcrypt.test" const val NOT_EXISTING_EMAIL = "not_existing@flowcrypt.test" - @get:ClassRule - @JvmStatic - val mockWebServerRule = FlowCryptMockWebServerRule(TestConstants.MOCK_WEB_SERVER_PORT, - object : Dispatcher() { - override fun dispatch(request: RecordedRequest): MockResponse { - val gson = ApiHelper.getInstance(ApplicationProvider.getApplicationContext()).gson - - when (request.path) { - "/.well-known/openpgpkey/policy" -> { - return MockResponse().setResponseCode(HttpURLConnection.HTTP_OK) - } - - genLookupUrlPath(EXISTING_EMAIL) -> { - return MockResponse().setResponseCode(HttpURLConnection.HTTP_OK) - .setBody( - PGPainless.generateKeyRing().simpleEcKeyRing(EXISTING_EMAIL).publicKey.armor() - ) - } - - genLookupUrlPath(NOT_EXISTING_EMAIL) -> { - return MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND) - .setBody( - gson.toJson( - ApiError( - code = HttpURLConnection.HTTP_NOT_FOUND, - message = "Public key not found" - ) - ) - ) - } - } - - return MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND) - } - }) - private fun genLookupUrlPath(email: String): String { val user = email.substringBefore("@") val hu = ZBase32().encodeAsString(DigestUtils.sha1(user.toByteArray())) diff --git a/build.gradle.kts b/build.gradle.kts index 30c57e1313..ea90de2be7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id("com.android.application") version "8.9.1" apply false + id("com.android.application") version "8.9.2" apply false id("org.jetbrains.kotlin.android") version "2.1.20" apply false id("androidx.navigation.safeargs.kotlin") version "2.8.9" apply false id("com.starter.easylauncher") version "6.4.0" apply false