mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-21 05:32:53 +00:00
test: pin android explicit setup auth selection
This commit is contained in:
@@ -781,16 +781,7 @@ class NodeRuntime(
|
||||
}
|
||||
operatorStatusText = "Connecting…"
|
||||
updateStatus()
|
||||
connectWithAuth(
|
||||
endpoint = endpoint,
|
||||
auth =
|
||||
GatewayConnectAuth(
|
||||
token = prefs.loadGatewayToken(),
|
||||
bootstrapToken = prefs.loadGatewayBootstrapToken(),
|
||||
password = prefs.loadGatewayPassword(),
|
||||
),
|
||||
reconnect = true,
|
||||
)
|
||||
connectWithAuth(endpoint = endpoint, auth = resolveGatewayConnectAuth(), reconnect = true)
|
||||
}
|
||||
|
||||
private fun connectWithAuth(
|
||||
@@ -856,15 +847,7 @@ class NodeRuntime(
|
||||
operatorStatusText = "Connecting…"
|
||||
nodeStatusText = "Connecting…"
|
||||
updateStatus()
|
||||
connectWithAuth(
|
||||
endpoint = endpoint,
|
||||
auth =
|
||||
GatewayConnectAuth(
|
||||
token = prefs.loadGatewayToken(),
|
||||
bootstrapToken = prefs.loadGatewayBootstrapToken(),
|
||||
password = prefs.loadGatewayPassword(),
|
||||
),
|
||||
)
|
||||
connectWithAuth(endpoint = endpoint, auth = resolveGatewayConnectAuth())
|
||||
}
|
||||
|
||||
fun connect(
|
||||
@@ -875,7 +858,16 @@ class NodeRuntime(
|
||||
operatorStatusText = "Connecting…"
|
||||
nodeStatusText = "Connecting…"
|
||||
updateStatus()
|
||||
connectWithAuth(endpoint = endpoint, auth = auth)
|
||||
connectWithAuth(endpoint = endpoint, auth = resolveGatewayConnectAuth(auth))
|
||||
}
|
||||
|
||||
internal fun resolveGatewayConnectAuth(explicitAuth: GatewayConnectAuth? = null): GatewayConnectAuth {
|
||||
return explicitAuth
|
||||
?: GatewayConnectAuth(
|
||||
token = prefs.loadGatewayToken(),
|
||||
bootstrapToken = prefs.loadGatewayBootstrapToken(),
|
||||
password = prefs.loadGatewayPassword(),
|
||||
)
|
||||
}
|
||||
|
||||
fun acceptGatewayTrustPrompt() {
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
package ai.openclaw.app
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
import java.util.UUID
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34])
|
||||
class GatewayBootstrapAuthTest {
|
||||
@Test
|
||||
fun connectsOperatorSessionWhenBootstrapAuthExists() {
|
||||
@@ -18,4 +27,32 @@ class GatewayBootstrapAuthTest {
|
||||
assertTrue(shouldConnectOperatorSession(token = null, bootstrapToken = null, password = null, storedOperatorToken = "stored-token"))
|
||||
assertFalse(shouldConnectOperatorSession(token = null, bootstrapToken = "", password = null, storedOperatorToken = null))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resolveGatewayConnectAuth_prefersExplicitSetupAuthOverStoredPrefs() {
|
||||
val app = RuntimeEnvironment.getApplication()
|
||||
val securePrefs =
|
||||
app.getSharedPreferences(
|
||||
"openclaw.node.secure.test.${UUID.randomUUID()}",
|
||||
android.content.Context.MODE_PRIVATE,
|
||||
)
|
||||
val prefs = SecurePrefs(app, securePrefsOverride = securePrefs)
|
||||
prefs.setGatewayToken("stale-shared-token")
|
||||
prefs.setGatewayBootstrapToken("")
|
||||
prefs.setGatewayPassword("stale-password")
|
||||
val runtime = NodeRuntime(app, prefs)
|
||||
|
||||
val auth =
|
||||
runtime.resolveGatewayConnectAuth(
|
||||
NodeRuntime.GatewayConnectAuth(
|
||||
token = null,
|
||||
bootstrapToken = "setup-bootstrap-token",
|
||||
password = null,
|
||||
),
|
||||
)
|
||||
|
||||
assertNull(auth.token)
|
||||
assertEquals("setup-bootstrap-token", auth.bootstrapToken)
|
||||
assertNull(auth.password)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user