|
1 | | -import json |
2 | 1 | import os |
3 | 2 | import re |
4 | 3 | import subprocess |
5 | 4 | import unittest |
| 5 | +from pathlib import Path |
6 | 6 |
|
7 | 7 | import pytest |
8 | 8 | from qubesadmin import Qubes |
|
21 | 21 |
|
22 | 22 | IS_CI = os.environ.get("CI") == "true" |
23 | 23 |
|
| 24 | +DEV_REPO = Path("/etc/yum.repos.d/securedrop-workstation-dom0-dev.repo") |
| 25 | +STAGING_REPO = Path("/etc/yum.repos.d/securedrop-workstation-dom0-staging.repo") |
| 26 | + |
24 | 27 |
|
25 | 28 | class SD_VM_Platform_Tests(unittest.TestCase): |
26 | 29 | def setUp(self): |
27 | 30 | self.app = Qubes() |
28 | | - with open("config.json") as c: |
29 | | - self.config = json.load(c) |
30 | | - if "environment" not in self.config: |
31 | | - self.config["environment"] = "dev" |
| 31 | + |
| 32 | + # Order matters; if dev .repo file is installed, |
| 33 | + # it wins, then staging, due to package versioning |
| 34 | + if DEV_REPO.exists: |
| 35 | + self.environment = "dev" |
| 36 | + elif STAGING_REPO.exists: |
| 37 | + self.environment = "staging" |
| 38 | + else: |
| 39 | + self.environment = "prod" |
32 | 40 |
|
33 | 41 | def tearDown(self): |
34 | 42 | pass |
@@ -63,11 +71,11 @@ def _validate_apt_sources(self, vm): |
63 | 71 | if vm.name in ["sd-whonix"]: |
64 | 72 | return |
65 | 73 |
|
66 | | - if self.config["environment"] == "prod": |
| 74 | + if self.environment == "prod": |
67 | 75 | component = "main" |
68 | 76 | url = "https://apt.freedom.press" |
69 | 77 | filename = "/etc/apt/sources.list.d/apt_freedom_press.sources" |
70 | | - elif self.config["environment"] == "staging": |
| 78 | + elif self.environment == "staging": |
71 | 79 | component = "main" |
72 | 80 | url = "https://apt-test.freedom.press" |
73 | 81 | filename = "/etc/apt/sources.list.d/apt-test_freedom_press.sources" |
@@ -200,13 +208,13 @@ def test_sd_vm_apt_sources(self): |
200 | 208 | assert ( |
201 | 209 | "Description: https://apt.freedom.press bookworm/main amd64 Packages\n" in contents |
202 | 210 | ) |
203 | | - if self.config["environment"] == "prod": |
| 211 | + if self.environment == "prod": |
204 | 212 | # prod setups shouldn't have any apt-test sources |
205 | 213 | assert "apt-test.freedom.press" not in contents |
206 | 214 | else: |
207 | 215 | # staging/dev |
208 | 216 | test_components = ["main"] |
209 | | - if self.config["environment"] == "dev": |
| 217 | + if self.environment == "dev": |
210 | 218 | test_components.append("nightlies") |
211 | 219 | for component in test_components: |
212 | 220 | assert ( |
|
0 commit comments