| 1 |
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv) |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (C) 2013 Red Hat, Inc. |
| 5 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 |
|
| 7 |
|
| 8 |
import testlib |
| 9 |
|
| 10 |
test_manifest = """ |
| 11 |
{ |
| 12 |
"tools": { |
| 13 |
"test": { |
| 14 |
"label": "Test" |
| 15 |
} |
| 16 |
}, |
| 17 |
|
| 18 |
"content-security-policy": "script-src 'self' 'unsafe-inline'" |
| 19 |
} |
| 20 |
""" |
| 21 |
|
| 22 |
test_html = """ |
| 23 |
<html> |
| 24 |
<head> |
| 25 |
<meta charset="utf-8"> |
| 26 |
<script src="../base1/cockpit.js"></script> |
| 27 |
<script> |
| 28 |
cockpit.transport.wait(function () { }); |
| 29 |
</script> |
| 30 |
</head> |
| 31 |
<body> |
| 32 |
<h1>Test</h1> |
| 33 |
</body> |
| 34 |
</html> |
| 35 |
""" |
| 36 |
|
| 37 |
|
| 38 |
@testlib.nondestructive |
| 39 |
@testlib.skipBeiboot("no local cockpit packages in beiboot mode") |
| 40 |
class TestPackages(testlib.MachineCase): |
| 41 |
|
| 42 |
def testBasic(self): |
| 43 |
m = self.machine |
| 44 |
b = self.browser |
| 45 |
|
| 46 |
self.restore_dir("/usr/local/share/cockpit") |
| 47 |
|
| 48 |
def reload_packages(): |
| 49 |
b.go("/playground/pkgs") |
| 50 |
b.enter_page("/playground/pkgs") |
| 51 |
b.click("#reload") |
| 52 |
|
| 53 |
def check_nav_entry(label, present): |
| 54 |
b.switch_to_top() |
| 55 |
if present: |
| 56 |
b.wait_visible(f"#nav-system li:contains('{label}')") |
| 57 |
else: |
| 58 |
b.wait_not_present(f"#nav-system li:contains('{label}')") |
| 59 |
|
| 60 |
self.login_and_go("/playground/pkgs") |
| 61 |
|
| 62 |
check_nav_entry("Terminal", present=True) |
| 63 |
|
| 64 |
m.write("/usr/local/share/cockpit/test/manifest.json", test_manifest) |
| 65 |
m.write("/usr/local/share/cockpit/test/test.html", test_html) |
| 66 |
reload_packages() |
| 67 |
|
| 68 |
b.switch_to_top() |
| 69 |
b.click("#nav-system a:contains('Test')") |
| 70 |
|
| 71 |
b.enter_page("/test/test") |
| 72 |
b.wait_text("h1", "Test") |
| 73 |
|
| 74 |
m.execute("rm -rf /usr/local/share/cockpit/test") |
| 75 |
reload_packages() |
| 76 |
check_nav_entry("Test", present=False) |
| 77 |
|
| 78 |
# Hide the terminal with a system override |
| 79 |
m.write("/etc/cockpit/systemd.override.json", """{ |
| 80 |
"tools": { |
| 81 |
"terminal": null |
| 82 |
} |
| 83 |
}""") |
| 84 |
reload_packages() |
| 85 |
check_nav_entry("Terminal", present=False) |
| 86 |
|
| 87 |
# user override on top which renames the services label |
| 88 |
self.restore_dir("/home/admin") |
| 89 |
m.write("/home/admin/.config/cockpit/systemd.override.json", """{ |
| 90 |
"menu": { |
| 91 |
"services": { "label": "Hackices" } |
| 92 |
} |
| 93 |
}""") |
| 94 |
reload_packages() |
| 95 |
check_nav_entry("Services", present=False) |
| 96 |
check_nav_entry("Hackices", present=True) |
| 97 |
# it adds to, not replaces the /etc override |
| 98 |
check_nav_entry("Terminal", present=False) |
| 99 |
|
| 100 |
|
| 101 |
if __name__ == '__main__': |
| 102 |
testlib.test_main() |