diff --git a/app/src/androidTest/kotlin/io/flamenet/messenger/app/ChatFlowTest.kt b/app/src/androidTest/kotlin/io/flamenet/messenger/app/ChatFlowTest.kt index 3ed6bb9..e49c040 100644 --- a/app/src/androidTest/kotlin/io/flamenet/messenger/app/ChatFlowTest.kt +++ b/app/src/androidTest/kotlin/io/flamenet/messenger/app/ChatFlowTest.kt @@ -10,7 +10,9 @@ import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextClearance import androidx.compose.ui.test.performTextInput import androidx.compose.ui.test.printToString +import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.junit.Assume.assumeTrue import org.junit.Before import org.junit.Rule import org.junit.Test @@ -36,7 +38,25 @@ class ChatFlowTest { @get:Rule val compose = createAndroidComposeRule() - private val relay = "relay1.flamenet.io" + /** + * Which relay to drive. + * + * 🔴 Defaults to the production relay, which is what this has always used — + * so an unqualified run still does what it did. Pass `-e relay ` to + * point it somewhere else, and a LOCAL one is what you want while + * developing: these tests create real accounts, and doing that on + * production for every run is a cost nobody chose. + * + * ./gradlew :app:connectedDebugAndroidTest \ + * -Pandroid.testInstrumentationRunnerArguments.relay=10.0.2.2:18810 + */ + private val relay: String + get() = InstrumentationRegistry.getArguments().getString("relay") + ?: "relay1.flamenet.io" + + /** A local relay is plain HTTP; anything else is not. */ + private val relayScheme: String get() = if (relay.startsWith("10.0.2.2") || + relay.startsWith("127.0.0.1") || relay.startsWith("localhost")) "http" else "https" private val peerHandle = "peerjvmone" private lateinit var handle: String @@ -48,7 +68,7 @@ class ChatFlowTest { @Test fun aPersonCanAddAContactAndSendThemAMessage() { - if (!relayReachable()) return + assumeTrue("the relay is unreachable - skipped, and a skip is not a pass", relayReachable()) signUp() @@ -97,7 +117,7 @@ class ChatFlowTest { */ @Test fun aReplyFromSomebodyElseAppearsInTheThread() { - if (!relayReachable()) return + assumeTrue("the relay is unreachable - skipped, and a skip is not a pass", relayReachable()) signUp() compose.onNodeWithTag("add-contact").performClick() @@ -232,7 +252,7 @@ class ChatFlowTest { }.getOrElse { "(could not read the screen: $it)" } private fun relayReachable(): Boolean = runCatching { - (java.net.URL("https://$relay/e2e/log/head").openConnection() as java.net.HttpURLConnection) + (java.net.URL("$relayScheme://$relay/e2e/log/head").openConnection() as java.net.HttpURLConnection) .apply { connectTimeout = 8000; readTimeout = 8000 } .responseCode in 200..299 }.getOrDefault(false) diff --git a/app/src/androidTest/kotlin/io/flamenet/messenger/app/CrudSurfaceTest.kt b/app/src/androidTest/kotlin/io/flamenet/messenger/app/CrudSurfaceTest.kt index 272f5e3..9034d0a 100644 --- a/app/src/androidTest/kotlin/io/flamenet/messenger/app/CrudSurfaceTest.kt +++ b/app/src/androidTest/kotlin/io/flamenet/messenger/app/CrudSurfaceTest.kt @@ -10,7 +10,9 @@ import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextClearance import androidx.compose.ui.test.performTextInput import androidx.compose.ui.test.printToString +import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.junit.Assume.assumeTrue import org.junit.Before import org.junit.Rule import org.junit.Test @@ -35,7 +37,25 @@ class CrudSurfaceTest { @get:Rule val compose = createAndroidComposeRule() - private val relay = "relay1.flamenet.io" + /** + * Which relay to drive. + * + * 🔴 Defaults to the production relay, which is what this has always used — + * so an unqualified run still does what it did. Pass `-e relay ` to + * point it somewhere else, and a LOCAL one is what you want while + * developing: these tests create real accounts, and doing that on + * production for every run is a cost nobody chose. + * + * ./gradlew :app:connectedDebugAndroidTest \ + * -Pandroid.testInstrumentationRunnerArguments.relay=10.0.2.2:18810 + */ + private val relay: String + get() = InstrumentationRegistry.getArguments().getString("relay") + ?: "relay1.flamenet.io" + + /** A local relay is plain HTTP; anything else is not. */ + private val relayScheme: String get() = if (relay.startsWith("10.0.2.2") || + relay.startsWith("127.0.0.1") || relay.startsWith("localhost")) "http" else "https" private val peerHandle = "peerjvmone" private lateinit var handle: String @@ -74,7 +94,7 @@ class CrudSurfaceTest { @Test fun everyContactActionIsReachable() { - if (!relayReachable()) return + assumeTrue("the relay is unreachable - skipped, and a skip is not a pass", relayReachable()) signUp() // Presence is a claim about you, so you can set it. @@ -110,7 +130,7 @@ class CrudSurfaceTest { @Test fun theOtherScreensAreReachableAndComplete() { - if (!relayReachable()) return + assumeTrue("the relay is unreachable - skipped, and a skip is not a pass", relayReachable()) signUp() // Stories are reachable from the contact list, and say what they are @@ -143,7 +163,7 @@ class CrudSurfaceTest { @Test fun aThreadCanSendTextAndPhotos() { - if (!relayReachable()) return + assumeTrue("the relay is unreachable - skipped, and a skip is not a pass", relayReachable()) signUp() compose.onNodeWithTag("add-contact").performClick() compose.onNodeWithTag("new-contact").performTextInput(peerHandle) @@ -282,7 +302,7 @@ class CrudSurfaceTest { }.getOrElse { "(could not read the screen: $it)" } private fun relayReachable(): Boolean = runCatching { - (java.net.URL("https://$relay/e2e/log/head").openConnection() as java.net.HttpURLConnection) + (java.net.URL("$relayScheme://$relay/e2e/log/head").openConnection() as java.net.HttpURLConnection) .apply { connectTimeout = 8000; readTimeout = 8000 } .responseCode in 200..299 }.getOrDefault(false) diff --git a/app/src/androidTest/kotlin/io/flamenet/messenger/app/FeatureUseTest.kt b/app/src/androidTest/kotlin/io/flamenet/messenger/app/FeatureUseTest.kt index e1671d8..db74cb2 100644 --- a/app/src/androidTest/kotlin/io/flamenet/messenger/app/FeatureUseTest.kt +++ b/app/src/androidTest/kotlin/io/flamenet/messenger/app/FeatureUseTest.kt @@ -8,7 +8,9 @@ import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextClearance import androidx.compose.ui.test.performTextInput import androidx.compose.ui.test.printToString +import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.junit.Assume.assumeTrue import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Rule @@ -40,7 +42,25 @@ class FeatureUseTest { @get:Rule val compose = createAndroidComposeRule() - private val relay = "relay1.flamenet.io" + /** + * Which relay to drive. + * + * 🔴 Defaults to the production relay, which is what this has always used — + * so an unqualified run still does what it did. Pass `-e relay ` to + * point it somewhere else, and a LOCAL one is what you want while + * developing: these tests create real accounts, and doing that on + * production for every run is a cost nobody chose. + * + * ./gradlew :app:connectedDebugAndroidTest \ + * -Pandroid.testInstrumentationRunnerArguments.relay=10.0.2.2:18810 + */ + private val relay: String + get() = InstrumentationRegistry.getArguments().getString("relay") + ?: "relay1.flamenet.io" + + /** A local relay is plain HTTP; anything else is not. */ + private val relayScheme: String get() = if (relay.startsWith("10.0.2.2") || + relay.startsWith("127.0.0.1") || relay.startsWith("localhost")) "http" else "https" private lateinit var handle: String @Before @@ -59,7 +79,7 @@ class FeatureUseTest { */ @Test fun aVoiceNoteRecordsAndCanBeDiscarded() { - if (!relayReachable()) return + assumeTrue("the relay is unreachable - skipped, and a skip is not a pass", relayReachable()) signUpAndOpenAThread() compose.onNodeWithTag("record-voice").performClick() @@ -88,7 +108,7 @@ class FeatureUseTest { */ @Test fun aGroupIsCreatedAndListed() { - if (!relayReachable()) return + assumeTrue("the relay is unreachable - skipped, and a skip is not a pass", relayReachable()) signUpAndAddPeer() compose.onNodeWithTag("new-group").performClick() @@ -120,7 +140,7 @@ class FeatureUseTest { */ @Test fun theStorySurfaceOpensAndExplainsItself() { - if (!relayReachable()) return + assumeTrue("the relay is unreachable - skipped, and a skip is not a pass", relayReachable()) signUp() compose.onNodeWithTag("stories").assertExists() @@ -143,7 +163,7 @@ class FeatureUseTest { */ @Test fun placingACallRaisesTheBannerAndHangingUpClearsIt() { - if (!relayReachable()) return + assumeTrue("the relay is unreachable - skipped, and a skip is not a pass", relayReachable()) signUpAndOpenAThread() compose.onNodeWithTag("start-call").performClick() @@ -256,7 +276,7 @@ class FeatureUseTest { }.getOrElse { "(could not read the screen: $it)" } private fun relayReachable(): Boolean = runCatching { - (java.net.URL("https://$relay/e2e/log/head").openConnection() as java.net.HttpURLConnection) + (java.net.URL("$relayScheme://$relay/e2e/log/head").openConnection() as java.net.HttpURLConnection) .apply { connectTimeout = 8000; readTimeout = 8000 } .responseCode in 200..299 }.getOrDefault(false) diff --git a/app/src/androidTest/kotlin/io/flamenet/messenger/app/LiveSignUpFleetTest.kt b/app/src/androidTest/kotlin/io/flamenet/messenger/app/LiveSignUpFleetTest.kt index c0d0eef..816dc30 100644 --- a/app/src/androidTest/kotlin/io/flamenet/messenger/app/LiveSignUpFleetTest.kt +++ b/app/src/androidTest/kotlin/io/flamenet/messenger/app/LiveSignUpFleetTest.kt @@ -11,6 +11,7 @@ import androidx.compose.ui.test.performTextInput import androidx.compose.ui.test.printToString import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assume.assumeTrue import org.junit.Before import org.junit.Rule import org.junit.Test @@ -75,13 +76,13 @@ class LiveSignUpFleetTest { @Test fun signUpOnTheManagedRelay() { - if (args.getString("live") != "true") return + assumeTrue("pass -e live true to run this - it creates real accounts", args.getString("live") == "true") signUpLive(managed, "m") } @Test fun signUpOnASharedSelfHostedRelay() { - if (args.getString("live") != "true") return + assumeTrue("pass -e live true to run this - it creates real accounts", args.getString("live") == "true") signUpLive(sharedSelfHosted, "s") } diff --git a/app/src/androidTest/kotlin/io/flamenet/messenger/app/SignUpFlowTest.kt b/app/src/androidTest/kotlin/io/flamenet/messenger/app/SignUpFlowTest.kt index 84f217c..68e3b0c 100644 --- a/app/src/androidTest/kotlin/io/flamenet/messenger/app/SignUpFlowTest.kt +++ b/app/src/androidTest/kotlin/io/flamenet/messenger/app/SignUpFlowTest.kt @@ -9,7 +9,9 @@ import androidx.compose.ui.test.printToString import androidx.compose.ui.test.performClick import androidx.compose.ui.test.performTextClearance import androidx.compose.ui.test.performTextInput +import androidx.test.platform.app.InstrumentationRegistry import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.junit.Assume.assumeTrue import org.junit.Before import org.junit.Rule import org.junit.Test @@ -36,7 +38,25 @@ class SignUpFlowTest { @get:Rule val compose = createAndroidComposeRule() - private val relay = "relay1.flamenet.io" + /** + * Which relay to drive. + * + * 🔴 Defaults to the production relay, which is what this has always used — + * so an unqualified run still does what it did. Pass `-e relay ` to + * point it somewhere else, and a LOCAL one is what you want while + * developing: these tests create real accounts, and doing that on + * production for every run is a cost nobody chose. + * + * ./gradlew :app:connectedDebugAndroidTest \ + * -Pandroid.testInstrumentationRunnerArguments.relay=10.0.2.2:18810 + */ + private val relay: String + get() = InstrumentationRegistry.getArguments().getString("relay") + ?: "relay1.flamenet.io" + + /** A local relay is plain HTTP; anything else is not. */ + private val relayScheme: String get() = if (relay.startsWith("10.0.2.2") || + relay.startsWith("127.0.0.1") || relay.startsWith("localhost")) "http" else "https" private lateinit var handle: String @Before @@ -155,14 +175,14 @@ class SignUpFlowTest { }.getOrElse { "(could not read the screen: $it)" } private fun relayReachable(): Boolean = runCatching { - (java.net.URL("https://$relay/e2e/log/head").openConnection() as java.net.HttpURLConnection) + (java.net.URL("$relayScheme://$relay/e2e/log/head").openConnection() as java.net.HttpURLConnection) .apply { connectTimeout = 8000; readTimeout = 8000 } .responseCode in 200..299 }.getOrDefault(false) @Test fun aPersonCanCreateAnAccountOnASelfHostedRelay() { - if (!relayReachable()) return + assumeTrue("the relay is unreachable - skipped, and a skip is not a pass", relayReachable()) compose.onNodeWithTag("relay").performTextClearance() compose.onNodeWithTag("relay").performTextInput(relay) @@ -191,7 +211,7 @@ class SignUpFlowTest { */ @Test fun signingOutReturnsToSignIn() { - if (!relayReachable()) return + assumeTrue("the relay is unreachable - skipped, and a skip is not a pass", relayReachable()) aPersonCanCreateAnAccountOnASelfHostedRelay() signOutIfSignedIn() diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml new file mode 100644 index 0000000..e573324 --- /dev/null +++ b/app/src/debug/AndroidManifest.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/app/src/debug/res/xml/network_security_config.xml b/app/src/debug/res/xml/network_security_config.xml new file mode 100644 index 0000000..40af9d7 --- /dev/null +++ b/app/src/debug/res/xml/network_security_config.xml @@ -0,0 +1,22 @@ + + + + + 10.0.2.2 + 127.0.0.1 + localhost + +