Debian Codegraph @

test/verify/check-reauthorize

raw
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 @testlib.nondestructive
12 class TestReauthorize(testlib.MachineCase):
13 def testBasic(self):
14 self.allow_journal_messages('.*dropping message while waiting for child to exit.*')
15 b = self.browser
16 m = self.machine
17
18 # Log in without being authorized
19 self.login_and_go("/playground/test", superuser=False)
20 b.leave_page()
21 b.check_superuser_indicator("Limited access")
22 b.enter_page("/playground/test")
23 b.click(".cockpit-internal-reauthorize button")
24 b.wait_in_text(".cockpit-internal-reauthorize span", 'result:')
25 self.assertEqual(b.text(".cockpit-internal-reauthorize span"), 'result: access-denied')
26
27 # Log in again but be authorized
28 b.relogin("/playground/test", superuser=True)
29 b.leave_page()
30 b.check_superuser_indicator("Administrative access")
31 b.enter_page("/playground/test")
32 b.click(".cockpit-internal-reauthorize button")
33 b.wait_in_text(".cockpit-internal-reauthorize span", 'result:')
34 self.assertEqual(b.text(".cockpit-internal-reauthorize span"), 'result: authorized')
35
36 # Lock a file so that we can check that the lock went away
37 # after deauthorizing.
38 m.execute("touch /tmp/playground-test-lock")
39 b.click(".lock-channel button")
40 b.wait_in_text(".lock-channel span", 'locked')
41 m.execute("! flock --nonblock /tmp/playground-test-lock true")
42
43 # Deauthorize user
44 b.drop_superuser()
45 m.execute("flock --timeout 10 /tmp/playground-test-lock true")
46 b.click(".cockpit-internal-reauthorize button")
47 b.wait_in_text(".cockpit-internal-reauthorize span", 'result:')
48 self.assertEqual(b.text(".cockpit-internal-reauthorize span"), 'result: access-denied')
49
50 @testlib.skipWsContainer("ssh root login not allowed")
51 def testSuper(self):
52 b = self.browser
53
54 self.login_and_go("/playground/test")
55
56 b.click(".super-channel button")
57 b.wait_in_text(".super-channel span", 'result: uid=0')
58
59 # Deauthorize
60 b.drop_superuser()
61 b.click(".super-channel button")
62 b.wait_in_text(".super-channel span", 'result: access-denied')
63
64 # When root, the 'Limited access' etc indicators should not be visible
65 b.logout()
66 self.login_and_go("/playground/test", user="root", enable_root_login=True)
67 b.click(".super-channel button")
68 b.wait_in_text(".super-channel span", 'result: uid=0')
69 b.leave_page()
70 b.check_superuser_indicator("")
71
72 @testlib.skipImage("TODO: fix for OpenSUSE", "opensuse-tumbleweed")
73 def testSudo(self):
74 m = self.machine
75 b = self.browser
76
77 m.execute("useradd user -s /bin/bash -c Barney")
78 m.execute("echo user:foobar | chpasswd")
79
80 b.default_user = "user"
81 self.login_and_go("/playground/test")
82 b.click(".super-channel button")
83 b.wait_in_text(".super-channel span", 'result: ')
84
85 # TODO: this should only be 'access-denied'
86 legit_results = [f'result: {err}' for err in ('access-denied', 'authentication-failed', 'terminated')]
87 self.assertIn(b.text(".super-channel span"), legit_results)
88
89 b.logout()
90
91 # So first ask the user to retype their password
92 self.write_file("/etc/sudoers.d/user-override", "user ALL=(ALL) ALL", append=True)
93 self.login_and_go("/playground/test")
94 b.click(".super-channel button")
95 b.wait_in_text(".super-channel span", 'result: ')
96 self.assertIn('result: uid=0', b.text(".super-channel span"))
97 b.logout()
98
99 # Next login without starting a privileged bridge
100 self.login_and_go("/playground/test", superuser=False)
101 b.click(".super-channel button")
102 b.wait_in_text(".super-channel span", 'result: ')
103 self.assertEqual(b.text(".super-channel span"), 'result: access-denied')
104 b.logout()
105
106 # Even if sudo doesn't require a password, we shouldn't start a privileged bridge
107 self.write_file("/etc/sudoers.d/user-override", "user ALL=(ALL) NOPASSWD:ALL", append=True)
108 self.login_and_go("/playground/test", superuser=False)
109 b.click(".super-channel button")
110 b.wait_in_text(".super-channel span", 'result: ')
111 self.assertEqual(b.text(".super-channel span"), 'result: access-denied')
112
113
114 if __name__ == '__main__':
115 testlib.test_main()