42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
"""Tests for `raycast_api.discovery.binary`."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from raycast_api.discovery.binary import find_signature_secret
|
|
from raycast_api.errors import DiscoveryError
|
|
|
|
EXPECTED_FAKE_SECRET = ("DEAD" + "BEEF" * 15).lower()
|
|
|
|
|
|
def test_finds_secret_in_synthetic_app(mock_app: Path) -> None:
|
|
secret = find_signature_secret(mock_app)
|
|
assert secret == EXPECTED_FAKE_SECRET
|
|
|
|
|
|
def test_rejects_non_bundle(tmp_path: Path) -> None:
|
|
with pytest.raises(DiscoveryError, match="Not an app bundle"):
|
|
find_signature_secret(tmp_path / "nonexistent.app")
|
|
|
|
|
|
def test_rejects_missing_pattern(tmp_path: Path) -> None:
|
|
app = tmp_path / "Empty.app"
|
|
(app / "Contents" / "MacOS").mkdir(parents=True)
|
|
(app / "Contents" / "MacOS" / "Empty").write_bytes(b"\x00" * 1024)
|
|
with pytest.raises(DiscoveryError, match="Could not find"):
|
|
find_signature_secret(app)
|
|
|
|
|
|
def test_accepts_double_or_single_quoted_pattern(tmp_path: Path) -> None:
|
|
"""The launcher uses single quotes, but the regex tolerates either form."""
|
|
app = tmp_path / "DoubleQuote.app"
|
|
(app / "Contents" / "MacOS").mkdir(parents=True)
|
|
secret = "a" * 64
|
|
(app / "Contents" / "MacOS" / "DoubleQuote").write_bytes(
|
|
b"\x00" * 100 + f'window.signatureSecret = "{secret}"'.encode() + b"\x00" * 100
|
|
)
|
|
assert find_signature_secret(app) == secret
|