Refactor vscode endpoints to use fork directly.
This commit is contained in:
@ -122,26 +122,6 @@ describe("createApp", () => {
|
||||
expect(unlinkSpy).toHaveBeenCalledTimes(1)
|
||||
server.close()
|
||||
})
|
||||
it("should catch errors thrown when unlinking a socket", async () => {
|
||||
const tmpDir2 = await tmpdir("unlink-socket-error")
|
||||
const tmpFile = path.join(tmpDir2, "unlink-socket-file")
|
||||
// await promises.writeFile(tmpFile, "")
|
||||
const socketPath = tmpFile
|
||||
const defaultArgs = await setDefaults({
|
||||
_: [],
|
||||
socket: socketPath,
|
||||
})
|
||||
|
||||
const app = await createApp(defaultArgs)
|
||||
const server = app[2]
|
||||
|
||||
expect(spy).toHaveBeenCalledTimes(1)
|
||||
expect(spy).toHaveBeenCalledWith(`ENOENT: no such file or directory, unlink '${socketPath}'`)
|
||||
|
||||
server.close()
|
||||
// Ensure directory was removed
|
||||
rmdirSync(tmpDir2, { recursive: true })
|
||||
})
|
||||
|
||||
it("should create an https server if args.cert exists", async () => {
|
||||
const testCertificate = await generateCertificate("localhost")
|
||||
|
@ -1,10 +1,16 @@
|
||||
import { promises as fs } from "fs"
|
||||
import * as path from "path"
|
||||
import { rootPath } from "../../../../src/node/constants"
|
||||
import { tmpdir } from "../../../utils/helpers"
|
||||
import * as httpserver from "../../../utils/httpserver"
|
||||
import * as integration from "../../../utils/integration"
|
||||
|
||||
describe("/static", () => {
|
||||
const NOT_FOUND = {
|
||||
code: 404,
|
||||
message: "not found",
|
||||
}
|
||||
|
||||
describe("/_static", () => {
|
||||
let _codeServer: httpserver.HttpServer | undefined
|
||||
function codeServer(): httpserver.HttpServer {
|
||||
if (!_codeServer) {
|
||||
@ -17,14 +23,8 @@ describe("/static", () => {
|
||||
let testFileContent: string | undefined
|
||||
let nonExistentTestFile: string | undefined
|
||||
|
||||
// The static endpoint expects a commit and then the full path of the file.
|
||||
// The commit is just for cache busting so we can use anything we want. `-`
|
||||
// and `development` are specially recognized in that they will cause the
|
||||
// static endpoint to avoid sending cache headers.
|
||||
const commit = "-"
|
||||
|
||||
beforeAll(async () => {
|
||||
const testDir = await tmpdir("static")
|
||||
const testDir = await tmpdir("_static")
|
||||
testFile = path.join(testDir, "test")
|
||||
testFileContent = "static file contents"
|
||||
nonExistentTestFile = path.join(testDir, "i-am-not-here")
|
||||
@ -39,20 +39,12 @@ describe("/static", () => {
|
||||
})
|
||||
|
||||
function commonTests() {
|
||||
it("should return a 404 when a commit and file are not provided", async () => {
|
||||
const resp = await codeServer().fetch("/static")
|
||||
expect(resp.status).toBe(404)
|
||||
|
||||
const content = await resp.json()
|
||||
expect(content).toStrictEqual({ error: "Not Found" })
|
||||
})
|
||||
|
||||
it("should return a 404 when a file is not provided", async () => {
|
||||
const resp = await codeServer().fetch(`/static/${commit}`)
|
||||
expect(resp.status).toBe(404)
|
||||
const resp = await codeServer().fetch(`/_static/`)
|
||||
expect(resp.status).toBe(NOT_FOUND.code)
|
||||
|
||||
const content = await resp.json()
|
||||
expect(content).toStrictEqual({ error: "Not Found" })
|
||||
expect(content.error).toContain(NOT_FOUND.message)
|
||||
})
|
||||
}
|
||||
|
||||
@ -64,73 +56,22 @@ describe("/static", () => {
|
||||
commonTests()
|
||||
|
||||
it("should return a 404 for a nonexistent file", async () => {
|
||||
const resp = await codeServer().fetch(`/static/${commit}/${nonExistentTestFile}`)
|
||||
expect(resp.status).toBe(404)
|
||||
const filePath = path.join("/_static/", nonExistentTestFile!)
|
||||
|
||||
const content = await resp.json()
|
||||
expect(content.error).toMatch("ENOENT")
|
||||
const resp = await codeServer().fetch(filePath)
|
||||
expect(resp.status).toBe(NOT_FOUND.code)
|
||||
})
|
||||
|
||||
it("should return a 200 and file contents for an existent file", async () => {
|
||||
const resp = await codeServer().fetch(`/static/${commit}${testFile}`)
|
||||
const resp = await codeServer().fetch("/_static/src/browser/robots.txt")
|
||||
expect(resp.status).toBe(200)
|
||||
|
||||
const localFilePath = path.join(rootPath, "src/browser/robots.txt")
|
||||
const localFileContent = await fs.readFile(localFilePath, "utf8")
|
||||
|
||||
// console.log(localFileContent)
|
||||
const content = await resp.text()
|
||||
expect(content).toStrictEqual(testFileContent)
|
||||
})
|
||||
})
|
||||
|
||||
describe("enabled authentication", () => {
|
||||
// Store whatever might be in here so we can restore it afterward.
|
||||
// TODO: We should probably pass this as an argument somehow instead of
|
||||
// manipulating the environment.
|
||||
const previousEnvPassword = process.env.PASSWORD
|
||||
|
||||
beforeEach(async () => {
|
||||
process.env.PASSWORD = "test"
|
||||
_codeServer = await integration.setup(["--auth=password"], "")
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
process.env.PASSWORD = previousEnvPassword
|
||||
})
|
||||
|
||||
commonTests()
|
||||
|
||||
describe("inside code-server root", () => {
|
||||
it("should return a 404 for a nonexistent file", async () => {
|
||||
const resp = await codeServer().fetch(`/static/${commit}/${__filename}-does-not-exist`)
|
||||
expect(resp.status).toBe(404)
|
||||
|
||||
const content = await resp.json()
|
||||
expect(content.error).toMatch("ENOENT")
|
||||
})
|
||||
|
||||
it("should return a 200 and file contents for an existent file", async () => {
|
||||
const resp = await codeServer().fetch(`/static/${commit}${__filename}`)
|
||||
expect(resp.status).toBe(200)
|
||||
|
||||
const content = await resp.text()
|
||||
expect(content).toStrictEqual(await fs.readFile(__filename, "utf8"))
|
||||
})
|
||||
})
|
||||
|
||||
describe("outside code-server root", () => {
|
||||
it("should return a 401 for a nonexistent file", async () => {
|
||||
const resp = await codeServer().fetch(`/static/${commit}/${nonExistentTestFile}`)
|
||||
expect(resp.status).toBe(401)
|
||||
|
||||
const content = await resp.json()
|
||||
expect(content).toStrictEqual({ error: "Unauthorized" })
|
||||
})
|
||||
|
||||
it("should return a 401 for an existent file", async () => {
|
||||
const resp = await codeServer().fetch(`/static/${commit}${testFile}`)
|
||||
expect(resp.status).toBe(401)
|
||||
|
||||
const content = await resp.json()
|
||||
expect(content).toStrictEqual({ error: "Unauthorized" })
|
||||
})
|
||||
expect(content).toStrictEqual(localFileContent)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -457,31 +457,6 @@ describe("escapeHtml", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("pathToFsPath", () => {
|
||||
it("should convert a path to a file system path", () => {
|
||||
expect(util.pathToFsPath("/foo/bar/baz")).toBe("/foo/bar/baz")
|
||||
})
|
||||
it("should lowercase drive letter casing by default", () => {
|
||||
expect(util.pathToFsPath("/C:/far/boo")).toBe("c:/far/boo")
|
||||
})
|
||||
it("should keep drive letter casing when set to true", () => {
|
||||
expect(util.pathToFsPath("/C:/far/bo", true)).toBe("C:/far/bo")
|
||||
})
|
||||
it("should replace / with \\ on Windows", () => {
|
||||
const ORIGINAL_PLATFORM = process.platform
|
||||
|
||||
Object.defineProperty(process, "platform", {
|
||||
value: "win32",
|
||||
})
|
||||
|
||||
expect(util.pathToFsPath("/C:/far/boo")).toBe("c:\\far\\boo")
|
||||
|
||||
Object.defineProperty(process, "platform", {
|
||||
value: ORIGINAL_PLATFORM,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("isFile", () => {
|
||||
const testDir = path.join(tmpdir, "tests", "isFile")
|
||||
let pathToFile = ""
|
||||
|
Reference in New Issue
Block a user