fix(agent): run the setup package install as fake root (#2539)

This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-13 08:48:23 -05:00
1 parent d058bab64f
commit 33dbd8755f
7 files changed
+110 -9

No files matched your search

@@ -0,0 +1,18 @@
package com.droiddeck.launcher.agent
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
class AgentGuestPathTest {
private val dirs = AgentHost.GUEST_PATH.split(':')
@Test fun includesTheSystemBinariesDpkgNeedsAsRoot() {
assertTrue(dirs.containsAll(listOf("/usr/local/sbin", "/usr/sbin", "/sbin")))
}
@Test fun keepsUserBinariesFirstAndTheStandardDirs() {
assertEquals("/root/.local/bin", dirs.first())
assertTrue(dirs.containsAll(listOf("/usr/local/bin", "/usr/bin", "/bin")))
}
}
@@ -0,0 +1,10 @@
package com.droiddeck.launcher.agent
import org.junit.Assert.assertEquals
import org.junit.Test
class AgentSetupRootTest {
@Test fun onlyThePackageInstallRunsAsRoot() {
assertEquals(listOf(AgentSetup.Step.INSTALL), AgentSetup.Step.values().filter { AgentSetup.runsAsRoot(it) })
}
}
@@ -0,0 +1,54 @@
package com.droiddeck.launcher.runtime
import android.app.Application
import android.system.Os
import android.system.StructUtsname
import androidx.test.core.app.ApplicationProvider
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.annotation.Implementation
import org.robolectric.annotation.Implements
import java.io.File
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33], manifest = Config.NONE, application = Application::class, shadows = [LinuxRuntimeRootPrefixTest.Uname::class])
class LinuxRuntimeRootPrefixTest {
private val context: Application = ApplicationProvider.getApplicationContext()
private val root = File(context.filesDir, "rootfs")
private val guest = listOf("/usr/bin/dpkg", "--configure", "-a")
@Test fun fakeRootEmulatesHardLinksForPackageManagers() {
val cmd = LinuxRuntime.commandWithBinds(context, root, emptyList(), guest, true)
assertTrue("-0" in cmd)
assertTrue("--link2symlink" in cmd)
assertFalse("-i" in cmd)
assertEquals(guest, cmd.takeLast(guest.size))
}
@Test fun rootSpawnerAndFakeRootCommandsShareOnePrefix() {
assertEquals(LinuxRuntime.rootPrefix(context, root, "/root"),
LinuxRuntime.commandWithBinds(context, root, emptyList(), emptyList(), true))
}
@Test fun userCommandsKeepTheAppUidAndRealLinks() {
val cmd = LinuxRuntime.commandWithBinds(context, root, emptyList(), guest)
val uid = android.os.Process.myUid()
assertFalse("-0" in cmd)
assertFalse("--link2symlink" in cmd)
assertEquals("$uid:$uid", cmd[cmd.indexOf("-i") + 1])
assertEquals(LinuxRuntime.prootPrefix(context, root, "/root"), cmd.dropLast(guest.size))
}
@Implements(Os::class)
class Uname {
companion object {
@JvmStatic @Implementation
fun uname() = StructUtsname("Linux", "localhost", "6.1.0", "#1 SMP", "aarch64")
}
}
}