-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-add frame-src CSP to allow downloading the desktop viewer file #1801
Merged
mvollmer
merged 1 commit into
cockpit-project:main
from
jelly:frame-download-button-regression
Sep 4, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,18 @@ import testlib | |
@testlib.nondestructive | ||
class TestMachinesConsoles(machineslib.VirtualMachinesCase): | ||
|
||
def waitDownloadFile(self, filename: str, expected_size: int | None = None, content: str | None = None) -> None: | ||
b = self.browser | ||
filepath = b.driver.download_dir / filename | ||
|
||
# Big downloads can take a while | ||
testlib.wait(filepath.exists, tries=120) | ||
if expected_size is not None: | ||
testlib.wait(lambda: filepath.stat().st_size == expected_size) | ||
|
||
if content is not None: | ||
self.assertEqual(filepath.read_text(), content) | ||
|
||
@testlib.skipImage('SPICE not supported on RHEL', "rhel-*", "centos-*") | ||
def testExternalConsole(self): | ||
b = self.browser | ||
|
@@ -43,14 +55,27 @@ class TestMachinesConsoles(machineslib.VirtualMachinesCase): | |
b.wait_in_text(".pf-v5-c-console__manual-connection dl > div:first-child dd", "127.0.0.1") | ||
b.wait_in_text(".pf-v5-c-console__manual-connection dl > div:nth-child(2) dd", "5900") | ||
|
||
b.allow_download() | ||
b.click(".pf-v5-c-console__remote-viewer-launch-vv") # "Launch Remote Viewer" button | ||
b.wait_visible("#dynamically-generated-file") # is .vv file generated for download? | ||
self.assertEqual(b.attr("#dynamically-generated-file", "href"), | ||
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") | ||
|
||
# HACK: clicking 'Launch Remote Viewer' kills execution context and thus CDP fails | ||
b.reload() | ||
b.enter_page("/machines") | ||
content = """[virt-viewer] | ||
type=spice | ||
host=127.0.0.1 | ||
port=5900 | ||
delete-this-file=1 | ||
fullscreen=0 | ||
|
||
[...............................GraphicsConsole] | ||
""" | ||
# HACK: Due to a bug in cockpit-machines, Firefox downloads the desktop | ||
# viewer file as a randomly generated file while chromium as | ||
# "download". As we want to download this as "$vmName.vv" in the end | ||
# work around the issue for now. | ||
if b.browser == "chromium": | ||
self.waitDownloadFile("download", content=content) | ||
else: | ||
b.wait_visible("#dynamically-generated-file") # is .vv file generated for download? | ||
self.assertEqual(b.attr("#dynamically-generated-file", "href"), | ||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of interest, why doesn't this include the funny |
||
|
||
# Go to the expanded console view | ||
b.click("button:contains(Expand)") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For context, this just checked that there is an HTML element which the
file-saver
library creates for downloading. As we now wait on the download this is not needed anymore and an implementation detail.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually not the
file-saver
library but our own code...