| 1 |
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv) |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (C) 2020 Red Hat, Inc. |
| 5 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 |
|
| 7 |
|
| 8 |
import time |
| 9 |
|
| 10 |
import testlib |
| 11 |
|
| 12 |
|
| 13 |
class HostSwitcherHelpers: |
| 14 |
|
| 15 |
def open_host_switcher(self, browser=None): |
| 16 |
b = browser or self.browser |
| 17 |
b.click("#hosts-sel button") |
| 18 |
b.wait_visible("#nav-hosts.interact") |
| 19 |
# the opening animation takes quite long, don't move elements underneath mouse clicks |
| 20 |
b.wait_js_cond('ph_count_animations("#nav-hosts") == 0') |
| 21 |
time.sleep(0.2) |
| 22 |
|
| 23 |
def edit_hosts(self, browser=None): |
| 24 |
b = browser or self.browser |
| 25 |
b.click("button:contains('Edit hosts')") |
| 26 |
# the opening animation takes quite long, don't move elements underneath mouse clicks |
| 27 |
b.wait_js_cond('ph_count_animations("#nav-hosts") == 0') |
| 28 |
b.wait_visible("button:contains('Stop editing hosts')") |
| 29 |
|
| 30 |
def check_discovered_addresses(self, b, addresses): |
| 31 |
b.click("button:contains('Add new host')") |
| 32 |
b.wait_visible('#hosts_setup_server_dialog') |
| 33 |
self.wait_discovered_addresses(b, addresses) |
| 34 |
b.click('#hosts_setup_server_dialog .pf-m-link') |
| 35 |
b.wait_not_present('#hosts_setup_server_dialog') |
| 36 |
|
| 37 |
def wait_discovered_addresses(self, b, expected): |
| 38 |
b.wait_js_cond(f'ph_select("#hosts_setup_server_dialog datalist option").length == {len(expected)}') |
| 39 |
# Check that we rendered all expected hosts |
| 40 |
for address in expected: |
| 41 |
b._wait_present(f"#hosts_setup_server_dialog datalist option[value='{address}']") |
| 42 |
|
| 43 |
def wait_host_addresses(self, b, expected, host_switcher_is_open=True): |
| 44 |
if not host_switcher_is_open: |
| 45 |
# wait for host switcher to close |
| 46 |
b.wait_not_present("#nav-hosts.interact") |
| 47 |
# open it again |
| 48 |
self.open_host_switcher(b) |
| 49 |
b.wait_js_cond(f'ph_select("#nav-hosts .nav-item a").length == {len(expected)}') |
| 50 |
for address in expected: |
| 51 |
if address == "localhost": |
| 52 |
b.wait_visible("#nav-hosts .nav-item a[href='/']") |
| 53 |
else: |
| 54 |
b.wait_visible(f"#nav-hosts .nav-item a[href='/@{address}']") |
| 55 |
|
| 56 |
def machine_remove(self, b, address, second_to_last=False): |
| 57 |
self.edit_hosts(b) |
| 58 |
b.click(f".nav-item a[href='/@{address}'] + span button.nav-action.pf-m-danger") |
| 59 |
if second_to_last: |
| 60 |
b.wait_not_present("button:contains('Stop editing hosts')") |
| 61 |
b.wait_not_present(".nav-item a[href='/'] + span button.nav-action.pf-m-danger") |
| 62 |
else: |
| 63 |
b.click("button:contains('Stop editing hosts')") |
| 64 |
|
| 65 |
# Wait until all related iframes are gone |
| 66 |
b.wait_js_func("""(function (dropped) { |
| 67 |
const frames = document.getElementsByTagName("iframe"); |
| 68 |
for (i = 0; i < frames.length; i++) |
| 69 |
if (frames[i].getAttribute['data-host'] === dropped) |
| 70 |
return false; |
| 71 |
return true; |
| 72 |
})""", address) |
| 73 |
|
| 74 |
# HACK: Dropping the machine does not terminate SSH connection; https://github.com/cockpit-project/cockpit/issues/19672 |
| 75 |
self.machine.execute(f"pkill -f [s]sh.*{address}; while pgrep -f [s]sh.*{address}; do sleep 1; done") |
| 76 |
|
| 77 |
def add_new_machine(self, b, address, known_host=False, pixel_label=None, user=None, expect_password_auth=False, |
| 78 |
expect_warning=False): |
| 79 |
b.click("button:contains('Add new host')") |
| 80 |
b.wait_visible('#hosts_setup_server_dialog') |
| 81 |
b.set_input_text('#add-machine-address', address) |
| 82 |
if user: |
| 83 |
b.set_input_text('#add-machine-user', user) |
| 84 |
if pixel_label: |
| 85 |
b.assert_pixels("#hosts_setup_server_dialog", pixel_label) |
| 86 |
b.click('#hosts_setup_server_dialog .pf-m-primary:contains("Add")') |
| 87 |
if expect_warning: |
| 88 |
b.wait_visible('#hosts_connect_server_dialog') |
| 89 |
b.click('#hosts_connect_server_dialog button.pf-m-warning') |
| 90 |
b.wait_not_present('#hosts_connect_server_dialog') |
| 91 |
if not known_host: |
| 92 |
b.wait_in_text('#hosts_setup_server_dialog', |
| 93 |
f"You are connecting to {address.removeprefix('ssh://')} for the first time") |
| 94 |
b.click('#hosts_setup_server_dialog .pf-m-primary') |
| 95 |
if expect_password_auth: |
| 96 |
b.wait_in_text("#hosts_setup_server_dialog", "Unable to log in to") |
| 97 |
b.set_input_text('#login-custom-password', "foobar") |
| 98 |
b.click('#hosts_setup_server_dialog button:contains("Log in")') |
| 99 |
with b.wait_timeout(30): |
| 100 |
b.wait_not_present('#hosts_setup_server_dialog') |
| 101 |
|
| 102 |
def wait_connected(self, b, address, expected_user=None): |
| 103 |
b.wait_visible(f".connected a[href='/@{address}']") |
| 104 |
if expected_user: |
| 105 |
b.wait_text("#current-username", expected_user) |
| 106 |
# Switch back to localhost, since the rest of the test expects that |
| 107 |
b.click("a[href='/']") |
| 108 |
self.open_host_switcher(b) |
| 109 |
|
| 110 |
def connect_and_wait(self, b, address, expected_user=None, expect_warning=False): |
| 111 |
b.click(f"a[href='/@{address}']") |
| 112 |
if expect_warning: |
| 113 |
b.wait_visible('#hosts_connect_server_dialog') |
| 114 |
b.click('#hosts_connect_server_dialog button.pf-m-warning') |
| 115 |
b.wait_not_present('#hosts_connect_server_dialog') |
| 116 |
# wait for host switcher to close after connecting |
| 117 |
b.wait_not_present("#nav-hosts.interact") |
| 118 |
# open it again |
| 119 |
self.open_host_switcher(b) |
| 120 |
self.wait_connected(b, address, expected_user) |
| 121 |
|
| 122 |
|
| 123 |
@testlib.skipBeiboot("host switching disabled in beiboot mode") |
| 124 |
class TestHostSwitching(testlib.MachineCase, HostSwitcherHelpers): |
| 125 |
provision = { |
| 126 |
'machine1': {"address": "10.111.113.1/20"}, |
| 127 |
'machine2': {"address": "10.111.113.2/20"}, |
| 128 |
'machine3': {"address": "10.111.113.3/20"} |
| 129 |
} |
| 130 |
|
| 131 |
def setUp(self): |
| 132 |
super().setUp() |
| 133 |
|
| 134 |
self.setup_provisioned_hosts(disable_preload=True) |
| 135 |
# Override hostname from machine1 to localhost |
| 136 |
self.machines["machine1"].execute("hostnamectl set-hostname localhost") |
| 137 |
|
| 138 |
self.setup_ssh_auth() |
| 139 |
|
| 140 |
# removing machines interrupts channels |
| 141 |
self.allow_restart_journal_messages() |
| 142 |
self.allow_hostkey_messages() |
| 143 |
|
| 144 |
def testBasic(self): |
| 145 |
b = self.browser |
| 146 |
m1 = self.machines["machine1"] |
| 147 |
m2 = self.machines["machine2"] |
| 148 |
m3 = self.machines["machine3"] |
| 149 |
|
| 150 |
m2.execute("hostnamectl set-hostname machine2") |
| 151 |
m3.execute("hostnamectl set-hostname machine3") |
| 152 |
|
| 153 |
# Switch the switcher off for the beginning of this test. |
| 154 |
if self.multihost_enabled: |
| 155 |
m1.write("/etc/cockpit/cockpit.conf", |
| 156 |
'[WebService]\nAllowMultiHost=no\n') |
| 157 |
|
| 158 |
# This should all work without being admin on machine1 |
| 159 |
self.login_and_go(superuser=False) |
| 160 |
|
| 161 |
b.wait_text("#hosts-sel .ct-switcher-localonly", "admin@localhost") |
| 162 |
self.assertFalse(b.is_present("#hosts-sel button")) |
| 163 |
b.assert_pixels("#hosts-sel", "no-switching", skip_layouts=["mobile"]) |
| 164 |
|
| 165 |
# Check that URLs to remote hosts get redirected to the local |
| 166 |
# session. |
| 167 |
b.wait_js_cond('window.location.pathname == "/system"') |
| 168 |
b.go("/@10.111.113.2/storage") |
| 169 |
b.wait_js_cond('window.location.pathname == "/storage"') |
| 170 |
|
| 171 |
# Enable host switcher for the rest of the test |
| 172 |
b.logout() |
| 173 |
if self.multihost_enabled: |
| 174 |
# clean up AllowMultiHost=no from above |
| 175 |
m1.execute("rm /etc/cockpit/cockpit.conf") |
| 176 |
self.enable_multihost(m1) |
| 177 |
m1.restart_cockpit() |
| 178 |
b.login_and_go(superuser=False) |
| 179 |
|
| 180 |
b.assert_pixels("#nav-system", "nav-system", skip_layouts=["mobile"]) |
| 181 |
b.set_layout("mobile") |
| 182 |
b.click("#nav-system-item") |
| 183 |
b.wait_visible("#nav-system.interact") |
| 184 |
b.assert_pixels_in_current_layout("#nav-system", "nav-system") |
| 185 |
b.click("#nav-system-item") |
| 186 |
b.wait_not_present("#nav-system.interact") |
| 187 |
b.set_layout("desktop") |
| 188 |
|
| 189 |
b.assert_pixels("#hosts-sel", "hosts-sel-closed") |
| 190 |
|
| 191 |
self.open_host_switcher() |
| 192 |
self.wait_host_addresses(b, ["localhost"]) |
| 193 |
|
| 194 |
b.wait_not_present("button:contains('Edit hosts')") |
| 195 |
|
| 196 |
# Test that transient hostname shows up |
| 197 |
m1.execute("hostnamectl set-hostname ''") |
| 198 |
m1.execute("hostnamectl set-hostname --transient 'mydhcpname'") |
| 199 |
b.wait_in_text("#nav-hosts .nav-item a", "mydhcpname") |
| 200 |
m1.execute("hostnamectl set-hostname 'localhost'") |
| 201 |
|
| 202 |
# Add a host with a couple of mistakes on the way |
| 203 |
b.click("button:contains('Add new host')") |
| 204 |
b.wait_visible('#hosts_setup_server_dialog') |
| 205 |
b.set_input_text('#add-machine-address', "10.111.113.2:1234") |
| 206 |
b.click('#hosts_setup_server_dialog .pf-m-primary:contains("Add")') |
| 207 |
# Port is wrong but we first have to confirm that we really want to connect |
| 208 |
b.wait_visible('#hosts_connect_server_dialog') |
| 209 |
b.assert_pixels("#hosts_connect_server_dialog", "host-connect-dialog") |
| 210 |
b.click('#hosts_connect_server_dialog button.pf-m-warning') |
| 211 |
# Now we are back in the "Add host" dialog with the error |
| 212 |
b.wait_in_text('#hosts_setup_server_dialog', "Unable to contact the given host 10.111.113.2:1234. Make sure it has ssh running on port 1234, or specify another port in the address.") |
| 213 |
# Give another wrong address |
| 214 |
b.set_input_text('#add-machine-address', "10.111.113.2:4321") |
| 215 |
b.click('#hosts_setup_server_dialog .pf-m-primary:contains("Add")') |
| 216 |
# Error happens immediately now. |
| 217 |
b.wait_in_text('#hosts_setup_server_dialog', "Unable to contact the given host 10.111.113.2:4321. Make sure it has ssh running on port 4321, or specify another port in the address.") |
| 218 |
# Now do it right |
| 219 |
b.set_input_text('#add-machine-address', "10.111.113.2") |
| 220 |
# move the mouse away to avoid highlighting any UI element (pixel ref does not expect that) |
| 221 |
b.mouse("#hosts-sel", "mouseenter") |
| 222 |
b.assert_pixels("#hosts_setup_server_dialog", "host-add-dialog") |
| 223 |
b.click('#hosts_setup_server_dialog .pf-m-primary:contains("Add")') |
| 224 |
b.wait_in_text('#hosts_setup_server_dialog', "You are connecting to 10.111.113.2 for the first time") |
| 225 |
b.click('#hosts_setup_server_dialog .pf-m-primary') |
| 226 |
b.wait_not_present('#hosts_setup_server_dialog') |
| 227 |
|
| 228 |
self.wait_host_addresses(b, ["localhost", "10.111.113.2"], host_switcher_is_open=False) |
| 229 |
# defaults to current host user name "admin" |
| 230 |
self.wait_connected(b, "10.111.113.2", "admin") |
| 231 |
|
| 232 |
# Main host should have both buttons disabled, the second both enabled |
| 233 |
self.edit_hosts() |
| 234 |
b.wait_visible(".nav-item a[href='/'] + span button.nav-action.pf-m-danger:disabled") |
| 235 |
b.wait_visible(".nav-item a[href='/'] + span button.nav-action.pf-m-secondary:disabled") |
| 236 |
b.wait_visible(".nav-item a[href='/@10.111.113.2'] + span button.nav-action.pf-m-danger:not(:disabled)") |
| 237 |
b.wait_visible(".nav-item a[href='/@10.111.113.2'] + span button.nav-action.pf-m-secondary:not(:disabled)") |
| 238 |
b.assert_pixels(".edit-hosts", "edit-hosts") |
| 239 |
b.click("button:contains('Stop editing hosts')") |
| 240 |
b.wait_not_present(".nav-item a[href='/'] + span button.nav-action.pf-m-danger") |
| 241 |
b.wait_not_present(".nav-item a[href='/@10.111.113.2'] + span button.nav-action.pf-m-secondary") |
| 242 |
|
| 243 |
b.wait_not_present(".nav-item a[href='/@10.111.113.2'] .nav-status") |
| 244 |
|
| 245 |
self.add_new_machine(b, "10.111.113.3") |
| 246 |
self.wait_host_addresses(b, ["localhost", "10.111.113.3", "10.111.113.2"], host_switcher_is_open=False) |
| 247 |
self.wait_connected(b, "10.111.113.3", "admin") |
| 248 |
|
| 249 |
b.assert_pixels("#nav-hosts", "nav-hosts-2-remotes") |
| 250 |
|
| 251 |
# Remove two |
| 252 |
self.machine_remove(b, "10.111.113.2") |
| 253 |
self.wait_host_addresses(b, ["localhost", "10.111.113.3"]) |
| 254 |
|
| 255 |
self.machine_remove(b, "10.111.113.3", second_to_last=True) |
| 256 |
self.wait_host_addresses(b, ["localhost"]) |
| 257 |
|
| 258 |
# Check that the two removed machines are listed in "Add Host" |
| 259 |
self.check_discovered_addresses(b, ["10.111.113.2", "10.111.113.3"]) |
| 260 |
|
| 261 |
# Add one back, check addresses on both browsers |
| 262 |
self.add_new_machine(b, "10.111.113.2", known_host=True) |
| 263 |
self.wait_host_addresses(b, ["localhost", "10.111.113.2"], host_switcher_is_open=False) |
| 264 |
self.wait_connected(b, "10.111.113.2") |
| 265 |
self.check_discovered_addresses(b, ["10.111.113.3"]) |
| 266 |
|
| 267 |
b.wait_not_present(".nav-item a[href='/@10.111.113.2'] .nav-status") |
| 268 |
|
| 269 |
# And the second one, check addresses |
| 270 |
self.add_new_machine(b, "10.111.113.3", known_host=True) |
| 271 |
self.wait_host_addresses(b, ["localhost", "10.111.113.2", "10.111.113.3"], host_switcher_is_open=False) |
| 272 |
self.wait_connected(b, "10.111.113.3") |
| 273 |
self.check_discovered_addresses(b, []) |
| 274 |
|
| 275 |
# Test change user, not doing in edit to reuse machines |
| 276 |
|
| 277 |
# Navigate to load iframe |
| 278 |
b.click("#nav-hosts .nav-item a[href='/@10.111.113.3']") |
| 279 |
b.wait_visible("iframe.container-frame[name='cockpit1:10.111.113.3/system']") |
| 280 |
|
| 281 |
self.open_host_switcher() |
| 282 |
self.edit_hosts() |
| 283 |
|
| 284 |
b.click("#nav-hosts .nav-item a[href='/@10.111.113.3'] + span button.nav-action.pf-m-secondary") |
| 285 |
|
| 286 |
b.wait_visible('#hosts_setup_server_dialog') |
| 287 |
b.set_input_text('#add-machine-user', 'bad-user') |
| 288 |
b.click('#hosts_setup_server_dialog .pf-m-primary') |
| 289 |
b.wait_in_text("#hosts_setup_server_dialog", "Unable to log in to") |
| 290 |
b.click('#hosts_setup_server_dialog button:contains("Cancel")') |
| 291 |
b.wait_not_present('#hosts_setup_server_dialog') |
| 292 |
|
| 293 |
# Test switching |
| 294 |
b.wait_js_cond('ph_select("#nav-hosts .nav-item a").length == 3') |
| 295 |
|
| 296 |
b.click("#nav-hosts .nav-item a[href='/']") |
| 297 |
b.wait_js_cond('window.location.pathname == "/system"') |
| 298 |
|
| 299 |
self.open_host_switcher() |
| 300 |
b.click("#nav-hosts .nav-item a[href='/@10.111.113.2']") |
| 301 |
b.wait_js_cond('window.location.pathname.indexOf("/@10.111.113.2") === 0') |
| 302 |
|
| 303 |
self.open_host_switcher() |
| 304 |
b.click("#nav-hosts .nav-item a[href='/@10.111.113.3']") |
| 305 |
b.wait_js_cond('window.location.pathname.indexOf("/@10.111.113.3") === 0') |
| 306 |
|
| 307 |
b.enter_page("/system", "10.111.113.3") |
| 308 |
b.wait_text_not("#system_information_systime_button", "") |
| 309 |
b.click(".system-information a") # View hardware details |
| 310 |
b.enter_page("/system/hwinfo", "10.111.113.3") |
| 311 |
b.click(".pf-v6-c-breadcrumb li:first-child") |
| 312 |
b.enter_page("/system", "10.111.113.3") |
| 313 |
b.wait_in_text(".ct-overview-header-hostname", "machine3") |
| 314 |
|
| 315 |
# Remove host underneath ourselves |
| 316 |
b.switch_to_top() |
| 317 |
self.open_host_switcher() |
| 318 |
self.edit_hosts() |
| 319 |
b.click("#nav-hosts .nav-item a[href='/@10.111.113.3'] + span button.nav-action.pf-m-danger") |
| 320 |
b.wait_not_present("iframe.container-frame[name='cockpit1:10.111.113.3/network']") |
| 321 |
b.wait_js_cond('window.location.pathname == "/system"') |
| 322 |
|
| 323 |
b.enter_page("/system", "localhost") |
| 324 |
|
| 325 |
# remove machine2 as well, to return to a blank slate |
| 326 |
b.switch_to_top() |
| 327 |
self.open_host_switcher() |
| 328 |
self.machine_remove(b, "10.111.113.2", second_to_last=True) |
| 329 |
self.wait_host_addresses(b, ["localhost"]) |
| 330 |
|
| 331 |
# |
| 332 |
# check various connection string formats and user names |
| 333 |
# the tests above only covers implied "admin" user |
| 334 |
# |
| 335 |
|
| 336 |
self.machines["machine2"].execute("useradd --create-home someone; echo someone:foobar | chpasswd") |
| 337 |
|
| 338 |
# plain address and separate "User name:" field |
| 339 |
self.add_new_machine(b, "10.111.113.2", known_host=True, user="someone", expect_password_auth=True) |
| 340 |
self.wait_host_addresses(b, ["localhost", "10.111.113.2"], host_switcher_is_open=False) |
| 341 |
self.wait_connected(b, "10.111.113.2", "someone") |
| 342 |
self.machine_remove(b, "10.111.113.2", second_to_last=True) |
| 343 |
|
| 344 |
# address with user and different "User name:" field, latter wins |
| 345 |
self.add_new_machine(b, "[email protected]", known_host=True, user="someone", expect_password_auth=True) |
| 346 |
self.wait_host_addresses(b, ["localhost", "10.111.113.2"], host_switcher_is_open=False) |
| 347 |
self.wait_connected(b, "10.111.113.2", "someone") |
| 348 |
self.machine_remove(b, "10.111.113.2", second_to_last=True) |
| 349 |
|
| 350 |
# switch off warnings for the rest of this test (nneds the |
| 351 |
# relogin below to take effect) |
| 352 |
m1.write("/etc/cockpit/cockpit.conf", |
| 353 |
'[Session]\nWarnBeforeConnecting=false\n', |
| 354 |
append=True) |
| 355 |
|
| 356 |
# reset session store to forget previous user/host connections |
| 357 |
b.relogin() |
| 358 |
self.open_host_switcher() |
| 359 |
|
| 360 |
# ssh:// prefix and implied user, no warning because we switched it off above |
| 361 |
self.add_new_machine(b, "ssh://10.111.113.2", known_host=True, expect_warning=False) |
| 362 |
self.wait_host_addresses(b, ["localhost", "10.111.113.2"], host_switcher_is_open=False) |
| 363 |
self.wait_connected(b, "10.111.113.2", "admin") |
| 364 |
self.machine_remove(b, "10.111.113.2", second_to_last=True) |
| 365 |
|
| 366 |
# ssh:// prefix and separate "User name:" field |
| 367 |
self.add_new_machine(b, "ssh://10.111.113.2", known_host=True, user="admin") |
| 368 |
self.wait_host_addresses(b, ["localhost", "10.111.113.2"], host_switcher_is_open=False) |
| 369 |
self.wait_connected(b, "10.111.113.2", "admin") |
| 370 |
self.machine_remove(b, "10.111.113.2", second_to_last=True) |
| 371 |
|
| 372 |
self.add_new_machine(b, "ssh://10.111.113.2", known_host=True, user="someone", expect_password_auth=True) |
| 373 |
self.wait_host_addresses(b, ["localhost", "10.111.113.2"], host_switcher_is_open=False) |
| 374 |
self.wait_connected(b, "10.111.113.2", "someone") |
| 375 |
self.machine_remove(b, "10.111.113.2", second_to_last=True) |
| 376 |
|
| 377 |
# ssh:// prefix with user name |
| 378 |
self.add_new_machine(b, "ssh://[email protected]", known_host=True, expect_password_auth=True) |
| 379 |
self.wait_host_addresses(b, ["localhost", "10.111.113.2"], host_switcher_is_open=False) |
| 380 |
self.wait_connected(b, "10.111.113.2", "someone") |
| 381 |
self.machine_remove(b, "10.111.113.2", second_to_last=True) |
| 382 |
|
| 383 |
# ssh:// prefix with user and different "User name:" field, latter wins |
| 384 |
self.add_new_machine(b, "ssh://[email protected]", known_host=True, user="someone", expect_password_auth=True) |
| 385 |
self.wait_host_addresses(b, ["localhost", "10.111.113.2"], host_switcher_is_open=False) |
| 386 |
self.wait_connected(b, "10.111.113.2", "someone") |
| 387 |
self.machine_remove(b, "10.111.113.2", second_to_last=True) |
| 388 |
|
| 389 |
# ssh:// prefix with user name and port in the connection target |
| 390 |
self.add_new_machine(b, "ssh://[email protected]:22", known_host=True) |
| 391 |
self.wait_host_addresses(b, ["localhost", "10.111.113.2"], host_switcher_is_open=False) |
| 392 |
self.wait_connected(b, "10.111.113.2") |
| 393 |
self.machine_remove(b, "10.111.113.2", second_to_last=True) |
| 394 |
|
| 395 |
self.allow_journal_messages(".*server offered unsupported authentication methods: password public-key.*") |
| 396 |
|
| 397 |
# Sometimes, adding and removing machines seems to happen so |
| 398 |
# fast that something goes wrong with serving files, |
| 399 |
# especially when those files are large in the "devel" |
| 400 |
# scenario. |
| 401 |
self.allow_journal_messages(".*: failure while serving external channel: internal-error") |
| 402 |
|
| 403 |
def testBasicAsAdmin(self): |
| 404 |
b = self.browser |
| 405 |
self.enable_multihost(self.machine) |
| 406 |
|
| 407 |
# When being admin, changes in the host switcher are supposed |
| 408 |
# to be reflected in all browser sessions. |
| 409 |
|
| 410 |
self.login_and_go() |
| 411 |
|
| 412 |
self.open_host_switcher() |
| 413 |
self.wait_host_addresses(b, ["localhost"]) |
| 414 |
|
| 415 |
b.wait_not_present("button:contains('Edit hosts')") |
| 416 |
|
| 417 |
# Start second browser and check that it is in sync |
| 418 |
b2 = self.new_browser() |
| 419 |
b2.default_user = "admin" |
| 420 |
b2.login_and_go() |
| 421 |
|
| 422 |
self.open_host_switcher(b2) |
| 423 |
self.wait_host_addresses(b2, ["localhost"]) |
| 424 |
|
| 425 |
self.add_new_machine(b, "10.111.113.2", expect_warning=True) |
| 426 |
self.wait_host_addresses(b, ["localhost", "10.111.113.2"], host_switcher_is_open=False) |
| 427 |
self.wait_host_addresses(b2, ["localhost", "10.111.113.2"]) |
| 428 |
self.wait_connected(b, "10.111.113.2") |
| 429 |
self.connect_and_wait(b2, "10.111.113.2", expect_warning=True) |
| 430 |
|
| 431 |
# Main host should have both buttons disabled, the second both enabled |
| 432 |
self.edit_hosts() |
| 433 |
b.wait_visible(".nav-item a[href='/'] + span button.nav-action.pf-m-danger:disabled") |
| 434 |
b.wait_visible(".nav-item a[href='/'] + span button.nav-action.pf-m-secondary:disabled") |
| 435 |
b.wait_visible(".nav-item a[href='/@10.111.113.2'] + span button.nav-action.pf-m-danger:not(:disabled)") |
| 436 |
b.wait_visible(".nav-item a[href='/@10.111.113.2'] + span button.nav-action.pf-m-secondary:not(:disabled)") |
| 437 |
b.click("button:contains('Stop editing hosts')") |
| 438 |
b.wait_not_present(".nav-item a[href='/'] + span button.nav-action.pf-m-danger") |
| 439 |
b.wait_not_present(".nav-item a[href='/@10.111.113.2'] + span button.nav-action.pf-m-secondary") |
| 440 |
|
| 441 |
b.wait_not_present(".nav-item a[href='/@10.111.113.2'] .nav-status") |
| 442 |
|
| 443 |
self.add_new_machine(b, "10.111.113.3") |
| 444 |
self.wait_host_addresses(b, ["localhost", "10.111.113.3", "10.111.113.2"], host_switcher_is_open=False) |
| 445 |
self.wait_host_addresses(b2, ["localhost", "10.111.113.3", "10.111.113.2"]) |
| 446 |
self.wait_connected(b, "10.111.113.3") |
| 447 |
self.connect_and_wait(b2, "10.111.113.3") |
| 448 |
|
| 449 |
# Remove two |
| 450 |
self.machine_remove(b, "10.111.113.2") |
| 451 |
self.wait_host_addresses(b, ["localhost", "10.111.113.3"]) |
| 452 |
self.wait_host_addresses(b2, ["localhost", "10.111.113.3"]) |
| 453 |
|
| 454 |
self.machine_remove(b, "10.111.113.3", second_to_last=True) |
| 455 |
self.wait_host_addresses(b, ["localhost"]) |
| 456 |
self.wait_host_addresses(b2, ["localhost"]) |
| 457 |
|
| 458 |
# Check that the two removed machines are listed in "Add Host" |
| 459 |
# on both browsers |
| 460 |
self.check_discovered_addresses(b, ["10.111.113.2", "10.111.113.3"]) |
| 461 |
self.check_discovered_addresses(b2, ["10.111.113.2", "10.111.113.3"]) |
| 462 |
|
| 463 |
# Add one back, check addresses on both browsers |
| 464 |
self.add_new_machine(b, "10.111.113.2", known_host=True) |
| 465 |
self.wait_host_addresses(b, ["localhost", "10.111.113.2"], host_switcher_is_open=False) |
| 466 |
self.wait_host_addresses(b2, ["localhost", "10.111.113.2"]) |
| 467 |
self.wait_connected(b, "10.111.113.2") |
| 468 |
self.check_discovered_addresses(b, ["10.111.113.3"]) |
| 469 |
self.check_discovered_addresses(b2, ["10.111.113.3"]) |
| 470 |
|
| 471 |
b.wait_not_present(".nav-item a[href='/@10.111.113.2'] .nav-status") |
| 472 |
|
| 473 |
# And the second one, check addresses on both browsers |
| 474 |
self.add_new_machine(b, "10.111.113.3", known_host=True) |
| 475 |
self.wait_host_addresses(b, ["localhost", "10.111.113.2", "10.111.113.3"], host_switcher_is_open=False) |
| 476 |
self.wait_host_addresses(b2, ["localhost", "10.111.113.2", "10.111.113.3"]) |
| 477 |
self.wait_connected(b, "10.111.113.3") |
| 478 |
self.check_discovered_addresses(b, []) |
| 479 |
self.check_discovered_addresses(b2, []) |
| 480 |
|
| 481 |
@testlib.no_retry_when_changed |
| 482 |
def testEdit(self): |
| 483 |
b = self.browser |
| 484 |
m1 = self.machines['machine1'] |
| 485 |
m2 = self.machines['machine2'] |
| 486 |
m3 = self.machines['machine3'] |
| 487 |
|
| 488 |
self.enable_multihost(m1) |
| 489 |
|
| 490 |
m2.execute("hostnamectl set-hostname machine2") |
| 491 |
m3.execute("hostnamectl set-hostname machine3") |
| 492 |
|
| 493 |
for user in ["franz", "hera"]: |
| 494 |
self.allow_journal_messages(f"Could not chdir to home directory /home/{user}: No such file or directory") |
| 495 |
m1.execute(f"useradd {user}") |
| 496 |
m1.execute(f"echo {user}:foobar | chpasswd") |
| 497 |
m3.execute(f"useradd {user}") |
| 498 |
m3.execute(f"echo {user}:foobar | chpasswd") |
| 499 |
self.authorize_pubkey(m3, user, self.get_pubkey(m1, "admin")) |
| 500 |
|
| 501 |
# This should all work without being admin on m1 |
| 502 |
self.login_and_go(superuser=False) |
| 503 |
|
| 504 |
self.open_host_switcher() |
| 505 |
self.add_new_machine(b, "10.111.113.3", expect_warning=True) |
| 506 |
self.wait_host_addresses(b, ["localhost", "10.111.113.3"], host_switcher_is_open=False) |
| 507 |
self.wait_connected(b, "10.111.113.3") |
| 508 |
|
| 509 |
self.edit_hosts() |
| 510 |
b.click("#nav-hosts .nav-item a[href='/@10.111.113.3'] + span button.nav-action.pf-m-secondary") |
| 511 |
|
| 512 |
b.wait_text('#hosts_setup_server_dialog .pf-v6-c-modal-box__title', 'Edit host') |
| 513 |
b.set_input_text('#add-machine-user', 'hera') |
| 514 |
b.click('#hosts_setup_server_dialog .pf-m-primary') |
| 515 |
with b.wait_timeout(30): |
| 516 |
b.wait_not_present('#hosts_setup_server_dialog') |
| 517 |
|
| 518 |
b.wait_text(".nav-item a[href='/@10.111.113.3']", "hera @machine3") |
| 519 |
|
| 520 |
# Editing the username of an existing host is possible |
| 521 |
b.click("#nav-hosts .nav-item a[href='/@10.111.113.3'] + span button.nav-action.pf-m-secondary") |
| 522 |
b.set_input_text('#add-machine-user', 'franz') |
| 523 |
|
| 524 |
# <input type="color /> is rather difficult to set with tests |
| 525 |
# On Firefox the popup window cannot be targeted nor with mouse nor keayboard |
| 526 |
# On Chomium it is possible to tab-navigate through the color selector |
| 527 |
# So tab to RGB inputs and type in zeros |
| 528 |
if b.browser == "chromium": |
| 529 |
b.focus("input[type=color]") |
| 530 |
b.click("input[type=color]") |
| 531 |
time.sleep(1) # We cannot wait until the popup opens up, so just little of waiting |
| 532 |
b.key("Tab", repeat=3) |
| 533 |
b.input_text("0") |
| 534 |
b.key("Tab") |
| 535 |
b.input_text("0") |
| 536 |
b.key("Tab") |
| 537 |
b.input_text("0") |
| 538 |
b.key("Enter") |
| 539 |
|
| 540 |
b.click('#hosts_setup_server_dialog .pf-m-primary') |
| 541 |
with b.wait_timeout(30): |
| 542 |
b.wait_not_present('#hosts_setup_server_dialog') |
| 543 |
|
| 544 |
b.wait_text(".nav-item a[href='/@10.111.113.3']", "franz @machine3") |
| 545 |
|
| 546 |
# Go to the updated machine and try to change whilst on it |
| 547 |
b.click("#nav-hosts .nav-item a[href='/@10.111.113.3']") |
| 548 |
b.wait_visible("iframe.container-frame[name='cockpit1:[email protected]/system']") |
| 549 |
|
| 550 |
b.wait_text("#hosts-sel button .pf-v6-c-select__toggle-text", "franz@machine3") |
| 551 |
self.open_host_switcher() |
| 552 |
b.wait_text(".nav-item a[href='/@10.111.113.3']", "franz @machine3") |
| 553 |
self.edit_hosts() |
| 554 |
b.click("#nav-hosts .nav-item a[href='/@10.111.113.3'] + span button.nav-action.pf-m-secondary") |
| 555 |
|
| 556 |
b.wait_val('#add-machine-address', "10.111.113.3") |
| 557 |
if b.browser == "chromium": |
| 558 |
self.assertEqual(b.attr("input[type=color]", "value"), "#000000") |
| 559 |
b.wait_val('#add-machine-user', 'franz') |
| 560 |
b.set_input_text('#add-machine-address', "10.111.113.2") |
| 561 |
b.set_input_text('#add-machine-user', 'admin') |
| 562 |
if b.browser == "chromium": |
| 563 |
self.assertNotEqual(b.attr("input[type=color]", "value"), "#000000") |
| 564 |
b.click('#hosts_setup_server_dialog .pf-m-primary') |
| 565 |
b.wait_in_text('#hosts_setup_server_dialog', "You are connecting to 10.111.113.2 for the first time.") |
| 566 |
b.click('#hosts_setup_server_dialog .pf-m-primary') |
| 567 |
with b.wait_timeout(30): |
| 568 |
b.wait_not_present('#hosts_setup_server_dialog') |
| 569 |
|
| 570 |
b.wait_text("#hosts-sel button .pf-v6-c-select__toggle-text", "admin@machine2") |
| 571 |
|
| 572 |
# Changing the address of a host will navigate to that host, |
| 573 |
# and that will close the host switcher. Let's open it again |
| 574 |
# to check it. |
| 575 |
self.open_host_switcher() |
| 576 |
b.wait_not_present(".nav-item a[href='/@10.111.113.3']") |
| 577 |
b.wait_text(".nav-item a[href='/@10.111.113.2']", "admin @machine2") |
| 578 |
|
| 579 |
def testNoAutoconnect(self): |
| 580 |
b = self.browser |
| 581 |
m2 = self.machines["machine2"] |
| 582 |
|
| 583 |
self.enable_multihost(self.machine) |
| 584 |
self.login_and_go(None) |
| 585 |
|
| 586 |
# Add and connect to a second machine |
| 587 |
self.open_host_switcher() |
| 588 |
self.add_new_machine(b, "10.111.113.2", expect_warning=True) |
| 589 |
b.wait_visible("iframe.container-frame[name='cockpit1:10.111.113.2/system']") |
| 590 |
self.assertIn("admin", m2.execute("loginctl")) |
| 591 |
self.open_host_switcher() |
| 592 |
b.click("a[href='/']") |
| 593 |
b.relogin() |
| 594 |
m2.execute("while loginctl | grep admin; do sleep 1; done") |
| 595 |
|
| 596 |
|
| 597 |
if __name__ == '__main__': |
| 598 |
testlib.test_main() |