Skip to content

Commit acc50a5

Browse files
authoredSep 22, 2023
Update dependencies and force-update qs (#6440)
* Update dependencies and force-update qs This is mainly an attempt to get rid of as many resolutions as possible since it seems they are unnecessary except for qs (according to yarn/npm audit). For qs use 6.9.7 since Express is using 6.9.6 and that matches the most closely. Also add overrides since this is npm's version of yarn's resolutions and we need it for the shrinkwrap to generate with the right dependencies. Decided to keep pinning @types/node as well although I am not sure it is necessary. Express is pulling in v20 types. Since this is development-only we only need it in resolutions. * Run formatter Some rules seem to have changed with the dependency updates. * Replace deprecated bodyParser.json() usage * Audit npm shrinkwrap as well * Skip installing dependencies in audit It seems the tools only require the lock files. * Fix tests when using ipv6 * Add missing openssl dependency to flake
1 parent 47ee7ae commit acc50a5

File tree

19 files changed

+1054
-1219
lines changed

19 files changed

+1054
-1219
lines changed
 

‎.github/workflows/build.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
uses: actions/checkout@v3
3232

3333
- name: Run prettier with actionsx/prettier
34-
uses: actionsx/prettier@v2
34+
uses: actionsx/prettier@v3
3535
with:
3636
args: --check --loglevel=warn .
3737

‎.github/workflows/security.yaml

+5-14
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,12 @@ jobs:
3434
with:
3535
node-version: "18"
3636

37-
- name: Fetch dependencies from cache
38-
id: cache-yarn
39-
uses: actions/cache@v3
40-
with:
41-
path: "**/node_modules"
42-
key: yarn-build-${{ hashFiles('**/yarn.lock') }}
43-
restore-keys: |
44-
yarn-build-
45-
46-
- name: Install dependencies
47-
if: steps.cache-yarn.outputs.cache-hit != 'true'
48-
run: SKIP_SUBMODULE_DEPS=1 yarn --frozen-lockfile
37+
- name: Audit yarn for vulnerabilities
38+
run: yarn audit
39+
if: success()
4940

50-
- name: Audit for vulnerabilities
51-
run: yarn _audit
41+
- name: Audit npm for vulnerabilities
42+
run: npm shrinkwrap && npm audit
5243
if: success()
5344

5445
trivy-scan-repo:

‎flake.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
in {
1313
devShells.default = pkgs.mkShell {
1414
nativeBuildInputs = with pkgs; [
15-
nodejs yarn' python3 pkg-config git rsync jq moreutils quilt bats
15+
nodejs yarn' python3 pkg-config git rsync jq moreutils quilt bats openssl
1616
];
1717
buildInputs = with pkgs; (lib.optionals (!stdenv.isDarwin) [ libsecret libkrb5 ]
1818
++ (with xorg; [ libX11 libxkbfile ])

‎package.json

+44-57
Original file line numberDiff line numberDiff line change
@@ -38,75 +38,62 @@
3838
},
3939
"main": "out/node/entry.js",
4040
"devDependencies": {
41-
"@schemastore/package": "^0.0.6",
42-
"@types/compression": "^1.7.0",
43-
"@types/cookie-parser": "^1.4.2",
44-
"@types/express": "^4.17.8",
45-
"@types/http-proxy": "^1.17.4",
46-
"@types/js-yaml": "^4.0.0",
41+
"@schemastore/package": "^0.0.10",
42+
"@types/compression": "^1.7.3",
43+
"@types/cookie-parser": "^1.4.4",
44+
"@types/express": "^4.17.17",
45+
"@types/http-proxy": "1.17.7",
46+
"@types/js-yaml": "^4.0.6",
4747
"@types/node": "^18.0.0",
48-
"@types/pem": "^1.9.5",
48+
"@types/pem": "^1.14.1",
4949
"@types/proxy-from-env": "^1.0.1",
5050
"@types/safe-compare": "^1.1.0",
51-
"@types/semver": "^7.1.0",
52-
"@types/trusted-types": "^2.0.2",
53-
"@types/ws": "^8.5.3",
54-
"@typescript-eslint/eslint-plugin": "^5.41.0",
55-
"@typescript-eslint/parser": "^5.41.0",
56-
"audit-ci": "^6.0.0",
57-
"doctoc": "2.2.1",
58-
"eslint": "^8.26.0",
59-
"eslint-config-prettier": "^8.5.0",
60-
"eslint-import-resolver-typescript": "^3.5.2",
61-
"eslint-plugin-import": "^2.26.0",
62-
"eslint-plugin-prettier": "^4.2.1",
63-
"prettier": "2.8.0",
64-
"prettier-plugin-sh": "^0.12.8",
65-
"ts-node": "^10.0.0",
66-
"typescript": "^5.0.4"
67-
},
68-
"resolutions": {
69-
"ansi-regex": "^5.0.1",
70-
"normalize-package-data": "^5.0.0",
71-
"doctoc/underscore": "^1.13.1",
72-
"doctoc/**/trim": "^1.0.0",
73-
"postcss": "^8.2.1",
74-
"browserslist": "^4.16.5",
75-
"safe-buffer": "^5.1.1",
76-
"vfile-message": "^2.0.2",
77-
"tar": "^6.1.9",
78-
"path-parse": "^1.0.7",
79-
"vm2": "^3.9.11",
80-
"follow-redirects": "^1.14.8",
81-
"node-fetch": "^2.6.7",
82-
"nanoid": "^3.1.31",
83-
"minimist": "npm:minimist-lite@2.2.1",
84-
"glob-parent": "^6.0.1",
85-
"@types/node": "^18.0.0",
86-
"qs": "^6.7.3"
51+
"@types/semver": "^7.5.2",
52+
"@types/trusted-types": "^2.0.4",
53+
"@types/ws": "^8.5.5",
54+
"@typescript-eslint/eslint-plugin": "^6.7.2",
55+
"@typescript-eslint/parser": "^6.7.2",
56+
"audit-ci": "^6.6.1",
57+
"doctoc": "^2.2.1",
58+
"eslint": "^8.49.0",
59+
"eslint-config-prettier": "^9.0.0",
60+
"eslint-import-resolver-typescript": "^3.6.0",
61+
"eslint-plugin-import": "^2.28.1",
62+
"eslint-plugin-prettier": "^5.0.0",
63+
"prettier": "^3.0.3",
64+
"prettier-plugin-sh": "^0.13.1",
65+
"ts-node": "^10.9.1",
66+
"typescript": "^5.2.2"
8767
},
8868
"dependencies": {
89-
"@coder/logger": "^3.0.0",
90-
"argon2": "0.31.0",
69+
"@coder/logger": "^3.0.1",
70+
"argon2": "^0.31.1",
9171
"compression": "^1.7.4",
92-
"cookie-parser": "^1.4.5",
93-
"env-paths": "^2.2.0",
72+
"cookie-parser": "^1.4.6",
73+
"env-paths": "^2.2.1",
9474
"express": "5.0.0-alpha.8",
95-
"http-proxy": "^1.18.0",
75+
"http-proxy": "^1.18.1",
9676
"httpolyglot": "^0.1.2",
97-
"i18next": "^23.2.11",
98-
"js-yaml": "^4.0.0",
77+
"i18next": "^23.5.1",
78+
"js-yaml": "^4.1.0",
9979
"limiter": "^2.1.0",
100-
"pem": "^1.14.2",
101-
"proxy-agent": "^6.2.1",
102-
"qs": "6.11.0",
103-
"rotating-file-stream": "^3.0.0",
104-
"safe-buffer": "^5.1.1",
80+
"pem": "^1.14.8",
81+
"proxy-agent": "^6.3.1",
82+
"qs": "6.9.7",
83+
"rotating-file-stream": "^3.1.1",
84+
"safe-buffer": "^5.2.1",
10585
"safe-compare": "^1.1.4",
106-
"semver": "^7.1.3",
107-
"ws": "^8.0.0",
86+
"semver": "^7.5.4",
87+
"ws": "^8.14.2",
10888
"xdg-basedir": "^4.0.0"
10989
},
90+
"resolutions": {
91+
"@types/node": "^18.0.0",
92+
"qs": "6.9.7"
93+
},
94+
"overrides": {
95+
"qs": "6.9.7"
96+
},
11097
"bin": {
11198
"code-server": "out/node/entry.js"
11299
},

‎src/browser/pages/error.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />

‎src/browser/pages/global.css

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ button {
4646
.card-box {
4747
background-color: rgb(250, 253, 258);
4848
border-radius: 5px;
49-
box-shadow: rgba(60, 66, 87, 0.117647) 0px 7px 14px 0px, rgba(0, 0, 0, 0.117647) 0px 3px 6px 0px;
49+
box-shadow:
50+
rgba(60, 66, 87, 0.117647) 0px 7px 14px 0px,
51+
rgba(0, 0, 0, 0.117647) 0px 3px 6px 0px;
5052
max-width: 650px;
5153
width: 100%;
5254
}

‎src/browser/pages/login.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />

‎src/common/http.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ export enum HttpCode {
1414
* used in the HTTP response.
1515
*/
1616
export class HttpError extends Error {
17-
public constructor(message: string, public readonly statusCode: HttpCode, public readonly details?: object) {
17+
public constructor(
18+
message: string,
19+
public readonly statusCode: HttpCode,
20+
public readonly details?: object,
21+
) {
1822
super(message)
1923
this.name = this.constructor.name
2024
}

‎src/node/heart.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ export class Heart {
99
private heartbeatInterval = 60000
1010
public lastHeartbeat = 0
1111

12-
public constructor(private readonly heartbeatPath: string, private readonly isActive: () => Promise<boolean>) {
12+
public constructor(
13+
private readonly heartbeatPath: string,
14+
private readonly isActive: () => Promise<boolean>,
15+
) {
1316
this.beat = this.beat.bind(this)
1417
this.alive = this.alive.bind(this)
1518
}

‎src/node/i18n/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import i18next, { init } from "i18next"
22
import * as en from "./locales/en.json"
3+
import * as ja from "./locales/ja.json"
34
import * as th from "./locales/th.json"
45
import * as zhCn from "./locales/zh-cn.json"
5-
import * as ja from "./locales/ja.json"
66
init({
77
lng: "en",
88
fallbackLng: "en", // language to use if translations in user language are not available.

‎src/node/wrapper.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ type ChildMessage = RelaunchMessage | ChildHandshakeMessage
7878
type ParentMessage = ParentHandshakeMessage
7979

8080
class ProcessError extends Error {
81-
public constructor(message: string, public readonly code: number | undefined) {
81+
public constructor(
82+
message: string,
83+
public readonly code: number | undefined,
84+
) {
8285
super(message)
8386
this.name = this.constructor.name
8487
Error.captureStackTrace(this, this.constructor)

‎test/e2e/models/CodeServer.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ export class CodeServer {
269269
export class CodeServerPage {
270270
private readonly editorSelector = "div.monaco-workbench"
271271

272-
constructor(private readonly codeServer: CodeServer, public readonly page: Page) {
272+
constructor(
273+
private readonly codeServer: CodeServer,
274+
public readonly page: Page,
275+
) {
273276
this.page.on("console", (message) => {
274277
this.codeServer.logger.debug(message.text())
275278
})

‎test/unit/node/app.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ describe("createApp", () => {
9292
app.dispose()
9393
}
9494

95-
expect(() => masterBall()).rejects.toThrow(`listen EACCES: permission denied 127.0.0.1:${port}`)
95+
expect(() => masterBall()).rejects.toThrow("listen EACCES: permission denied")
9696
})
9797

9898
it("should unlink a socket before listening on the socket", async () => {

‎test/unit/node/proxy.test.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as bodyParser from "body-parser"
21
import * as express from "express"
32
import * as http from "http"
43
import nodeFetch from "node-fetch"
@@ -110,7 +109,7 @@ describe("proxy", () => {
110109
})
111110

112111
it("should allow post bodies", async () => {
113-
e.use(bodyParser.json({ strict: false }))
112+
e.use(express.json({ strict: false }))
114113
e.post("/wsup", (req, res) => {
115114
res.json(req.body)
116115
})
@@ -127,7 +126,7 @@ describe("proxy", () => {
127126
})
128127

129128
it("should handle bad requests", async () => {
130-
e.use(bodyParser.json({ strict: false }))
129+
e.use(express.json({ strict: false }))
131130
e.post("/wsup", (req, res) => {
132131
res.json(req.body)
133132
})
@@ -154,7 +153,7 @@ describe("proxy", () => {
154153
})
155154

156155
it("should handle errors", async () => {
157-
e.use(bodyParser.json({ strict: false }))
156+
e.use(express.json({ strict: false }))
158157
e.post("/wsup", (req, res) => {
159158
throw new Error("BROKEN")
160159
})

‎test/unit/node/test-plugin/public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />

‎test/unit/node/update.test.ts

+44-51
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { logger } from "@coder/logger"
22
import * as http from "http"
3-
import { AddressInfo } from "net"
43
import * as path from "path"
4+
import { ensureAddress } from "../../../src/node/app"
55
import { SettingsProvider, UpdateSettings } from "../../../src/node/settings"
66
import { LatestResponse, UpdateProvider } from "../../../src/node/update"
7-
import { clean, isAddressInfo, mockLogger, tmpdir } from "../../utils/helpers"
7+
import { clean, mockLogger, tmpdir } from "../../utils/helpers"
88

99
describe("update", () => {
1010
let version = "1.0.0"
@@ -79,14 +79,14 @@ describe("update", () => {
7979
}
8080

8181
let _provider: UpdateProvider | undefined
82-
let _address: string | AddressInfo | null
8382
const provider = (): UpdateProvider => {
8483
if (!_provider) {
8584
throw new Error("Update provider has not been created")
8685
}
8786
return _provider
8887
}
8988

89+
let address = new URL("http://localhost")
9090
beforeAll(async () => {
9191
mockLogger()
9292

@@ -105,12 +105,13 @@ describe("update", () => {
105105
})
106106
})
107107

108-
_address = server.address()
109-
if (!isAddressInfo(_address)) {
110-
throw new Error("unexpected address")
108+
const addr = ensureAddress(server, "http")
109+
if (typeof addr === "string") {
110+
throw new Error("unable to run update tests with unix sockets")
111111
}
112-
113-
_provider = new UpdateProvider(`http://${_address?.address}:${_address?.port}/latest`, _settings)
112+
address = addr
113+
address.pathname = "/latest"
114+
_provider = new UpdateProvider(address.toString(), _settings)
114115
})
115116

116117
afterAll(() => {
@@ -220,59 +221,51 @@ describe("update", () => {
220221
})
221222

222223
it("should reject if response has status code 500", async () => {
223-
if (isAddressInfo(_address)) {
224-
const mockURL = `http://${_address.address}:${_address.port}/reject-status-code`
225-
const provider = new UpdateProvider(mockURL, settings())
226-
const update = await provider.getUpdate(true)
227-
228-
expect(update.version).toBe("unknown")
229-
expect(logger.error).toHaveBeenCalled()
230-
expect(logger.error).toHaveBeenCalledWith("Failed to get latest version", {
231-
identifier: "error",
232-
value: `${mockURL}: 500`,
233-
})
234-
}
224+
address.pathname = "/reject-status-code"
225+
const provider = new UpdateProvider(address.toString(), settings())
226+
const update = await provider.getUpdate(true)
227+
228+
expect(update.version).toBe("unknown")
229+
expect(logger.error).toHaveBeenCalled()
230+
expect(logger.error).toHaveBeenCalledWith("Failed to get latest version", {
231+
identifier: "error",
232+
value: `${address.toString()}: 500`,
233+
})
235234
})
236235

237236
it("should reject if no location header provided", async () => {
238-
if (isAddressInfo(_address)) {
239-
const mockURL = `http://${_address.address}:${_address.port}/no-location-header`
240-
const provider = new UpdateProvider(mockURL, settings())
241-
const update = await provider.getUpdate(true)
242-
243-
expect(update.version).toBe("unknown")
244-
expect(logger.error).toHaveBeenCalled()
245-
expect(logger.error).toHaveBeenCalledWith("Failed to get latest version", {
246-
identifier: "error",
247-
value: `received redirect with no location header`,
248-
})
249-
}
237+
address.pathname = "/no-location-header"
238+
const provider = new UpdateProvider(address.toString(), settings())
239+
const update = await provider.getUpdate(true)
240+
241+
expect(update.version).toBe("unknown")
242+
expect(logger.error).toHaveBeenCalled()
243+
expect(logger.error).toHaveBeenCalledWith("Failed to get latest version", {
244+
identifier: "error",
245+
value: `received redirect with no location header`,
246+
})
250247
})
251248

252249
it("should resolve the request with response.headers.location", async () => {
253250
version = "4.1.1"
254-
if (isAddressInfo(_address)) {
255-
const mockURL = `http://${_address.address}:${_address.port}/with-location-header`
256-
const provider = new UpdateProvider(mockURL, settings())
257-
const update = await provider.getUpdate(true)
251+
address.pathname = "/with-location-header"
252+
const provider = new UpdateProvider(address.toString(), settings())
253+
const update = await provider.getUpdate(true)
258254

259-
expect(logger.error).not.toHaveBeenCalled()
260-
expect(update.version).toBe("4.1.1")
261-
}
255+
expect(logger.error).not.toHaveBeenCalled()
256+
expect(update.version).toBe("4.1.1")
262257
})
263258

264259
it("should reject if more than 10 redirects", async () => {
265-
if (isAddressInfo(_address)) {
266-
const mockURL = `http://${_address.address}:${_address.port}/redirect/11`
267-
const provider = new UpdateProvider(mockURL, settings())
268-
const update = await provider.getUpdate(true)
269-
270-
expect(update.version).toBe("unknown")
271-
expect(logger.error).toHaveBeenCalled()
272-
expect(logger.error).toHaveBeenCalledWith("Failed to get latest version", {
273-
identifier: "error",
274-
value: `reached max redirects`,
275-
})
276-
}
260+
address.pathname = "/redirect/11"
261+
const provider = new UpdateProvider(address.toString(), settings())
262+
const update = await provider.getUpdate(true)
263+
264+
expect(update.version).toBe("unknown")
265+
expect(logger.error).toHaveBeenCalled()
266+
expect(logger.error).toHaveBeenCalledWith("Failed to get latest version", {
267+
identifier: "error",
268+
value: `reached max redirects`,
269+
})
277270
})
278271
})

‎test/utils/helpers.ts

-14
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,6 @@ export function idleTimer(message: string, reject: (error: Error) => void, delay
108108
}
109109
}
110110

111-
/**
112-
* A helper function which returns a boolean indicating whether
113-
* the given address is AddressInfo and has .address
114-
* and a .port property.
115-
*/
116-
export function isAddressInfo(address: unknown): address is net.AddressInfo {
117-
return (
118-
address !== null &&
119-
typeof address !== "string" &&
120-
(address as net.AddressInfo).port !== undefined &&
121-
(address as net.AddressInfo).address !== undefined
122-
)
123-
}
124-
125111
/**
126112
* If using a proxy, return the address of the proxy.
127113
*

‎test/utils/httpserver.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class HttpServer {
3535
return new Promise((resolve, reject) => {
3636
this.hs.on("error", reject)
3737

38-
this.hs.listen(0, "localhost", () => {
38+
this.hs.listen(0, "127.0.0.1", () => {
3939
this.hs.off("error", reject)
4040
resolve()
4141

‎yarn.lock

+930-1,066
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.