| 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 json |
| 9 |
import os |
| 10 |
import subprocess |
| 11 |
import tempfile |
| 12 |
import time |
| 13 |
from pathlib import Path |
| 14 |
|
| 15 |
import testlib |
| 16 |
from lib.constants import TEST_OS_DEFAULT |
| 17 |
|
| 18 |
RHEL_DOC_BASE = "https://docs.redhat.com/en/documentation" |
| 19 |
|
| 20 |
|
| 21 |
@testlib.nondestructive |
| 22 |
class TestPages(testlib.MachineCase): |
| 23 |
def checkDocs(self, items): |
| 24 |
m = self.machine |
| 25 |
b = self.browser |
| 26 |
|
| 27 |
b.click("#toggle-docs") |
| 28 |
b.wait_visible("#toggle-docs-menu") |
| 29 |
expected = "Web Console" |
| 30 |
expected += "".join(items) |
| 31 |
expected += "About Web Console" |
| 32 |
# DOCUMENTATION_URL is only in Fedora, RHEL and Arch |
| 33 |
if "fedora" in m.image: |
| 34 |
expected = "Fedora Linux documentation" + expected |
| 35 |
elif m.image.startswith("rhel"): |
| 36 |
expected = "Red Hat Enterprise Linux documentation" + expected |
| 37 |
elif m.image == "arch": |
| 38 |
expected = "Arch Linux documentation" + expected |
| 39 |
|
| 40 |
b.wait_collected_text("#toggle-docs-menu", expected) |
| 41 |
b.click("#toggle-docs") |
| 42 |
b.wait_not_present("#toggle-docs-menu") |
| 43 |
|
| 44 |
def check_system_menu(self, label, present): |
| 45 |
b = self.browser |
| 46 |
if present: |
| 47 |
b.wait_visible(f"#host-apps li a:contains('{label}')") |
| 48 |
else: |
| 49 |
b.wait_not_present(f"#host-apps li a:contains('{label}')") |
| 50 |
|
| 51 |
def open_lang_modal(self): |
| 52 |
self.browser.switch_to_top() |
| 53 |
self.browser.open_session_menu() |
| 54 |
|
| 55 |
self.browser.click("button.display-language-menu") |
| 56 |
self.browser.wait_visible('#display-language-modal') |
| 57 |
|
| 58 |
def testBasic(self): |
| 59 |
m = self.machine |
| 60 |
b = self.browser |
| 61 |
|
| 62 |
self.restore_dir("/etc/systemd/system", post_restore_action="systemctl daemon-reload") |
| 63 |
self.addCleanup(m.execute, "systemctl stop test.timer test.service") |
| 64 |
m.write("/etc/systemd/system/test.service", |
| 65 |
""" |
| 66 |
[Unit] |
| 67 |
Description=Test Service |
| 68 |
|
| 69 |
[Service] |
| 70 |
ExecStart=/bin/true |
| 71 |
|
| 72 |
[Install] |
| 73 |
WantedBy=default.target |
| 74 |
""") |
| 75 |
m.write("/etc/systemd/system/test.timer", |
| 76 |
""" |
| 77 |
[Unit] |
| 78 |
Description=Test timer |
| 79 |
|
| 80 |
[Timer] |
| 81 |
OnCalendar=daily |
| 82 |
""") |
| 83 |
# After writing files out tell systemd about them |
| 84 |
m.execute("systemctl daemon-reload") |
| 85 |
|
| 86 |
m.execute("systemctl start test.timer") |
| 87 |
|
| 88 |
self.allow_journal_messages("Failed to get realtime timestamp: Cannot assign requested address") |
| 89 |
|
| 90 |
# On Debian and Ubuntu we have to generate the other locales |
| 91 |
if "debian" in m.image: |
| 92 |
m.write("/etc/locale.gen", "de_DE.UTF-8 UTF-8\n", append=True) |
| 93 |
m.execute("locale-gen; update-locale") |
| 94 |
elif "arch" == m.image: |
| 95 |
m.write("/etc/locale.gen", "de_DE.UTF-8 UTF-8\n", append=True) |
| 96 |
m.execute("locale-gen") |
| 97 |
elif "ubuntu" in m.image: |
| 98 |
m.execute("locale-gen de_DE; locale-gen de_DE.UTF-8; update-locale") |
| 99 |
|
| 100 |
# login so that we have a cookie. |
| 101 |
self.login_and_go("/system/services#/test.service") |
| 102 |
|
| 103 |
# check that reloading a page with parameters works |
| 104 |
b.enter_page("/system/services") |
| 105 |
b.reload() |
| 106 |
b.enter_page("/system/services") |
| 107 |
b.wait_text(".service-name", "Test Service") |
| 108 |
b.switch_to_top() |
| 109 |
self.checkDocs(["Managing services"]) |
| 110 |
b.click("#toggle-docs") |
| 111 |
b.wait_visible(f'#toggle-docs-menu a:contains("Managing services")[href^="{RHEL_DOC_BASE}"]') |
| 112 |
b.wait_visible(f'#toggle-docs-menu a:contains("Web Console")[href^="{RHEL_DOC_BASE}"]') |
| 113 |
b.click("#toggle-docs") |
| 114 |
b.wait_not_present("#toggle-docs-menu") |
| 115 |
b.go("/network") |
| 116 |
self.checkDocs(["Managing networking bonds", "Managing networking teams", |
| 117 |
"Managing networking bridges", "Managing VLANs", "Managing firewall"]) |
| 118 |
b.go("/system") |
| 119 |
self.checkDocs(["Configuring system settings"]) |
| 120 |
b.go("/network/firewall") |
| 121 |
self.checkDocs(["Managing networking bonds", "Managing networking teams", |
| 122 |
"Managing networking bridges", "Managing VLANs", "Managing firewall"]) |
| 123 |
b.go("/system/services") |
| 124 |
|
| 125 |
m.restart_cockpit() |
| 126 |
b.relogin("/system/services") |
| 127 |
b.wait_text(".service-name", "Test Service") |
| 128 |
|
| 129 |
# check that navigating away and back preserves place |
| 130 |
b.click_system_menu("/system") |
| 131 |
b.wait_visible("#system_information_systime_button") |
| 132 |
b.switch_to_top() |
| 133 |
self.checkDocs(["Configuring system settings"]) |
| 134 |
b.click_system_menu("/system/services") |
| 135 |
b.wait_visible("ol.pf-v6-c-breadcrumb__list") |
| 136 |
b.wait_text(".service-name", "Test Service") |
| 137 |
b.switch_to_top() |
| 138 |
b.wait_js_cond('window.location.pathname === "/system/services"') |
| 139 |
b.wait_js_cond('window.location.hash === "#/test.service"') |
| 140 |
|
| 141 |
# check that when inside the component clicking the navbar |
| 142 |
# takes you home |
| 143 |
b.click_system_menu("/system/services") |
| 144 |
b.wait_visible("#services-list") |
| 145 |
b.wait_not_present("#service-details") |
| 146 |
b.switch_to_top() |
| 147 |
b.wait_js_cond('window.location.pathname === "/system/services"') |
| 148 |
b.wait_js_cond('window.location.hash === ""') |
| 149 |
|
| 150 |
# Navigate inside an iframe |
| 151 |
b.switch_to_top() |
| 152 |
b.go("/@localhost/playground/test") |
| 153 |
b.enter_page("/playground/test") |
| 154 |
b.click("button:contains('Go down')") |
| 155 |
b.click("button:contains('Go down')") |
| 156 |
b.switch_to_top() |
| 157 |
b.wait_js_cond("window.location.hash == '#/0/1?length=1'") |
| 158 |
|
| 159 |
# This should be visible now |
| 160 |
b.switch_to_frame("cockpit1:localhost/playground/test") |
| 161 |
b.wait_visible("#hidden") |
| 162 |
|
| 163 |
# This should now say invisible |
| 164 |
b.switch_to_top() |
| 165 |
b.go("/@localhost/system/services") |
| 166 |
b.switch_to_frame("cockpit1:localhost/playground/test") |
| 167 |
b.wait_not_visible("#hidden") |
| 168 |
|
| 169 |
# Test 'parent' manifest option |
| 170 |
b.switch_to_top() |
| 171 |
b.go("/metrics") |
| 172 |
self.check_system_menu("Overview", present=True) |
| 173 |
self.checkDocs(["Performance Co-Pilot"]) |
| 174 |
|
| 175 |
# Lets try changing the language |
| 176 |
|
| 177 |
self.open_lang_modal() |
| 178 |
b.click('#display-language-modal li[data-value=de-de] button') |
| 179 |
b.click("#display-language-modal footer button.pf-m-primary") |
| 180 |
b.wait_language("de-de") |
| 181 |
|
| 182 |
# Wait for the shell to be fully loaded again so that b.go() |
| 183 |
# starts working. |
| 184 |
b.enter_page("/metrics") |
| 185 |
|
| 186 |
# Check that the system page is translated |
| 187 |
b.go("/system") |
| 188 |
b.enter_page("/system") |
| 189 |
b.click(".ct-overview-header button:contains('Neustart')") |
| 190 |
|
| 191 |
# Restart dialog is loaded from pkg/lib and it also needs to be translated |
| 192 |
b.wait_in_text("#shutdown-dialog", "Nachricht an angemeldete Benutzer") |
| 193 |
|
| 194 |
# Systemd timer localization |
| 195 |
b.go("/system/services") |
| 196 |
b.switch_to_top() |
| 197 |
b.wait_js_cond('document.title.indexOf("Dienste") === 0') |
| 198 |
b.enter_page("/system/services") |
| 199 |
b.click('#services-filter li:nth-child(4) a') |
| 200 |
# HACK: the timers' next run/last trigger (col 3/4) don't always get filled (issue #9439) |
| 201 |
# b.wait_in_text("tr[data-goto-unit='test\.timer'] td:nth-child(3)", "morgen um") |
| 202 |
|
| 203 |
# BIOS date parsing; we don't want to introduce too many assumptions, just that the original MM/DD/YYYY |
| 204 |
# was parsed at all, and the bios is from the 21st century (20YY) |
| 205 |
# TestSystemInfo.testHardwareInfo does this more carefully |
| 206 |
b.go("/system/hwinfo") |
| 207 |
b.enter_page("/system/hwinfo") |
| 208 |
b.wait_in_text('#hwinfo-system-info-list .hwinfo-system-info-list-item:nth-of-type(2) .pf-v6-c-description-list__group:nth-of-type(3) dd', " 20") |
| 209 |
|
| 210 |
# Check the playground page |
| 211 |
b.switch_to_top() |
| 212 |
b.go("/playground/translate") |
| 213 |
b.wait_js_cond('document.title.indexOf("Entwicklung") === 0') |
| 214 |
b.enter_page("/playground/translate") |
| 215 |
|
| 216 |
# HTML section |
| 217 |
self.assertEqual(b.text("#translate-html"), "Bereit") |
| 218 |
self.assertEqual(b.text("#translate-html-context"), "Bereiten") |
| 219 |
self.assertEqual(b.text("#translate-html-yes"), "Nicht bereit") |
| 220 |
|
| 221 |
# Glade section |
| 222 |
self.assertEqual(b.text("#translatable-glade"), "Leer") |
| 223 |
self.assertEqual(b.text("#translatable-glade-context"), "Leeren") |
| 224 |
|
| 225 |
# Javascript |
| 226 |
self.assertEqual(b.text("#underscore-empty"), "Leer") |
| 227 |
self.assertEqual(b.text("#underscore-context-empty"), "Leeren") |
| 228 |
self.assertEqual(b.text("#cunderscore-context-empty"), "Leeren") |
| 229 |
self.assertEqual(b.text("#gettext-control"), "Steuerung") |
| 230 |
self.assertEqual(b.text("#gettext-context-control"), "Strg") |
| 231 |
self.assertEqual(b.text("#ngettext-disks-1"), "$0 Festplatte fehlt") |
| 232 |
self.assertEqual(b.text("#ngettext-disks-2"), "$0 Festplatten fehlen") |
| 233 |
self.assertEqual(b.text("#ngettext-context-disks-1"), "$0 Datenträger fehlt") |
| 234 |
self.assertEqual(b.text("#ngettext-context-disks-2"), "$0 Datenträger fehlen") |
| 235 |
|
| 236 |
# Frame title |
| 237 |
b.switch_to_top() |
| 238 |
b.wait_attr("iframe[name='cockpit1:localhost/system']", "title", "Überblick") |
| 239 |
|
| 240 |
# Log out and check that login page is translated now |
| 241 |
b.logout() |
| 242 |
b.wait_visible('#password-group') |
| 243 |
b.wait_text("#password-group > label", "Passwort") |
| 244 |
|
| 245 |
def testAllLanguages(self): |
| 246 |
# Test that pages do not oops |
| 247 |
m = self.machine |
| 248 |
b = self.browser |
| 249 |
|
| 250 |
def line_sel(i): |
| 251 |
return '.terminal .xterm-accessibility-tree div:nth-child(%d)' % i |
| 252 |
|
| 253 |
pages = ["/system", "/system/logs", "/network", "/users", "/system/services", "/system/terminal"] |
| 254 |
|
| 255 |
self.login_and_go('/system') |
| 256 |
b.wait_visible('#overview') |
| 257 |
|
| 258 |
self.open_lang_modal() |
| 259 |
languages = b.eval_js("ph_select('#display-language-list li').map(e => e.attributes['data-value'].nodeValue)") |
| 260 |
self.assertIn('en-us', languages) |
| 261 |
b.click("#display-language-modal footer button.pf-m-link") # Close the menu |
| 262 |
|
| 263 |
for language in languages: |
| 264 |
# Remove failed units which will show up in the first terminal line |
| 265 |
m.execute("systemctl reset-failed") |
| 266 |
|
| 267 |
b.go("/system") |
| 268 |
b.enter_page("/system") |
| 269 |
|
| 270 |
self.open_lang_modal() |
| 271 |
b.click(f"#display-language-modal li[data-value={language}] button") |
| 272 |
b.click("#display-language-modal footer button.pf-m-primary") |
| 273 |
b.wait_language(language) |
| 274 |
|
| 275 |
# Test some pages |
| 276 |
for page in pages: |
| 277 |
b.go(page) |
| 278 |
b.enter_page(page) |
| 279 |
b.wait_language(language) |
| 280 |
|
| 281 |
# FIXME: bridge does not set locale |
| 282 |
# locale = language.split("-") |
| 283 |
# if len(locale) == 1: |
| 284 |
# locale.append("") |
| 285 |
# locale = f"{locale[0]}_{locale[1].upper()}.UTF-8" |
| 286 |
|
| 287 |
# b.wait_visible(".terminal .xterm-accessibility-tree") |
| 288 |
# b.wait_in_text(line_sel(1), "admin") |
| 289 |
# b.input_text("echo $LANG\n") |
| 290 |
# b.wait_in_text(line_sel(2), locale) |
| 291 |
|
| 292 |
b.switch_to_top() |
| 293 |
|
| 294 |
b.wait_js_func("""(function (lang) { |
| 295 |
let correct = true; |
| 296 |
const rtl_langs = ["ar-eg", "fa-ir", "he-il", "ur-in"]; |
| 297 |
const dir = rtl_langs.includes(lang) ? "rtl" : "ltr"; |
| 298 |
document.querySelectorAll('#content iframe').forEach(el => { |
| 299 |
if (el.contentDocument.documentElement.lang !== lang) |
| 300 |
correct = false; |
| 301 |
if (el.contentDocument.documentElement.dir !== dir) |
| 302 |
correct = false; |
| 303 |
}); |
| 304 |
return correct; |
| 305 |
})""", language) |
| 306 |
b.wait_attr(".index-page", "lang", language) |
| 307 |
|
| 308 |
self.allow_restart_journal_messages() |
| 309 |
|
| 310 |
def testPtBRLocale(self): |
| 311 |
m = self.machine |
| 312 |
b = self.browser |
| 313 |
|
| 314 |
m.execute('useradd scruffy -s /bin/bash -c Scruffy') |
| 315 |
m.execute('echo scruffy:foobar | chpasswd') |
| 316 |
|
| 317 |
if "debian" in m.image: |
| 318 |
m.execute('echo \'pt_BR.UTF-8 UTF-8\' >> /etc/locale.gen; locale-gen; update-locale') |
| 319 |
elif "ubuntu" in m.image: |
| 320 |
m.execute('locale-gen pt_BR; locale-gen pt_BR.UTF-8; update-locale') |
| 321 |
elif "arch" == m.image: |
| 322 |
m.execute('echo \'pt_BR.UTF-8 UTF-8\' >> /etc/locale.gen; locale-gen') |
| 323 |
|
| 324 |
self.login_and_go('/system') |
| 325 |
b.wait_visible('#overview') |
| 326 |
self.open_lang_modal() |
| 327 |
b.click('#display-language-modal li[data-value=pt-br] button') |
| 328 |
b.click('#display-language-modal footer button.pf-m-primary') |
| 329 |
b.wait_language("pt-br") |
| 330 |
|
| 331 |
# Check that the system page is translated |
| 332 |
b.go('/system') |
| 333 |
b.enter_page('/system') |
| 334 |
b.wait_language("pt-br") |
| 335 |
b.wait_in_text('.ct-overview-header', 'Reiniciar') |
| 336 |
|
| 337 |
# Systemd timer localization |
| 338 |
b.go('/system/services') |
| 339 |
b.enter_page('/system/services') |
| 340 |
b.wait_language("pt-br") |
| 341 |
b.click('#services-filter li:nth-child(4) a') |
| 342 |
# HACK: the timers' next run/last trigger (col 3/4) don't always get filled (issue #9439) |
| 343 |
# b.wait_in_text('tr[data-goto-unit=\'test\.timer\'] td:nth-child(3)', 'morgen um') |
| 344 |
|
| 345 |
# Check the playground page |
| 346 |
b.switch_to_top() |
| 347 |
b.go('/playground/translate') |
| 348 |
b.enter_page('/playground/translate') |
| 349 |
b.wait_language("pt-br") |
| 350 |
|
| 351 |
# HTML section |
| 352 |
self.assertEqual(b.text('#translate-html'), 'Pronto') |
| 353 |
self.assertEqual(b.text('#translate-html-context'), 'Pronto') |
| 354 |
self.assertEqual(b.text('#translate-html-yes'), 'Não está pronto') |
| 355 |
|
| 356 |
# Glade section |
| 357 |
self.assertEqual(b.text('#translatable-glade'), 'Vazio') |
| 358 |
self.assertEqual(b.text('#translatable-glade-context'), 'Vazio') |
| 359 |
|
| 360 |
# Javascript |
| 361 |
self.assertEqual(b.text('#underscore-empty'), 'Vazio') |
| 362 |
self.assertEqual(b.text('#underscore-context-empty'), 'Vazio') |
| 363 |
self.assertEqual(b.text('#cunderscore-context-empty'), 'Vazio') |
| 364 |
self.assertEqual(b.text('#gettext-control'), 'Controle') |
| 365 |
self.assertEqual(b.text('#gettext-context-control'), 'Controle') |
| 366 |
self.assertEqual(b.text('#ngettext-disks-1'), '$0 disco não encontrado') |
| 367 |
self.assertEqual(b.text('#ngettext-disks-2'), '$0 discos não encontrados') |
| 368 |
self.assertEqual(b.text('#ngettext-context-disks-1'), '$0 disco não encontrado') |
| 369 |
self.assertEqual(b.text('#ngettext-context-disks-2'), '$0 discos não encontrados') |
| 370 |
|
| 371 |
# Log out and check that login page is translated now |
| 372 |
b.logout() |
| 373 |
b.wait_text('#password-group > label', 'Senha') |
| 374 |
|
| 375 |
# translated variants of standard messages in testlib.py |
| 376 |
self.allow_journal_messages("xargs: basename: .*13.*") |
| 377 |
|
| 378 |
def testFrameReload(self): |
| 379 |
b = self.browser |
| 380 |
m = self.machine |
| 381 |
|
| 382 |
frame = "cockpit1:localhost/playground/test" |
| 383 |
self.addCleanup(self.machine.execute, "rm -f /tmp/counter") |
| 384 |
|
| 385 |
self.login_and_go("/playground/test") |
| 386 |
|
| 387 |
# Check that channels are closed when a frame is reloaded. |
| 388 |
|
| 389 |
# Lock a file, that keeps a channel open. |
| 390 |
m.execute("touch /tmp/playground-test-lock") |
| 391 |
b.click(".lock-channel button") |
| 392 |
b.wait_in_text(".lock-channel span", 'locked') |
| 393 |
m.execute("! flock --nonblock /tmp/playground-test-lock true") |
| 394 |
|
| 395 |
# Now reload the frame by kicking its "src" attribute. |
| 396 |
b.switch_to_top() |
| 397 |
b.eval_js('ph_set_attr("iframe[name=\'%s\']", "src", "../playground/test.html?i=1#/")' % frame) |
| 398 |
|
| 399 |
# The channel and the lock should have gone away |
| 400 |
m.execute("flock --timeout 10 /tmp/playground-test-lock true") |
| 401 |
|
| 402 |
b.enter_page("/playground/test") |
| 403 |
b.wait_not_in_text(".lock-channel span", 'locked') |
| 404 |
|
| 405 |
self.allow_restart_journal_messages() |
| 406 |
|
| 407 |
@testlib.skipBeiboot("no local overrides/config in beiboot mode") |
| 408 |
def testShellReload(self): |
| 409 |
b = self.browser |
| 410 |
m = self.machine |
| 411 |
|
| 412 |
self.login_and_go() |
| 413 |
|
| 414 |
self.check_system_menu("Overview", present=True) |
| 415 |
self.restore_dir("/home/admin") |
| 416 |
m.write("/home/admin/.local/share/cockpit/foo/manifest.json", |
| 417 |
'{ "menu": { "index": { "label": "FOO!" } } }') |
| 418 |
b.reload() |
| 419 |
self.check_system_menu("FOO!", present=True) |
| 420 |
|
| 421 |
def testMenuSearch(self): |
| 422 |
b = self.browser |
| 423 |
m = self.machine |
| 424 |
|
| 425 |
# On Ubuntu and Debian we would need to generate locales - just ignore it |
| 426 |
self.allow_journal_messages("invalid or unusable locale: de_DE.UTF-8") |
| 427 |
|
| 428 |
self.login_and_go() |
| 429 |
|
| 430 |
filter_sel = ".pf-v6-c-text-input-group__text-input" |
| 431 |
|
| 432 |
# Check that some page disappears and some stay |
| 433 |
b.focus(filter_sel) |
| 434 |
b.input_text("se") |
| 435 |
b.wait_not_present("#host-apps li a:contains('Logs')") |
| 436 |
b.wait_visible("#host-apps li a:contains('Services')") |
| 437 |
b.wait_text("#host-apps li a[href='/system/services'] mark", "Se") |
| 438 |
|
| 439 |
b.focus(filter_sel) |
| 440 |
b.key("Backspace", 2) |
| 441 |
b.wait_visible("#host-apps li a:contains('Logs')") |
| 442 |
b.wait_visible("#host-apps li a:contains('Services')") |
| 443 |
|
| 444 |
# Check that any substring work |
| 445 |
b.focus(filter_sel) |
| 446 |
b.input_text("CoUN") |
| 447 |
b.wait_not_present("#host-apps li a:contains('Overview')") |
| 448 |
b.wait_visible("#host-apps li a:contains('Accounts')") |
| 449 |
b.wait_text("#host-apps li a[href='/users'] mark", "coun") |
| 450 |
|
| 451 |
# Check it can also search by keywords |
| 452 |
b.focus(filter_sel) |
| 453 |
b.key("Backspace", 4) |
| 454 |
b.input_text("systemd") |
| 455 |
b.wait_visible("#host-apps li a:contains('Services')") |
| 456 |
b.wait_text("#host-apps li a:contains('Services')", "ServicesContains: systemd") |
| 457 |
b.wait_text("#host-apps li a[href='/system/services'] mark", "systemd") |
| 458 |
|
| 459 |
# Clean up failed services for screenshots |
| 460 |
m.execute("systemctl reset-failed") |
| 461 |
b.wait_not_present("#services-error") |
| 462 |
|
| 463 |
b.assert_pixels("#nav-system", "menu-search", skip_layouts=["mobile"]) |
| 464 |
b.set_layout("mobile") |
| 465 |
b.click("#nav-system-item") |
| 466 |
b.assert_pixels_in_current_layout("#nav-system", "menu-search") |
| 467 |
b.click("#nav-system-item") |
| 468 |
b.set_layout("desktop") |
| 469 |
|
| 470 |
# Check that enter activates first result |
| 471 |
b.focus(filter_sel) |
| 472 |
b.key("Backspace", 7) |
| 473 |
b.input_text("logs") |
| 474 |
b.wait_not_present("#host-apps li a:contains('Services')") |
| 475 |
b.wait_visible("#host-apps li a:contains('Logs')") |
| 476 |
b.focus(filter_sel) |
| 477 |
b.key("Enter") |
| 478 |
b.enter_page("/system/logs") |
| 479 |
b.wait_visible("#journal") |
| 480 |
|
| 481 |
# Visited page, search should be cleaned up |
| 482 |
b.switch_to_top() |
| 483 |
b.wait_val(filter_sel, "") |
| 484 |
|
| 485 |
# Check that escape cleans the search |
| 486 |
b.input_text("logs") |
| 487 |
b.wait_not_present("#host-apps li a:contains('Services')") |
| 488 |
b.wait_visible("#host-apps li a:contains('Logs')") |
| 489 |
b.focus(filter_sel) |
| 490 |
b.key("Escape") |
| 491 |
b.wait_val(filter_sel, "") |
| 492 |
b.wait_visible("#host-apps li a:contains('Services')") |
| 493 |
|
| 494 |
# Check that clicking on `Clear search` cleans the search |
| 495 |
b.input_text("logs") |
| 496 |
b.wait_not_present("#host-apps li a:contains('Services')") |
| 497 |
b.wait_visible("#host-apps li a:contains('Logs')") |
| 498 |
b.click("button:contains('Clear search')") |
| 499 |
b.key("Backspace", 4) |
| 500 |
b.wait_visible("#host-apps li a:contains('Services')") |
| 501 |
b.wait_not_present("button:contains('Clear search')") |
| 502 |
|
| 503 |
# Check that arrows navigate the menu |
| 504 |
b.focus(filter_sel) |
| 505 |
b.input_text("s") |
| 506 |
b.wait_not_present("#host-apps li a:contains('Logs')") |
| 507 |
b.key("ArrowDown", 2) |
| 508 |
b.key("Enter") |
| 509 |
# CoreOS images don't have cockpit-storaged; all others including bootc do |
| 510 |
if "coreos" in m.image: |
| 511 |
b.enter_page("/users") |
| 512 |
else: |
| 513 |
b.enter_page("/storage") |
| 514 |
|
| 515 |
# Check we jump into subpage when defined in manifest |
| 516 |
b.switch_to_top() |
| 517 |
b.focus(filter_sel) |
| 518 |
b.input_text("firew") |
| 519 |
b.wait_visible("#host-apps li a:contains('Networking')") |
| 520 |
b.wait_not_present("#host-apps li a:contains('Overview')") |
| 521 |
b.click("#host-apps li a:contains('Networking')") |
| 522 |
b.enter_page("/network/firewall") |
| 523 |
|
| 524 |
# Search internationalized menu |
| 525 |
self.open_lang_modal() |
| 526 |
|
| 527 |
# Filter the available languages |
| 528 |
b.set_input_text('#display-language-modal input[type=search]', "Deutsch") |
| 529 |
b.click('#display-language-modal li[data-value=de-de] button') |
| 530 |
b.wait_count("#display-language-modal li", 1) |
| 531 |
b.set_input_text('#display-language-modal input[type=search]', "") |
| 532 |
|
| 533 |
b.click('#display-language-modal li[data-value=de-de] button') |
| 534 |
b.click("#display-language-modal footer button.pf-m-primary") |
| 535 |
b.wait_language("de-de") |
| 536 |
|
| 537 |
# Wait for the shell to be fully loaded again so that b.go() |
| 538 |
# starts working. |
| 539 |
b.enter_page("/network/firewall") |
| 540 |
|
| 541 |
b.go("/system") |
| 542 |
b.enter_page("/system") |
| 543 |
b.wait_in_text(".ct-overview-header", "Neustart") |
| 544 |
|
| 545 |
b.switch_to_top() |
| 546 |
b.wait_visible("#host-apps li a:contains('Dienste')") |
| 547 |
b.wait_visible("#host-apps li a:contains('Protokolle')") |
| 548 |
b.focus(filter_sel) |
| 549 |
b.input_text("dien") |
| 550 |
b.wait_not_present("#host-apps li a:contains('Protokolle')") |
| 551 |
b.wait_visible("#host-apps li a:contains('Dienste')") |
| 552 |
b.wait_text("#host-apps li a[href='/system/services'] mark", "Dien") |
| 553 |
|
| 554 |
def testShellPreload(self): |
| 555 |
b = self.browser |
| 556 |
m = self.machine |
| 557 |
|
| 558 |
self.login_and_go() |
| 559 |
|
| 560 |
# Check what's going on while playground/preloaded is still invisible |
| 561 |
b.switch_to_top() |
| 562 |
b.wait_attr('iframe[name="cockpit1:localhost/playground/preloaded"]', 'data-loaded', 1) |
| 563 |
b.switch_to_frame("cockpit1:localhost/playground/preloaded") |
| 564 |
b.wait_js_func('ph_text_is', "#host", m.execute("hostname").replace("\n", "")) |
| 565 |
time.sleep(3) |
| 566 |
b.wait_js_func('ph_text_is', "#release", "") |
| 567 |
|
| 568 |
# Now navigate to it. |
| 569 |
b.switch_to_top() |
| 570 |
b.go("/playground/preloaded") |
| 571 |
b.enter_page("/playground/preloaded") |
| 572 |
b.wait_text("#release", m.execute("cat /etc/os-release").replace("\n", "")) |
| 573 |
|
| 574 |
def testReactPatterns(self): |
| 575 |
b = self.browser |
| 576 |
m = self.machine |
| 577 |
|
| 578 |
self.restore_dir('/home/admin') |
| 579 |
|
| 580 |
stuff = os.path.join(self.vm_tmpdir, "stuff") |
| 581 |
# prepare a directory for testing file autocomplete widget |
| 582 |
m.execute(f"mkdir -p {stuff}/dir") |
| 583 |
m.execute(f"mkdir -p {stuff}/dir1") |
| 584 |
m.write(f"{stuff}/file1.txt", "") |
| 585 |
|
| 586 |
self.login_and_go("/playground/react-patterns") |
| 587 |
|
| 588 |
# test file completion widget |
| 589 |
b.focus("#demo-file-ac input[type=text]") |
| 590 |
b.input_text(stuff + "/") |
| 591 |
# need to wait for the widget's "fast typing" inhibition delay to trigger the completion popup |
| 592 |
b.wait_in_text(".pf-v6-c-menu li:nth-of-type(1) button", stuff + "/") |
| 593 |
b.wait_in_text(".pf-v6-c-menu li:nth-of-type(2) button", "dir/") |
| 594 |
b.wait_in_text(".pf-v6-c-menu li:nth-of-type(3) button", "dir1/") |
| 595 |
b.wait_in_text(".pf-v6-c-menu li:nth-of-type(4) button", "file1.txt") |
| 596 |
b.click(".pf-v6-c-menu li:nth-of-type(2) button") |
| 597 |
|
| 598 |
# clear the file completion widget |
| 599 |
b.click("#demo-file-ac div:first-of-type div:first-of-type button:nth-of-type(1)") |
| 600 |
# test if input matches one entry, but is the prefix of other entry, widget should not descend into directory |
| 601 |
b.focus("#demo-file-ac input[type=text]") |
| 602 |
b.input_text(stuff + "/dir") |
| 603 |
b.wait_in_text(".pf-v6-c-menu li:nth-of-type(1) button", stuff + "/dir") |
| 604 |
b.wait_in_text(".pf-v6-c-menu li:nth-of-type(2) button", stuff + "/dir1") |
| 605 |
|
| 606 |
# clear the file completion widget |
| 607 |
b.click("#demo-file-ac div:first-of-type div:first-of-type button:nth-of-type(1)") |
| 608 |
b.focus("#demo-file-ac input[type=text]") |
| 609 |
b.input_text(stuff + "/") |
| 610 |
b.wait_in_text(".pf-v6-c-menu li:nth-of-type(1) button", stuff + "/") |
| 611 |
b.wait_in_text(".pf-v6-c-menu li:nth-of-type(4) button", "file1.txt") |
| 612 |
b.click(".pf-v6-c-menu li:nth-of-type(4) button") |
| 613 |
b.wait_not_present(".pf-v6-c-menu") |
| 614 |
|
| 615 |
# now update file1, check robustness with dynamic events |
| 616 |
m.execute(f"touch {stuff}/file1.txt") |
| 617 |
b.focus("#demo-file-ac input[type=text]") |
| 618 |
time.sleep(1) |
| 619 |
b.key("End") |
| 620 |
b.key("Backspace", 5) |
| 621 |
# input is now $stuff/file |
| 622 |
b.wait_in_text(".pf-v6-c-menu li:nth-of-type(1) button", "file1.txt") |
| 623 |
b.key("Backspace", 4) |
| 624 |
# input is now $stuff/, so all listings should be available |
| 625 |
b.wait_in_text(".pf-v6-c-menu li:nth-of-type(4) button", "file1.txt") |
| 626 |
|
| 627 |
# add new file |
| 628 |
m.execute(f"touch {stuff}/other") |
| 629 |
b.focus("#demo-file-ac input[type=text]") |
| 630 |
# We need to tickle the widget to re-read the directory by changing to |
| 631 |
# the previous directory and back to the directory we want to list. |
| 632 |
# This is an implementation choice, to avoid re-reading the directories |
| 633 |
# content with every user input change, which is definitely a performance cost |
| 634 |
b.key("Backspace", 6) |
| 635 |
time.sleep(1) |
| 636 |
b.input_text("stuff/") |
| 637 |
b.wait_in_text(".pf-v6-c-menu li:nth-of-type(5) button", "other") |
| 638 |
# close the selector |
| 639 |
b.click("#demo-file-ac input") |
| 640 |
b.wait_not_present(".pf-v6-c-menu") |
| 641 |
|
| 642 |
# Create test folder with known files |
| 643 |
m.execute("mkdir /home/admin/newdir") |
| 644 |
m.execute("mkdir /home/admin/newdir/dir1") |
| 645 |
m.execute("mkdir /home/admin/newdir/dir2") |
| 646 |
m.execute("touch /home/admin/newdir/file1") |
| 647 |
m.execute("touch /home/admin/newdir/file2") |
| 648 |
# test pre-selected autocomplete widget |
| 649 |
b.wait_val("#demo-file-ac-preselected input", "/home/admin/newdir/file1") |
| 650 |
# open the selector |
| 651 |
b.click("#demo-file-ac-preselected input") |
| 652 |
b.wait_visible(".pf-v6-c-menu") |
| 653 |
# close and open again to reload the dir (which just got created) |
| 654 |
b.click("#demo-file-ac-preselected .pf-v6-c-menu-toggle__button") |
| 655 |
b.wait_not_present(".pf-v6-c-menu") |
| 656 |
b.click("#demo-file-ac-preselected input") |
| 657 |
# selection has all the files in the directory |
| 658 |
paths = ["/home/admin/newdir", "/home/admin/newdir/dir1", "/home/admin/newdir/dir2", "/home/admin/newdir/file1", "/home/admin/newdir/file2"] |
| 659 |
for i in range(5): |
| 660 |
b.wait_in_text(f".pf-v6-c-menu li:nth-of-type({i + 1}) button", paths[i]) |
| 661 |
|
| 662 |
@testlib.skipOstree("No PCP available") |
| 663 |
def testPlots(self): |
| 664 |
b = self.browser |
| 665 |
m = self.machine |
| 666 |
|
| 667 |
self.addCleanup(m.execute, "systemctl stop pmcd") |
| 668 |
m.execute("systemctl start pmcd") |
| 669 |
|
| 670 |
# settroubleshootd eats memory in an unpredictable manner, silence it to reduce test flakes |
| 671 |
if m.image.startswith(("fedora-", "rhel-")): |
| 672 |
self.addCleanup(m.execute, "systemctl unmask setroubleshootd") |
| 673 |
m.execute("systemctl stop setroubleshootd; systemctl mask setroubleshootd") |
| 674 |
|
| 675 |
# packagekit/dnf often eats a lot of CPU/Memory; silence it to have better control over memory usage |
| 676 |
packagekitd = "/usr/lib/packagekitd" if m.image == "arch" else "/usr/libexec/packagekitd" |
| 677 |
m.execute(f"systemctl mask packagekit && killall -9 {packagekitd} && killall -9 dnf || true") |
| 678 |
self.addCleanup(m.execute, "systemctl unmask packagekit") |
| 679 |
|
| 680 |
# packagekitd consumes tons of memory on logging into Cockpit |
| 681 |
self.disable_preload("packagekit") |
| 682 |
|
| 683 |
self.login_and_go("/playground/plot") |
| 684 |
b.wait_visible("#plot-direct") |
| 685 |
b.wait_visible("#plot-pmcd") |
| 686 |
|
| 687 |
def read_mem_info(machine): |
| 688 |
info = {} |
| 689 |
for line in machine.execute("cat /proc/meminfo").splitlines(): |
| 690 |
(name, value) = line.strip().split(":") |
| 691 |
if value.endswith("kB"): |
| 692 |
info[name] = int(value[:-2]) * 1024 |
| 693 |
else: |
| 694 |
info[name] = int(value) |
| 695 |
return info |
| 696 |
|
| 697 |
# When checking whether the plots show the expected results, |
| 698 |
# we look for a segment of the data of a certain duration |
| 699 |
# whose average is in a certain range. Otherwise any short |
| 700 |
# outlier will make us miss the expected plateau. Such |
| 701 |
# outliers happen frequently with the CPU plot. We also |
| 702 |
# insist that the first and last value of the segment are in |
| 703 |
# range, otherwise we would find any arbitrary average in a |
| 704 |
# graph with a slope. |
| 705 |
|
| 706 |
b.eval_js(""" |
| 707 |
ph_plateau = function (data, min, max, duration, label) { |
| 708 |
var i, j; |
| 709 |
var sum; // sum of data[i..j] |
| 710 |
|
| 711 |
function ok(val) { |
| 712 |
return val >= min && val <= max; |
| 713 |
} |
| 714 |
|
| 715 |
sum = 0; |
| 716 |
i = 0; |
| 717 |
for (j = 0; j < data.length; j++) { |
| 718 |
sum += data[j][1]; |
| 719 |
while (i < j && (data[j][0] - data[i][0]) > duration * 1000) { |
| 720 |
avg = sum / (j - i + 1); |
| 721 |
if (ok(avg) && ok(data[i][1]) && ok(data[j][1])) |
| 722 |
return true; |
| 723 |
sum -= data[i][1]; |
| 724 |
i++; |
| 725 |
} |
| 726 |
} |
| 727 |
return false; |
| 728 |
} |
| 729 |
""") |
| 730 |
|
| 731 |
b.eval_js(""" |
| 732 |
ph_plot_data_plateau = function (sel, min, max, duration, label) { |
| 733 |
return ph_plateau(window.plot_state.data(sel)[0].data, min, max, duration, label); |
| 734 |
} |
| 735 |
""") |
| 736 |
|
| 737 |
meminfo = read_mem_info(m) |
| 738 |
mem_avail = meminfo['MemAvailable'] |
| 739 |
with b.wait_timeout(60): |
| 740 |
b.wait_js_func("ph_plot_data_plateau", "direct", mem_avail * 0.85, mem_avail * 1.15, 15, "mem") |
| 741 |
|
| 742 |
meminfo = read_mem_info(m) |
| 743 |
mem_avail = meminfo['MemAvailable'] |
| 744 |
with b.wait_timeout(60): |
| 745 |
b.wait_js_func("ph_plot_data_plateau", "pmcd", mem_avail * 0.85, mem_avail * 1.15, 15, "mem") |
| 746 |
|
| 747 |
# Internal metrics only has memory used (memory.used) as a metric not available memory. |
| 748 |
meminfo = read_mem_info(m) |
| 749 |
mem_avail = meminfo['MemTotal'] - meminfo['MemAvailable'] |
| 750 |
with b.wait_timeout(60): |
| 751 |
b.wait_js_func("ph_plot_data_plateau", "internal", mem_avail * 0.85, mem_avail * 1.15, 15, "mem") |
| 752 |
|
| 753 |
def testPageStatus(self): |
| 754 |
b = self.browser |
| 755 |
|
| 756 |
self.login_and_go("/playground") |
| 757 |
|
| 758 |
b.set_input_text("#type", "info") |
| 759 |
b.set_input_text("#title", "My Little Page Status") |
| 760 |
b.click("#set-status") |
| 761 |
|
| 762 |
b.switch_to_top() |
| 763 |
b.wait_visible("#development-info") |
| 764 |
b.mouse("#development-info", "mouseenter") |
| 765 |
b.wait_in_text(".pf-v6-c-tooltip", "My Little Page Status") |
| 766 |
b.mouse("#development-info", "mouseleave") |
| 767 |
b.wait_not_present(".pf-v6-c-tooltip") |
| 768 |
|
| 769 |
b.go("/playground/notifications-receiver") |
| 770 |
b.enter_page("/playground/notifications-receiver") |
| 771 |
b.wait_text("#received-type", "info") |
| 772 |
b.wait_text("#received-title", "My Little Page Status") |
| 773 |
|
| 774 |
b.switch_to_top() |
| 775 |
b.go("/playground") |
| 776 |
b.enter_page("/playground") |
| 777 |
b.click("#clear-status") |
| 778 |
|
| 779 |
b.switch_to_top() |
| 780 |
b.wait_not_present("#development-info") |
| 781 |
|
| 782 |
b.go("/playground/notifications-receiver") |
| 783 |
b.enter_page("/playground/notifications-receiver") |
| 784 |
b.wait_text("#received-type", "-") |
| 785 |
b.wait_text("#received-title", "-") |
| 786 |
|
| 787 |
def testHistory(self): |
| 788 |
|
| 789 |
b = self.browser |
| 790 |
|
| 791 |
def assert_location(path_hash): |
| 792 |
self.assertEqual(path_hash, |
| 793 |
self.browser.eval_js("window.location.pathname + window.location.hash")) |
| 794 |
|
| 795 |
self.login_and_go("/system") |
| 796 |
|
| 797 |
# Create a login entry so that the "View last login" button appears |
| 798 |
b.logout() |
| 799 |
self.login_and_go("/system") |
| 800 |
|
| 801 |
b.switch_to_top() |
| 802 |
assert_location("/system") |
| 803 |
|
| 804 |
b.click('#nav-system a[href="/users"]') |
| 805 |
b.enter_page("/users") |
| 806 |
b.switch_to_top() |
| 807 |
assert_location("/users") |
| 808 |
|
| 809 |
b.enter_page("/users") |
| 810 |
b.click('a[href="#/root"]') |
| 811 |
b.wait_visible("#account-title") |
| 812 |
self.assertIn(b.text("#account-title"), ["root", "Super User"]) |
| 813 |
b.switch_to_top() |
| 814 |
assert_location("/users#/root") |
| 815 |
|
| 816 |
b.enter_page("/users") |
| 817 |
b.click("nav a:contains('Accounts')") |
| 818 |
b.wait_visible("button:contains('Create new account')") |
| 819 |
b.switch_to_top() |
| 820 |
assert_location("/users") |
| 821 |
|
| 822 |
b.eval_js("window.history.back()") |
| 823 |
b.enter_page("/users") |
| 824 |
b.wait_visible("#account-title") |
| 825 |
self.assertIn(b.text("#account-title"), ["root", "Super User"]) |
| 826 |
b.switch_to_top() |
| 827 |
assert_location("/users#/root") |
| 828 |
|
| 829 |
b.eval_js("window.history.forward()") |
| 830 |
b.enter_page("/users") |
| 831 |
b.wait_visible("button:contains('Create new account')") |
| 832 |
b.switch_to_top() |
| 833 |
assert_location("/users") |
| 834 |
|
| 835 |
b.eval_js("window.history.back()") |
| 836 |
b.enter_page("/users") |
| 837 |
b.wait_visible("#account-title") |
| 838 |
self.assertIn(b.text("#account-title"), ["root", "Super User"]) |
| 839 |
b.switch_to_top() |
| 840 |
assert_location("/users#/root") |
| 841 |
|
| 842 |
b.eval_js("window.history.back()") |
| 843 |
b.enter_page("/users") |
| 844 |
b.wait_visible("button:contains('Create new account')") |
| 845 |
b.switch_to_top() |
| 846 |
assert_location("/users") |
| 847 |
|
| 848 |
b.click('#nav-system a[href="/system/terminal"]') |
| 849 |
b.enter_page("/system/terminal") |
| 850 |
b.switch_to_top() |
| 851 |
assert_location("/system/terminal") |
| 852 |
|
| 853 |
b.eval_js("window.history.back()") |
| 854 |
b.enter_page("/users") |
| 855 |
b.wait_visible("button:contains('Create new account')") |
| 856 |
b.switch_to_top() |
| 857 |
assert_location("/users") |
| 858 |
|
| 859 |
b.eval_js("window.history.back()") |
| 860 |
b.enter_page("/system") |
| 861 |
b.switch_to_top() |
| 862 |
assert_location("/system") |
| 863 |
|
| 864 |
# ws container does not keep login history |
| 865 |
if not self.machine.ws_container: |
| 866 |
|
| 867 |
b.enter_page("/system") |
| 868 |
b.click("button:contains('View login history')") |
| 869 |
b.enter_page("/users") |
| 870 |
b.wait_text("#account-title", "Administrator") |
| 871 |
b.switch_to_top() |
| 872 |
assert_location("/users#/admin") |
| 873 |
|
| 874 |
b.eval_js("window.history.back()") |
| 875 |
b.enter_page("/system") |
| 876 |
b.switch_to_top() |
| 877 |
assert_location("/system") |
| 878 |
|
| 879 |
def testAllNavEntries(self): |
| 880 |
b = self.browser |
| 881 |
self.login_and_go() |
| 882 |
|
| 883 |
# the <a> links should be unique by their href= attributes, so get these |
| 884 |
hrefs = b.eval_js("[...document.querySelectorAll('#nav-system .nav-item a')].map(el => el.getAttribute('href'))") |
| 885 |
for href in hrefs: |
| 886 |
b.click(f"#nav-system .nav-item a[href='{href}']") |
| 887 |
b.wait_visible(f"iframe.container-frame[name='cockpit1:localhost{href}'][data-loaded]") |
| 888 |
|
| 889 |
# Same skips as in test/verify/check-kdump |
| 890 |
img = self.machine.image |
| 891 |
expect_kdump = (img != "arch" and |
| 892 |
not img.startswith("debian") and |
| 893 |
not img.startswith("ubuntu") and |
| 894 |
"coreos" not in img) # does show up on bootc |
| 895 |
self.check_system_menu("Kernel dump", present=expect_kdump) |
| 896 |
|
| 897 |
# logging out too fast, some D-Bus services get disconnected |
| 898 |
self.allow_restart_journal_messages() |
| 899 |
|
| 900 |
def testUpload(self) -> None: |
| 901 |
b = self.browser |
| 902 |
m = self.machine |
| 903 |
|
| 904 |
self.restore_dir("/home/admin") |
| 905 |
self.login_and_go("/playground/react-patterns") # , debugging="upload") |
| 906 |
files_dir = Path(testlib.TEST_DIR) / "verify" / "files" / "metrics-archives" |
| 907 |
test_upload_file = str(files_dir / "double_events.zip") |
| 908 |
dest_file = "/home/admin/double_events.zip" |
| 909 |
|
| 910 |
filehash = subprocess.check_output(["sha512sum", test_upload_file]).strip().decode().split(' ')[0] |
| 911 |
filesize = subprocess.check_output(["stat", "--format", "%s", test_upload_file]).strip().decode() |
| 912 |
|
| 913 |
b.upload_files("#demo-upload input[type='file']", [test_upload_file]) |
| 914 |
|
| 915 |
testlib.wait(lambda: m.execute(f"test -f {dest_file} && echo {dest_file} || echo 'no'").strip() == dest_file) |
| 916 |
self.assertEqual(m.execute(f"stat --format '%s' {dest_file}").strip(), filesize) |
| 917 |
self.assertEqual(m.execute(f"sha512sum {dest_file} | awk '{{ print $1 }}'").strip(), filehash) |
| 918 |
b.wait_visible("#upload-file-btn:not(:disabled)") |
| 919 |
|
| 920 |
# Various cases of big file upload |
| 921 |
with tempfile.TemporaryDirectory() as tmpdir: |
| 922 |
|
| 923 |
if b.browser == 'chromium': |
| 924 |
# Chromium BiDi driver craps out with uploading large files, so throttle network speed there |
| 925 |
# https://issues.chromium.org/issues/399131925 |
| 926 |
b.cdp_command("Network.emulateNetworkConditions", |
| 927 |
offline=False, latency=0, downloadThroughput=-1, uploadThroughput=50000) |
| 928 |
big_size = "15MB" |
| 929 |
expected_size = 15 * 1000 * 1000 |
| 930 |
else: |
| 931 |
# BiDi does not have a network speed API, so we can't throttle on Firefox |
| 932 |
# but that's happy with large files |
| 933 |
big_size = "1500MB" |
| 934 |
expected_size = 1500 * 1000 * 1000 |
| 935 |
|
| 936 |
big_file = str(Path(tmpdir) / "bigfile.img") |
| 937 |
# the VM has a total of 1.5G memory, so this would fill it |
| 938 |
# use SI sizes to make sure we test the last incomplete block |
| 939 |
subprocess.check_call(["truncate", "-s", big_size, big_file]) |
| 940 |
|
| 941 |
# Uploaded to completion. It's slow, so only do it on default OS. |
| 942 |
# We do this to make sure the file is spooled to disk, not memory. |
| 943 |
if self.machine.image == TEST_OS_DEFAULT: |
| 944 |
b.upload_files("#demo-upload input[type='file']", [big_file]) |
| 945 |
b.wait(lambda: b.get_pf_progress_value(".upload-progress-0") >= 2) |
| 946 |
with b.wait_timeout(120): |
| 947 |
b.wait_visible("#upload-file-btn:not(:disabled)") |
| 948 |
self.assertEqual(int(m.execute('stat -c%s /home/admin/bigfile.img')), expected_size) |
| 949 |
m.execute('rm /home/admin/bigfile.img') |
| 950 |
|
| 951 |
# Cancelled |
| 952 |
b.upload_files("#demo-upload input[type='file']", [big_file]) |
| 953 |
b.wait(lambda: b.get_pf_progress_value(".upload-progress-0") >= 2) |
| 954 |
b.click(".cancel-button-0") |
| 955 |
b.wait_visible("#upload-file-btn:not(:disabled)") |
| 956 |
b.wait_in_text(".pf-v6-c-alert", "Aborted") |
| 957 |
m.execute('! test -f /home/admin/bigfile.img') |
| 958 |
|
| 959 |
# Early ENOSPC error (before we would block on 'ack') |
| 960 |
m.execute("mkdir -p /mnt/upload; mount -t tmpfs -o size=1M none /mnt/upload;") |
| 961 |
self.addCleanup(m.execute, "umount /mnt/upload; rmdir /mnt/upload;") |
| 962 |
b.set_file_autocomplete_val("#demo-upload", "/mnt/upload/") |
| 963 |
b.upload_files("#demo-upload input[type='file']", [big_file]) |
| 964 |
b.wait_visible("#upload-file-btn:not(:disabled)") |
| 965 |
b.wait_in_text(".pf-v6-c-alert", "No space left on device") |
| 966 |
self.assertEqual(m.execute('ls -A /mnt/upload'), '') # nothing left behind |
| 967 |
|
| 968 |
# Later ENOSPC error (after we've blocked) |
| 969 |
m.execute("umount /mnt/upload; mount -t tmpfs -o size=10M none /mnt/upload;") |
| 970 |
b.set_file_autocomplete_val("#demo-upload", "/mnt/upload/") |
| 971 |
b.upload_files("#demo-upload input[type='file']", [big_file]) |
| 972 |
b.wait_visible("#upload-file-btn:not(:disabled)") |
| 973 |
b.wait_in_text(".pf-v6-c-alert", "No space left on device") |
| 974 |
self.assertEqual(m.execute('ls -A /mnt/upload'), '') |
| 975 |
|
| 976 |
# Upload permission error |
| 977 |
b.drop_superuser() |
| 978 |
b.set_file_autocomplete_val("#demo-upload", "/var/") |
| 979 |
b.upload_files("#demo-upload input[type='file']", [test_upload_file]) |
| 980 |
b.wait_in_text(".pf-v6-c-alert", "Not permitted to perform this action") |
| 981 |
|
| 982 |
def testUploadMultiple(self) -> None: |
| 983 |
b = self.browser |
| 984 |
m = self.machine |
| 985 |
|
| 986 |
self.restore_dir("/home/admin") |
| 987 |
dest_dir = "/home/admin/keys/" |
| 988 |
m.execute(['runuser', '-u', 'admin', 'mkdir', dest_dir]) |
| 989 |
files_dir = Path(testlib.TEST_DIR) / "verify" / "files" / "ssh" |
| 990 |
files = [str(files_dir / f) for f in os.listdir(files_dir)] |
| 991 |
print("to be uploaded files", files) |
| 992 |
|
| 993 |
self.login_and_go("/playground/react-patterns") # , debugging="upload") |
| 994 |
b.wait_visible("#demo-upload") |
| 995 |
b.set_file_autocomplete_val("#demo-upload", dest_dir) |
| 996 |
b.upload_files("#demo-upload input[type='file']", files) |
| 997 |
|
| 998 |
with b.wait_timeout(30): |
| 999 |
b.wait(lambda: int(m.execute(f"ls {dest_dir} | wc -l").strip()) == len(files)) |
| 1000 |
b.wait_visible("#upload-file-btn:not(:disabled)") |
| 1001 |
|
| 1002 |
def testUserInfo(self) -> None: |
| 1003 |
b = self.browser |
| 1004 |
m = self.machine |
| 1005 |
|
| 1006 |
m.execute(""" |
| 1007 |
groupadd test |
| 1008 |
gpasswd -a admin test |
| 1009 |
""") |
| 1010 |
|
| 1011 |
self.login_and_go("/playground/test") |
| 1012 |
b.wait_visible("#user-info") |
| 1013 |
b.wait(lambda: "groups" in b.text("#user-info")) |
| 1014 |
user_info = json.loads(b.text("#user-info")) |
| 1015 |
self.assertEqual(user_info["home"], "/var/home/admin" if m.ostree_image else "/home/admin") |
| 1016 |
# default group is first |
| 1017 |
self.assertEqual(user_info["groups"][0], m.execute("id -gn admin").strip()) |
| 1018 |
self.assertIn("test", user_info["groups"]) |
| 1019 |
self.assertEqual(str(user_info["id"]), m.execute("id -u admin").strip()) |
| 1020 |
self.assertEqual(str(user_info["gid"]), m.execute("id -g admin").strip()) |
| 1021 |
|
| 1022 |
@testlib.skipImage("No SELinux", "debian-*", "ubuntu-*", "arch") |
| 1023 |
def testFSReplaceSELinuxContext(self) -> None: |
| 1024 |
b = self.browser |
| 1025 |
m = self.machine |
| 1026 |
|
| 1027 |
def set_content_and_validate(path, content, custom_context): |
| 1028 |
b.set_input_text("#fsreplace1-filename", path) |
| 1029 |
b.set_input_text("#fsreplace1-content", content) |
| 1030 |
b.set_checked("#fsreplace1-use-tag", val=True) |
| 1031 |
b.click("#fsreplace1-create") |
| 1032 |
b.wait_visible("#fsreplace1-create:not(:disabled)") |
| 1033 |
|
| 1034 |
self.assertEqual(m.execute(f"cat {path}"), content) |
| 1035 |
se_context = m.execute(f"stat --format=%C {path}").strip() |
| 1036 |
self.assertEqual(se_context, custom_context) |
| 1037 |
|
| 1038 |
path = f"{self.vm_tmpdir}/custom-selinux-context" |
| 1039 |
custom_context = "system_u:object_r:proc_t:s0" |
| 1040 |
m.execute(f""" |
| 1041 |
touch {path} |
| 1042 |
chcon {custom_context} {path} |
| 1043 |
""") |
| 1044 |
|
| 1045 |
self.login_and_go("/playground/test") |
| 1046 |
b.wait_visible("#fsreplace1-create") |
| 1047 |
set_content_and_validate(path, "data", custom_context) |
| 1048 |
|
| 1049 |
# As normal user |
| 1050 |
b.drop_superuser() |
| 1051 |
self.restore_dir("/home/admin") |
| 1052 |
path = "/home/admin/custom-selinux-context-user" |
| 1053 |
custom_context = "system_u:object_r:proc_t:s0" |
| 1054 |
m.execute("runuser -u admin -- sh -ex", input=f"touch {path}") |
| 1055 |
m.execute(f"chcon {custom_context} {path}") |
| 1056 |
|
| 1057 |
b.wait_visible("#fsreplace1-create") |
| 1058 |
set_content_and_validate(path, "user data", custom_context) |
| 1059 |
|
| 1060 |
@testlib.skipBeiboot("no local overrides/config in beiboot mode") |
| 1061 |
def testInvalidManifest(self): |
| 1062 |
b = self.browser |
| 1063 |
m = self.machine |
| 1064 |
|
| 1065 |
self.login_and_go("/system") |
| 1066 |
b.switch_to_top() |
| 1067 |
self.check_system_menu("Overview", present=True) |
| 1068 |
self.check_system_menu("Networking", present=True) |
| 1069 |
|
| 1070 |
# Break the Networking manifest by violating the type of the "order" field. |
| 1071 |
m.write("/etc/cockpit/networkmanager.override.json", '{"menu":{"index":{"order":"not-a-number"}}}') |
| 1072 |
|
| 1073 |
b.reload() |
| 1074 |
self.check_system_menu("Overview", present=True) |
| 1075 |
self.check_system_menu("Networking", present=False) |
| 1076 |
|
| 1077 |
def testFsreplaceOwnership(self) -> None: |
| 1078 |
b = self.browser |
| 1079 |
|
| 1080 |
self.login_and_go("/playground/test") |
| 1081 |
|
| 1082 |
def stat(fmt: str, path: str) -> str: |
| 1083 |
return self.machine.execute(['stat', f'--format={fmt}', path]).strip() |
| 1084 |
|
| 1085 |
def assert_stat(fmt: str, path: str, expected: str) -> None: |
| 1086 |
self.assertEqual(stat(fmt, path), expected) |
| 1087 |
|
| 1088 |
def assert_mode(path: str, mode: str) -> None: |
| 1089 |
assert_stat('%a', path, mode) |
| 1090 |
|
| 1091 |
def assert_owner(path: str, owner: str) -> None: |
| 1092 |
assert_stat('%U:%G', path, owner) |
| 1093 |
|
| 1094 |
def assert_content(path: str, expected: str) -> None: |
| 1095 |
self.assertEqual(self.machine.execute(f"cat {path}").strip(), expected) |
| 1096 |
|
| 1097 |
def set_file_bits(filename: str, content: str, |
| 1098 |
owner: str = "", group: str = "", |
| 1099 |
mode: str | None = None) -> None: |
| 1100 |
b.set_input_text("#fsreplace1-filename", filename) |
| 1101 |
b.set_input_text("#fsreplace1-content", content) |
| 1102 |
b.set_input_text("#fsreplace1-user", owner) |
| 1103 |
b.set_input_text("#fsreplace1-group", group) |
| 1104 |
if mode is not None: |
| 1105 |
b.set_input_text("#fsreplace1-mode", mode) |
| 1106 |
|
| 1107 |
b.click("#fsreplace1-create") |
| 1108 |
b.wait_visible("#fsreplace1-create:not(:disabled)") |
| 1109 |
|
| 1110 |
# Set file permissions on new files |
| 1111 |
filename = "/home/admin/admin.txt" |
| 1112 |
content = "adminfile" |
| 1113 |
set_file_bits(filename, content, "admin", "root") |
| 1114 |
assert_owner(filename, "admin:root") |
| 1115 |
assert_content(filename, content) |
| 1116 |
|
| 1117 |
filename = "/home/admin/root.txt" |
| 1118 |
content = "rootfile" |
| 1119 |
set_file_bits(filename, content, "root", "root") |
| 1120 |
assert_owner(filename, "root:root") |
| 1121 |
assert_content(filename, content) |
| 1122 |
|
| 1123 |
filename = "/home/admin/root.txt" |
| 1124 |
content = "rootfile" |
| 1125 |
set_file_bits(filename, content, "root", "root") |
| 1126 |
assert_owner(filename, "root:root") |
| 1127 |
assert_content(filename, content) |
| 1128 |
|
| 1129 |
filename = f"{self.vm_tmpdir}/root-mode.txt" |
| 1130 |
set_file_bits(filename, content, "root", "root", str(0o600)) |
| 1131 |
assert_owner(filename, "root:root") |
| 1132 |
assert_mode(filename, "600") |
| 1133 |
assert_content(filename, content) |
| 1134 |
|
| 1135 |
# Mode on existing files |
| 1136 |
filename = f"{self.vm_tmpdir}/existing.txt" |
| 1137 |
self.machine.execute(f"install -m 644 -g admin -o admin /dev/null {filename}") |
| 1138 |
set_file_bits(filename, content, "root", "root", str(0o600)) |
| 1139 |
assert_owner(filename, "root:root") |
| 1140 |
assert_mode(filename, "600") |
| 1141 |
assert_content(filename, content) |
| 1142 |
|
| 1143 |
|
| 1144 |
if __name__ == '__main__': |
| 1145 |
testlib.test_main() |