|
1 | 1 | from unittest.mock import patch |
2 | 2 |
|
3 | 3 | from socketsecurity.core import Core |
| 4 | +from socketsecurity.core.utils import socket_globs |
4 | 5 |
|
5 | 6 | # Minimal patterns matching what the Socket API returns |
6 | 7 | MOCK_PATTERNS = { |
7 | 8 | "npm": { |
8 | 9 | "packagejson": {"pattern": "package.json"}, |
9 | 10 | "packagelockjson": {"pattern": "package-lock.json"}, |
10 | 11 | "yarnlock": {"pattern": "yarn.lock"}, |
| 12 | + "bunlock": {"pattern": "bun.lock"}, |
| 13 | + "bunlockb": {"pattern": "bun.lockb"}, |
| 14 | + "vltlockjson": {"pattern": "vlt-lock.json"}, |
11 | 15 | }, |
12 | 16 | "pypi": { |
13 | 17 | "requirements": {"pattern": "*requirements.txt"}, |
@@ -66,3 +70,42 @@ def test_dot_slash_prefix_normalized(self, mock_patterns): |
66 | 70 | def test_pom_xml_root(self, mock_patterns): |
67 | 71 | core = Core.__new__(Core) |
68 | 72 | assert core.has_manifest_files(["pom.xml"]) is True |
| 73 | + |
| 74 | + def test_bun_lock_root(self, mock_patterns): |
| 75 | + core = Core.__new__(Core) |
| 76 | + assert core.has_manifest_files(["bun.lock"]) is True |
| 77 | + |
| 78 | + def test_bun_lockb_root(self, mock_patterns): |
| 79 | + core = Core.__new__(Core) |
| 80 | + assert core.has_manifest_files(["bun.lockb"]) is True |
| 81 | + |
| 82 | + def test_vlt_lock_json_root(self, mock_patterns): |
| 83 | + core = Core.__new__(Core) |
| 84 | + assert core.has_manifest_files(["vlt-lock.json"]) is True |
| 85 | + |
| 86 | + def test_bun_lock_subdirectory(self, mock_patterns): |
| 87 | + core = Core.__new__(Core) |
| 88 | + assert core.has_manifest_files(["apps/web/bun.lock"]) is True |
| 89 | + |
| 90 | + |
| 91 | +@patch.object(Core, "get_supported_patterns", side_effect=RuntimeError("API unreachable")) |
| 92 | +@patch.object(Core, "__init__", lambda self, *a, **kw: None) |
| 93 | +class TestHasManifestFilesFallback: |
| 94 | + """Exercises the socket_globs fallback path used when the Socket API is unreachable.""" |
| 95 | + |
| 96 | + def test_fallback_matches_bun_lock(self, mock_patterns): |
| 97 | + core = Core.__new__(Core) |
| 98 | + assert core.has_manifest_files(["bun.lock"]) is True |
| 99 | + |
| 100 | + def test_fallback_matches_bun_lockb(self, mock_patterns): |
| 101 | + core = Core.__new__(Core) |
| 102 | + assert core.has_manifest_files(["bun.lockb"]) is True |
| 103 | + |
| 104 | + def test_fallback_matches_vlt_lock_json(self, mock_patterns): |
| 105 | + core = Core.__new__(Core) |
| 106 | + assert core.has_manifest_files(["vlt-lock.json"]) is True |
| 107 | + |
| 108 | + def test_fallback_patterns_dict_contains_new_entries(self, mock_patterns): |
| 109 | + assert "bun.lock" in socket_globs["npm"] |
| 110 | + assert "bun.lockb" in socket_globs["npm"] |
| 111 | + assert "vlt-lock.json" in socket_globs["npm"] |
0 commit comments