-
Notifications
You must be signed in to change notification settings - Fork 12
Live-test fixes: button labels, su auto-grant, reboot-order copy, Launch/Restart instance #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,7 +9,9 @@ | |||||||||
|
|
||||||||||
| import pytest | ||||||||||
|
|
||||||||||
| from adb_handler import MANAGER_PACKAGE, install_manager, uninstall_manager | ||||||||||
| from adb_handler import ( | ||||||||||
| MANAGER_PACKAGE, install_manager, install_module, uninstall_manager, | ||||||||||
| ) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def _cp(stdout="", stderr="", rc=0): | ||||||||||
|
|
@@ -86,6 +88,30 @@ def handle(cmd): | |||||||||
| install_manager("adb", 5555, apk, runner=_runner(handle)) | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def test_install_module_preauthorizes_shell_su_before_flashing(tmp_path): | ||||||||||
| """The flash first writes an allow policy for the shell uid so magiskd | ||||||||||
| doesn't auto-deny the su during the flash.""" | ||||||||||
| zip_path = tmp_path / "mod.zip" | ||||||||||
| zip_path.write_bytes(b"PK\x03\x04mod") | ||||||||||
|
|
||||||||||
| def handle(cmd): | ||||||||||
| if cmd[1] == "connect": | ||||||||||
| return _cp("connected to 127.0.0.1:5555") | ||||||||||
| if "install-module" in " ".join(cmd): | ||||||||||
| return _cp("Success") | ||||||||||
| return _cp() # sqlite pre-grant, push, rm | ||||||||||
|
|
||||||||||
| runner = _runner(handle) | ||||||||||
| install_module("adb", 5555, str(zip_path), runner=runner) | ||||||||||
|
|
||||||||||
| joined = [" ".join(c) for c in runner.calls] | ||||||||||
| # a permanent allow policy for the shell uid (2000) was set before the flash | ||||||||||
| policy = next(i for i, c in enumerate(joined) | ||||||||||
| if "magisk --sqlite" in c and "policies" in c and "2000,2,0" in c) | ||||||||||
|
Comment on lines
+109
to
+110
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the test assertion to expect the correct policy value of
Suggested change
|
||||||||||
| flash = next(i for i, c in enumerate(joined) if "install-module" in c) | ||||||||||
| assert policy < flash | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def test_uninstall_manager_success(tmp_path): | ||||||||||
| def handle(cmd): | ||||||||||
| if cmd[1] == "connect": | ||||||||||
|
|
||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import pytest | ||
|
|
||
| import instance_handler as ih | ||
|
|
||
|
|
||
| def test_launch_instance_starts_hd_player_with_instance(tmp_path, monkeypatch): | ||
| exe = tmp_path / "HD-Player.exe" | ||
| exe.write_bytes(b"x") | ||
| calls = [] | ||
| monkeypatch.setattr(ih.subprocess, "Popen", lambda args, **k: calls.append(args)) | ||
|
|
||
| ih.launch_instance(str(tmp_path), "Tiramisu64") | ||
|
|
||
| assert calls and calls[0][:3] == [str(exe), "--instance", "Tiramisu64"] | ||
|
|
||
|
|
||
| def test_launch_instance_missing_player_raises(tmp_path): | ||
| with pytest.raises(RuntimeError, match="HD-Player"): | ||
| ih.launch_instance(str(tmp_path), "Whatever") | ||
|
|
||
|
|
||
| def test_restart_instance_kills_then_relaunches(tmp_path, monkeypatch): | ||
| exe = tmp_path / "HD-Player.exe" | ||
| exe.write_bytes(b"x") | ||
| order = [] | ||
| monkeypatch.setattr(ih, "terminate_bluestacks", lambda: order.append("kill")) | ||
| monkeypatch.setattr(ih.time, "sleep", lambda s: order.append("wait")) | ||
| monkeypatch.setattr(ih.subprocess, "Popen", lambda args, **k: order.append("launch")) | ||
|
|
||
| ih.restart_instance(str(tmp_path), "Tiramisu64", wait_ms=10) | ||
|
|
||
| assert order == ["kill", "wait", "launch"] # kill, settle, then relaunch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Magisk's Superuser database (
policiestable), the policy values are defined as:0= Deny (POLICY_DENY)1= Allow (POLICY_ALLOW)2= Ask (POLICY_ASK)By setting the policy value to
2, you are configuring it to "Ask" (prompt), which means subsequentsucommands will still trigger a prompt. To pre-grant root access (auto-allow) for the shell UID (2000), the policy value should be set to1.