| 1 |
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv) |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (C) 2013 Red Hat, Inc. |
| 5 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 |
|
| 7 |
|
| 8 |
import testlib |
| 9 |
|
| 10 |
|
| 11 |
class TestRoles(testlib.MachineCase): |
| 12 |
|
| 13 |
@testlib.nondestructive |
| 14 |
def testBasic(self): |
| 15 |
m = self.machine |
| 16 |
b = self.browser |
| 17 |
|
| 18 |
# Create a user without any role |
| 19 |
m.execute("useradd user -s /bin/bash -c User") |
| 20 |
m.execute("echo user:foobar | chpasswd") |
| 21 |
|
| 22 |
# Give name to admin account |
| 23 |
m.execute("usermod -c Administrator admin") |
| 24 |
|
| 25 |
m.start_cockpit() |
| 26 |
|
| 27 |
def login(user, password): |
| 28 |
b.set_val("#login-user-input", user) |
| 29 |
b.set_val("#login-password-input", password) |
| 30 |
b.click('#login-button') |
| 31 |
|
| 32 |
# login |
| 33 |
b.open("/system") |
| 34 |
b.wait_visible("#login") |
| 35 |
login("user", "foobar") |
| 36 |
b.enter_page("/system") |
| 37 |
b.switch_to_top() |
| 38 |
b.wait_text('#current-username', 'user') |
| 39 |
|
| 40 |
b.go("/users#/user") |
| 41 |
b.enter_page("/users") |
| 42 |
|
| 43 |
admin_rol_sel = "#account-groups-form-group .pf-v6-c-label-group" |
| 44 |
|
| 45 |
b.wait_text("#account-user-name", "user") |
| 46 |
b.wait_visible("#account-locked[disabled]") |
| 47 |
b.wait_visible('output#account-real-name') |
| 48 |
b.wait_visible("#account-set-password:not([disabled])") |
| 49 |
b.wait_not_present("#account-delete") |
| 50 |
b.wait_not_present("#account-logout") |
| 51 |
b.wait_not_in_text(admin_rol_sel, m.get_admin_group()) |
| 52 |
|
| 53 |
# Check permissions for admin account |
| 54 |
b.go("/users") |
| 55 |
b.wait_visible("#accounts-list tbody tr[data-row-id='admin'] td[data-label='Group'] .pf-v6-c-label.pf-m-blue:contains(admin)") |
| 56 |
b.go("#/admin") |
| 57 |
b.wait_text("#account-user-name", "admin") |
| 58 |
b.wait_visible("#account-locked") |
| 59 |
b.wait_visible('output#account-real-name') |
| 60 |
b.wait_not_present("#account-set-password") |
| 61 |
b.wait_not_present("#account-delete") |
| 62 |
b.wait_not_present("#account-logout") |
| 63 |
b.wait_not_present("#account-groups") |
| 64 |
b.wait_in_text(admin_rol_sel, m.get_admin_group()) |
| 65 |
|
| 66 |
# Add admin role from the outside (and wait for it to stick) |
| 67 |
b.go("#/user") |
| 68 |
b.wait_text("#account-user-name", "user") |
| 69 |
|
| 70 |
b.wait_not_in_text(admin_rol_sel, m.get_admin_group()) |
| 71 |
m.execute(f"usermod -a -G {m.get_admin_group()} user") |
| 72 |
b.wait_in_text(admin_rol_sel, m.get_admin_group()) |
| 73 |
|
| 74 |
b.relogin("/users", "user", superuser=True) |
| 75 |
b.wait_text("#account-user-name", "user") |
| 76 |
|
| 77 |
# Check permissions for admin again |
| 78 |
b.go("#/admin") |
| 79 |
b.wait_text("#account-user-name", "admin") |
| 80 |
b.wait_visible("#account-locked:not([disabled])") |
| 81 |
b.wait_visible("input#account-real-name") |
| 82 |
b.wait_visible("#account-set-password:not([disabled])") |
| 83 |
b.wait_visible("#account-delete:not([disabled])") |
| 84 |
# admin is not logged in, thus still disabled |
| 85 |
b.wait_visible("#account-logout[disabled]") |
| 86 |
b.wait_in_text(admin_rol_sel, m.get_admin_group()) |
| 87 |
b.wait_visible("#account-groups") |
| 88 |
|
| 89 |
@testlib.nondestructive |
| 90 |
def testDynamic(self): |
| 91 |
m = self.machine |
| 92 |
b = self.browser |
| 93 |
|
| 94 |
self.addCleanup(m.execute, "groupdel docker || true") |
| 95 |
m.execute("getent group docker >/dev/null || groupadd docker") |
| 96 |
|
| 97 |
self.login_and_go("/users") |
| 98 |
b.go("#/admin") |
| 99 |
|
| 100 |
b.click("#account-groups > button") |
| 101 |
b.wait_in_text(".pf-v6-c-menu", "docker") |
| 102 |
|
| 103 |
m.execute("groupdel docker") |
| 104 |
b.wait_not_in_text(".pf-v6-c-menu", "docker") |
| 105 |
|
| 106 |
|
| 107 |
if __name__ == '__main__': |
| 108 |
testlib.test_main() |