Skip to content

Commit 7b1ef1a

Browse files
jellymvollmer
authored andcommitted
Re-add frame-src CSP to allow downloading the desktop viewer file
This was removed 0dcf864 under the impression it wasn't needed as all integration tests but the tests never validated if the desktop viewer file could be downloaded. Additionally add an integration test which verifies that the file can be downloaded successfully. Hide the iframe to avoid showing a temporary scrollbar which flakes the pixel test. Closes: #1799
1 parent b49cead commit 7b1ef1a

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/helpers.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,8 @@ export function fileDownload({ data, fileName = 'myFile.dat', mimeType = 'applic
321321
} else */ { // do iframe dataURL download
322322
logDebug('fileDownload() is using IFRAME');
323323
const f = document.createElement('iframe');
324-
f.width = '1';
325-
f.height = '1';
326324
document.body.appendChild(f);
325+
f.setAttribute("hidden", "hidden");
327326
const nicerText = '\n[...............................GraphicsConsole]\n';
328327
f.src = `data:${mimeType},${encodeURIComponent(data + nicerText)}`;
329328
window.setTimeout(() => document.body.removeChild(f), 333);

src/manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
]
2525
}
2626
},
27+
"content-security-policy": "frame-src 'self' data:",
2728
"config": {
2829
"StorageMigrationSupported": {
2930
"rhel": false

test/check-machines-consoles

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ import testlib
2626
@testlib.nondestructive
2727
class TestMachinesConsoles(machineslib.VirtualMachinesCase):
2828

29+
def waitDownloadFile(self, filename: str, expected_size: int | None = None, content: str | None = None) -> None:
30+
b = self.browser
31+
filepath = b.driver.download_dir / filename
32+
33+
# Big downloads can take a while
34+
testlib.wait(filepath.exists, tries=120)
35+
if expected_size is not None:
36+
testlib.wait(lambda: filepath.stat().st_size == expected_size)
37+
38+
if content is not None:
39+
self.assertEqual(filepath.read_text(), content)
40+
2941
@testlib.skipImage('SPICE not supported on RHEL', "rhel-*", "centos-*")
3042
def testExternalConsole(self):
3143
b = self.browser
@@ -43,14 +55,27 @@ class TestMachinesConsoles(machineslib.VirtualMachinesCase):
4355
b.wait_in_text(".pf-v5-c-console__manual-connection dl > div:first-child dd", "127.0.0.1")
4456
b.wait_in_text(".pf-v5-c-console__manual-connection dl > div:nth-child(2) dd", "5900")
4557

58+
b.allow_download()
4659
b.click(".pf-v5-c-console__remote-viewer-launch-vv") # "Launch Remote Viewer" button
47-
b.wait_visible("#dynamically-generated-file") # is .vv file generated for download?
48-
self.assertEqual(b.attr("#dynamically-generated-file", "href"),
49-
u"data:application/x-virt-viewer,%5Bvirt-viewer%5D%0Atype%3Dspice%0Ahost%3D127.0.0.1%0Aport%3D5900%0Adelete-this-file%3D1%0Afullscreen%3D0%0A")
50-
51-
# HACK: clicking 'Launch Remote Viewer' kills execution context and thus CDP fails
52-
b.reload()
53-
b.enter_page("/machines")
60+
content = """[virt-viewer]
61+
type=spice
62+
host=127.0.0.1
63+
port=5900
64+
delete-this-file=1
65+
fullscreen=0
66+
67+
[...............................GraphicsConsole]
68+
"""
69+
# HACK: Due to a bug in cockpit-machines, Firefox downloads the desktop
70+
# viewer file as a randomly generated file while chromium as
71+
# "download". As we want to download this as "$vmName.vv" in the end
72+
# work around the issue for now.
73+
if b.browser == "chromium":
74+
self.waitDownloadFile("download", content=content)
75+
else:
76+
b.wait_visible("#dynamically-generated-file") # is .vv file generated for download?
77+
self.assertEqual(b.attr("#dynamically-generated-file", "href"),
78+
u"data:application/x-virt-viewer,%5Bvirt-viewer%5D%0Atype%3Dspice%0Ahost%3D127.0.0.1%0Aport%3D5900%0Adelete-this-file%3D1%0Afullscreen%3D0%0A")
5479

5580
# Go to the expanded console view
5681
b.click("button:contains(Expand)")

0 commit comments

Comments
 (0)