1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
import os
from pathlib import Path
import pytest
from briefcase.platforms.macOS import SigningIdentity
from ....utils import create_file, create_plist_file
@pytest.fixture
def sekrit_identity():
return SigningIdentity(id="CAFEBEEF", name="Sekrit identity (DEADBEEF)")
@pytest.fixture
def sekrit_installer_identity():
return SigningIdentity(id="CAFEFACE", name="Sekrit Installer identity (DEADBEEF)")
@pytest.fixture
def adhoc_identity():
return SigningIdentity()
@pytest.fixture
def first_app_templated(first_app_config, tmp_path):
app_path = tmp_path / "base_path/build/first-app/macos/app/First App.app"
# Create the briefcase.toml file
create_file(
tmp_path / "base_path/build/first-app/macos/app/briefcase.toml",
"""
[briefcase]
target_version = "0.3.20"
[paths]
app_packages_path="First App.app/Contents/Resources/app_packages"
support_path="First App.app/Contents/Frameworks"
runtime_path="Python.xcframework/macos-arm64_x86_64/Python.framework"
info_plist_path="First App.app/Contents/Info.plist"
entitlements_path="Entitlements.plist"
""",
)
# Create the plist file for the app
create_plist_file(
app_path / "Contents/Info.plist",
{
"MainModule": "first_app",
},
)
# Create the entitlements file for the app
create_plist_file(
tmp_path / "base_path/build/first-app/macos/app/Entitlements.plist",
{
"com.apple.security.cs.allow-unsigned-executable-memory": True,
"com.apple.security.cs.disable-library-validation": True,
},
)
# Create some folders that need to exist.
(app_path / "Contents/Resources/app_packages").mkdir(parents=True)
(app_path / "Contents/Frameworks").mkdir(parents=True)
# Create an installer Distribution.xml
create_file(
tmp_path / "base_path/build/first-app/macos/app/installer/Distribution.xml",
"""<?xml?>\n<installer-script></installer-script>""",
)
# Select dmg packaging by default
first_app_config.packaging_format = "dmg"
return first_app_config
@pytest.fixture
def first_app_with_binaries(first_app_templated, first_app_config, tmp_path):
app_path = tmp_path / "base_path/build/first-app/macos/app/First App.app"
# Create the stub binary
create_file(app_path / "Contents/MacOS/First App", "Stub binary")
# Create some libraries that need to be signed.
lib_path = app_path / "Contents/Resources/app_packages"
frameworks_path = app_path / "Contents/Frameworks"
for lib in [
"first_so.so",
Path("subfolder/second_so.so"),
"first_dylib.dylib",
Path("subfolder/second_dylib.dylib"),
"other_binary",
]:
create_file(
lib_path / lib,
mode="wb",
content=b"\xca\xfe\xba\xbeBinary content here",
)
# Mach-O file that is executable, with an odd extension
create_file(
lib_path / "special.binary",
mode="wb",
content=b"\xca\xfe\xba\xbeBinary content here",
)
os.chmod(lib_path / "special.binary", 0o755)
# An embedded app
create_file(
lib_path / "Extras.app/Contents/MacOS/Extras",
mode="wb",
content=b"\xca\xfe\xba\xbeBinary content here",
)
# An embedded framework
create_plist_file(frameworks_path / "Extras.framework/Resources/Info.plist", {})
create_file(
frameworks_path / "Extras.framework/Versions/1.2/libs/extras.dylib",
mode="wb",
content=b"\xca\xfe\xba\xbeBinary content here",
)
(frameworks_path / "Extras.framework/Versions/1.2/Extras").symlink_to(
frameworks_path / "Extras.framework/Versions/1.2/libs/extras.dylib"
)
(frameworks_path / "Extras.framework/Versions/Current").symlink_to(
frameworks_path / "Extras.framework/Versions/1.2"
)
(frameworks_path / "Extras.framework/Extras").symlink_to(
frameworks_path / "Extras.framework/Versions/Current/Extras"
)
# Make sure there are some files in the bundle that *don't* need to be signed...
create_file(lib_path / "first.other", "other")
create_file(lib_path / "second.other", "other")
# A file that has a Mach-O header, but isn't executable
create_file(
lib_path / "unknown.binary",
mode="wb",
content=b"\xca\xfe\xba\xbeother",
)
return first_app_config
|