Skip to content

Commit 4bd118c

Browse files
committed
Drop environment check from test config.json samples and check environment via .repo file and installed packages in dom0 tests.
Check environment via .repo files instead of config.json in VM tests. openqa
1 parent 110fe0f commit 4bd118c

8 files changed

Lines changed: 37 additions & 19 deletions

files/sdw-admin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ def import_config():
506506
"hostname": ji_addr + ".onion",
507507
"key": ji_auth_token,
508508
},
509-
"environment": "prod",
510509
"vmsizes": {"sd_app": sd_app_gb, "sd_log": sd_log_gb},
511510
}
512511
temp_file = "/tmp/config.json"

tests/conftest.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,20 @@ def dom0_config():
4444

4545
@pytest.fixture
4646
def env():
47-
with open("config.json") as c:
48-
config = json.load(c)
49-
return config.get("environment")
47+
"""
48+
Check build variant based on installed .repo filename.
49+
Developers who are experimenting with additional disabled .repo files in
50+
/etc/yum.repos.d/ should ensure no naming collisions with securedrop-workstation-keyring
51+
files, per REPO_CONFIG above or per the securedrop-workstation-keyring rpm spec file.
52+
"""
53+
# Order matters due to package versioning
54+
for env_type in ["dev", "staging", "prod"]:
55+
repo_filename = REPO_CONFIG[env_type]["repo_file_name"]
56+
repo_path = Path(f"/etc/yum.repos.d/{repo_filename}")
57+
if repo_path.exists:
58+
return env_type
59+
60+
pytest.fail("Misconfigured environment, env could not be determined.")
5061

5162

5263
@pytest.fixture

tests/files/testconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"hostname": "sdolvtfhatvsysc6l34d65ymdwxcujausv7k5jk4cy5ttzhjoi6fzvyd.onion",
55
"key": "5U4JPYSZ34N2ZDSOUAL2YLEX2NPI5BLL2Y66QJW24KLSH7R3FEPQ"
66
},
7-
"environment": "prod",
87
"vmsizes": {
98
"sd_app": 10,
109
"sd_log": 5

tests/files/testconfig.json.malformedfpr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"hostname": "sdolvtfhatvsysc6l34d65ymdwxcujausv7k5jk4cy5ttzhjoi6fzvyd.onion",
55
"key": "5U4JPYSZ34N2ZDSOUAL2YLEX2NPI5BLL2Y66QJW24KLSH7R3FEPQ"
66
},
7-
"environment": "prod",
87
"vmsizes": {
98
"sd_app": 10,
109
"sd_log": 5

tests/files/testconfig.json.malformedonion

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"hostname": "sdolvtfhatvsysc6l34d65ymdwxcuj.onion",
55
"key": "5U4JPYSZ34N2ZDSOUAL2YLEX2NPI5BLL2Y66QJW24KLSH7R3FEPQ"
66
},
7-
"environment": "prod",
87
"vmsizes": {
98
"sd_app": 10,
109
"sd_log": 5

tests/test_dom0_and_templates_correct_key.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ def test_dom0_has_keyring_package(env):
129129
assert _is_installed("securedrop-workstation-keyring-dev")
130130
elif env == "staging":
131131
assert _is_installed("securedrop-workstation-keyring-staging")
132+
else:
133+
assert env == "prod"
132134

133135

134136
def test_rpm_repo_config(config):

tests/test_vms_exist.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import subprocess
33
import unittest
4+
from pathlib import Path
45

56
from qubesadmin import Qubes
67

@@ -16,8 +17,8 @@
1617
SD_VMS,
1718
)
1819

19-
with open("config.json") as f:
20-
CONFIG = json.load(f)
20+
DEV_REPO = Path("/etc/yum.repos.d/securedrop-workstation-dom0-dev.repo")
21+
STAGING_REPO = Path("/etc/yum.repos.d/securedrop-workstation-dom0-staging.repo")
2122

2223

2324
class SD_VM_Tests(unittest.TestCase):
@@ -40,7 +41,7 @@ def test_expected(self):
4041
for vm_name in SD_UNTAGGED_DEPRECATED_VMS:
4142
assert vm_name not in self.app.domains
4243

43-
@unittest.skipIf(CONFIG["environment"] != "prod", "Skipping on non-prod system")
44+
@unittest.skipIf(STAGING_REPO.exists or DEV_REPO.exists, "Skipping on non-prod system")
4445
def test_internal(self):
4546
internal = ["sd-proxy", "sd-proxy-dvm", "sd-viewer"]
4647

tests/test_vms_platform.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import json
21
import os
32
import re
43
import subprocess
54
import unittest
5+
from pathlib import Path
66

77
import pytest
88
from qubesadmin import Qubes
@@ -21,14 +21,22 @@
2121

2222
IS_CI = os.environ.get("CI") == "true"
2323

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+
2427

2528
class SD_VM_Platform_Tests(unittest.TestCase):
2629
def setUp(self):
2730
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"
3240

3341
def tearDown(self):
3442
pass
@@ -63,11 +71,11 @@ def _validate_apt_sources(self, vm):
6371
if vm.name in ["sd-whonix"]:
6472
return
6573

66-
if self.config["environment"] == "prod":
74+
if self.environment == "prod":
6775
component = "main"
6876
url = "https://apt.freedom.press"
6977
filename = "/etc/apt/sources.list.d/apt_freedom_press.sources"
70-
elif self.config["environment"] == "staging":
78+
elif self.environment == "staging":
7179
component = "main"
7280
url = "https://apt-test.freedom.press"
7381
filename = "/etc/apt/sources.list.d/apt-test_freedom_press.sources"
@@ -200,13 +208,13 @@ def test_sd_vm_apt_sources(self):
200208
assert (
201209
"Description: https://apt.freedom.press bookworm/main amd64 Packages\n" in contents
202210
)
203-
if self.config["environment"] == "prod":
211+
if self.environment == "prod":
204212
# prod setups shouldn't have any apt-test sources
205213
assert "apt-test.freedom.press" not in contents
206214
else:
207215
# staging/dev
208216
test_components = ["main"]
209-
if self.config["environment"] == "dev":
217+
if self.environment == "dev":
210218
test_components.append("nightlies")
211219
for component in test_components:
212220
assert (

0 commit comments

Comments
 (0)