Skip to content

Commit

Permalink
test: re-use self.stat() for verifying file/dir permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
jelly committed Nov 5, 2024
1 parent 11a94c6 commit b0ef557
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions test/check-application
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ class TestFiles(testlib.MachineCase):
# Check sidebar info
m.execute("touch /home/admin/newfile")
b.click("[data-item='newfile']")
self.assertEqual(m.execute("ls -l /home/admin/newfile")[:10], "-rw-r--r--")
self.assertEqual(self.stat("%A", "/home/admin/newfile"), "-rw-r--r--")
check_perms_match('newfile', '/home/admin')

# Test changing owner/group
Expand Down Expand Up @@ -1305,13 +1305,13 @@ class TestFiles(testlib.MachineCase):
open_permissions_dialog('newfile')
select_access("no-access")
b.click(".pf-v5-c-modal-box button.pf-m-primary")
self.assertEqual(m.execute("ls -l /home/admin/newfile")[:10], "----------")
self.assertEqual(self.stat("%A", "/home/admin/newfile"), "----------")
check_perms_match('newfile', '/home/admin')

open_permissions_dialog('newfile')
select_access("read-write")
b.click(".pf-v5-c-modal-box button.pf-m-primary")
self.assertEqual(m.execute("ls -l /home/admin/newfile")[:10], "-rw-rw-rw-")
self.assertEqual(self.stat("%A", "/home/admin/newfile"), "-rw-rw-rw-")
check_perms_match('newfile', '/home/admin')

# Test changing CWD permissions
Expand All @@ -1331,7 +1331,7 @@ class TestFiles(testlib.MachineCase):
b.click(".pf-v5-c-modal-box button.pf-m-primary")
b.wait_not_present(".pf-v5-c-modal-box")

self.assertEqual(m.execute(f"ls -ld {test_dir}")[:10], "drwxr-xr-x")
self.assertEqual(self.stat("%A", test_dir), "drwxr-xr-x")

# Via kebab
b.click("#dropdown-menu")
Expand All @@ -1343,7 +1343,7 @@ class TestFiles(testlib.MachineCase):
b.click(".pf-v5-c-modal-box button.pf-m-primary")
b.wait_not_present(".pf-v5-c-modal-box")

self.assertEqual(m.execute(f"ls -ld {test_dir}")[:10], "dr-x------")
self.assertEqual(self.stat("%A", test_dir), "dr-x------")

# Can set a file as executable
b.click("li[data-location='/home/admin'] a")
Expand All @@ -1367,7 +1367,7 @@ class TestFiles(testlib.MachineCase):
b.click(".pf-v5-c-modal-box button.pf-m-primary")
b.wait_not_present(".pf-v5-c-modal-box")

self.assertEqual(m.execute(f"ls -ld /home/admin/{shell_script}")[:10], "-rwxr-xr-x")
self.assertEqual(self.stat("%A", f"/home/admin/{shell_script}"), "-rwxr-xr-x")
check_perms_match(shell_script, '/home/admin')

open_permissions_dialog(shell_script)
Expand All @@ -1382,7 +1382,7 @@ class TestFiles(testlib.MachineCase):
b.set_checked("#is-executable", False)
b.click(".pf-v5-c-modal-box button.pf-m-primary")
b.wait_not_present(".pf-v5-c-modal-box")
self.assertEqual(m.execute(f"ls -l /home/admin/{shell_script}")[:10], "-rw-r--r--")
self.assertEqual(self.stat("%A", f"/home/admin/{shell_script}"), "-rw-r--r--")

# Not executable for .png
img_file = "cockpit.png"
Expand Down Expand Up @@ -1434,7 +1434,7 @@ class TestFiles(testlib.MachineCase):
b.select_from_dropdown("#edit-permissions-other-access", "no-access")
b.click(".pf-v5-c-modal-box button.pf-m-primary")
b.wait_not_present(".pf-v5-c-modal-box")
self.assertEqual(m.execute(f"ls -l /home/admin/{shell_script}")[:10], "-r-xrw----")
self.assertEqual(self.stat("%A", f"/home/admin/{shell_script}"), "-r-xrw----")

b.go("/files#/?path=/")
self.assert_last_breadcrumb("/")
Expand Down Expand Up @@ -1522,7 +1522,7 @@ class TestFiles(testlib.MachineCase):
# A user cannot change ownership
b.wait_not_in_text(".pf-v5-c-modal-box__body", "Ownership")
b.click(".pf-v5-c-modal-box button.pf-m-primary")
self.assertEqual(m.execute("ls -l /home/admin/adminfile")[:10], "-rw-rw-rw-")
self.assertEqual(self.stat("%A", "/home/admin/adminfile"), "-rw-rw-rw-")
check_perms_match('adminfile', '/home/admin')
# Does not change ownership
b.wait_in_text("[data-item='adminfile'] .item-owner", "admin")
Expand Down

0 comments on commit b0ef557

Please sign in to comment.