diff --git a/ui/app/components/fs/file.js b/ui/app/components/fs/file.js index a9e323544..9ea695d5a 100644 --- a/ui/app/components/fs/file.js +++ b/ui/app/components/fs/file.js @@ -52,10 +52,15 @@ export default class File extends Component { isStreaming = false; @computed('allocation.id', 'taskState.name', 'file') - get catUrl() { + get catUrlWithoutRegion() { const taskUrlPrefix = this.taskState ? `${this.taskState.name}/` : ''; const encodedPath = encodeURIComponent(`${taskUrlPrefix}${this.file}`); - let apiPath = `/v1/client/fs/cat/${this.allocation.id}?path=${encodedPath}`; + return `/v1/client/fs/cat/${this.allocation.id}?path=${encodedPath}`; + } + + @computed('catUrlWithoutRegion') + get catUrl() { + let apiPath = this.catUrlWithoutRegion; if (this.system.shouldIncludeRegion) { apiPath += `®ion=${this.system.activeRegion}`; } @@ -180,12 +185,14 @@ export default class File extends Component { var url = window.URL.createObjectURL(blob); var a = document.createElement('a'); a.href = url; + a.target = '_blank'; + a.rel = 'noopener noreferrer'; a.download = this.file; document.body.appendChild(a); // we need to append the element to the dom -> otherwise it will not work in firefox a.click(); a.remove(); //afterwards we remove the element again + window.URL.revokeObjectURL(url); }); - - fileDownload(this.catUrl); + fileDownload(this.catUrlWithoutRegion); } } diff --git a/ui/app/templates/components/fs/file.hbs b/ui/app/templates/components/fs/file.hbs index d5aec5483..f28801f84 100644 --- a/ui/app/templates/components/fs/file.hbs +++ b/ui/app/templates/components/fs/file.hbs @@ -9,7 +9,7 @@ {{#unless this.fileTypeIsUnknown}} - View Raw File + {{/unless}} {{#if (and this.isLarge this.isStreamable)}} @@ -32,7 +32,7 @@

Unsupported File Type

The Nomad UI could not render this file, but you can still view the file directly.

- View Raw File +

{{/if}} diff --git a/ui/tests/integration/components/fs/file-test.js b/ui/tests/integration/components/fs/file-test.js index 95a953059..90762357f 100644 --- a/ui/tests/integration/components/fs/file-test.js +++ b/ui/tests/integration/components/fs/file-test.js @@ -1,6 +1,6 @@ import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; -import { find, render, settled } from '@ember/test-helpers'; +import { find, click, render, settled } from '@ember/test-helpers'; import hbs from 'htmlbars-inline-precompile'; import Pretender from 'pretender'; import { logEncode } from '../../../../mirage/data/logs'; @@ -140,21 +140,17 @@ module('Integration | Component | fs/file', function(hooks) { this.setProperties(props); await render(commonTemplate); - - const rawLink = find('[data-test-log-action="raw"]'); - assert.equal( - rawLink.getAttribute('href'), - `/v1/client/fs/cat/${props.allocation.id}?path=${encodeURIComponent( - `${props.taskState.name}/${props.file}` - )}`, - 'Raw link href is correct' - ); - - assert.equal(rawLink.getAttribute('target'), '_blank', 'Raw link opens in a new tab'); - assert.equal( - rawLink.getAttribute('rel'), - 'noopener noreferrer', - 'Raw link rel correctly bars openers and referrers' + click('[data-test-log-action="raw"]'); + await settled(); + assert.ok( + this.server.handledRequests.find( + ({ url: url }) => + url === + `/v1/client/fs/cat/${props.allocation.id}?path=${encodeURIComponent( + `${props.taskState.name}/${props.file}` + )}` + ), + 'Request to file is made' ); }); @@ -168,13 +164,17 @@ module('Integration | Component | fs/file', function(hooks) { await this.system.get('regions'); await render(commonTemplate); - const rawLink = find('[data-test-log-action="raw"]'); - assert.equal( - rawLink.getAttribute('href'), - `/v1/client/fs/cat/${props.allocation.id}?path=${encodeURIComponent( - `${props.taskState.name}/${props.file}` - )}®ion=${region}`, - 'Raw link href includes the active region from local storage' + click('[data-test-log-action="raw"]'); + await settled(); + assert.ok( + this.server.handledRequests.find( + ({ url: url }) => + url === + `/v1/client/fs/cat/${props.allocation.id}?path=${encodeURIComponent( + `${props.taskState.name}/${props.file}` + )}®ion=${region}` + ), + 'Request to file is made with region' ); });