Repository navigation
Conversation
* Update `ApiConfig` to include `allowInsecureTls` property for local testing * Refactor `NetworkModule` to use the `allowInsecureTls` flag when configuring `OkHttpClient` instead of checking the URL protocol prefix
* Update `ApiConfig` to include `allowInsecureTls` property for local testing * Refactor `NetworkModule` to use the `allowInsecureTls` flag when configuring `OkHttpClient` instead of checking the URL protocol prefix
* Update `ApiConfig` test helper to include the `allowInsecureTls` parameter * Refactor `OkHttpClient` provider tests to explicitly verify standard vs. unsafe clients based on the `allowInsecureTls` flag * Add assertions to validate hostname verification behavior for secure and insecure configurations
dubdabasoduba
left a comment
There was a problem hiding this comment.
Clean up the linting issues then we can merge it
| if (config.baseUrl.startsWith("https")) { | ||
| OkHttpClient.Builder() | ||
| } else { | ||
| if (config.allowInsecureTls) { |
There was a problem hiding this comment.
Smart way to do it thanks
There was a problem hiding this comment.
Pull request overview
This PR introduces an explicit ApiConfig.allowInsecureTls switch and updates the app DI NetworkModule to use the unsafe OkHttp builder only when that flag is enabled, fixing the prior scheme-based logic that failed for self-signed https:// endpoints during local testing.
Changes:
- Add
allowInsecureTls(defaultfalse) toApiConfigto explicitly opt into bypassing TLS verification. - Update
NetworkModule.provideOkHttpClientto chooseUnsafeOkHttpClientbased onallowInsecureTlsrather than URL scheme. - Update
NetworkModuleTestto validate the new behavior and expectations.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| android/momo-api-sdk/src/commonMain/kotlin/io/rekast/sdk/utils/ApiConfig.kt | Adds allowInsecureTls flag to runtime SDK configuration. |
| android/app/src/main/kotlin/io/rekast/sdk/app/di/NetworkModule.kt | Switches unsafe-client selection logic to be driven by the new config flag. |
| android/app/src/test/kotlin/io/rekast/sdk/app/di/NetworkModuleTest.kt | Updates tests and assertions to reflect allowInsecureTls behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| ApiConfig( | ||
| baseUrl = "http://10.0.2.2:8080/", | ||
| apiUserId = "user-id", | ||
| environment = "sandbox" | ||
| environment = "sandbox", | ||
| allowInsecureTls = true |
| val isUnsafe = try { | ||
| client.hostnameVerifier.verify("any-hostname.example.com", null) | ||
| } catch (e: NullPointerException) { | ||
| false | ||
| } | ||
| org.junit.Assert.assertFalse(isUnsafe) |
| if (config.allowInsecureTls) { | ||
| UnsafeOkHttpClient().unsafeOkHttpClient | ||
| } else { | ||
| OkHttpClient.Builder() | ||
| } |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
* Update indentation and line wrapping for the `try-catch` block in `NetworkModuleTest` to comply with formatting standards.
Head branch was pushed to by a user without write access
Linting issues resolved! |
Description
This PR adds an option to allow insecure TLS in ApiConfig
In NetworkModule.kt, there is a flawed condition for when to use the UnsafeOkHttpClient. This logic assumes any URL starting with https has a valid production certificate, and any URL that doesn't (i.e., http://) needs TLS disabled. But http:// traffic doesn't use TLS anyway! The actual use case for UnsafeOkHttpClient is for local testing with self-signed HTTPS certificates. If a developer uses a self-signed https://10.0.2.2/, this code will give them a regular OkHttpClient which will immediately crash on a certificate error.
Type of change
Checklist
./gradlew build).