Compare commits

...
2 changed files with 26 additions and 0 deletions

No files matched your search

@@ -275,6 +275,7 @@ public final class LinuxRuntime {
}
}
String[][] seeded = {
{"filesystems", ""},
{"file-max", "9223372036854775807\n"},
{"overcommit_memory", "0\n"},
};
@@ -287,6 +288,7 @@ public final class LinuxRuntime {
}
}
String[][] procFiles = {
{"filesystems", "/proc/filesystems"},
{"pci_devices", "/proc/bus/pci/devices"},
{"stat", "/proc/stat"},
{"version", "/proc/version"},
@@ -4,6 +4,8 @@ import android.content.ContextWrapper
import java.io.File
import java.nio.file.Files
import org.junit.After
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@@ -35,4 +37,26 @@ class LinuxRuntimeProcFilesTest {
LinuxRuntime.binds(context, null, null, null, null)
assertEquals("1\n", File(fakeProc, "overcommit_memory").readText())
}
@Test fun restrictedFilesystemsHaveAConservativeFallback() {
val binds = LinuxRuntime.binds(context, null, null, null, null)
val fallback = File(fakeProc, "filesystems")
assertEquals("", fallback.readText())
assertEquals(!File("/proc/filesystems").canRead(), binds.contains("${fallback.path}:/proc/filesystems"))
assertTrue(binds.contains("/proc"))
assertFalse(binds.any { it.endsWith(":/proc/self/status") })
}
@Test fun explicitFilesystemsBindingWins() {
val source = File(root, "supported-fs").apply { writeText("nodev\ttmpfs\n") }
val explicit = "${source.path}:/proc/filesystems"
val binds = LinuxRuntime.binds(context, null, null, null, listOf(explicit))
assertEquals(listOf(explicit), binds.filter { it.endsWith(":/proc/filesystems") })
}
@Test fun existingFilesystemsDataIsPreserved() {
val fallback = File(fakeProc, "filesystems").apply { parentFile!!.mkdirs(); writeText("nodev\ttmpfs\n") }
LinuxRuntime.binds(context, null, null, null, null)
assertEquals("nodev\ttmpfs\n", fallback.readText())
}
}