|
1 | 1 | import hashlib |
| 2 | +import io |
2 | 3 | import json |
3 | 4 | from pathlib import Path |
4 | 5 | import tempfile |
|
9 | 10 | from release_policy import ( |
10 | 11 | ReleasePolicyError, |
11 | 12 | ensure_version_code_is_newer, |
| 13 | + fetch_published_codes, |
12 | 14 | parse_release_codes, |
13 | 15 | validate_promotion_bundle, |
14 | 16 | validate_version, |
|
17 | 19 |
|
18 | 20 |
|
19 | 21 | class ReleasePolicyTest(unittest.TestCase): |
| 22 | + def test_release_listing_uses_available_token_without_forwarding_it_to_assets(self): |
| 23 | + report = {"version": "2.3.7-beta.1", "versionCode": 1790000109, |
| 24 | + "certificateSha256": "fa4547514e795b2daca48bd05e9a5f9348e62531d791d746e0ffe93bb90247a3"} |
| 25 | + download = "https://github.com/Lecheeel/Portal/releases/download/v2.3.7-beta.1/verification.json" |
| 26 | + releases = [{"tag_name": "v2.3.7-beta.1", "assets": [ |
| 27 | + {"name": "verification.json", "browser_download_url": download}]}] |
| 28 | + for variable in ("GH_TOKEN", "GITHUB_TOKEN", None): |
| 29 | + with self.subTest(variable=variable): |
| 30 | + environment = {"GH_TOKEN": "", "GITHUB_TOKEN": ""} |
| 31 | + if variable: |
| 32 | + environment[variable] = "test-only-token" |
| 33 | + requests = [] |
| 34 | + def respond(request): |
| 35 | + requests.append(request) |
| 36 | + return io.BytesIO(json.dumps(releases if len(requests) == 1 else report).encode()) |
| 37 | + with patch.dict("os.environ", environment), patch("release_policy.open_release_url", side_effect=respond): |
| 38 | + self.assertEqual([1790000109], fetch_published_codes()) |
| 39 | + self.assertTrue(requests[0].full_url.startswith("https://api.github.com/")) |
| 40 | + self.assertEqual("Bearer test-only-token" if variable else None, |
| 41 | + requests[0].get_header("Authorization")) |
| 42 | + self.assertEqual(download, requests[1].full_url) |
| 43 | + self.assertIsNone(requests[1].get_header("Authorization")) |
| 44 | + |
20 | 45 | def test_version_names_allow_stable_and_supported_prerelease_channels(self): |
21 | 46 | for version in ("1.7.5", "1.7.5-beta.1", "1.7.5-canary.2", "1.7.5-rc.3"): |
22 | 47 | with self.subTest(version=version): |
|
0 commit comments