Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions test/common/testlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2402,15 +2402,20 @@ def settle_cpu(self) -> None:
break
time.sleep(3)

def sed_file(self, expr: str, path: str, apply_change_action: str | None = None) -> None:
def sed_file(self, expr: str, path: str, apply_change_action: str | None = None, absent_content: str | None = None) -> None:
"""sed a file on primary machine

This is safe for @nondestructive tests, the file will be restored during cleanup.

The optional apply_change_action will be run both after sedding and after restoring the file.

The optional absent_content will create a file in path with the specified contents should the file not exist
"""
m = self.machine
m.execute(f"sed -i.cockpittest '{expr}' {path}")
if absent_content and not self.file_exists(path):
m.write(path, absent_content)
else:
m.execute(f"sed -i.cockpittest '{expr}' {path}")
if apply_change_action:
m.execute(apply_change_action)

Expand Down
8 changes: 4 additions & 4 deletions test/verify/check-networkmanager-firewall
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,10 @@ class TestFirewall(netlib.NetworkCase):
set_field("#tcp-ports", "", "")
set_field("#tcp-ports", "80,7", "custom--http-echo")
set_field("#udp-ports", "123", "custom--http-echo-ntp")
set_field("#udp-ports", "123, 50000", "custom--http-echo-ntp-50000")
set_field("#tcp-ports", "", "custom--ntp-50000")
set_field("#tcp-ports", "https", "custom--https-ntp-50000")
save("custom--https-ntp-50000", "443", "123, 50000")
set_field("#udp-ports", "123, 51234", "custom--http-echo-ntp-51234")
set_field("#tcp-ports", "", "custom--ntp-51234")
set_field("#tcp-ports", "https", "custom--https-ntp-51234")
save("custom--https-ntp-51234", "443", "123, 51234")

open_dialog()
set_field("#tcp-ports", "80-82", "custom--80-82")
Expand Down
4 changes: 2 additions & 2 deletions test/verify/check-static-login
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ account required pam_succeed_if.so user ingroup %s""" % m.get_admin_group
verify_correct(has_last=True, n_fail=0)

@testlib.skipImage("Arch Linux has no pwquality by default", "arch")
@testlib.skipImage("TODO: fix for OpenSUSE", "opensuse-tumbleweed")
def testExpired(self):
m = self.machine
b = self.browser
Expand All @@ -292,7 +291,8 @@ account required pam_succeed_if.so user ingroup %s""" % m.get_admin_group

# test steps below assume a pam_pwquality config with retry > 1; on some images authselect drops that setting
if not m.image.startswith('debian') and not m.image.startswith('ubuntu') and not m.image.startswith("arch"):
self.sed_file("/password.*requisite.*pam_pwquality/ s/$/ retry=3/", "/etc/pam.d/password-auth")
self.sed_file("/password.*requisite.*pam_pwquality/ s/$/ retry=3/",
path="/etc/pam.d/common-password-pc" if "suse" in m.image else "/etc/pam.d/password-auth")

m.execute("chage -d 0 admin")
m.start_cockpit()
Expand Down
6 changes: 3 additions & 3 deletions test/verify/check-users
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def createUser(


@testlib.nondestructive
@testlib.skipImage("TODO: fix for OpenSUSE", "opensuse-tumbleweed")
class TestAccounts(testlib.MachineCase):

def testBasic(self):
Expand Down Expand Up @@ -212,7 +211,8 @@ class TestAccounts(testlib.MachineCase):
b.wait_visible("#accounts-create")

# Create a user from the UI
self.sed_file('s@^SHELL=.*$@SHELL=/bin/true@', '/etc/default/useradd')
self.sed_file('s@^SHELL=.*$@SHELL=/bin/true@', '/etc/default/useradd', absent_content="SHELL=/bin/true")

b.click('#accounts-create')
b.wait_visible('#accounts-create-dialog')
b.set_input_text('#accounts-create-user-name', "Berta")
Expand Down Expand Up @@ -455,7 +455,7 @@ class TestAccounts(testlib.MachineCase):

self.login_and_go("/users")
# Create a locked user with weak password
self.sed_file('s/^SHELL=.*$/SHELL=/', '/etc/default/useradd')
self.sed_file('s/^SHELL=.*$/SHELL=/', '/etc/default/useradd', absent_content="SHELL=")
self.allow_journal_messages(".*required to change your password immediately.*")
self.allow_journal_messages(".*user account or password has expired.*")

Expand Down