mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-11 11:01:07 +00:00
Flatpak starts bwrap with an empty environment, so the bwrap shim lost DROIDDECK_BWRAP_SOCKET and dialled the default package's socket. The session now writes the socket name to /etc/droiddeck/bwrap-socket and the shim reads it when the variable is missing. Fixes #1092
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
import os
|
|
import runpy
|
|
import shutil
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest import mock
|
|
|
|
BWRAP = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-bwrap"
|
|
|
|
|
|
class BwrapSocketTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.dir = Path(tempfile.mkdtemp())
|
|
self.addCleanup(shutil.rmtree, self.dir, True)
|
|
self.shim = runpy.run_path(str(BWRAP))
|
|
self.shim["socket_name"].__globals__["SOCKET_FILE"] = str(self.dir / "bwrap-socket")
|
|
|
|
def name(self, env):
|
|
with mock.patch.dict(os.environ, env, clear=True):
|
|
return self.shim["socket_name"]()
|
|
|
|
def test_flatpak_empty_environment_reaches_a_renamed_package(self):
|
|
(self.dir / "bwrap-socket").write_text("com.antutu.benchmark.full.bwrap\n")
|
|
self.assertEqual("\0com.antutu.benchmark.full.bwrap", self.name({}))
|
|
|
|
def test_the_environment_still_wins(self):
|
|
(self.dir / "bwrap-socket").write_text("com.antutu.benchmark.full.bwrap\n")
|
|
self.assertEqual("\0com.tencent.ig.bwrap", self.name({"DROIDDECK_BWRAP_SOCKET": "com.tencent.ig.bwrap"}))
|
|
|
|
def test_without_either_the_standard_package_is_asked(self):
|
|
self.assertEqual("\0com.droiddeck.launcher.bwrap", self.name({}))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|