add CLI argument `--disable-workspace-trust` (#5638)

Add CLI flag to disable workspace trust feature, as
described in documentation:
https://code.visualstudio.com/docs/editor/workspace-trust

Add test for workspace trust argument.
This commit is contained in:
kotborealis 2022-10-13 22:57:04 +03:00 committed by GitHub
parent ba68656353
commit f61ec4a41c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 41 additions and 21 deletions

View File

@ -50,6 +50,7 @@ export interface UserProvidedCodeArgs {
"github-auth"?: string "github-auth"?: string
"disable-update-check"?: boolean "disable-update-check"?: boolean
"disable-file-downloads"?: boolean "disable-file-downloads"?: boolean
"disable-workspace-trust"?: boolean
} }
/** /**
@ -163,6 +164,10 @@ export const options: Options<Required<UserProvidedArgs>> = {
description: description:
"Disable file downloads from Code. This can also be set with CS_DISABLE_FILE_DOWNLOADS set to 'true' or '1'.", "Disable file downloads from Code. This can also be set with CS_DISABLE_FILE_DOWNLOADS set to 'true' or '1'.",
}, },
"disable-workspace-trust": {
type: "boolean",
description: "Disable Workspace Trust feature. This switch only affects the current session.",
},
// --enable can be used to enable experimental features. These features // --enable can be used to enable experimental features. These features
// provide no guarantees. // provide no guarantees.
enable: { type: "string[]" }, enable: { type: "string[]" },

View File

@ -4,7 +4,7 @@ import { getMaybeProxiedCodeServer } from "../utils/helpers"
import { describe, test, expect } from "./baseFixture" import { describe, test, expect } from "./baseFixture"
import { CodeServer } from "./models/CodeServer" import { CodeServer } from "./models/CodeServer"
describe("code-server", [], {}, () => { describe("code-server", ["--disable-workspace-trust"], {}, () => {
// TODO@asher: Generalize this? Could be nice if we were to ever need // TODO@asher: Generalize this? Could be nice if we were to ever need
// multiple migration tests in other suites. // multiple migration tests in other suites.
const instances = new Map<string, CodeServer>() const instances = new Map<string, CodeServer>()

View File

@ -3,7 +3,11 @@ import { describe, test, expect } from "./baseFixture"
// Given a code-server environment with Spanish Language Pack extension installed // Given a code-server environment with Spanish Language Pack extension installed
// and a languagepacks.json in the data-dir // and a languagepacks.json in the data-dir
describe("--locale es", ["--extensions-dir", path.join(__dirname, "./extensions"), "--locale", "es"], {}, () => { describe(
"--locale es",
["--disable-workspace-trust", "--extensions-dir", path.join(__dirname, "./extensions"), "--locale", "es"],
{},
() => {
test("should load code-server in Spanish", async ({ codeServerPage }) => { test("should load code-server in Spanish", async ({ codeServerPage }) => {
// When // When
const visible = await codeServerPage.page.isVisible("text=Explorador") const visible = await codeServerPage.page.isVisible("text=Explorador")
@ -11,4 +15,5 @@ describe("--locale es", ["--extensions-dir", path.join(__dirname, "./extensions"
// Then // Then
expect(visible).toBe(true) expect(visible).toBe(true)
}) })
}) },
)

View File

@ -3,7 +3,7 @@ import * as path from "path"
import { clean } from "../utils/helpers" import { clean } from "../utils/helpers"
import { describe, test, expect } from "./baseFixture" import { describe, test, expect } from "./baseFixture"
describe("Downloads (enabled)", [], {}, async () => { describe("Downloads (enabled)", ["--disable-workspace-trust"], {}, async () => {
const testName = "downloads-enabled" const testName = "downloads-enabled"
test.beforeAll(async () => { test.beforeAll(async () => {
await clean(testName) await clean(testName)
@ -25,7 +25,7 @@ describe("Downloads (enabled)", [], {}, async () => {
}) })
}) })
describe("Downloads (disabled)", ["--disable-file-downloads"], {}, async () => { describe("Downloads (disabled)", ["--disable-workspace-trust", "--disable-file-downloads"], {}, async () => {
const testName = "downloads-disabled" const testName = "downloads-disabled"
test.beforeAll(async () => { test.beforeAll(async () => {
await clean(testName) await clean(testName)

View File

@ -19,7 +19,7 @@ function runTestExtensionTests() {
}) })
} }
const flags = ["--extensions-dir", path.join(__dirname, "./extensions")] const flags = ["--disable-workspace-trust", "--extensions-dir", path.join(__dirname, "./extensions")]
describe("Extensions", flags, {}, () => { describe("Extensions", flags, {}, () => {
runTestExtensionTests() runTestExtensionTests()

View File

@ -2,7 +2,7 @@ import { test as base } from "@playwright/test"
import { describe, expect, test } from "./baseFixture" import { describe, expect, test } from "./baseFixture"
if (process.env.GITHUB_TOKEN) { if (process.env.GITHUB_TOKEN) {
describe("GitHub token", [], {}, () => { describe("GitHub token", ["--disable-workspace-trust"], {}, () => {
test("should be logged in to pull requests extension", async ({ codeServerPage }) => { test("should be logged in to pull requests extension", async ({ codeServerPage }) => {
await codeServerPage.exec("git init") await codeServerPage.exec("git init")
await codeServerPage.exec("git remote add origin https://github.com/coder/code-server") await codeServerPage.exec("git remote add origin https://github.com/coder/code-server")
@ -16,7 +16,7 @@ if (process.env.GITHUB_TOKEN) {
}) })
}) })
describe("No GitHub token", [], { GITHUB_TOKEN: "" }, () => { describe("No GitHub token", ["--disable-workspace-trust"], { GITHUB_TOKEN: "" }, () => {
test("should not be logged in to pull requests extension", async ({ codeServerPage }) => { test("should not be logged in to pull requests extension", async ({ codeServerPage }) => {
await codeServerPage.exec("git init") await codeServerPage.exec("git init")
await codeServerPage.exec("git remote add origin https://github.com/coder/code-server") await codeServerPage.exec("git remote add origin https://github.com/coder/code-server")

View File

@ -1,7 +1,7 @@
import { PASSWORD } from "../utils/constants" import { PASSWORD } from "../utils/constants"
import { describe, test, expect } from "./baseFixture" import { describe, test, expect } from "./baseFixture"
describe("login", ["--auth", "password"], {}, () => { describe("login", ["--disable-workspace-trust", "--auth", "password"], {}, () => {
test("should see the login page", async ({ codeServerPage }) => { test("should see the login page", async ({ codeServerPage }) => {
// It should send us to the login page // It should send us to the login page
expect(await codeServerPage.page.title()).toBe("code-server login") expect(await codeServerPage.page.title()).toBe("code-server login")

View File

@ -1,7 +1,7 @@
// NOTE@jsjoeio commenting out until we can figure out what's wrong // NOTE@jsjoeio commenting out until we can figure out what's wrong
// import { describe, test, expect } from "./baseFixture" // import { describe, test, expect } from "./baseFixture"
// describe("logout", true, [], {}, () => { // describe("logout", true, ["--disable-workspace-trust"], {}, () => {
// test("should be able logout", async ({ codeServerPage }) => { // test("should be able logout", async ({ codeServerPage }) => {
// // Recommended by Playwright for async navigation // // Recommended by Playwright for async navigation
// // https://github.com/microsoft/playwright/issues/1987#issuecomment-620182151 // // https://github.com/microsoft/playwright/issues/1987#issuecomment-620182151

View File

@ -82,9 +82,6 @@ export class CodeServer {
path.join(dir, "User/settings.json"), path.join(dir, "User/settings.json"),
JSON.stringify({ JSON.stringify({
"workbench.startupEditor": "none", "workbench.startupEditor": "none",
// NOTE@jsjoeio - needed to prevent Trust Policy prompt
// in end-to-end tests.
"security.workspace.trust.enabled": false,
}), }),
"utf8", "utf8",
) )

View File

@ -1,7 +1,7 @@
import { version } from "../../src/node/constants" import { version } from "../../src/node/constants"
import { describe, test, expect } from "./baseFixture" import { describe, test, expect } from "./baseFixture"
describe("Open Help > About", [], {}, () => { describe("Open Help > About", ["--disable-workspace-trust"], {}, () => {
test("should see code-server version in about dialog", async ({ codeServerPage }) => { test("should see code-server version in about dialog", async ({ codeServerPage }) => {
// Open using the menu. // Open using the menu.
await codeServerPage.navigateMenus(["Help", "About"]) await codeServerPage.navigateMenus(["Help", "About"])

View File

@ -5,7 +5,7 @@ import util from "util"
import { clean, getMaybeProxiedCodeServer, tmpdir } from "../utils/helpers" import { clean, getMaybeProxiedCodeServer, tmpdir } from "../utils/helpers"
import { describe, expect, test } from "./baseFixture" import { describe, expect, test } from "./baseFixture"
describe("Integrated Terminal", [], {}, () => { describe("Integrated Terminal", ["--disable-workspace-trust"], {}, () => {
const testName = "integrated-terminal" const testName = "integrated-terminal"
test.beforeAll(async () => { test.beforeAll(async () => {
await clean(testName) await clean(testName)

13
test/e2e/trust.test.ts Normal file
View File

@ -0,0 +1,13 @@
import { describe, test, expect } from "./baseFixture"
describe("Workspace trust (enabled)", [], {}, async () => {
test("should see the 'I Trust...' option", async ({ codeServerPage }) => {
expect(await codeServerPage.page.isVisible("text=Yes, I trust")).toBe(true)
})
})
describe("Workspace trust (disabled)", ["--disable-workspace-trust"], {}, async () => {
test("should not see the 'I Trust...' option", async ({ codeServerPage }) => {
expect(await codeServerPage.page.isVisible("text=Yes, I trust")).toBe(false)
})
})