From 75bf2c042450ea9cbb22de007323207c38358adc Mon Sep 17 00:00:00 2001 From: DenBond7 Date: Thu, 12 Aug 2021 17:21:33 +0300 Subject: [PATCH] Added one more test. Refactored code.| #1201 --- .../assets/pgp/keys/wkd_prv@localhost_sec.asc | Bin 0 -> 445 bytes .../activity/CreateMessageActivityWkdTest.kt | 51 +++++++++--------- 2 files changed, 27 insertions(+), 24 deletions(-) create mode 100644 FlowCrypt/src/androidTest/assets/pgp/keys/wkd_prv@localhost_sec.asc diff --git a/FlowCrypt/src/androidTest/assets/pgp/keys/wkd_prv@localhost_sec.asc b/FlowCrypt/src/androidTest/assets/pgp/keys/wkd_prv@localhost_sec.asc new file mode 100644 index 0000000000000000000000000000000000000000..ca9c623a4b9d0bdca572192bcb09390fbd861378 GIT binary patch literal 445 zcmbOd!ICJd>m$ag&Bn;Wc*~uik&)d&CEcGJ))5l4fQVV`64xVBzNEU}qKO;^g3Fl4E3&WMtst z6ma-+d3vGck?$Te7#Y6JT@f2Dpx!vC_}Z_-vFkd5g|FL1yl!ARw)$3GxYklNhX0PY zANdOVmahGxFIClQOY6#^q4HnV?5YAhT^L?4FAiY=O^o2X7w*-68Zkf z*zoV1icgR4HI*Op?-4$%ymjG9hCh5iwEqdun!dS7hE37@jDJRa(Dm~P^MoS`)*R-v IKfR3`01;fL;Q#;t literal 0 HcmV?d00001 diff --git a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/CreateMessageActivityWkdTest.kt b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/CreateMessageActivityWkdTest.kt index d90e8940af..4644cad25c 100644 --- a/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/CreateMessageActivityWkdTest.kt +++ b/FlowCrypt/src/androidTest/java/com/flowcrypt/email/ui/activity/CreateMessageActivityWkdTest.kt @@ -37,12 +37,13 @@ import org.junit.rules.TestRule import org.junit.runner.RunWith import java.net.HttpURLConnection -/*adb root -adb shell "echo 1 > /proc/sys/net/ipv4/ip_forward" -adb shell "iptables -t nat -A PREROUTING -s 127.0.0.1 -p tcp --dport 443 -j REDIRECT --to 1212" -adb shell "iptables -t nat -A OUTPUT -s 127.0.0.1 -p tcp --dport 443 -j REDIRECT --to 1212"*/ - /** + * To be able to test WKD need to execute the following: + * adb root + * adb shell "echo 1 > /proc/sys/net/ipv4/ip_forward" + * adb shell "iptables -t nat -A PREROUTING -s 127.0.0.1 -p tcp --dport 443 -j REDIRECT --to 1212" + * adb shell "iptables -t nat -A OUTPUT -s 127.0.0.1 -p tcp --dport 443 -j REDIRECT --to 1212" + * * @author Denis Bondarenko * Date: 8/12/21 * Time: 10:58 AM @@ -150,9 +151,19 @@ class CreateMessageActivityWkdTest : BaseCreateMessageActivityTest() { ) } + @Test + fun testWkdPrv() { + check( + recipient = "wkd_prv@localhost", + colorResourcesId = CustomChipSpanChipCreator.CHIP_COLOR_RES_ID_PGP_NOT_EXISTS + ) + } + private fun handleAdvancedPolicyRequest(): MockResponse { return when (testNameRule.methodName) { - "testWkdAdvancedNoResult", "testWkdAdvancedPub" -> { + "testWkdAdvancedNoResult", + "testWkdAdvancedPub", + "testWkdPrv" -> { MockResponse().setResponseCode(HttpURLConnection.HTTP_OK) } @@ -173,15 +184,11 @@ class CreateMessageActivityWkdTest : BaseCreateMessageActivityTest() { } "testWkdAdvancedPub" -> { - MockResponse() - .setResponseCode(HttpURLConnection.HTTP_OK) - .setBody( - Buffer().write( - TestGeneralUtil.readFileFromAssetsAsByteArray( - "pgp/keys/wkd_advanced_pub@localhost_pub.asc" - ) - ) - ) + genSuccessMockResponseWithKey("pgp/keys/wkd_advanced_pub@localhost_pub.asc") + } + + "testWkdPrv" -> { + genSuccessMockResponseWithKey("pgp/keys/wkd_prv@localhost_sec.asc") } else -> MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND) @@ -213,21 +220,17 @@ class CreateMessageActivityWkdTest : BaseCreateMessageActivityTest() { "testWkdAdvancedSkippedWkdDirectPub", "testWkdAdvancedTimeOutWkdDirectAvailable" -> { - MockResponse() - .setResponseCode(HttpURLConnection.HTTP_OK) - .setBody( - Buffer().write( - TestGeneralUtil.readFileFromAssetsAsByteArray( - "pgp/keys/wkd_direct_pub@localhost_pub.asc" - ) - ) - ) + genSuccessMockResponseWithKey("pgp/keys/wkd_direct_pub@localhost_pub.asc") } else -> MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND) } } + private fun genSuccessMockResponseWithKey(keyPath: String) = MockResponse() + .setResponseCode(HttpURLConnection.HTTP_OK) + .setBody(Buffer().write(TestGeneralUtil.readFileFromAssetsAsByteArray(keyPath))) + private fun check(recipient: String, colorResourcesId: Int) { fillInAllFields(recipient) onView(withId(R.id.editTextRecipientTo))