Skip to content

Commit

Permalink
Added one more test. Refactored code.| #1201
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed Aug 12, 2021
1 parent 4e9af72 commit 75bf2c0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 75bf2c0

Please sign in to comment.