diff --git a/examples/demo/app/build.gradle.kts b/examples/demo/app/build.gradle.kts index 25aafbaacb..705637a319 100644 --- a/examples/demo/app/build.gradle.kts +++ b/examples/demo/app/build.gradle.kts @@ -134,6 +134,30 @@ android { } } +// `-PRETRY_TEST_CA=` makes debug builds trust that CA, so scripts/retry can proxy SDK traffic +// without installing a certificate on the device. +demoOverride("RETRY_TEST_CA")?.let { caPath -> + val resDir = layout.buildDirectory.dir("generated/retryTestCa/res").get().asFile + file(caPath).copyTo(resDir.resolve("raw/retry_test_ca.pem"), overwrite = true) + resDir.resolve("xml/network_security_config.xml").apply { + parentFile.mkdirs() + writeText( + """ + + + + + + + + + + """.trimIndent(), + ) + } + android.sourceSets.getByName("debug").res.srcDir(resDir) +} + dependencies { // Kotlin implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion") diff --git a/examples/demo/app/src/main/AndroidManifest.xml b/examples/demo/app/src/main/AndroidManifest.xml index c91d1c923a..cd06b9aa51 100644 --- a/examples/demo/app/src/main/AndroidManifest.xml +++ b/examples/demo/app/src/main/AndroidManifest.xml @@ -21,6 +21,7 @@ android:allowBackup="true" android:icon="@mipmap/ic_onesignal_launcher" android:label="@string/app_name" + android:networkSecurityConfig="@xml/network_security_config" android:roundIcon="@mipmap/ic_onesignal_launcher" android:supportsRtl="true" android:theme="@style/AppTheme" diff --git a/examples/demo/app/src/main/res/xml/network_security_config.xml b/examples/demo/app/src/main/res/xml/network_security_config.xml new file mode 100644 index 0000000000..3e57ccf4c9 --- /dev/null +++ b/examples/demo/app/src/main/res/xml/network_security_config.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/examples/demo/scripts/retry/.gitignore b/examples/demo/scripts/retry/.gitignore new file mode 100644 index 0000000000..ad18e553d6 --- /dev/null +++ b/examples/demo/scripts/retry/.gitignore @@ -0,0 +1,2 @@ +.state/ +__pycache__/ diff --git a/examples/demo/scripts/retry/README.md b/examples/demo/scripts/retry/README.md new file mode 100644 index 0000000000..3d0c57c175 --- /dev/null +++ b/examples/demo/scripts/retry/README.md @@ -0,0 +1,127 @@ +# Retry test harness + +Injects failures into the SDK's requests from the demo app, so OperationRepo retries and backoff can +be watched and checked. A [mitmproxy](https://mitmproxy.org) addon fails only requests that carry +the SDK's `SDK-Version` header. The demo's own REST calls and all other traffic pass through. Only +`onesignal.com` traffic is decrypted. + +```bash +brew install mitmproxy mobile-dev-inc/tap/maestro +cd examples/demo/scripts/retry +./retry-test.sh help +``` + +[Maestro](https://maestro.mobile.dev) drives the demo's UI (`tap`) through the flows in `flows/`. + +## Setup + +1. Start an emulator, or connect a device. With more than one, pick it with + `RETRY_TEST_SERIAL=`. +2. `./retry-test.sh install` builds the demo against the local SDK source and installs it. The + debug build trusts the mitmproxy CA (`-PRETRY_TEST_CA`), so nothing has to be installed on the + device. If a demo signed with another key is already installed, `adb uninstall + com.onesignal.example` first. +3. `./retry-test.sh start` starts mitmproxy on port 8899 and sets the device's global HTTP proxy. + An emulator reaches it at `10.0.2.2`, a physical device through `adb reverse`. +4. `./retry-test.sh fresh` clears the demo's data so the SDK starts as a new install. +5. In another terminal, `./retry-test.sh watch` follows each SDK request. +6. When done, **`./retry-test.sh stop`** clears the device's proxy. Until then the whole device + goes through the proxy. + +## Commands + +| Command | Does | +| --- | --- | +| `fail [--times N] [--retry-after S] [--add]` | Fail matching requests. Status `0` drops the connection, like being offline. Without `--times` it fails until `clear`. `--add` keeps earlier rules. Applies right away. | +| `clear` / `rules` | Remove or show the rules | +| `report [regex]` | Per operation: each attempt, the gap since the previous one, and the gap expected. Also lists any SDK request sent during a Retry-After | +| `reset-log` | Forget recorded attempts, for example between scenarios | +| `tap [args]` | Use the demo: `add-tag `, `add-alias