Fix: Prevent AuthManager state pollution on connection verification (#348)

* Fix: Prevent AuthManager state pollution on connection verification

Modified `ConnectViewModel.connect()` to construct a temporary OkHttpClient and Retrofit builder, isolated from the global `ApiClient` state. The connection verification is executed using this temporary service. Only upon a successful HTTP response does the system persist the configured `host`, `port`, and `token` to the global `AuthManager` and triggers an `ApiClient.rebuild()`. This resolves the issue where a failed connection attempt would overwrite active and verified profiles. Extracted `createTempService` factory to `ApiClient` for robustness and clean tests.

Fixes #260

* Fix: Prevent AuthManager state pollution on connection verification

Modified `ConnectViewModel.connect()` to construct a temporary OkHttpClient and Retrofit builder, isolated from the global `ApiClient` state. The connection verification is executed using this temporary service. Only upon a successful HTTP response does the system persist the configured `host`, `port`, and `token` to the global `AuthManager` and triggers an `ApiClient.rebuild()`. This resolves the issue where a failed connection attempt would overwrite active and verified profiles. Extracted `createTempService` factory to `ApiClient` for robustness and clean tests.

Fixes #260

---------

Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
M57
2026-06-23 20:49:58 +03:00
committed by GitHub
co-authored by M57
parent c21e3e9ed0
commit 2c6e437a5b
42 changed files with 296 additions and 667 deletions
+10 -16
View File
@@ -41,21 +41,15 @@ android {
val alias = System.getenv("KEY_ALIAS")
val keyPass = System.getenv("KEY_PASSWORD")
if (storePath != null && storePass != null && alias != null && keyPass != null) {
storeFile = file(storePath)
storePassword = storePass
keyAlias = alias
keyPassword = keyPass
} else {
// Env vars missing — signing deferred to release workflow.
// Don't hard-require(): that would break compileReleaseKotlin
// in CI where keystore secrets aren't set.
logger.warn("Release signing config missing env vars — signing deferred to release workflow")
storeFile = file("dummy.keystore")
storePassword = "dummy"
keyAlias = "dummy"
keyPassword = "dummy"
}
require(!storePath.isNullOrEmpty()) { "KEYSTORE_PATH environment variable is not set" }
require(!storePass.isNullOrEmpty()) { "KEYSTORE_PASSWORD environment variable is not set" }
require(!alias.isNullOrEmpty()) { "KEY_ALIAS environment variable is not set" }
require(!keyPass.isNullOrEmpty()) { "KEY_PASSWORD environment variable is not set" }
storeFile = file(storePath)
storePassword = storePass
keyAlias = alias
keyPassword = keyPass
} else {
// Dummy values for evaluation configuration during non-release builds
storeFile = file("dummy.keystore")
@@ -134,7 +128,7 @@ dependencies {
// Networking
implementation(libs.okhttp)
implementation(libs.okhttp.logging)
debugImplementation(libs.okhttp.logging)
implementation(libs.retrofit)
implementation(libs.retrofit.converter.gson)
implementation(libs.gson)