Add sepolicy.rule patching tests

This commit is contained in:
topjohnwu
2025-05-12 17:31:50 -07:00
committed by John Wu
parent 97901979dd
commit 4f4b1ff885
6 changed files with 31 additions and 21 deletions

View File

@@ -7,6 +7,7 @@ import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
import com.topjohnwu.magisk.core.model.module.LocalModule
import com.topjohnwu.magisk.core.utils.RootUtils
import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Assert.assertEquals
@@ -96,6 +97,10 @@ class AdditionalTest : BaseTest {
"/system/app/EasterEgg should be empty",
egg.isEmpty()
)
assertTrue(
"Module sepolicy.rule is not applied",
Shell.cmd("magiskpolicy --print-rules | grep -q magisk_test").exec().isSuccess
)
module!!
assertTrue("test_01 should be zygisk unloaded", module.zygiskUnloaded)
}

View File

@@ -28,6 +28,7 @@ import org.junit.Test
import org.junit.runner.RunWith
import timber.log.Timber
import java.io.File
import java.io.PrintStream
@Keep
@RunWith(AndroidJUnit4::class)
@@ -106,7 +107,15 @@ class Environment : BaseTest {
val module = LocalModule(path)
assertTrue(error, module.zygiskFolder.mkdir())
assertTrue(error, Shell.cmd("set_default_perm $path").exec().isSuccess)
// Add sepolicy patch
PrintStream(path.getChildFile("sepolicy.rule").newOutputStream()).use {
it.println("type magisk_test domain")
}
assertTrue(error, Shell.cmd(
"set_default_perm $path",
"copy_preinit_files"
).exec().isSuccess)
}
private fun setupModule02(root: ExtendedFile) {