| 1 |
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv) |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (C) 2017 Red Hat, Inc. |
| 5 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 |
|
| 7 |
import json |
| 8 |
import time |
| 9 |
|
| 10 |
import packagelib |
| 11 |
import testlib |
| 12 |
|
| 13 |
|
| 14 |
@testlib.skipWsContainer("Not supported") |
| 15 |
@testlib.skipImage("TODO: fix for OpenSUSE", "opensuse-tumbleweed") |
| 16 |
@testlib.nondestructive |
| 17 |
class TestApps(packagelib.PackageCase): |
| 18 |
|
| 19 |
def setUp(self) -> None: |
| 20 |
super().setUp() |
| 21 |
self.appstream_collection: 'set[str]' = set() |
| 22 |
self.machine.upload(["verify/files/test.png"], "/var/tmp/") |
| 23 |
|
| 24 |
def createAppStreamPackage(self, name: str, version: str, revision: str, install: bool = False) -> None: |
| 25 |
self.createPackage(name, version, revision, content={ |
| 26 |
f"/usr/share/metainfo/org.cockpit_project.{name}.metainfo.xml": f""" |
| 27 |
<component type="addon"> |
| 28 |
<extends>org.cockpit_project.cockpit</extends> |
| 29 |
<id>org.cockpit-project.{name}</id> |
| 30 |
<icon type="stock">{name}</icon> |
| 31 |
<name>{name}</name> |
| 32 |
<summary>{name} application for testing</summary> |
| 33 |
<launchable type="cockpit-manifest">{name}</launchable> |
| 34 |
</component> |
| 35 |
""", |
| 36 |
f"/usr/share/icons/hicolor/64x64/apps/{name}.png": {"path": "/var/tmp/test.png"}}, install=install) |
| 37 |
self.appstream_collection.add(name) |
| 38 |
|
| 39 |
def createAppStreamRepoPackage(self, subdir: str | None = None) -> None: |
| 40 |
if subdir is None: |
| 41 |
subdir = "swcatalog/xml" |
| 42 |
body = "" |
| 43 |
for p in self.appstream_collection: |
| 44 |
body += f""" |
| 45 |
<component type="addon"> |
| 46 |
<extends>org.cockpit_project.cockpit</extends> |
| 47 |
<id>org.cockpit-project.{p}</id> |
| 48 |
<icon type="cached">test.png</icon> |
| 49 |
<name>{p}</name> |
| 50 |
<summary>An application for testing</summary> |
| 51 |
<launchable type="cockpit-manifest">{p}</launchable> |
| 52 |
<description> |
| 53 |
<p>DESCRIPTION:none</p> |
| 54 |
</description> |
| 55 |
<url type="homepage">https://{p}.com</url> |
| 56 |
<pkgname>{p}</pkgname> |
| 57 |
</component> |
| 58 |
""" |
| 59 |
self.machine.execute(f"mkdir -p /usr/share/{subdir}") |
| 60 |
self.createPackage("appstream-data-test", "1.0", "1", content={ |
| 61 |
f"/usr/share/{subdir}/test.xml": f""" |
| 62 |
<components origin="test"> |
| 63 |
{body} |
| 64 |
</components> |
| 65 |
""", |
| 66 |
f"/usr/share/{subdir.split('/')[0]}/icons/test/64x64/test.png": {"path": "/var/tmp/test.png"}}) |
| 67 |
self.enableRepo(refresh_repo=True) |
| 68 |
# ignore the corresponding journal entry |
| 69 |
self.allow_journal_messages("org.freedesktop.PackageKit.*org.freedesktop.DBus.Error.NoReply.*") |
| 70 |
|
| 71 |
def testBasic(self, urlroot: str = ""): |
| 72 |
b = self.browser |
| 73 |
m = self.machine |
| 74 |
|
| 75 |
self.allow_journal_messages("can't remove watch: Invalid argument") |
| 76 |
|
| 77 |
self.restore_dir("/usr/share/metainfo", reboot_safe=True) |
| 78 |
self.restore_dir("/usr/share/swcatalog", reboot_safe=True) |
| 79 |
self.restore_dir("/usr/share/app-info", reboot_safe=True) |
| 80 |
self.restore_dir("/var/cache/app-info", reboot_safe=True) |
| 81 |
|
| 82 |
# Make sure none of the appstream directories exist. They |
| 83 |
# will be created later and we need to cope with that. |
| 84 |
m.execute("rm -rf /usr/share/metainfo /usr/share/swcatalog /usr/share/app-info /var/cache/app-info") |
| 85 |
|
| 86 |
# instead of the actual distro packages, use our own fake repo data package |
| 87 |
config = {"config": {"appstream_data_packages": ["appstream-data-test"]}} |
| 88 |
# Debian/Ubuntu have an appstream configuration package which makes apt update fetch appstream data |
| 89 |
if m.image.startswith("ubuntu") or m.image.startswith("debian"): |
| 90 |
self.createPackage("appstream-config", "1", "1") |
| 91 |
config["config"]["appstream_config_packages"] = ["appstream-config"] |
| 92 |
|
| 93 |
self.write_file("/etc/cockpit/apps.override.json", json.dumps(config)) |
| 94 |
|
| 95 |
if urlroot != "": |
| 96 |
m.write("/etc/cockpit/cockpit.conf", f"[WebService]\nUrlRoot={urlroot}") |
| 97 |
|
| 98 |
self.login_and_go("/apps", urlroot=urlroot) |
| 99 |
b.wait_in_text(".pf-v6-c-empty-state", "No applications installed or available") |
| 100 |
b.wait_in_text(".pf-v6-c-empty-state", "Application information is missing") |
| 101 |
|
| 102 |
# still no metadata, but already installed application |
| 103 |
self.createAppStreamPackage("already", "1.0", "1", install=True) |
| 104 |
b.wait_not_present(".pf-v6-c-empty-state") |
| 105 |
b.wait_visible(".app-list .pf-v6-c-data-list__item-action[rowid='already'] button:contains('Remove')") |
| 106 |
b.wait_in_text(".pf-v6-c-alert", "Application information is missing") |
| 107 |
|
| 108 |
self.createAppStreamPackage("app-1", "1.0", "1") |
| 109 |
self.createAppStreamRepoPackage() |
| 110 |
|
| 111 |
# Install package metadata |
| 112 |
b.click(".pf-v6-c-alert button") |
| 113 |
|
| 114 |
with b.wait_timeout(60): |
| 115 |
b.wait_visible(".app-list #app-1") |
| 116 |
b.wait_not_present(".pf-v6-c-alert") |
| 117 |
b.click(".app-list #app-1") |
| 118 |
|
| 119 |
b.wait_visible('a[href="https://app-1.com"]') |
| 120 |
b.wait_visible(f'#app-page img[src^="{urlroot}/cockpit/channel/"]') |
| 121 |
b.click(".pf-v6-c-breadcrumb a:contains('Applications')") |
| 122 |
|
| 123 |
b.wait_visible("#list-page") |
| 124 |
b.wait_not_present("#app-page") |
| 125 |
|
| 126 |
if urlroot == "": |
| 127 |
b.assert_pixels("#list-page", "list-page") |
| 128 |
|
| 129 |
b.click(".app-list .pf-v6-c-data-list__item-action[rowid='app-1'] button:contains('Install')") |
| 130 |
b.wait_text(".app-list .pf-v6-c-data-list__item-action[rowid='app-1'] button", "Remove") |
| 131 |
b.wait_visible(f".app-list .pf-v6-c-data-list__item-row img[alt='icon of app-1'][src^='{urlroot}/cockpit/channel/']") |
| 132 |
m.execute("test -f /stamp-app-1-1.0-1") |
| 133 |
|
| 134 |
b.click(".app-list .pf-v6-c-data-list__item-action[rowid='app-1'] button:contains('Remove')") |
| 135 |
b.wait_text(".app-list .pf-v6-c-data-list__item-action[rowid='app-1'] button", "Install") |
| 136 |
b.wait_visible(f".app-list .pf-v6-c-data-list__item-row img[alt='icon of app-1'][src^='{urlroot}/cockpit/channel/']") |
| 137 |
m.execute("! test -f /stamp-app-1-1.0-1") |
| 138 |
|
| 139 |
def testWithUrlRoot(self): |
| 140 |
self.testBasic(urlroot="/webcon") |
| 141 |
|
| 142 |
def testOsMap(self): |
| 143 |
b = self.browser |
| 144 |
m = self.machine |
| 145 |
|
| 146 |
self.allow_journal_messages("can't remove watch: Invalid argument") |
| 147 |
|
| 148 |
self.restore_dir("/usr/share/metainfo", reboot_safe=True) |
| 149 |
self.restore_dir("/usr/share/swcatalog", reboot_safe=True) |
| 150 |
self.restore_dir("/usr/share/app-info", reboot_safe=True) |
| 151 |
self.restore_dir("/var/cache/app-info", reboot_safe=True) |
| 152 |
|
| 153 |
# Make sure none of the appstream directories exist. They |
| 154 |
# will be created later and we need to cope with that. |
| 155 |
m.execute("rm -rf /usr/share/metainfo /usr/share/swcatalog /usr/share/app-info /var/cache/app-info") |
| 156 |
|
| 157 |
# use a fake distro map |
| 158 |
self.write_file("/etc/cockpit/apps.override.json", |
| 159 |
'{ "config": { "appstream_data_packages":' |
| 160 |
' {"testy": ["appstream-data-test"], "otheros": ["nosuchpackage"]},' |
| 161 |
' "appstream_config_packages": []' |
| 162 |
' }}') |
| 163 |
|
| 164 |
self.createAppStreamPackage("app-1", "1.0", "1") |
| 165 |
# old subdir until Fedora 39 |
| 166 |
self.createAppStreamRepoPackage(subdir="app-info/xmls") |
| 167 |
|
| 168 |
self.login_and_go("/apps") |
| 169 |
b.wait_visible(".pf-v6-c-empty-state") |
| 170 |
|
| 171 |
# os-release is a symlink target, don't clobber that |
| 172 |
self.restore_file("/etc/os-release") |
| 173 |
m.execute("rm /etc/os-release") |
| 174 |
|
| 175 |
# get along with absent os-release |
| 176 |
b.click("#refresh") |
| 177 |
# the progress bar is too fast to reliably catch it |
| 178 |
time.sleep(1) |
| 179 |
b.wait_not_present("#refresh-progress") |
| 180 |
b.wait_visible(".pf-v6-c-empty-state") |
| 181 |
# wait until check for installed metadata package finished |
| 182 |
b.wait_attr("#list-page", "data-packages-checked", "true") |
| 183 |
# no appstream metadata available, don't advertise it |
| 184 |
b.wait_in_text(".pf-v6-c-empty-state", "No applications installed or available") |
| 185 |
self.assertNotIn("Install application information", b.text(".pf-v6-c-empty-state")) |
| 186 |
b.wait_not_present(".pf-v6-c-empty-state button") |
| 187 |
|
| 188 |
# unknown OS: nothing gets installed |
| 189 |
m.write("/etc/os-release", 'ID="unmapped"\nID_LIKE="mysterious"\nVERSION_ID="1"\n') |
| 190 |
b.click("#refresh") |
| 191 |
# the progress bar is too fast to reliably catch it |
| 192 |
time.sleep(1) |
| 193 |
b.wait_not_present("#refresh-progress") |
| 194 |
b.wait_visible(".pf-v6-c-empty-state") |
| 195 |
|
| 196 |
# known OS: appstream-data-test gets installed from the map |
| 197 |
m.write("/etc/os-release", 'ID="derivative"\nID_LIKE="spicy testy"\nVERSION_ID="1"\n') |
| 198 |
b.click("#refresh") |
| 199 |
m.execute("until test -e /usr/share/app-info/xmls/test.xml; do sleep 1; done") |
| 200 |
b.wait_visible(".app-list #app-1") |
| 201 |
|
| 202 |
def testL10N(self): |
| 203 |
b = self.browser |
| 204 |
m = self.machine |
| 205 |
|
| 206 |
# Switching to a language might produce these messages, which seem to be harmless. |
| 207 |
self.allow_journal_messages("invalid or unusable locale.*", |
| 208 |
"Error .* data: Connection reset by peer") |
| 209 |
|
| 210 |
# Reset everything |
| 211 |
m.execute("for d in /usr/share/metainfo /usr/share/app-info /var/cache/app-info; do mkdir -p $d; mount -t tmpfs tmpfs $d; done") |
| 212 |
self.addCleanup(m.execute, "for d in /usr/share/metainfo /usr/share/app-info /var/cache/app-info; do umount $d; done") |
| 213 |
|
| 214 |
self.login_and_go("/apps") |
| 215 |
b.wait_visible(".pf-v6-c-empty-state") |
| 216 |
|
| 217 |
m.write("/usr/share/app-info/xmls/test.xml", """ |
| 218 |
<components origin="test"> |
| 219 |
<component type="addon"> |
| 220 |
<extends>org.cockpit_project.cockpit</extends> |
| 221 |
<id>org.cockpit-project.foo</id> |
| 222 |
<name>NAME:none</name> |
| 223 |
<name xml:lang="de">NAME:de</name> |
| 224 |
<summary>SUMMARY:none</summary> |
| 225 |
<summary xml:lang="de">SUMMARY:de</summary> |
| 226 |
<description> |
| 227 |
<p>DESCRIPTION:none</p> |
| 228 |
<p xml:lang="de">DESCRIPTION:de</p> |
| 229 |
</description> |
| 230 |
<launchable type="cockpit-manifest">foo</launchable> |
| 231 |
<pkgname>foo</pkgname> |
| 232 |
</component> |
| 233 |
</components>""") |
| 234 |
|
| 235 |
b.wait_text(".app-list .pf-v6-c-data-list__item-action[rowid='NAME:none'] button", "Install") |
| 236 |
b.click(".app-list .pf-v6-c-data-list__item-row button:contains('NAME:none')") |
| 237 |
b.wait_text(".app-description", "DESCRIPTION:none") |
| 238 |
|
| 239 |
def set_lang(lang: str) -> None: |
| 240 |
b.switch_to_top() |
| 241 |
b.open_session_menu() |
| 242 |
b.click("button.display-language-menu") |
| 243 |
b.wait_visible('#display-language-modal') |
| 244 |
b.click(f'#display-language-modal li[data-value={lang}] button') |
| 245 |
b.click("#display-language-modal footer button.pf-m-primary") |
| 246 |
b.wait_not_present('#display-language-modal') |
| 247 |
b.wait_language(lang) |
| 248 |
b.enter_page("/apps") |
| 249 |
|
| 250 |
set_lang("de-de") |
| 251 |
b.wait_text(".app-description", "DESCRIPTION:de") |
| 252 |
|
| 253 |
set_lang("ja-jp") |
| 254 |
b.wait_text(".app-description", "DESCRIPTION:none") |
| 255 |
|
| 256 |
# like in the general whitelist, but translated |
| 257 |
self.allow_journal_messages("xargs: basename: .*Signal 13.*") |
| 258 |
|
| 259 |
def testBrokenXML(self): |
| 260 |
b = self.browser |
| 261 |
m = self.machine |
| 262 |
|
| 263 |
# Reset everything |
| 264 |
m.execute("for d in /usr/share/metainfo /usr/share/app-info /var/cache/app-info /usr/share/swcatalog; do mkdir -p $d; mount -t tmpfs tmpfs $d; done") |
| 265 |
self.addCleanup(m.execute, "for d in /usr/share/metainfo /usr/share/app-info /var/cache/app-info /usr/share/swcatalog; do umount $d; done") |
| 266 |
|
| 267 |
appstream_folder = "/usr/share/app-info/xmls" |
| 268 |
|
| 269 |
self.login_and_go("/apps") |
| 270 |
b.wait_visible(".pf-v6-c-empty-state") |
| 271 |
|
| 272 |
self.allow_journal_messages(".*/usr/share/app-info/xmls/test.xml.*", |
| 273 |
".*xml.etree.ElementTree.ParseError.*") |
| 274 |
|
| 275 |
def reset(): |
| 276 |
m.write(f"{appstream_folder}/test.xml", """ |
| 277 |
<components origin="test"> |
| 278 |
<component type="addon"> |
| 279 |
<extends>org.cockpit_project.cockpit</extends> |
| 280 |
<id>org.cockpit-project.test</id> |
| 281 |
<name>Name</name> |
| 282 |
<summary>Summary</summary> |
| 283 |
<description> |
| 284 |
<p>Description</p> |
| 285 |
</description> |
| 286 |
<launchable type="cockpit-manifest">foo</launchable> |
| 287 |
<pkgname>foo</pkgname> |
| 288 |
</component> |
| 289 |
</components>""") |
| 290 |
b.wait_not_present(".pf-v6-c-empty-state") |
| 291 |
b.wait_visible(".app-list .pf-v6-c-data-list__item-row:contains('Summary')") |
| 292 |
|
| 293 |
# First lay down some good XML so that we can later detect the reaction to broken XML. |
| 294 |
reset() |
| 295 |
|
| 296 |
# Unparsable |
| 297 |
m.write(f"{appstream_folder}/test.xml", """ |
| 298 |
This <is <not XML. |
| 299 |
""") |
| 300 |
b.wait_visible(".pf-v6-c-empty-state") |
| 301 |
reset() |
| 302 |
|
| 303 |
# Not really AppStream |
| 304 |
m.write(f"{appstream_folder}/test.xml", """ |
| 305 |
<foo></foo> |
| 306 |
""") |
| 307 |
b.wait_visible(".pf-v6-c-empty-state") |
| 308 |
reset() |
| 309 |
|
| 310 |
# No origin |
| 311 |
m.write(f"{appstream_folder}/test.xml", """ |
| 312 |
<components> |
| 313 |
<component type="addon"> |
| 314 |
<extends>org.cockpit_project.cockpit</extends> |
| 315 |
<id>org.cockpit-project.test</id> |
| 316 |
<name>Name</name> |
| 317 |
<summary>Summary</summary> |
| 318 |
<description> |
| 319 |
<p>Description</p> |
| 320 |
</description> |
| 321 |
<launchable type="cockpit-manifest">foo</launchable> |
| 322 |
<pkgname>foo</pkgname> |
| 323 |
</component> |
| 324 |
</components>""") |
| 325 |
b.wait_visible(".pf-v6-c-empty-state") |
| 326 |
reset() |
| 327 |
|
| 328 |
# No package |
| 329 |
m.write(f"{appstream_folder}/test.xml", """ |
| 330 |
<components origin="test"> |
| 331 |
<component type="addon"> |
| 332 |
<extends>org.cockpit_project.cockpit</extends> |
| 333 |
<id>org.cockpit-project.test</id> |
| 334 |
<name>Name</name> |
| 335 |
<summary>Summary</summary> |
| 336 |
<description> |
| 337 |
<p>Description</p> |
| 338 |
</description> |
| 339 |
<launchable type="cockpit-manifest">foo</launchable> |
| 340 |
</component> |
| 341 |
</components>""") |
| 342 |
b.wait_visible(".pf-v6-c-empty-state") |
| 343 |
reset() |
| 344 |
|
| 345 |
# No id |
| 346 |
m.write(f"{appstream_folder}/test.xml", """ |
| 347 |
<components origin="test"> |
| 348 |
<component type="addon"> |
| 349 |
<extends>org.cockpit_project.cockpit</extends> |
| 350 |
<name>Name</name> |
| 351 |
<summary>No description</summary> |
| 352 |
<launchable type="cockpit-manifest">foo</launchable> |
| 353 |
<pkgname>foo</pkgname> |
| 354 |
</component> |
| 355 |
</components>""") |
| 356 |
b.wait_visible(".pf-v6-c-empty-state") |
| 357 |
reset() |
| 358 |
|
| 359 |
# Error (launchable without type) in earlier entry, shouldn't affect the later entry |
| 360 |
m.write(f"{appstream_folder}/test.xml", """ |
| 361 |
<components origin="test"> |
| 362 |
<component type="addon"> |
| 363 |
<extends>org.cockpit_project.cockpit</extends> |
| 364 |
<id>org.cockpit-project.test2</id> |
| 365 |
<name>Name</name> |
| 366 |
<summary>Summary</summary> |
| 367 |
<description> |
| 368 |
<p>Description 2</p> |
| 369 |
</description> |
| 370 |
<launchable>foo</launchable> |
| 371 |
<pkgname>foo</pkgname> |
| 372 |
</component> |
| 373 |
<component type="addon"> |
| 374 |
<extends>org.cockpit_project.cockpit</extends> |
| 375 |
<id>org.cockpit-project.test</id> |
| 376 |
<name>Name</name> |
| 377 |
<summary>Summary 2</summary> |
| 378 |
<description> |
| 379 |
<p>Description</p> |
| 380 |
</description> |
| 381 |
<launchable type="cockpit-manifest">foo</launchable> |
| 382 |
<pkgname>foo</pkgname> |
| 383 |
</component> |
| 384 |
</components>""") |
| 385 |
b.wait_not_present(".pf-v6-c-empty-state") |
| 386 |
b.wait_visible(".app-list .pf-v6-c-data-list__item-row:contains('Summary 2')") |
| 387 |
|
| 388 |
def testNoPackageManager(self): |
| 389 |
b = self.browser |
| 390 |
m = self.machine |
| 391 |
|
| 392 |
def disable_service(service_name: str) -> None: |
| 393 |
m.execute(f"systemctl stop {service_name}") |
| 394 |
system_service = m.execute(f"systemctl show -p FragmentPath {service_name}.service | cut -f2 -d=").strip() |
| 395 |
m.execute(f"mv {system_service} {system_service}.disabled") |
| 396 |
self.addCleanup(m.execute, f"mv {system_service}.disabled {system_service}") |
| 397 |
|
| 398 |
if m.image.startswith('fedora-'): |
| 399 |
disable_service("dnf5daemon-server") |
| 400 |
disable_service("packagekit") |
| 401 |
else: |
| 402 |
disable_service("packagekit") |
| 403 |
|
| 404 |
self.assertNotIn("\napps", m.execute("cockpit-bridge --packages")) |
| 405 |
self.login_and_go(None) |
| 406 |
b.wait_in_text("#host-apps", "Terminal") |
| 407 |
self.assertNotIn("Applications", b.text("#host-apps")) |
| 408 |
|
| 409 |
|
| 410 |
if __name__ == '__main__': |
| 411 |
testlib.test_main() |