feat: add option for disabling file downloads (#5055)
* feat(cli): add disable-file-downloads to cli * feat(e2e): add download test * feat(e2e): add downloads disabled test * refactor(e2e): explain how to debug unexpected close * feat(patches): add disable file downloads * wip: update diff * Update src/node/cli.ts Co-authored-by: Asher <ash@coder.com> * fixup! add missing common/contextkeys file to patch * fixup!: update patch * fixup!: default disable-file-downloads undefined * fixup!: combine e2e tests * fixup!: use different test names * feat: add CS_DISABLE_FILE_DOWNLOADS * fixup!: make explicit and cleanup test * fixup!: use beforeEach Co-authored-by: Asher <ash@coder.com>
This commit is contained in:
48
test/e2e/downloads.test.ts
Normal file
48
test/e2e/downloads.test.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import * as path from "path"
|
||||
import { promises as fs } from "fs"
|
||||
import { clean } from "../utils/helpers"
|
||||
import { describe, test, expect } from "./baseFixture"
|
||||
|
||||
describe("Downloads (enabled)", true, [], {}, async () => {
|
||||
const testName = "downloads-enabled"
|
||||
test.beforeAll(async () => {
|
||||
await clean(testName)
|
||||
})
|
||||
|
||||
test("should see the 'Download...' option", async ({ codeServerPage }) => {
|
||||
// Setup
|
||||
const workspaceDir = await codeServerPage.workspaceDir
|
||||
const tmpFilePath = path.join(workspaceDir, "unique-file.txt")
|
||||
await fs.writeFile(tmpFilePath, "hello world")
|
||||
|
||||
// Action
|
||||
const fileInExplorer = await codeServerPage.page.waitForSelector("text=unique-file.txt")
|
||||
await fileInExplorer.click({
|
||||
button: "right",
|
||||
})
|
||||
|
||||
expect(await codeServerPage.page.isVisible("text=Download...")).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe("Downloads (disabled)", true, ["--disable-file-downloads"], {}, async () => {
|
||||
const testName = "downloads-disabled"
|
||||
test.beforeAll(async () => {
|
||||
await clean(testName)
|
||||
})
|
||||
|
||||
test("should not see the 'Download...' option", async ({ codeServerPage }) => {
|
||||
// Setup
|
||||
const workspaceDir = await codeServerPage.workspaceDir
|
||||
const tmpFilePath = path.join(workspaceDir, "unique-file.txt")
|
||||
await fs.writeFile(tmpFilePath, "hello world")
|
||||
|
||||
// Action
|
||||
const fileInExplorer = await codeServerPage.page.waitForSelector("text=unique-file.txt")
|
||||
await fileInExplorer.click({
|
||||
button: "right",
|
||||
})
|
||||
|
||||
expect(await codeServerPage.page.isVisible("text=Download...")).toBe(false)
|
||||
})
|
||||
})
|
@ -134,7 +134,7 @@ export class CodeServer {
|
||||
})
|
||||
|
||||
proc.on("close", (code) => {
|
||||
const error = new Error("code-server closed unexpectedly")
|
||||
const error = new Error("code-server closed unexpectedly. Try running with LOG_LEVEL=debug to see more info.")
|
||||
if (!this.closed) {
|
||||
this.logger.error(error.message, field("code", code))
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ describe("parser", () => {
|
||||
beforeEach(() => {
|
||||
delete process.env.LOG_LEVEL
|
||||
delete process.env.PASSWORD
|
||||
delete process.env.CS_DISABLE_FILE_DOWNLOADS
|
||||
console.log = jest.fn()
|
||||
})
|
||||
|
||||
@ -92,6 +93,8 @@ describe("parser", () => {
|
||||
|
||||
"--port=8081",
|
||||
|
||||
"--disable-file-downloads",
|
||||
|
||||
["--host", "0.0.0.0"],
|
||||
"4",
|
||||
"--",
|
||||
@ -108,6 +111,7 @@ describe("parser", () => {
|
||||
cert: {
|
||||
value: path.resolve("path/to/cert"),
|
||||
},
|
||||
"disable-file-downloads": true,
|
||||
enable: ["feature1", "feature2"],
|
||||
help: true,
|
||||
host: "0.0.0.0",
|
||||
@ -346,6 +350,18 @@ describe("parser", () => {
|
||||
expect(process.env.GITHUB_TOKEN).toBe(undefined)
|
||||
})
|
||||
|
||||
it("should use env var CS_DISABLE_FILE_DOWNLOADS", async () => {
|
||||
process.env.CS_DISABLE_FILE_DOWNLOADS = "1"
|
||||
const args = parse([])
|
||||
expect(args).toEqual({})
|
||||
|
||||
const defaultArgs = await setDefaults(args)
|
||||
expect(defaultArgs).toEqual({
|
||||
...defaults,
|
||||
"disable-file-downloads": true,
|
||||
})
|
||||
})
|
||||
|
||||
it("should error if password passed in", () => {
|
||||
expect(() => parse(["--password", "supersecret123"])).toThrowError(
|
||||
"--password can only be set in the config file or passed in via $PASSWORD",
|
||||
|
@ -38,6 +38,7 @@ describe("plugin", () => {
|
||||
"proxy-domain": [],
|
||||
config: "~/.config/code-server/config.yaml",
|
||||
verbose: false,
|
||||
"disable-file-downloads": false,
|
||||
usingEnvPassword: false,
|
||||
usingEnvHashedPassword: false,
|
||||
"extensions-dir": "",
|
||||
|
Reference in New Issue
Block a user