Skip to content

Commit f7b79a3

Browse files
authored
Merge pull request #1440 from freedomofpress/test-apt-sources
Simplify and improve testing of apt sources
2 parents 43f1f09 + a0b9e51 commit f7b79a3

File tree

1 file changed

+35
-50
lines changed

1 file changed

+35
-50
lines changed

tests/test_vms_platform.py

Lines changed: 35 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -54,37 +54,6 @@ def _validate_vm_platform(self, vm):
5454
platform = self._get_platform_info(vm)
5555
assert SUPPORTED_SD_DEBIAN_DIST in platform
5656

57-
def _validate_apt_sources(self, vm):
58-
"""
59-
Check that the given AppVM has the proper apt .sources file
60-
"""
61-
62-
# sd-whonix does not use the fpf-apt-test-repo
63-
if vm.name in ["sd-whonix"]:
64-
return
65-
66-
if self.config["environment"] == "prod":
67-
component = "main"
68-
url = "https://apt.freedom.press"
69-
filename = "/etc/apt/sources.list.d/apt_freedom_press.sources"
70-
elif self.config["environment"] == "staging":
71-
component = "main"
72-
url = "https://apt-test.freedom.press"
73-
filename = "/etc/apt/sources.list.d/apt-test_freedom_press.sources"
74-
else:
75-
component = "main nightlies"
76-
url = "https://apt-test.freedom.press"
77-
filename = "/etc/apt/sources.list.d/apt-test_freedom_press.sources"
78-
79-
stdout, stderr = vm.run(f"cat {filename}")
80-
contents = stdout.decode("utf-8").rstrip("\n")
81-
82-
assert f"Components: {component}\n" in contents, f"{vm.name} wrong component"
83-
assert f"URIs: {url}\n" in contents, f"{vm.name} wrong URL"
84-
assert (
85-
f"Suites: {SUPPORTED_SD_DEBIAN_DIST}\n" in contents
86-
), f"{vm.name} wrong suite/codename"
87-
8857
def _ensure_packages_up_to_date(self, vm, fedora=False):
8958
"""
9059
Asserts that all available packages are installed; no pending
@@ -192,25 +161,41 @@ def test_sd_vm_apt_sources(self):
192161
f"whonix-gateway-{CURRENT_WHONIX_VERSION}",
193162
]:
194163
vm = self.app.domains[vm_name]
195-
# First verify it looks like what we provisioned
196-
self._validate_apt_sources(vm)
197164

198-
stdout, stderr = vm.run("apt-get indextargets")
199-
contents = stdout.decode().strip()
200-
assert (
201-
"Description: https://apt.freedom.press bookworm/main amd64 Packages\n" in contents
165+
# First, check the prod apt repo is configured, which happens unconditionally
166+
# via securedrop-keyring deb package
167+
self.assert_apt_source(
168+
vm,
169+
"main",
170+
"https://apt.freedom.press",
171+
"/etc/apt/sources.list.d/apt_freedom_press.sources",
202172
)
173+
203174
if self.config["environment"] == "prod":
204-
# prod setups shouldn't have any apt-test sources
205-
assert "apt-test.freedom.press" not in contents
206-
else:
207-
# staging/dev
208-
test_components = ["main"]
209-
if self.config["environment"] == "dev":
210-
test_components.append("nightlies")
211-
for component in test_components:
212-
assert (
213-
f"Description: https://apt-test.freedom.press bookworm/{component} "
214-
+ "amd64 Packages\n"
215-
in contents
216-
)
175+
# No test sources should be present
176+
stdout, stderr = vm.run("ls /etc/apt/sources.list.d/")
177+
sources_list = stdout.decode("utf-8").rstrip("\n")
178+
assert "apt-test_freedom_press.sources" not in sources_list
179+
continue
180+
181+
# we're in staging or dev, so check for that file
182+
components = ["main"]
183+
if self.config["environment"] == "dev":
184+
components.append("nightlies")
185+
186+
self.assert_apt_source(
187+
vm,
188+
" ".join(components),
189+
"https://apt-test.freedom.press",
190+
"/etc/apt/sources.list.d/apt-test_freedom_press.sources",
191+
)
192+
193+
def assert_apt_source(self, vm, component, url, filename):
194+
stdout, stderr = vm.run(f"cat {filename}")
195+
contents = stdout.decode("utf-8").rstrip("\n")
196+
197+
assert f"Components: {component}\n" in contents, f"{vm.name} wrong component"
198+
assert f"URIs: {url}\n" in contents, f"{vm.name} wrong URL"
199+
assert (
200+
f"Suites: {SUPPORTED_SD_DEBIAN_DIST}\n" in contents
201+
), f"{vm.name} wrong suite/codename"

0 commit comments

Comments
 (0)