mirror of
https://github.com/coder/code-server.git
synced 2026-05-05 03:55:18 +02:00
feat: use --app-name in error page title (#7693)
This commit is contained in:
@@ -38,6 +38,7 @@ const defaults = {
|
||||
"extensions-dir": path.join(paths.data, "extensions"),
|
||||
"user-data-dir": paths.data,
|
||||
"session-socket": path.join(paths.data, "code-server-ipc.sock"),
|
||||
"app-name": "code-server",
|
||||
_: [],
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import express from "express"
|
||||
import { UserProvidedArgs, setDefaults } from "../../../../src/node/cli"
|
||||
import { errorHandler } from "../../../../src/node/routes/errors"
|
||||
|
||||
describe("error page is rendered for text/html requests", () => {
|
||||
@@ -9,7 +10,7 @@ describe("error page is rendered for text/html requests", () => {
|
||||
statusCode: 404,
|
||||
message: ";>hello<script>alert(1)</script>",
|
||||
}
|
||||
const req = createRequest()
|
||||
const req = await createRequest()
|
||||
const res = {
|
||||
status: jest.fn().mockReturnValue(this),
|
||||
send: jest.fn().mockReturnValue(this),
|
||||
@@ -20,9 +21,41 @@ describe("error page is rendered for text/html requests", () => {
|
||||
expect(res.status).toHaveBeenCalledWith(404)
|
||||
expect(res.send).toHaveBeenCalledWith(expect.not.stringContaining("<script>"))
|
||||
})
|
||||
|
||||
it("should use custom app-name in error page title", async () => {
|
||||
const err = {
|
||||
statusCode: 404,
|
||||
message: "Not found",
|
||||
}
|
||||
const req = await createRequest({ "app-name": "MyCodeServer" })
|
||||
const res = {
|
||||
status: jest.fn().mockReturnValue(this),
|
||||
send: jest.fn().mockReturnValue(this),
|
||||
set: jest.fn().mockReturnValue(this),
|
||||
} as unknown as express.Response
|
||||
|
||||
await errorHandler(err, req, res, jest.fn())
|
||||
expect(res.send).toHaveBeenCalledWith(expect.stringContaining("<title>404 - MyCodeServer</title>"))
|
||||
})
|
||||
|
||||
it("should use default 'code-server' when app-name is not set", async () => {
|
||||
const err = {
|
||||
statusCode: 500,
|
||||
message: "Internal error",
|
||||
}
|
||||
const req = await createRequest()
|
||||
const res = {
|
||||
status: jest.fn().mockReturnValue(this),
|
||||
send: jest.fn().mockReturnValue(this),
|
||||
set: jest.fn().mockReturnValue(this),
|
||||
} as unknown as express.Response
|
||||
|
||||
await errorHandler(err, req, res, jest.fn())
|
||||
expect(res.send).toHaveBeenCalledWith(expect.stringContaining("<title>500 - code-server</title>"))
|
||||
})
|
||||
})
|
||||
|
||||
function createRequest(): express.Request {
|
||||
async function createRequest(args: UserProvidedArgs = {}): Promise<express.Request> {
|
||||
return {
|
||||
headers: {
|
||||
accept: ["text/html"],
|
||||
@@ -31,5 +64,6 @@ function createRequest(): express.Request {
|
||||
query: {
|
||||
to: "test",
|
||||
},
|
||||
args: await setDefaults(args),
|
||||
} as unknown as express.Request
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user