Debian Codegraph @

test/verify/check-embed

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 subprocess
9
10 import testlib
11
12
13 @testlib.nondestructive
14 @testlib.skipBeiboot("no local overrides/config in beiboot mode")
15 class TestEmbed(testlib.MachineCase):
16
17 def testBasic(self, allow_multi_host=True):
18 b = self.browser
19 m = self.machine
20
21 self.restore_dir("/home/admin")
22 m.execute("mkdir -p /home/admin/.local/share/cockpit/embed-cockpit")
23 m.upload(["verify/files/embed-cockpit/index.html",
24 "verify/files/embed-cockpit/embed.js",
25 "verify/files/embed-cockpit/embed.css",
26 "verify/files/embed-cockpit/manifest.json"],
27 "/home/admin/.local/share/cockpit/embed-cockpit/")
28
29 # replace the shell with our embedded page, this way we can avoid
30 # cross-origin errors when executing js in the iframe
31 m.write("/etc/cockpit/cockpit.conf", f"""
32 [WebService]
33 Shell=/embed-cockpit/index.html
34 AllowMultiHost={"yes" if allow_multi_host else "no"}
35 """)
36 m.start_cockpit()
37 self.login_and_go()
38
39 b.wait_visible("#embed-loaded")
40 b.wait_visible("#embed-address")
41 b.set_val("#embed-address", f"http://{m.web_address}:{m.web_port}")
42 b.click("#embed-full")
43 b.wait_visible("iframe[name='embed-full'][loaded]")
44 b.switch_to_frame("embed-full")
45 b.wait_visible("#system_information_os_text")
46
47 # Page should show automatically now that other frame logged in
48 b.switch_to_top()
49 b.click("#embed-terminal")
50 b.wait_visible("iframe[name='embed-terminal'][loaded]")
51 b.switch_to_frame("embed-terminal")
52 b.wait_visible("#terminal")
53
54 # Clicking on the link with separate auth, what happens
55 # depends on allow_multi_host
56 b.switch_to_top()
57 b.click("#embed-auth")
58 b.wait_visible("iframe[name='embed-auth'][loaded]")
59 b.switch_to_frame("embed-auth")
60 if allow_multi_host:
61 # When multiple connections are allowed, we get a fresh
62 # login page
63 b.wait_visible("#login-user-input")
64 else:
65 # When multiple connections are not allowed, we get
66 # redirected to "/" of the already open session. This
67 # loads the shell, which is /embed-cockpit/index.html in
68 # this test...
69 b.wait_visible("#embed-links")
70
71 def testNoMultiHost(self):
72 self.testBasic(allow_multi_host=False)
73
74 @testlib.skipBrowser("Chromium cannot inspect cross-origin frames", "chromium")
75 def testCrossOrigin(self):
76 b = self.browser
77 m = self.machine
78
79 pyhttpd = subprocess.Popen(['python3', '-m', 'http.server', '--bind=localhost',
80 '--directory=test/verify/files/embed-cockpit', '12346'])
81
82 def clean_pyhttpd():
83 pyhttpd.terminate()
84 pyhttpd.wait()
85
86 self.addCleanup(clean_pyhttpd)
87
88 # log in normally, to get the auth cookie into the browser and thus maximize possible cross-domain exposure
89 self.login_and_go()
90
91 b.open("http://localhost:12346/index.html")
92 b.set_val("#embed-address", f"http://{m.web_address}:{m.web_port}")
93 b.click("#embed-full")
94 b.wait_visible("iframe[name='embed-full'][loaded]")
95 b.switch_to_frame("embed-full")
96
97 # X-Frame-Options sameorigin blocks frame
98 if b.browser == "firefox":
99 b.wait_visible("body.felt-privacy-body")
100 self.assertFalse(b.is_present("#login"))
101
102
103 if __name__ == '__main__':
104 testlib.test_main()