| 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 datetime |
| 9 |
import os |
| 10 |
|
| 11 |
import testlib |
| 12 |
from machine import testvm |
| 13 |
|
| 14 |
good_password = "tqymuVh.ZfZnP§9Wr=LM3JyG5yx" |
| 15 |
SHADOW_UTILS_WITHOUT_EXPIRE = ["arch"] |
| 16 |
|
| 17 |
|
| 18 |
def getUserAddDetails(machine: testvm.Machine) -> dict[str, str]: |
| 19 |
useradd_defaults: dict[str, str] = {} |
| 20 |
for line in machine.execute("useradd -D").splitlines(): |
| 21 |
key, value = line.split("=") |
| 22 |
useradd_defaults[key] = value |
| 23 |
|
| 24 |
return useradd_defaults |
| 25 |
|
| 26 |
|
| 27 |
def performUserAction(browser: testlib.Browser, user: str, action: str) -> None: |
| 28 |
browser.click(f"#accounts-list tr[data-row-id='{user}'] button.pf-v6-c-menu-toggle") |
| 29 |
browser.wait_visible(f"#accounts-list tr[data-row-id='{user}'] button.pf-v6-c-menu-toggle[aria-expanded=true]") |
| 30 |
browser.click(f".pf-v6-c-menu button.pf-v6-c-menu__item:contains({action})") |
| 31 |
|
| 32 |
|
| 33 |
def performGroupAction(browser: testlib.Browser, group: str, action: str) -> None: |
| 34 |
browser.click(f"#groups-list tbody tr[data-row-id='{group}'] button.pf-v6-c-menu-toggle") |
| 35 |
browser.click(f".pf-v6-c-menu button.pf-v6-c-menu__item:contains({action})") |
| 36 |
|
| 37 |
|
| 38 |
def createUser( |
| 39 |
browser: testlib.Browser, |
| 40 |
machine: testvm.Machine, |
| 41 |
user_name: str, |
| 42 |
real_name: str, |
| 43 |
locked: bool, |
| 44 |
force_password_change: bool, |
| 45 |
password: str | None = None, |
| 46 |
custom_home_dir: str | None = None, |
| 47 |
default_shell: str | None = None, |
| 48 |
custom_shell: str | None = None, |
| 49 |
uid: str | None = None, |
| 50 |
expected_uid: str | None = None, |
| 51 |
verify_created: bool = True, |
| 52 |
run_assert_pixels: bool = False, |
| 53 |
) -> None: |
| 54 |
if default_shell is None: |
| 55 |
default_shell = getUserAddDetails(machine)["SHELL"] or "/bin/bash" |
| 56 |
browser.click('#accounts-create') |
| 57 |
browser.wait_visible('#accounts-create-dialog') |
| 58 |
if run_assert_pixels: |
| 59 |
browser.assert_pixels("#accounts-create-dialog", "accounts-create-dialog") |
| 60 |
|
| 61 |
browser.set_input_text('#accounts-create-user-name', user_name) |
| 62 |
browser.set_input_text('#accounts-create-real-name', real_name) |
| 63 |
if password: |
| 64 |
browser.set_input_text('#accounts-create-password-pw1', password) |
| 65 |
browser.set_input_text('#accounts-create-password-pw2', password) |
| 66 |
|
| 67 |
if locked: |
| 68 |
browser.click('#accounts-create-locked') |
| 69 |
browser.wait_visible('#accounts-create-locked:checked') |
| 70 |
else: |
| 71 |
browser.wait_visible('#account-use-password:checked') |
| 72 |
browser.set_checked('#accounts-create-force-password-change', force_password_change) |
| 73 |
browser.wait_visible('#accounts-create-locked:not(:checked)') |
| 74 |
|
| 75 |
if expected_uid is not None: |
| 76 |
browser.wait_visible(f'#accounts-create-user-uid[value="{expected_uid}"]') |
| 77 |
if uid is not None: |
| 78 |
browser.set_input_text('#accounts-create-user-uid', uid) |
| 79 |
if custom_home_dir is not None: |
| 80 |
browser.set_input_text('#accounts-create-user-home-dir', custom_home_dir) |
| 81 |
else: |
| 82 |
default_home_dir = getUserAddDetails(machine)["HOME"] |
| 83 |
expected_home_dir = default_home_dir + "/" + user_name |
| 84 |
browser.wait_visible(f"#accounts-create-user-home-dir[value='{expected_home_dir}']") |
| 85 |
|
| 86 |
if custom_shell: |
| 87 |
browser.select_from_dropdown("#accounts-create-user-shell", custom_shell) |
| 88 |
else: |
| 89 |
browser.wait_visible(f"#accounts-create-user-shell[data-selected='{default_shell}']") |
| 90 |
|
| 91 |
browser.click('#accounts-create-dialog button.apply') |
| 92 |
|
| 93 |
if verify_created: |
| 94 |
browser.wait_not_present('#accounts-create-dialog') |
| 95 |
browser.wait_in_text('#accounts-list', real_name) |
| 96 |
|
| 97 |
|
| 98 |
@testlib.nondestructive |
| 99 |
@testlib.skipImage("TODO: fix for OpenSUSE", "opensuse-tumbleweed") |
| 100 |
class TestAccounts(testlib.MachineCase): |
| 101 |
|
| 102 |
def testBasic(self) -> None: |
| 103 |
b = self.browser |
| 104 |
m = self.machine |
| 105 |
|
| 106 |
# Clean out the relevant logfiles |
| 107 |
m.execute("truncate -s0 /var/log/{[bw]tmp{,.db},lastlog} /run/utmp") |
| 108 |
m.execute("rm -f /var/lib/lastlog/lastlog2.db /var/lib/wtmpdb/wtmp.db") |
| 109 |
|
| 110 |
self.login_and_go("/users") |
| 111 |
|
| 112 |
# Add a user externally |
| 113 |
m.execute("useradd anton") |
| 114 |
m.execute("echo anton:foobar | chpasswd") |
| 115 |
with b.wait_timeout(30): |
| 116 |
b.wait_in_text('#accounts-list', "anton") |
| 117 |
|
| 118 |
# FIXME: rtl test was flaky, debug it and remove the skip |
| 119 |
b.assert_pixels("#users-page", "users-page", ignore=["td[data-label='Last active']", "button:contains('more...')"], skip_layouts=["rtl"]) |
| 120 |
|
| 121 |
# There is only one badge and it is for admin |
| 122 |
b.wait_text('#current-account-badge', 'Your account') |
| 123 |
b.wait_js_cond('document.querySelector("#current-account-badge").previousSibling.getAttribute("href") === "#/admin"') |
| 124 |
|
| 125 |
# The current account is the first in the list |
| 126 |
b.wait_visible("#accounts-list > tbody :first-child #current-account-badge") |
| 127 |
|
| 128 |
# Set a real name |
| 129 |
b.go("#/anton") |
| 130 |
b.wait_visible("#account-locked:not([disabled])") |
| 131 |
b.wait_text("#account-user-name", "anton") |
| 132 |
b.wait_text("#account-title", "anton") |
| 133 |
b.wait_text("#account-last-login", "Never") |
| 134 |
b.assert_pixels("#users-page", "user-detail-page") |
| 135 |
b.wait_not_attr("#account-delete", "disabled", "disabled") |
| 136 |
b.set_input_text('#account-real-name', "") # Check that we can delete the name before setting it up |
| 137 |
b.set_input_text('#account-real-name', 'foo:bar') |
| 138 |
b.wait_in_text('#account-real-name-helper', 'The full name must not contain colons.') |
| 139 |
b.set_input_text('#account-real-name', "Anton Arbitrary") |
| 140 |
b.wait_not_present('#account-real-name-helper') |
| 141 |
b.wait_visible('#account-real-name:not([disabled])') |
| 142 |
b.wait_text("#account-title", "Anton Arbitrary") |
| 143 |
b.wait_text("#account-home-dir", os.path.join(getUserAddDetails(m)["HOME"] + "/anton")) |
| 144 |
b.wait_text("#account-shell", getUserAddDetails(m)["SHELL"]) |
| 145 |
self.assertIn(":Anton Arbitrary:", m.execute("grep anton /etc/passwd")) |
| 146 |
|
| 147 |
# Add some other GECOS fields |
| 148 |
b.set_input_text('#account-real-name', "Anton Arbitrary,1,123") |
| 149 |
b.wait_visible('#account-real-name:not([disabled])') |
| 150 |
self.assertIn(":Anton Arbitrary,1,123:", m.execute("grep anton /etc/passwd")) |
| 151 |
# Table title only shows real name, no other GECOS fields |
| 152 |
b.wait_text("#account-title", "Anton Arbitrary") |
| 153 |
# On the overview page it also shows only real name |
| 154 |
b.go("/users") |
| 155 |
b.wait_text('#accounts-list td[data-label="Full name"]:contains("Anton")', "Anton Arbitrary") |
| 156 |
b.go("/users/#anton") |
| 157 |
|
| 158 |
# Delete it |
| 159 |
b.click('#account-delete') |
| 160 |
b.wait_visible('#account-confirm-delete-dialog') |
| 161 |
b.click('#account-confirm-delete-dialog button.apply') |
| 162 |
b.wait_not_present('#account-confirm-delete-dialog') |
| 163 |
b.wait_visible("#accounts") |
| 164 |
b.wait_not_in_text('#accounts-list', "Anton Arbitrary") |
| 165 |
|
| 166 |
m.execute("useradd --create-home barney") |
| 167 |
m.execute("echo barney:foobar | chpasswd") |
| 168 |
m.execute("runuser -u barney -- touch /home/barney/test.txt") |
| 169 |
m.execute("test -f /home/barney/test.txt") |
| 170 |
|
| 171 |
with b.wait_timeout(30): |
| 172 |
b.wait_in_text('#accounts-list', "barney") |
| 173 |
performUserAction(b, 'barney', 'Delete') |
| 174 |
b.set_checked("#account-confirm-delete-files", val=True) |
| 175 |
b.click('#account-confirm-delete-dialog button.apply') |
| 176 |
b.wait_not_present('#account-confirm-delete-dialog') |
| 177 |
m.execute("! test -e /home/barney/test.txt") |
| 178 |
b.wait_not_in_text('#accounts-list', "barney") |
| 179 |
|
| 180 |
# Attempt a real name with a colon |
| 181 |
b.click('#accounts-create') |
| 182 |
b.wait_visible('#accounts-create-dialog') |
| 183 |
b.set_input_text('#accounts-create-real-name', "Col:n Colon") # This should fail |
| 184 |
b.set_input_text('#accounts-create-password-pw1', good_password) |
| 185 |
b.set_input_text('#accounts-create-password-pw2', good_password) |
| 186 |
b.click('#accounts-create-dialog button.apply') |
| 187 |
b.wait_in_text("#accounts-create-dialog .pf-v6-c-form__helper-text .pf-m-error", "The full name must not contain colons.") |
| 188 |
b.click('#accounts-create-dialog button.cancel') |
| 189 |
b.wait_visible("#accounts") |
| 190 |
|
| 191 |
# Check root user |
| 192 |
b.go("#/root") |
| 193 |
b.wait_text("#account-user-name", "root") |
| 194 |
# some operations are not allowed for root user |
| 195 |
b.wait_visible("#account-delete[disabled]") |
| 196 |
b.wait_visible("#account-real-name[disabled]") |
| 197 |
b.wait_visible("#account-logout[disabled]") |
| 198 |
b.wait_visible("#account-locked:not(:checked)") |
| 199 |
# check home directory and shell for root |
| 200 |
b.wait_text("#account-home-dir", "/root") |
| 201 |
b.wait_in_text("#account-shell", "/bin/bash") # can be /usr/bin/bash or /bin/bash |
| 202 |
# root account should not be locked by default on our images |
| 203 |
self.assertIn(m.execute("passwd -S root").split()[1], ["P", "PS"]) |
| 204 |
# now lock account |
| 205 |
b.set_checked("#account-locked", val=True) |
| 206 |
b.wait(lambda: m.execute("passwd -S root").split()[1] in ["L", "LK"]) |
| 207 |
|
| 208 |
# Check admin user |
| 209 |
b.go("#/admin") |
| 210 |
b.wait_text("#account-user-name", "admin") |
| 211 |
# delete/logout are disabled for the current user |
| 212 |
b.wait_visible("#account-delete[disabled]") |
| 213 |
b.wait_visible("#account-logout[disabled]") |
| 214 |
|
| 215 |
# go back to accounts overview, check pf-v6-c-breadcrumb |
| 216 |
b.click("#account .pf-v6-c-breadcrumb a") |
| 217 |
b.wait_visible("#accounts-create") |
| 218 |
|
| 219 |
# Create a user from the UI |
| 220 |
self.sed_file('s@^SHELL=.*$@SHELL=/bin/true@', '/etc/default/useradd') |
| 221 |
b.click('#accounts-create') |
| 222 |
b.wait_visible('#accounts-create-dialog') |
| 223 |
b.set_input_text('#accounts-create-user-name', "Berta") |
| 224 |
b.set_input_text('#accounts-create-real-name', "Berta Bestimmt") |
| 225 |
b.set_input_text('#accounts-create-password-pw1', "foo") |
| 226 |
b.wait_visible("#accounts-create-password-meter.danger") |
| 227 |
b.set_input_text('#accounts-create-password-pw1', good_password) |
| 228 |
b.wait_visible("#accounts-create-password-meter.success") |
| 229 |
|
| 230 |
# Test password show/hide functionality |
| 231 |
b.wait_visible('#accounts-create-password-pw1[type="password"]') |
| 232 |
b.click("#accounts-create-password-pw1-group button[aria-label='Show password']") |
| 233 |
b.wait_visible('#accounts-create-password-pw1[type="text"]') |
| 234 |
b.click("#accounts-create-password-pw1-group button[aria-label='Hide password']") |
| 235 |
b.wait_visible('#accounts-create-password-pw1[type="password"]') |
| 236 |
|
| 237 |
# Test confirmation password show/hide functionality |
| 238 |
b.wait_visible('#accounts-create-password-pw2[type="password"]') |
| 239 |
b.click("#accounts-create-password-pw2-group button[aria-label='Show confirmation password']") |
| 240 |
b.wait_visible('#accounts-create-password-pw2[type="text"]') |
| 241 |
b.click("#accounts-create-password-pw2-group button[aria-label='Hide confirmation password']") |
| 242 |
b.wait_visible('#accounts-create-password-pw2[type="password"]') |
| 243 |
|
| 244 |
# wrong password confirmation |
| 245 |
b.set_input_text('#accounts-create-password-pw2', good_password + 'b') |
| 246 |
b.click('#accounts-create-dialog button.apply') |
| 247 |
b.wait_in_text("#accounts-create-dialog .pf-v6-c-form__helper-text .pf-m-error", "The passwords do not match") |
| 248 |
b.wait_not_present('#accounts-create-dialog button.pf-m-warning') |
| 249 |
|
| 250 |
# too long password |
| 251 |
long_password = "2a02-x!h4a" * 30 |
| 252 |
b.set_input_text('#accounts-create-password-pw1', long_password) |
| 253 |
b.set_input_text('#accounts-create-password-pw2', long_password) |
| 254 |
b.click('#accounts-create-dialog button.apply') |
| 255 |
b.wait_in_text("#accounts-create-dialog .pf-v6-c-form__helper-text .pf-m-warning", "Password is longer than 256 characters") |
| 256 |
b.wait_not_present('#accounts-create-dialog button.pf-m-warning') |
| 257 |
|
| 258 |
# changing input clears the error message |
| 259 |
b.set_input_text('#accounts-create-password-pw1', "test") |
| 260 |
b.set_input_text('#accounts-create-password-pw2', "test") |
| 261 |
b.wait_not_present("#accounts-create-dialog .pf-v6-c-form__helper-text .pf-m-warning") |
| 262 |
|
| 263 |
# correct password confirmation |
| 264 |
b.set_input_text('#accounts-create-password-pw1', good_password) |
| 265 |
b.set_input_text('#accounts-create-password-pw2', good_password) |
| 266 |
b.click('#accounts-create-dialog button.apply') |
| 267 |
b.wait_not_present("#accounts-create-dialog .pf-v6-c-form__helper-text .pf-m-warning") |
| 268 |
b.wait_not_present('#accounts-create-dialog') |
| 269 |
b.wait_in_text('#accounts-list', "Berta Bestimmt") |
| 270 |
|
| 271 |
# Check home directory |
| 272 |
home_dir = m.execute("getent passwd Berta | cut -f6 -d:").strip() |
| 273 |
self.assertTrue(home_dir.endswith("/Berta")) |
| 274 |
self.assertEqual(m.execute(f"stat -c '%U' {home_dir}").strip(), "Berta") |
| 275 |
|
| 276 |
# Check that we set up shell configured in /etc/default/useradd |
| 277 |
shell = m.execute("getent passwd Berta | cut -f7 -d:").strip() |
| 278 |
self.assertEqual(shell, '/bin/true') |
| 279 |
|
| 280 |
# Delete it externally |
| 281 |
m.execute("userdel Berta") |
| 282 |
b.wait_not_in_text('#accounts-list', "Berta Bestimmt") |
| 283 |
|
| 284 |
b.logout() |
| 285 |
b.login_and_go("/users") |
| 286 |
createUser( |
| 287 |
browser=b, |
| 288 |
machine=m, |
| 289 |
user_name="robert", |
| 290 |
real_name="Robert Robertson", |
| 291 |
password=good_password, |
| 292 |
locked=False, |
| 293 |
force_password_change=True, |
| 294 |
default_shell="/bin/true", |
| 295 |
run_assert_pixels=True |
| 296 |
) |
| 297 |
|
| 298 |
# Test actions in kebab menu |
| 299 |
# disable password |
| 300 |
performUserAction(b, 'robert', 'Lock account') |
| 301 |
b.click("#account-confirm-lock-dialog footer .pf-m-danger.apply") |
| 302 |
b.wait_not_present("#account-confirm-lock-dialog") |
| 303 |
# lock option is now disabled |
| 304 |
b.click("#accounts-list tbody tr[data-row-id='robert'] button.pf-v6-c-menu-toggle") |
| 305 |
b.wait_visible(".pf-v6-c-menu__list-item.pf-m-disabled:contains('Lock account')") |
| 306 |
b.click("#accounts-list tbody tr[data-row-id='robert'] button.pf-v6-c-menu-toggle") |
| 307 |
# change is visible on details page |
| 308 |
performUserAction(b, 'robert', 'Edit user') |
| 309 |
b.wait_in_text('#account-title', 'Robert Robertson') |
| 310 |
b.wait_visible('#account-locked:checked') |
| 311 |
b.click("#account-locked") |
| 312 |
b.go("/users") |
| 313 |
|
| 314 |
# In fedora-core userdel for this user consistently fails |
| 315 |
# userdel: user robert is currently used by process * |
| 316 |
if not m.ostree_image: |
| 317 |
performUserAction(b, 'robert', 'Delete account') |
| 318 |
b.click("#account-confirm-delete-dialog footer button.pf-m-danger.apply") |
| 319 |
b.wait_not_in_text('#accounts-list', "Robert Robertson") |
| 320 |
|
| 321 |
# test logout other user |
| 322 |
createUser( |
| 323 |
browser=b, |
| 324 |
machine=m, |
| 325 |
user_name="paul", |
| 326 |
real_name="Paul Robertson", |
| 327 |
password=good_password, |
| 328 |
locked=False, |
| 329 |
force_password_change=False, |
| 330 |
custom_shell="/bin/bash", # CoreOS defaults to /bin/true |
| 331 |
) |
| 332 |
b2 = self.new_browser(m) |
| 333 |
b2.login_and_go("/system", user="paul", password=good_password) |
| 334 |
b.wait_in_text("#accounts-list tbody tr:contains('paul')", "Logged in") |
| 335 |
|
| 336 |
performUserAction(b, 'paul', 'Log user out') |
| 337 |
b.click("#account-confirm-logout-dialog footer .pf-m-primary") |
| 338 |
b2.switch_to_top() |
| 339 |
b2.wait_in_text(".curtains-ct h1", "Disconnected") |
| 340 |
|
| 341 |
# HACK: lastlog does not record sessions from ssh |
| 342 |
if not m.ws_container: |
| 343 |
today = b.eval_js("Intl.DateTimeFormat('en', { dateStyle: 'medium' }).format()") |
| 344 |
b.wait_in_text("#accounts-list tbody tr:contains('paul')", today) |
| 345 |
|
| 346 |
self.allow_journal_messages("Password quality check failed:") |
| 347 |
self.allow_journal_messages("The password is a palindrome") |
| 348 |
self.allow_journal_messages("passwd: user.*does not exist") |
| 349 |
self.allow_journal_messages("passwd: Unknown user name '.*'.") |
| 350 |
self.allow_journal_messages("lastlog: Unknown user or range: anton") |
| 351 |
# when sed'ing, there is a short time when the config file does not exist |
| 352 |
self.allow_journal_messages(".*libuser initialization error: .*/etc/default/useradd.*: No such file or directory") |
| 353 |
|
| 354 |
def testFilterAndSort(self) -> None: |
| 355 |
b = self.browser |
| 356 |
m = self.machine |
| 357 |
|
| 358 |
self.login_and_go("/users") |
| 359 |
|
| 360 |
createUser( |
| 361 |
browser=b, |
| 362 |
machine=m, |
| 363 |
user_name="robert", |
| 364 |
real_name="Robert Robertson", |
| 365 |
password=good_password, |
| 366 |
locked=False, |
| 367 |
force_password_change=True, |
| 368 |
) |
| 369 |
|
| 370 |
# Check Robert's groups |
| 371 |
b.wait_not_present("#accounts-list tbody tr[data-row-id='robert'] td[data-label='Group'] .pf-v6-c-label:contains('users')") |
| 372 |
if not m.ostree_image: # Users group does not exist in coreos image |
| 373 |
m.execute("/usr/bin/gpasswd -a robert users") |
| 374 |
b.wait_in_text("#accounts-list tbody tr[data-row-id='robert'] td[data-label='Group'] .pf-v6-c-label.pf-m-blue:contains('users')", "users") |
| 375 |
m.execute(f"/usr/bin/gpasswd -a robert {m.get_admin_group()}") |
| 376 |
b.wait_in_text("#accounts-list tbody tr[data-row-id='robert'] td[data-label='Group'] .pf-v6-c-label.pf-m-yellow", m.get_admin_group()) |
| 377 |
m.execute(f"/usr/bin/gpasswd -d robert {m.get_admin_group()}") |
| 378 |
b.wait_not_present("#accounts-list tbody tr[data-row-id='robert'] td[data-label='Group'] .pf-v6-c-label.pf-m-yellow") |
| 379 |
|
| 380 |
# test filters |
| 381 |
b.set_input_text("#accounts-filter input", "root") |
| 382 |
b.wait_in_text("#accounts-list tbody:first-of-type td[data-label='Username']", "root") |
| 383 |
b.set_input_text("#accounts-filter input", "rOBeRt") |
| 384 |
b.wait_in_text("#accounts-list tbody:first-of-type td[data-label='Username']", "robert") |
| 385 |
|
| 386 |
uid = "1000" |
| 387 |
if "debian" in m.image or "ubuntu" in m.image: |
| 388 |
uid = "1001" |
| 389 |
b.set_input_text("#accounts-filter input", uid) |
| 390 |
b.wait_in_text("#accounts-list tbody:first-of-type td[data-label='ID']", uid) |
| 391 |
b.set_input_text("#accounts-filter input", "spooky") |
| 392 |
b.wait_visible("#accounts div.pf-v6-c-empty-state") |
| 393 |
|
| 394 |
# clear text filters |
| 395 |
b.click("#accounts-filter button[aria-label='Reset']") |
| 396 |
b.wait_not_present("#accounts div.pf-v6-c-empty-state") |
| 397 |
|
| 398 |
# clear via empty-state action |
| 399 |
b.set_input_text("#accounts-filter input", "spooky") |
| 400 |
b.wait_visible("#accounts div.pf-v6-c-empty-state") |
| 401 |
b.click("div.pf-v6-c-empty-state button.pf-m-link") |
| 402 |
b.wait_not_present("#accounts div.pf-v6-c-empty-state") |
| 403 |
|
| 404 |
b.eval_js(""" |
| 405 |
function getTextColumn(query_selector) { |
| 406 |
const values = []; |
| 407 |
document.querySelectorAll(query_selector).forEach(node => values.push(node.innerText)); |
| 408 |
return values; |
| 409 |
}""") |
| 410 |
|
| 411 |
def check_column_sort(query_selector: str, invert: bool = False) -> None: |
| 412 |
# current account is always in the first row |
| 413 |
b.wait_in_text("#accounts-list tbody:first-of-type td[data-label='Username']", "admin") |
| 414 |
values = b.eval_js(f"getTextColumn(\"{query_selector}\")") |
| 415 |
for i in range(2, len(values)): |
| 416 |
if values[i].isnumeric(): |
| 417 |
value_current = int(values[i]) |
| 418 |
value_prev = int(values[i - 1]) |
| 419 |
else: |
| 420 |
value_current = values[i].lower() |
| 421 |
value_prev = values[i - 1].lower() |
| 422 |
|
| 423 |
if (invert): |
| 424 |
b.wait(lambda: value_prev > value_current) |
| 425 |
else: |
| 426 |
b.wait(lambda: value_prev < value_current) |
| 427 |
|
| 428 |
# robert should be in users group |
| 429 |
if not m.ostree_image: # Users group does not exist in coreos image |
| 430 |
b.set_input_text("#accounts-filter input", "users") |
| 431 |
names = b.eval_js("getTextColumn(\"[data-label='Username'] a\")") |
| 432 |
b.wait(lambda: "robert" in names) |
| 433 |
b.click("#accounts-filter button[aria-label='Reset']") |
| 434 |
|
| 435 |
# check alphabetical order of Username |
| 436 |
check_column_sort("[data-label='Username'] a") |
| 437 |
b.wait_visible("#accounts-list > thead > tr > th:nth-child(1) > button") |
| 438 |
b.click("#accounts-list > thead > tr > th:nth-child(1) > button") |
| 439 |
check_column_sort("[data-label='Username'] a", invert=True) |
| 440 |
|
| 441 |
# sort by full name |
| 442 |
b.click("#accounts-list > thead > tr > th:nth-child(2) > button") |
| 443 |
check_column_sort("[data-label='Full name']") |
| 444 |
b.click("#accounts-list > thead > tr > th:nth-child(2) > button") |
| 445 |
check_column_sort("[data-label='Full name']", invert=True) |
| 446 |
|
| 447 |
# sort by ID |
| 448 |
b.click("#accounts-list > thead > tr > th:nth-child(3) > button") |
| 449 |
check_column_sort("[data-label='ID']", invert=True) |
| 450 |
b.click("#accounts-list > thead > tr > th:nth-child(3) > button") |
| 451 |
check_column_sort("[data-label='ID']") |
| 452 |
|
| 453 |
def testUserPasswords(self) -> None: |
| 454 |
b = self.browser |
| 455 |
m = self.machine |
| 456 |
|
| 457 |
# Clean out the relevant logfiles |
| 458 |
m.execute("truncate -s0 /var/log/{[bw]tmp{,.db},lastlog} /run/utmp") |
| 459 |
m.execute("rm -f /var/lib/lastlog/lastlog2.db /var/lib/wtmpdb/wtmp.db") |
| 460 |
|
| 461 |
self.login_and_go("/users") |
| 462 |
# Create a locked user with weak password |
| 463 |
self.sed_file('s/^SHELL=.*$/SHELL=/', '/etc/default/useradd') |
| 464 |
self.allow_journal_messages(".*required to change your password immediately.*") |
| 465 |
self.allow_journal_messages(".*user account or password has expired.*") |
| 466 |
|
| 467 |
createUser( |
| 468 |
browser=b, |
| 469 |
machine=m, |
| 470 |
user_name="js", |
| 471 |
real_name="Jussi Senior", |
| 472 |
locked=True, |
| 473 |
force_password_change=False, |
| 474 |
verify_created=False, |
| 475 |
) |
| 476 |
|
| 477 |
# Check Confirm password is not validated until it's at least the same length as the first password |
| 478 |
# Once they are the same length, it should valitate the Confirm password after each keystroke |
| 479 |
b.set_input_text('#accounts-create-password-pw1', "foobar") |
| 480 |
b.set_input_text('#accounts-create-password-pw2', "bar") |
| 481 |
b.wait_not_present("#accounts-create-password-pw2-helper") |
| 482 |
b.set_input_text('#accounts-create-password-pw2', "foobarfoo") |
| 483 |
b.wait_in_text("#accounts-create-password-pw2-helper", "The passwords do not match") |
| 484 |
b.set_input_text('#accounts-create-password-pw2', "bar") |
| 485 |
b.wait_in_text("#accounts-create-password-pw2-helper", "The passwords do not match") |
| 486 |
b.set_input_text('#accounts-create-password-pw2', "foobar") |
| 487 |
b.wait_not_present("#accounts-create-password-pw2-helper") |
| 488 |
|
| 489 |
b.click('#accounts-create-dialog button.cancel') |
| 490 |
b.wait_not_present('#account-set-password-dialog') |
| 491 |
|
| 492 |
createUser( |
| 493 |
browser=b, |
| 494 |
machine=m, |
| 495 |
user_name="js", |
| 496 |
real_name="Jussi Senior", |
| 497 |
locked=True, |
| 498 |
force_password_change=False, |
| 499 |
verify_created=False, |
| 500 |
) |
| 501 |
|
| 502 |
# Check Confirm password is not validated until the form is submitted |
| 503 |
# Once it is submitted, it should valitate the Confirm password after each keystroke |
| 504 |
b.set_input_text('#accounts-create-password-pw1', "foobar") |
| 505 |
b.set_input_text('#accounts-create-password-pw2', "bar") |
| 506 |
b.wait_not_present("#accounts-create-password-pw2-helper") |
| 507 |
b.click('#accounts-create-dialog button.apply') |
| 508 |
b.wait_in_text("#accounts-create-password-pw2-helper", "The passwords do not match") |
| 509 |
b.set_input_text('#accounts-create-password-pw2', "barfoo") |
| 510 |
b.wait_in_text("#accounts-create-password-pw2-helper", "The passwords do not match") |
| 511 |
b.set_input_text('#accounts-create-password-pw2', "foobarfoo") |
| 512 |
b.wait_in_text("#accounts-create-password-pw2-helper", "The passwords do not match") |
| 513 |
b.set_input_text('#accounts-create-password-pw2', "foobar") |
| 514 |
b.wait_not_present("#accounts-create-password-pw2-helper") |
| 515 |
|
| 516 |
b.click('#accounts-create-dialog button.cancel') |
| 517 |
b.wait_not_present('#account-set-password-dialog') |
| 518 |
|
| 519 |
createUser( |
| 520 |
browser=b, |
| 521 |
machine=m, |
| 522 |
user_name="jussi", |
| 523 |
real_name="Jussi Junior", |
| 524 |
password="foo", |
| 525 |
locked=True, |
| 526 |
force_password_change=False, |
| 527 |
verify_created=False, |
| 528 |
) |
| 529 |
|
| 530 |
# Password is weak, lets change it to another weak - this should still not accept |
| 531 |
b.wait_in_text("#accounts-create-dialog .pf-v6-c-form__helper-text .pf-m-warning", "Password quality check failed:") |
| 532 |
b.wait_visible('#accounts-create-dialog button.pf-m-warning') |
| 533 |
b.set_input_text('#accounts-create-password-pw1', "bar") |
| 534 |
b.set_input_text('#accounts-create-password-pw2', "bar") |
| 535 |
b.wait_not_present("#accounts-create-dialog .pf-v6-c-form__helper-text .pf-m-warning") |
| 536 |
b.wait_not_present('#accounts-create-dialog button.pf-m-warning') |
| 537 |
b.click('#accounts-create-dialog button.apply') |
| 538 |
|
| 539 |
# Password is weak, confirm button should be disabled after first click |
| 540 |
b.wait_in_text("#accounts-create-dialog .pf-v6-c-form__helper-text .pf-m-warning", "Password quality check failed:") |
| 541 |
b.wait_visible("button.apply:disabled") |
| 542 |
|
| 543 |
# Lets confirm the weak password now |
| 544 |
b.click('#accounts-create-dialog button.pf-m-warning') |
| 545 |
|
| 546 |
b.wait_not_present('#accounts-create-dialog') |
| 547 |
b.wait_in_text('#accounts-list', "Jussi Junior") |
| 548 |
|
| 549 |
def is_locked() -> bool: |
| 550 |
return m.execute("passwd -S jussi | cut -d' ' -f2").strip() in ["L", "LK"] |
| 551 |
|
| 552 |
def is_admin() -> bool: |
| 553 |
return "jussi" in m.execute(f"getent group {m.get_admin_group()}") |
| 554 |
|
| 555 |
admin_role_sel = '#account-groups-form-group' |
| 556 |
b.wait(lambda: "jussi" in m.execute("grep jussi /etc/passwd")) |
| 557 |
b.wait(lambda: not is_admin()) |
| 558 |
b.wait(is_locked) |
| 559 |
|
| 560 |
# Check that by default we set up `/bin/bash` |
| 561 |
shell = m.execute("getent passwd jussi | cut -f7 -d:").strip() |
| 562 |
self.assertEqual(shell, '/bin/bash') |
| 563 |
|
| 564 |
# Unlock it and make it an admin |
| 565 |
b.go("#/jussi") |
| 566 |
b.wait_text("#account-user-name", "jussi") |
| 567 |
b.wait_visible("#account-locked:checked") |
| 568 |
b.set_checked('#account-locked', val=False) |
| 569 |
b.wait(lambda: not is_locked()) |
| 570 |
b.wait_not_present(admin_role_sel + f" .pf-v6-c-label:contains(':{m.get_admin_group()}')") |
| 571 |
b.click("#account-groups > button") |
| 572 |
b.click(f"body .pf-v6-c-menu li:contains('{m.get_admin_group()}') > button") |
| 573 |
b.wait(is_admin) |
| 574 |
b.wait_not_present("#account-groups-helper") |
| 575 |
|
| 576 |
# Login as jussi and change role admin for itself |
| 577 |
b.logout() |
| 578 |
b.login_and_go("/users", user="jussi", password="bar") |
| 579 |
|
| 580 |
# There is only one badge and it is for jussi |
| 581 |
b.wait_text('#current-account-badge', 'Your account') |
| 582 |
b.wait_js_cond('document.querySelector("#current-account-badge").previousSibling.getAttribute("href") === "#/jussi"') |
| 583 |
|
| 584 |
# The current account is the first in the list |
| 585 |
b.wait_visible("#accounts-list > tbody:first-of-type #current-account-badge") |
| 586 |
|
| 587 |
# Use [x] button on the group label to remove the account from group |
| 588 |
b.go("#/jussi") |
| 589 |
b.wait_text("#account-user-name", "jussi") |
| 590 |
b.wait_in_text(f"{admin_role_sel} #account-groups .pf-v6-c-label-group", m.get_admin_group()) |
| 591 |
b.wait_not_present("#account-groups-helper") |
| 592 |
b.click(f"#account-groups .pf-v6-c-label__actions button[aria-label='Close {m.get_admin_group()}']") |
| 593 |
b.wait(lambda: not is_admin()) |
| 594 |
b.wait_not_in_text(f"{admin_role_sel} #account-groups .pf-v6-c-label-group", m.get_admin_group()) |
| 595 |
if not m.ostree_image: # User is not shown as logged in when logged in through Cockpit |
| 596 |
b.wait_visible("#account-groups-helper") |
| 597 |
m.execute(f"/usr/bin/gpasswd -a jussi {m.get_admin_group()}") |
| 598 |
with b.wait_timeout(20): |
| 599 |
b.wait_in_text(f"{admin_role_sel} #account-groups .pf-v6-c-label-group", m.get_admin_group()) |
| 600 |
|
| 601 |
# Cannot lock the current account |
| 602 |
b.wait_visible("#account-locked[disabled]") |
| 603 |
|
| 604 |
b.go("#/admin") |
| 605 |
b.wait_text("#account-user-name", "admin") |
| 606 |
b.wait_in_text(f"{admin_role_sel} #account-groups .pf-v6-c-label-group", m.get_admin_group()) |
| 607 |
b.wait_not_present("#account-groups-helper") |
| 608 |
b.logout() |
| 609 |
b.login_and_go("/users") |
| 610 |
|
| 611 |
# Change the password of this account |
| 612 |
b.go("#/jussi") |
| 613 |
b.wait_text("#account-user-name", "jussi") |
| 614 |
b.click('#account-set-password') |
| 615 |
b.wait_visible('#account-set-password-dialog') |
| 616 |
|
| 617 |
# weak password |
| 618 |
b.set_input_text("#account-set-password-pw1", 'a') |
| 619 |
b.set_input_text("#account-set-password-pw2", 'a') |
| 620 |
b.wait_visible("#account-set-password-meter.danger") |
| 621 |
b.click('#account-set-password-dialog button.apply') |
| 622 |
b.wait_in_text("#account-set-password-dialog .pf-v6-c-form__helper-text .pf-m-warning", "Password quality check failed:") |
| 623 |
b.wait_visible('#account-set-password-dialog button.pf-m-warning') |
| 624 |
|
| 625 |
# password mismatch |
| 626 |
b.set_input_text("#account-set-password-pw1", good_password + 'a') |
| 627 |
b.set_input_text("#account-set-password-pw2", good_password + 'b') |
| 628 |
b.click('#account-set-password-dialog button.apply') |
| 629 |
b.wait_in_text("#account-set-password-dialog .pf-v6-c-form__helper-text .pf-m-error", "The passwords do not match") |
| 630 |
b.wait_not_present('#account-set-password-dialog button.pf-m-warning') |
| 631 |
|
| 632 |
# too long password |
| 633 |
long_password = "2a02-x!h4a" * 30 |
| 634 |
b.set_input_text('#account-set-password-pw1', long_password) |
| 635 |
b.set_input_text('#account-set-password-pw2', long_password) |
| 636 |
b.wait_not_present("#account-set-password-dialog .pf-v6-c-form__helper-text .pf-m-warning") |
| 637 |
b.click('#account-set-password-dialog button.apply') |
| 638 |
b.wait_in_text("#account-set-password-dialog .pf-v6-c-form__helper-text .pf-m-warning", "Password is longer than 256 characters") |
| 639 |
b.wait_not_present('#account-set-password-dialog button.pf-m-warning') |
| 640 |
|
| 641 |
good_password_2 = "cEwghLY§X9R&m8RLwk4Xfed9Bw=" |
| 642 |
# Now set to something valid |
| 643 |
b.set_input_text("#account-set-password-pw1", good_password_2) |
| 644 |
b.set_input_text("#account-set-password-pw2", good_password_2) |
| 645 |
b.wait_visible("#account-set-password-meter.success") |
| 646 |
b.wait_not_present("#account-set-password-dialog .pf-v6-c-form__helper-text .pf-m-warning") |
| 647 |
b.click('#account-set-password-dialog button.apply') |
| 648 |
b.wait_not_present('#account-set-password-dialog') |
| 649 |
|
| 650 |
# incomplete passwd entry; fixed in PR #13384 |
| 651 |
m.execute('echo "damaged:x:1234:1234:Damaged" >> /etc/passwd') |
| 652 |
|
| 653 |
# Logout and login with the new password |
| 654 |
b.relogin(path="/users", user="jussi", password=good_password_2) |
| 655 |
|
| 656 |
b.go("/users") |
| 657 |
b.enter_page("/users") |
| 658 |
b.wait_in_text('#accounts-list', "damaged") |
| 659 |
b.click('#accounts-list td[data-label="Username"] a[href="#/damaged"]') |
| 660 |
b.wait_in_text("#account-title", "Damaged") |
| 661 |
|
| 662 |
if not m.ws_container: # User is not shown as logged in when logged in through Cockpit |
| 663 |
b.go("#/admin") |
| 664 |
b.wait_visible("#account-logout[disabled]") |
| 665 |
|
| 666 |
(year, month) = m.execute("date +'%Y %b'").strip().split() |
| 667 |
|
| 668 |
# Log in as "admin" and the open details in other browser should update |
| 669 |
b2 = self.new_browser(m) |
| 670 |
b2.login_and_go("/system") |
| 671 |
b.wait_text("#account-last-login", "Logged in") |
| 672 |
b.wait_visible("#account-logout:not(:disabled)") |
| 673 |
|
| 674 |
# Now log out and it should update again |
| 675 |
b2.logout() |
| 676 |
b.wait_in_text("#account-last-login", year) |
| 677 |
b.wait_in_text("#account-last-login", month) |
| 678 |
b.wait_visible("#account-logout[disabled]") |
| 679 |
|
| 680 |
# Terminate session |
| 681 |
b2.login_and_go("/system") |
| 682 |
b.wait_text("#account-last-login", "Logged in") |
| 683 |
b.click("#account-details button:contains('Terminate session')") |
| 684 |
b.wait_in_text("#account-last-login", year) |
| 685 |
b.wait_in_text("#account-last-login", month) |
| 686 |
b.wait_visible("#account-logout[disabled]") |
| 687 |
|
| 688 |
# Create an account and force password change on first login |
| 689 |
b.go('/users') |
| 690 |
createUser( |
| 691 |
browser=b, |
| 692 |
machine=m, |
| 693 |
user_name="robert", |
| 694 |
real_name="Robert Robertson", |
| 695 |
password=good_password, |
| 696 |
locked=False, |
| 697 |
force_password_change=True, |
| 698 |
) |
| 699 |
# Login as robert and check if password change is required |
| 700 |
b.logout() |
| 701 |
|
| 702 |
# login in second window to check if last login is updated in accounts list |
| 703 |
if not m.ws_container: # User is not shown as logged in when logged in through Cockpit |
| 704 |
b2.login_and_go("/users") |
| 705 |
b2.wait_in_text("#accounts-list tbody tr[data-row-id='robert'] td[data-label='Last active']", "Never logged in") |
| 706 |
|
| 707 |
# With the ws container this happens over ssh and we need |
| 708 |
# ChallengeResponseAuthentication (or |
| 709 |
# KbdInteractiveAuthentication, it's new name) to be allowed. |
| 710 |
# Without that, OpenSSH will do the required password change |
| 711 |
# without PAM and by running "/bin/passwd" instead. |
| 712 |
# |
| 713 |
if m.ws_container: |
| 714 |
self.restore_dir("/etc/ssh", restart_unit=self.sshd_service) |
| 715 |
m.execute("sed -i 's/.*ChallengeResponseAuthentication.*/ChallengeResponseAuthentication yes/' " |
| 716 |
"/etc/ssh/sshd_config $(ls /etc/ssh/sshd_config.d/* 2>/dev/null || true)") |
| 717 |
m.execute("sed -i 's/.*KbdInteractiveAuthentication.*/KbdInteractiveAuthentication yes/' " |
| 718 |
"/etc/ssh/sshd_config $(ls /etc/ssh/sshd_config.d/* 2>/dev/null || true)") |
| 719 |
m.execute(self.restart_sshd) |
| 720 |
|
| 721 |
b.wait_visible("#login") |
| 722 |
b.wait_not_visible("#conversation-group") |
| 723 |
b.try_login(user="robert", password=good_password) |
| 724 |
b.wait_visible('#conversation-input') |
| 725 |
b.set_val('#conversation-input', good_password) |
| 726 |
b.click('#login-button') |
| 727 |
|
| 728 |
# Set new password |
| 729 |
b.wait_in_text('#conversation-prompt', "New password:") |
| 730 |
b.set_val('#conversation-input', good_password_2) |
| 731 |
b.click('#login-button') |
| 732 |
|
| 733 |
# Confirm new password |
| 734 |
b.wait_in_text('#conversation-prompt', "Retype new password:") |
| 735 |
b.set_val('#conversation-input', good_password_2) |
| 736 |
b.click('#login-button') |
| 737 |
b.wait_visible('#content') |
| 738 |
|
| 739 |
def testCustomUID(self) -> None: |
| 740 |
b = self.browser |
| 741 |
m = self.machine |
| 742 |
|
| 743 |
self.login_and_go("/users") |
| 744 |
|
| 745 |
# Test custom UID |
| 746 |
createUser( |
| 747 |
browser=b, |
| 748 |
machine=m, |
| 749 |
user_name="bob", |
| 750 |
real_name="Bob Bobson", |
| 751 |
password=good_password, |
| 752 |
locked=False, |
| 753 |
force_password_change=False, |
| 754 |
uid="1500", |
| 755 |
verify_created=True, |
| 756 |
) |
| 757 |
b.wait_text("#accounts-list tr[data-row-id='bob'] td[data-label='ID']", "1500") |
| 758 |
|
| 759 |
# Test dialog correctly predicts the next available UID |
| 760 |
createUser( |
| 761 |
browser=b, |
| 762 |
machine=m, |
| 763 |
user_name="john", |
| 764 |
real_name="John Johnson", |
| 765 |
password=good_password, |
| 766 |
locked=False, |
| 767 |
force_password_change=False, |
| 768 |
expected_uid="1501", |
| 769 |
verify_created=True, |
| 770 |
) |
| 771 |
b.wait_text("#accounts-list tr[data-row-id='john'] td[data-label='ID']", "1501") |
| 772 |
|
| 773 |
# Test creation of users with the same UID |
| 774 |
createUser( |
| 775 |
browser=b, |
| 776 |
machine=m, |
| 777 |
user_name="jack", |
| 778 |
real_name="Jack Jackson", |
| 779 |
password=good_password, |
| 780 |
locked=False, |
| 781 |
force_password_change=False, |
| 782 |
uid="1501", |
| 783 |
verify_created=False, |
| 784 |
) |
| 785 |
b.wait_visible("#accounts-create-dialog") |
| 786 |
b.wait_in_text("#accounts-create-user-uid-helper", "already used") |
| 787 |
b.wait_visible("button.apply:disabled") |
| 788 |
b.click("button:contains('Create account with non-unique UID')") |
| 789 |
b.wait_not_present("#accounts-create-dialog") |
| 790 |
b.wait_in_text("#accounts-list", "Jack Jackson") |
| 791 |
b.wait_text("#accounts-list tr[data-row-id='jack'] td[data-label='ID']", "1501") |
| 792 |
b.wait_text("#accounts-list tr[data-row-id='john'] td[data-label='ID']", "1501") |
| 793 |
|
| 794 |
# No UID specified -> useradd chooses UID for us |
| 795 |
createUser( |
| 796 |
browser=b, |
| 797 |
machine=m, |
| 798 |
user_name="nouidspecified", |
| 799 |
real_name="NoUID Specified", |
| 800 |
password=good_password, |
| 801 |
locked=False, |
| 802 |
force_password_change=False, |
| 803 |
uid="", |
| 804 |
verify_created=True, |
| 805 |
) |
| 806 |
|
| 807 |
# UID cannot be lower than UID_MIN |
| 808 |
createUser( |
| 809 |
browser=b, |
| 810 |
machine=m, |
| 811 |
user_name="failedfailson", |
| 812 |
real_name="Failed Failson", |
| 813 |
password=good_password, |
| 814 |
locked=False, |
| 815 |
force_password_change=False, |
| 816 |
uid="1", |
| 817 |
verify_created=False, |
| 818 |
) |
| 819 |
b.wait_visible("#accounts-create-dialog") |
| 820 |
b.wait_in_text("#accounts-create-user-uid-helper", "lower than") |
| 821 |
b.click("#accounts-create-dialog button.cancel") |
| 822 |
b.wait_not_present("#accounts-create-dialog") |
| 823 |
|
| 824 |
# UID cannot be higher than UID_MAX |
| 825 |
createUser( |
| 826 |
browser=b, |
| 827 |
machine=m, |
| 828 |
user_name="failedfailson", |
| 829 |
real_name="Failed Failson", |
| 830 |
password=good_password, |
| 831 |
locked=False, |
| 832 |
force_password_change=False, |
| 833 |
uid="9999999", |
| 834 |
verify_created=False, |
| 835 |
) |
| 836 |
b.wait_visible("#accounts-create-dialog") |
| 837 |
b.wait_in_text("#accounts-create-user-uid-helper", "higher than") |
| 838 |
b.click("#accounts-create-dialog button.cancel") |
| 839 |
b.wait_not_present("#accounts-create-dialog") |
| 840 |
|
| 841 |
# UID must be a positive integer |
| 842 |
createUser( |
| 843 |
browser=b, |
| 844 |
machine=m, |
| 845 |
user_name="failedfailson", |
| 846 |
real_name="Failed Failson", |
| 847 |
password=good_password, |
| 848 |
locked=False, |
| 849 |
force_password_change=False, |
| 850 |
uid="abc", |
| 851 |
verify_created=False, |
| 852 |
) |
| 853 |
b.wait_visible("#accounts-create-dialog") |
| 854 |
b.wait_in_text("#accounts-create-user-uid-helper", "positive integer") |
| 855 |
b.click("#accounts-create-dialog button.cancel") |
| 856 |
b.wait_not_present("#accounts-create-dialog") |
| 857 |
|
| 858 |
def testCustomUserProperties(self) -> None: |
| 859 |
b = self.browser |
| 860 |
m = self.machine |
| 861 |
|
| 862 |
self.login_and_go("/users") |
| 863 |
|
| 864 |
# Test custom home directory |
| 865 |
custom_dir_path = "/home/mycustomdir" |
| 866 |
createUser( |
| 867 |
browser=b, |
| 868 |
machine=m, |
| 869 |
user_name="jussi", |
| 870 |
real_name="Jussi Junior", |
| 871 |
password=good_password, |
| 872 |
locked=False, |
| 873 |
custom_home_dir=custom_dir_path, |
| 874 |
force_password_change=False, |
| 875 |
verify_created=True, |
| 876 |
) |
| 877 |
|
| 878 |
b.go("#/jussi") |
| 879 |
b.wait_text("#account-home-dir", custom_dir_path) |
| 880 |
m.execute(f"test -d {custom_dir_path}") |
| 881 |
m.execute("! test -d /home/jussi") |
| 882 |
|
| 883 |
b.go("/users") |
| 884 |
# Check assigning a file as home directory fails |
| 885 |
m.execute("touch /home/isfile") |
| 886 |
createUser( |
| 887 |
browser=b, |
| 888 |
machine=m, |
| 889 |
user_name="file", |
| 890 |
real_name="File Filerson", |
| 891 |
password=good_password, |
| 892 |
locked=False, |
| 893 |
custom_home_dir="/home/isfile", |
| 894 |
force_password_change=False, |
| 895 |
verify_created=False, |
| 896 |
) |
| 897 |
b.wait_visible("#accounts-create-dialog") |
| 898 |
b.wait_in_text("#accounts-create-user-home-dir-helper", "existing file") |
| 899 |
b.wait_visible("button.apply:disabled") |
| 900 |
b.click("button.cancel") |
| 901 |
b.wait_not_present("#accounts-create-dialog") |
| 902 |
|
| 903 |
b.go("/users") |
| 904 |
# Check assigning existing home directory to a new user |
| 905 |
m.execute("mkdir /home/existingdir") |
| 906 |
createUser( |
| 907 |
browser=b, |
| 908 |
machine=m, |
| 909 |
user_name="stealer", |
| 910 |
real_name="Stealer OfHomeDirectison", |
| 911 |
password=good_password, |
| 912 |
locked=False, |
| 913 |
custom_home_dir="/home/existingdir", |
| 914 |
force_password_change=False, |
| 915 |
verify_created=False, |
| 916 |
) |
| 917 |
b.wait_visible("#accounts-create-dialog") |
| 918 |
b.wait_in_text("#accounts-create-user-home-dir-helper", "already exists") |
| 919 |
b.wait_visible("button.apply:disabled") |
| 920 |
self.assertEqual(m.execute("stat -c '%U %G' /home/existingdir").rstrip(), "root root") |
| 921 |
b.click("button:contains('Create and change ownership of home directory')") |
| 922 |
b.wait_not_present("#accounts-create-dialog") |
| 923 |
b.wait_in_text("#accounts-list", "Stealer OfHomeDirectison") |
| 924 |
# Verify that ownership of home directory was changed to the new user |
| 925 |
self.assertEqual(m.execute("stat -c '%U %G' /home/existingdir").rstrip(), "stealer stealer") |
| 926 |
|
| 927 |
default_shell = getUserAddDetails(m)["SHELL"] |
| 928 |
custom_shell = "/bin/sh" |
| 929 |
if default_shell == custom_shell: |
| 930 |
custom_shell = "/bin/bash" |
| 931 |
|
| 932 |
createUser( |
| 933 |
browser=b, |
| 934 |
machine=m, |
| 935 |
user_name="robert", |
| 936 |
real_name="Robert Robertson", |
| 937 |
password=good_password, |
| 938 |
locked=False, |
| 939 |
custom_shell=custom_shell, |
| 940 |
force_password_change=False, |
| 941 |
verify_created=True, |
| 942 |
) |
| 943 |
|
| 944 |
b.go("#/robert") |
| 945 |
b.wait_text("#account-shell", custom_shell) |
| 946 |
|
| 947 |
def testUnprivileged(self) -> None: |
| 948 |
m = self.machine |
| 949 |
b = self.browser |
| 950 |
new_password = "tqymuVh.Zf5" |
| 951 |
new_password_2 = "cEwghLYX" |
| 952 |
|
| 953 |
m.execute("useradd antoine; echo antoine:foobar | chpasswd") |
| 954 |
self.login_and_go("/users", user="antoine", superuser=False) |
| 955 |
b.go("#/antoine") |
| 956 |
b.wait_text("#account-user-name", "antoine") |
| 957 |
b.wait_visible('#account-set-password:enabled') |
| 958 |
b.click('#account-set-password') |
| 959 |
b.wait_visible('#account-set-password-dialog') |
| 960 |
b.set_input_text("#account-set-password-old", "foobar") |
| 961 |
b.set_input_text("#account-set-password-pw1", new_password) |
| 962 |
b.set_input_text("#account-set-password-pw2", new_password) |
| 963 |
b.click('#account-set-password-dialog button.apply') |
| 964 |
b.wait_not_present('#account-set-password-dialog') |
| 965 |
|
| 966 |
# Logout and login with the new password |
| 967 |
b.logout() |
| 968 |
b.open("/users") |
| 969 |
b.wait_visible("#login") |
| 970 |
b.set_val("#login-user-input", "antoine") |
| 971 |
b.set_val("#login-password-input", new_password) |
| 972 |
b.click('#login-button') |
| 973 |
b.wait_visible('#content') |
| 974 |
|
| 975 |
# --mindays is being deprecated in "chage" utility, see |
| 976 |
# https://github.com/shadow-maint/shadow/pull/1482 for deprecation of --mindays and |
| 977 |
# https://github.com/shadow-maint/shadow/pull/1432 for full plan what is being deprecated |
| 978 |
# |
| 979 |
# This will eventually show up in other distributions too |
| 980 |
if m.image in SHADOW_UTILS_WITHOUT_EXPIRE: |
| 981 |
return |
| 982 |
|
| 983 |
# Set minimum age to disallow changing it immediately again |
| 984 |
m.execute("chage --mindays 7 antoine") |
| 985 |
b.enter_page("/users") |
| 986 |
b.go("#/antoine") |
| 987 |
b.wait_text("#account-user-name", "antoine") |
| 988 |
b.wait_visible('#account-set-password:enabled') |
| 989 |
b.click('#account-set-password') |
| 990 |
b.wait_visible('#account-set-password-dialog') |
| 991 |
b.set_input_text("#account-set-password-old", new_password) |
| 992 |
b.set_input_text("#account-set-password-pw1", new_password_2) |
| 993 |
b.set_input_text("#account-set-password-pw2", new_password_2) |
| 994 |
b.click('#account-set-password-dialog button.apply') |
| 995 |
b.wait_in_text("#account-set-password-dialog .pf-v6-c-modal-box__body", "must wait longer") |
| 996 |
|
| 997 |
@testlib.skipWsContainer("ssh root login not allowed") |
| 998 |
def testRootLogin(self) -> None: |
| 999 |
m = self.machine |
| 1000 |
b = self.browser |
| 1001 |
new_password = "tqymuVh.Zf5" |
| 1002 |
|
| 1003 |
# this test uses quick logouts; async preloads cause "ReferenceError: cockpit is not defined" |
| 1004 |
self.disable_preload("packagekit", "playground", "systemd") |
| 1005 |
|
| 1006 |
m.execute("useradd anton; echo anton:foobar | chpasswd") |
| 1007 |
self.enable_root_login() |
| 1008 |
self.login_and_go("/users", user="root", superuser=False) |
| 1009 |
|
| 1010 |
# test this on root and a normal user account |
| 1011 |
for user in ["anton", "root"]: |
| 1012 |
b.go("#/" + user) |
| 1013 |
b.wait_text("#account-user-name", user) |
| 1014 |
b.wait_visible('#account-set-password:enabled') |
| 1015 |
b.click('#account-set-password') |
| 1016 |
b.wait_visible('#account-set-password-dialog') |
| 1017 |
b.wait_visible("#account-set-password-pw1") |
| 1018 |
# root does not need to know old password |
| 1019 |
b.wait_not_present("#account-set-password-old") |
| 1020 |
b.set_input_text("#account-set-password-pw1", new_password) |
| 1021 |
b.set_input_text("#account-set-password-pw2", new_password) |
| 1022 |
b.click('#account-set-password-dialog button.apply') |
| 1023 |
b.wait_not_present('#account-set-password-dialog') |
| 1024 |
|
| 1025 |
b.logout() |
| 1026 |
|
| 1027 |
# Logout and login with the new password |
| 1028 |
for user in ["anton", "root"]: |
| 1029 |
b.login_and_go("/users", user=user, password=new_password) |
| 1030 |
b.logout() |
| 1031 |
|
| 1032 |
def accountExpiryInfo(self, account: str, field: str) -> str | None: |
| 1033 |
for line in self.machine.execute(f"LC_ALL=C chage -l {account}").split("\n"): |
| 1034 |
if line.startswith(field): |
| 1035 |
_, _, value = line.partition(":") |
| 1036 |
return value.strip() |
| 1037 |
return None |
| 1038 |
|
| 1039 |
def testExpire(self) -> None: |
| 1040 |
m = self.machine |
| 1041 |
b = self.browser |
| 1042 |
|
| 1043 |
m.execute("useradd scruffy -s /bin/bash -c Scruffy") |
| 1044 |
m.execute("echo scruffy:foobar | chpasswd") |
| 1045 |
|
| 1046 |
self.login_and_go("/users#/scruffy") |
| 1047 |
b.wait_text("#account-user-name", "scruffy") |
| 1048 |
|
| 1049 |
# Try to expire the account |
| 1050 |
b.wait_text("#account-expiration-text", "Never expire account") |
| 1051 |
self.assertEqual(self.accountExpiryInfo("scruffy", "Account expires"), "never") |
| 1052 |
b.click("#account-expiration-button") |
| 1053 |
b.wait_visible("#account-expiration") |
| 1054 |
b.click("#account-expiration-expires") |
| 1055 |
|
| 1056 |
# Try an invalid date |
| 1057 |
b.set_input_text("#account-expiration-input input", "blah") |
| 1058 |
b.click("#account-expiration .pf-v6-c-modal-box__footer button:contains('Change')") |
| 1059 |
b.wait_text("#account-expiration .pf-v6-c-form__helper-text .pf-m-error", "Invalid expiration date") |
| 1060 |
|
| 1061 |
# Now a valid date 30 days in the future |
| 1062 |
when = datetime.datetime.now(datetime.timezone.utc) + datetime.timedelta(days=30) |
| 1063 |
b.set_input_text("#account-expiration-input input", when.isoformat().split("T")[0]) |
| 1064 |
b.click("#account-expiration .pf-v6-c-modal-box__footer button:contains('Change')") |
| 1065 |
b.wait_not_present("#account-expiration") |
| 1066 |
b.wait_in_text("#account-expiration-text", "Expire account on") |
| 1067 |
self.assertNotEqual(self.accountExpiryInfo("scruffy", "Account expires"), "never") |
| 1068 |
|
| 1069 |
# Now try and change it back |
| 1070 |
b.click("#account-expiration-button") |
| 1071 |
b.wait_visible("#account-expiration") |
| 1072 |
b.click("#account-expiration-never") |
| 1073 |
b.click("#account-expiration .pf-v6-c-modal-box__footer button:contains('Change')") |
| 1074 |
b.wait_not_present("#account-expiration") |
| 1075 |
b.wait_text("#account-expiration-text", "Never expire account") |
| 1076 |
self.assertEqual(self.accountExpiryInfo("scruffy", "Account expires"), "never") |
| 1077 |
|
| 1078 |
# Try to expire a password |
| 1079 |
b.wait_text("#password-expiration-text", "Never expire password") |
| 1080 |
|
| 1081 |
# arch now uses the "modern" value "-1" to indicate the password has no expiration set |
| 1082 |
EXPIRE_NEVER_VALUE = "-1" if m.image in SHADOW_UTILS_WITHOUT_EXPIRE else "99999" |
| 1083 |
self.assertEqual(self.accountExpiryInfo("scruffy", "Maximum number of days between password change"), EXPIRE_NEVER_VALUE) |
| 1084 |
b.click("#password-expiration-button") |
| 1085 |
b.wait_visible("#password-expiration") |
| 1086 |
b.click("#password-expiration-expires") |
| 1087 |
|
| 1088 |
# Try an invalid number |
| 1089 |
b.set_input_text("#password-expiration-input", "-3") |
| 1090 |
b.click("#password-expiration .pf-v6-c-modal-box__footer button:contains('Change')") |
| 1091 |
b.wait_text("#password-expiration .pf-v6-c-form__helper-text .pf-m-error", "Invalid number of days") |
| 1092 |
|
| 1093 |
# Expire password every 30 days |
| 1094 |
b.set_input_text("#password-expiration-input", "30") |
| 1095 |
b.click("#password-expiration .pf-v6-c-modal-box__footer button:contains('Change')") |
| 1096 |
b.wait_not_present("#password-expiration") |
| 1097 |
b.wait_in_text("#password-expiration-text", "Require password change on") |
| 1098 |
self.assertNotEqual(self.accountExpiryInfo("scruffy", "Password expires"), "never") |
| 1099 |
|
| 1100 |
# Now try and change it back |
| 1101 |
b.click("#password-expiration-button") |
| 1102 |
b.wait_visible("#password-expiration") |
| 1103 |
b.click("#password-expiration-never") |
| 1104 |
b.click("#password-expiration .pf-v6-c-modal-box__footer button:contains('Change')") |
| 1105 |
b.wait_not_present("#password-expiration") |
| 1106 |
b.wait_text("#password-expiration-text", "Never expire password") |
| 1107 |
self.assertEqual(self.accountExpiryInfo("scruffy", "Password expires"), "never") |
| 1108 |
self.assertEqual(self.accountExpiryInfo("scruffy", "Maximum number of days between password change"), "-1") |
| 1109 |
|
| 1110 |
# Now change it to expire again |
| 1111 |
b.click("#password-expiration-button") |
| 1112 |
b.wait_visible("#password-expiration") |
| 1113 |
b.click("#password-expiration-expires") |
| 1114 |
b.set_input_text("#password-expiration-input", "30") |
| 1115 |
b.click("#password-expiration .pf-v6-c-modal-box__footer button:contains('Change')") |
| 1116 |
b.wait_not_present("#password-expiration") |
| 1117 |
|
| 1118 |
b.logout() |
| 1119 |
# HACK: https://github.com/cockpit-project/cockpit/issues/20262 |
| 1120 |
self.login_and_go("/users#/scruffy", user="scruffy", superuser=False) |
| 1121 |
b.wait_text("#account-user-name", "scruffy") |
| 1122 |
b.wait_text("#account-expiration-text", "Never expire account") |
| 1123 |
b.wait_visible("#account-expiration-button[disabled]") |
| 1124 |
b.wait_in_text("#password-expiration-text", "Require password change on") |
| 1125 |
b.wait_visible("#password-expiration-button[disabled]") |
| 1126 |
|
| 1127 |
# Lastly force a password change |
| 1128 |
b.logout() |
| 1129 |
self.login_and_go("/users#/scruffy") |
| 1130 |
b.wait_text("#account-user-name", "scruffy") |
| 1131 |
b.click("#password-reset-button") |
| 1132 |
b.wait_visible("#password-reset") |
| 1133 |
b.click("#password-reset .pf-v6-c-modal-box__footer button:contains('Reset')") |
| 1134 |
b.wait_not_present("password-reset") |
| 1135 |
b.wait_in_text("#password-expiration-text", "Password must be changed") |
| 1136 |
self.assertEqual(self.accountExpiryInfo("scruffy", "Password expires"), "password must be changed") |
| 1137 |
|
| 1138 |
@testlib.skipWsContainer("User is not shown as logged in with cockpit/ws") |
| 1139 |
def testAccountLogs(self) -> None: |
| 1140 |
b = self.browser |
| 1141 |
m = self.machine |
| 1142 |
|
| 1143 |
# Clean out the relevant logfiles |
| 1144 |
m.execute("truncate -s0 /var/log/{[bw]tmp{,.db},lastlog} /run/utmp") |
| 1145 |
m.execute("rm -f /var/lib/lastlog/lastlog2.db /var/lib/wtmpdb/wtmp.db") |
| 1146 |
|
| 1147 |
# First login: no entries yet |
| 1148 |
self.login_and_go("/users#/admin") |
| 1149 |
# just the header, nothing else |
| 1150 |
b.wait_text("#account-logs", "Login history") |
| 1151 |
self.assertFalse(b.is_present("#account-logs tr")) |
| 1152 |
b.logout() |
| 1153 |
|
| 1154 |
year = m.execute("date +%Y").strip() |
| 1155 |
|
| 1156 |
# second login: one entry from the first one |
| 1157 |
self.login_and_go("/users#/admin") |
| 1158 |
# Header + one line of logins |
| 1159 |
b.wait_count("#account-logs tr", 2) |
| 1160 |
started = b.text("#account-logs [data-label='Started']") |
| 1161 |
ended = b.text("#account-logs [data-label='Ended']") |
| 1162 |
self.assertIn(year, started) |
| 1163 |
self.assertIn(year, ended) |
| 1164 |
self.assertGreaterEqual(ended, started) |
| 1165 |
# this is the correct IP for our CI, and we don't run this on tmt |
| 1166 |
b.wait_text("#account-logs [data-label='From']", "::ffff:172.27.0.2") |
| 1167 |
|
| 1168 |
def testGroups(self) -> None: |
| 1169 |
b = self.browser |
| 1170 |
m = self.machine |
| 1171 |
|
| 1172 |
def selectGroupFromMenu(group: str, enabled: bool) -> None: |
| 1173 |
if enabled: |
| 1174 |
testlib.wait(lambda: "testgroup0" not in m.execute("groups admin")) |
| 1175 |
else: |
| 1176 |
testlib.wait(lambda: "testgroup0" in m.execute("groups admin")) |
| 1177 |
|
| 1178 |
b.wait_not_present(".pf-v6-c-menu") |
| 1179 |
b.click("#account-groups > button") |
| 1180 |
b.click(f".pf-v6-c-menu li:contains('{group}') button") |
| 1181 |
if enabled: |
| 1182 |
b.wait_in_text(".pf-v6-c-label-group__list", group) |
| 1183 |
b.wait_not_present(f".pf-v6-c-select__menu li:contains('{group}') button") |
| 1184 |
testlib.wait(lambda: "testgroup0" in m.execute("groups admin")) |
| 1185 |
else: |
| 1186 |
b.wait_not_in_text(".pf-v6-c-label-group__list", group) |
| 1187 |
b.wait_not_present(f".pf-v6-c-select__menu li:contains('{group}') button") |
| 1188 |
testlib.wait(lambda: "testgroup0" not in m.execute("groups admin")) |
| 1189 |
|
| 1190 |
m.execute("groupadd testgroup0") |
| 1191 |
m.execute("useradd anton") |
| 1192 |
|
| 1193 |
self.login_and_go("/users") |
| 1194 |
|
| 1195 |
# Groups filter is only visible in the expanded view |
| 1196 |
b.wait_not_present("#groups-filter") |
| 1197 |
|
| 1198 |
b.click("#groups-view-toggle") |
| 1199 |
b.wait_visible('#groups-list td[data-label="Group name"]:contains("testgroup0")') |
| 1200 |
|
| 1201 |
# Check group filter in expanded mode and the filter clear button |
| 1202 |
b.set_input_text("#groups-filter input", "casablanca") |
| 1203 |
b.wait_not_present('#groups-list td[data-label="Group name"]:contains("testgroup0")') |
| 1204 |
b.click("#groups-filter button") |
| 1205 |
b.wait_val("#groups-filter input", "") |
| 1206 |
b.wait_visible('#groups-list td[data-label="Group name"]:contains("testgroup0")') |
| 1207 |
|
| 1208 |
# FIXME: rtl test was flaky, debug it and remove the skip |
| 1209 |
b.assert_pixels("#groups-list tr:contains('testgroup0')", "group-row", skip_layouts=["rtl"]) |
| 1210 |
|
| 1211 |
# Delete it |
| 1212 |
performGroupAction(b, 'testgroup0', 'Delete group') |
| 1213 |
b.wait_text("#group-confirm-delete-dialog footer .pf-v6-c-button.apply", "Delete") |
| 1214 |
b.click("#group-confirm-delete-dialog footer .pf-v6-c-button.apply") |
| 1215 |
b.wait_not_present('#group-confirm-delete-dialog') |
| 1216 |
b.wait_not_in_text('#groups-list', "testgroup0") |
| 1217 |
|
| 1218 |
# Add testgroup0 back |
| 1219 |
m.execute("groupadd testgroup0") |
| 1220 |
|
| 1221 |
# Groups used as primary need force deletion |
| 1222 |
performGroupAction(b, 'anton', 'Delete group') |
| 1223 |
b.wait_text("#group-confirm-delete-dialog footer .pf-v6-c-button.apply", "Force delete") |
| 1224 |
b.assert_pixels("#group-confirm-delete-dialog", "group-delete-dialog") |
| 1225 |
b.click("#group-confirm-delete-dialog footer .pf-v6-c-button.apply") |
| 1226 |
b.wait_not_present('#account-confirm-delete-dialog') |
| 1227 |
b.wait(lambda: "#/" == b.eval_js('window.location.hash')) |
| 1228 |
b.wait_not_in_text('#groups-list', "anton") |
| 1229 |
|
| 1230 |
b.click('#accounts-list td[data-label="Username"] a[href="#/admin"]') |
| 1231 |
|
| 1232 |
# Existing groups appear in labels |
| 1233 |
b.wait_in_text(".pf-v6-c-label-group__list", "admin") |
| 1234 |
b.wait_in_text(".pf-v6-c-label-group__list", m.get_admin_group()) |
| 1235 |
|
| 1236 |
# Primary group cannot be remove but others have a remove button |
| 1237 |
b.wait_in_text("#account-groups .pf-v6-c-label-group", "admin") |
| 1238 |
b.wait_not_present("#account-groups button[aria-label='Close user']") |
| 1239 |
close_button = f"#account-groups button[aria-label='Close {m.get_admin_group()}']" |
| 1240 |
b.wait_visible(close_button) |
| 1241 |
|
| 1242 |
# Clicking on the close button removes the group |
| 1243 |
b.click(close_button) |
| 1244 |
b.wait_not_in_text("#account-groups .pf-v6-c-label-group", m.get_admin_group()) |
| 1245 |
b.wait_not_present(".pf-v6-c-select__menu") |
| 1246 |
|
| 1247 |
# Add admin to the testgroup0 group |
| 1248 |
selectGroupFromMenu("testgroup0", enabled=True) |
| 1249 |
|
| 1250 |
# Check that changes ar persistent after reload |
| 1251 |
b.reload() |
| 1252 |
b.enter_page("/users") |
| 1253 |
b.wait_in_text(".pf-v6-c-label-group__list", "testgroup0") |
| 1254 |
|
| 1255 |
# Clicking on a used groups in the menu will remove it |
| 1256 |
selectGroupFromMenu("testgroup0", enabled=False) |
| 1257 |
|
| 1258 |
# Clicking on the undo button will add the removed group back |
| 1259 |
b.click("#group-undo-btn") |
| 1260 |
b.wait_in_text(".pf-v6-c-label-group__list", "testgroup0") |
| 1261 |
m.execute("/usr/bin/gpasswd -d admin testgroup0") |
| 1262 |
|
| 1263 |
# Clicking on the undo button will remove the added group back |
| 1264 |
b.reload() |
| 1265 |
b.enter_page("/users") |
| 1266 |
selectGroupFromMenu("testgroup0", enabled=True) |
| 1267 |
b.click("#group-undo-btn") |
| 1268 |
b.wait_not_in_text(".pf-v6-c-label-group__list", "testgroup0") |
| 1269 |
testlib.wait(lambda: "testgroup0" not in m.execute("groups admin")) |
| 1270 |
|
| 1271 |
def testGroupCreate(self) -> None: |
| 1272 |
b = self.browser |
| 1273 |
|
| 1274 |
self.login_and_go("/users") |
| 1275 |
|
| 1276 |
# Create new group |
| 1277 |
b.click("#groups-create") |
| 1278 |
b.set_input_text("#groups-create-name", "titan") |
| 1279 |
b.wait_not_val("#groups-create-id", "") |
| 1280 |
b.click("#groups-create-dialog button.pf-m-primary") |
| 1281 |
b.wait_not_present("#groups-create-dialog") |
| 1282 |
b.wait_visible('#groups-list tr[data-row-id="titan"]') |
| 1283 |
|
| 1284 |
# Validation check for duplicate group name and id |
| 1285 |
b.click("#groups-create") |
| 1286 |
b.set_input_text("#groups-create-name", "titan") |
| 1287 |
b.set_input_text("#groups-create-id", "0") |
| 1288 |
b.click("#groups-create-dialog button.pf-m-primary") |
| 1289 |
b.wait_in_text("#groups-create-name-helper", "A group with this name already exists") |
| 1290 |
b.set_input_text("#groups-create-name", "titans") |
| 1291 |
b.click("#groups-create-dialog button.pf-m-primary") |
| 1292 |
b.wait_in_text("#groups-create-dialog .pf-v6-c-alert", "GID '0' already exists") |
| 1293 |
|
| 1294 |
# Validation check for chars used in group name and valid group ID |
| 1295 |
b.set_input_text("#groups-create-name", "titan@1000") |
| 1296 |
b.set_input_text("#groups-create-id", "12f") |
| 1297 |
b.click("#groups-create-dialog button.pf-m-primary") |
| 1298 |
b.wait_in_text("#groups-create-name-helper", "Group name can only consist of letters") |
| 1299 |
b.wait_in_text("#groups-create-id-helper", "Group ID must be positive integer") |
| 1300 |
b.set_input_text("#groups-create-id", "-12") |
| 1301 |
b.wait_not_present("#groups-create-id-helper") |
| 1302 |
b.click("#groups-create-dialog button.pf-m-primary") |
| 1303 |
b.wait_in_text("#groups-create-id-helper", "Group ID must be positive integer") |
| 1304 |
|
| 1305 |
# Validate no name and no group |
| 1306 |
b.set_input_text("#groups-create-name", "") |
| 1307 |
b.set_input_text("#groups-create-id", "") |
| 1308 |
b.click("#groups-create-dialog button.pf-m-primary") |
| 1309 |
b.wait_in_text("#groups-create-name-helper", "No group name specified") |
| 1310 |
b.wait_in_text("#groups-create-id-helper", "No ID specified") |
| 1311 |
|
| 1312 |
# Create new group with custom ID |
| 1313 |
b.set_input_text("#groups-create-name", "saturn") |
| 1314 |
b.set_input_text("#groups-create-id", "1234") |
| 1315 |
b.click("#groups-create-dialog button.pf-m-primary") |
| 1316 |
b.wait_not_present("#groups-create-dialog") |
| 1317 |
b.wait_visible('#groups-list td[data-label="Group name"]:contains("saturn")') |
| 1318 |
|
| 1319 |
def testGroupRename(self) -> None: |
| 1320 |
b = self.browser |
| 1321 |
m = self.machine |
| 1322 |
|
| 1323 |
m.execute("groupadd titan; useradd uranus") |
| 1324 |
|
| 1325 |
self.login_and_go("/users") |
| 1326 |
b.click("button:contains('more...')") |
| 1327 |
b.wait_visible('#groups-list tr[data-row-id="titan"]') |
| 1328 |
performGroupAction(b, "titan", "Rename group") |
| 1329 |
|
| 1330 |
b.set_input_text("#group-confirm-rename-dialog #group-name", "foo bar") |
| 1331 |
b.click("#group-confirm-rename-dialog .apply") |
| 1332 |
b.wait_in_text("#group-name-helper", "Group name can only consist of letters") |
| 1333 |
|
| 1334 |
b.set_input_text("#group-confirm-rename-dialog #group-name", "") |
| 1335 |
b.click("#group-confirm-rename-dialog .apply") |
| 1336 |
b.wait_in_text("#group-name-helper", "Group name cannot be empty") |
| 1337 |
|
| 1338 |
b.set_input_text("#group-confirm-rename-dialog #group-name", "phoebe") |
| 1339 |
b.wait_not_present("#group-name-helper") |
| 1340 |
b.click("#group-confirm-rename-dialog .apply") |
| 1341 |
b.wait_not_present("#group-confirm-rename-dialog") |
| 1342 |
self.assertIn("phoebe", m.execute("getent group")) |
| 1343 |
self.assertNotIn("titan", m.execute("getent group")) |
| 1344 |
|
| 1345 |
# Rename and delete actions are available only for user created groups |
| 1346 |
b.wait_not_present(f"#groups-list tbody tr[data-row-id='{m.get_admin_group()}'] button.pf-v6-c-menu-toggle") |
| 1347 |
|
| 1348 |
def testChangeShell(self) -> None: |
| 1349 |
b = self.browser |
| 1350 |
m = self.machine |
| 1351 |
|
| 1352 |
self.login_and_go("/users") |
| 1353 |
|
| 1354 |
# Add a user externally |
| 1355 |
m.execute("useradd anton") |
| 1356 |
m.execute("echo anton:foobar | chpasswd") |
| 1357 |
with b.wait_timeout(30): |
| 1358 |
b.wait_in_text('#accounts-list', "anton") |
| 1359 |
|
| 1360 |
b.go("#/anton") |
| 1361 |
b.wait_text("#account-shell", getUserAddDetails(m)["SHELL"]) |
| 1362 |
b.click("#change-shell-button") |
| 1363 |
b.wait_visible("#shell-dialog") |
| 1364 |
new_shell = "/bin/sh" |
| 1365 |
b.select_from_dropdown("#edit-user-shell", new_shell) |
| 1366 |
b.click('#shell-dialog button.apply') |
| 1367 |
b.wait_text("#account-shell", new_shell) |
| 1368 |
|
| 1369 |
|
| 1370 |
if __name__ == '__main__': |
| 1371 |
testlib.test_main() |