Skip to content

Commit 5a827e7

Browse files
committed
revert: "refactor: migrate from argon2 -> @node-rs/argon2 (#4733)"
This reverts commit 723469a.
1 parent 00224fa commit 5a827e7

File tree

8 files changed

+242
-108
lines changed

8 files changed

+242
-108
lines changed

ci/build/build-standalone-release.sh

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
# This is due to an upstream issue with RHEL7/CentOS 7 comptability with node-argon2
5+
# See: https://github.com/cdr/code-server/pull/3422#pullrequestreview-677765057
6+
export npm_config_build_from_source=true
7+
48
main() {
59
cd "$(dirname "${0}")/../.."
610

ci/build/npm-postinstall.sh

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ detect_arch() {
1818
}
1919

2020
ARCH="${NPM_CONFIG_ARCH:-$(detect_arch)}"
21+
# This is due to an upstream issue with RHEL7/CentOS 7 comptability with node-argon2
22+
# See: https://github.com/cdr/code-server/pull/3422#pullrequestreview-677765057
23+
export npm_config_build_from_source=true
2124

2225
main() {
2326
# Grabs the major version of node from $npm_config_user_agent which looks like

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
},
8686
"dependencies": {
8787
"@coder/logger": "1.1.16",
88-
"@node-rs/argon2": "^1.0.5",
88+
"argon2": "^0.28.4",
8989
"compression": "^1.7.4",
9090
"cookie-parser": "^1.4.5",
9191
"env-paths": "^2.2.0",

src/node/util.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { logger } from "@coder/logger"
2-
import * as argon2 from "@node-rs/argon2"
1+
import * as argon2 from "argon2"
32
import * as cp from "child_process"
43
import * as crypto from "crypto"
54
import envPaths from "env-paths"
@@ -58,10 +57,10 @@ export const paths = getEnvPaths()
5857
* On MacOS this function gets the standard XDG directories instead of using the native macOS
5958
* ones. Most CLIs do this as in practice only GUI apps use the standard macOS directories.
6059
*/
61-
export function getEnvPaths(platform = process.platform): Paths {
60+
export function getEnvPaths(): Paths {
6261
const paths = envPaths("code-server", { suffix: "" })
6362
const append = (p: string): string => path.join(p, "code-server")
64-
switch (platform) {
63+
switch (process.platform) {
6564
case "darwin":
6665
return {
6766
// envPaths uses native directories so force Darwin to use the XDG spec
@@ -170,8 +169,7 @@ export const isHashMatch = async (password: string, hash: string) => {
170169
try {
171170
return await argon2.verify(hash, password)
172171
} catch (error: any) {
173-
logger.error(error)
174-
return false
172+
throw new Error(error)
175173
}
176174
}
177175

test/e2e/extensions/test-extension/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
"typescript": "^4.0.5"
2525
},
2626
"scripts": {
27-
"build": "tsc"
27+
"build": "tsc extension.ts"
2828
}
2929
}

test/e2e/extensions/test-extension/tsconfig.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
"module": "commonjs",
55
"outDir": ".",
66
"strict": true,
7-
"baseUrl": "./",
8-
"skipLibCheck": true
7+
"baseUrl": "./"
98
},
10-
"include": ["./extension.ts"],
11-
"exclude": ["node_modules"]
9+
"include": ["./extension.ts"]
1210
}

test/unit/node/util.test.ts

+64-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ import * as util from "../../../src/node/util"
77

88
describe("getEnvPaths", () => {
99
describe("on darwin", () => {
10+
let ORIGINAL_PLATFORM = ""
11+
12+
beforeAll(() => {
13+
ORIGINAL_PLATFORM = process.platform
14+
15+
Object.defineProperty(process, "platform", {
16+
value: "darwin",
17+
})
18+
})
19+
1020
beforeEach(() => {
1121
jest.resetModules()
1222
jest.mock("env-paths", () => {
@@ -17,14 +27,23 @@ describe("getEnvPaths", () => {
1727
})
1828
})
1929
})
30+
31+
afterAll(() => {
32+
// Restore old platform
33+
34+
Object.defineProperty(process, "platform", {
35+
value: ORIGINAL_PLATFORM,
36+
})
37+
})
38+
2039
it("should return the env paths using xdgBasedir", () => {
2140
jest.mock("xdg-basedir", () => ({
2241
data: "/home/usr/.local/share",
2342
config: "/home/usr/.config",
2443
runtime: "/tmp/runtime",
2544
}))
2645
const getEnvPaths = require("../../../src/node/util").getEnvPaths
27-
const envPaths = getEnvPaths("darwin")
46+
const envPaths = getEnvPaths()
2847

2948
expect(envPaths.data).toEqual("/home/usr/.local/share/code-server")
3049
expect(envPaths.config).toEqual("/home/usr/.config/code-server")
@@ -34,14 +53,24 @@ describe("getEnvPaths", () => {
3453
it("should return the env paths using envPaths when xdgBasedir is undefined", () => {
3554
jest.mock("xdg-basedir", () => ({}))
3655
const getEnvPaths = require("../../../src/node/util").getEnvPaths
37-
const envPaths = getEnvPaths("darwin")
56+
const envPaths = getEnvPaths()
3857

3958
expect(envPaths.data).toEqual("/home/envPath/.local/share")
4059
expect(envPaths.config).toEqual("/home/envPath/.config")
4160
expect(envPaths.runtime).toEqual("/tmp/envPath/runtime")
4261
})
4362
})
4463
describe("on win32", () => {
64+
let ORIGINAL_PLATFORM = ""
65+
66+
beforeAll(() => {
67+
ORIGINAL_PLATFORM = process.platform
68+
69+
Object.defineProperty(process, "platform", {
70+
value: "win32",
71+
})
72+
})
73+
4574
beforeEach(() => {
4675
jest.resetModules()
4776
jest.mock("env-paths", () => {
@@ -53,16 +82,34 @@ describe("getEnvPaths", () => {
5382
})
5483
})
5584

85+
afterAll(() => {
86+
// Restore old platform
87+
88+
Object.defineProperty(process, "platform", {
89+
value: ORIGINAL_PLATFORM,
90+
})
91+
})
92+
5693
it("should return the env paths using envPaths", () => {
5794
const getEnvPaths = require("../../../src/node/util").getEnvPaths
58-
const envPaths = getEnvPaths("win32")
95+
const envPaths = getEnvPaths()
5996

6097
expect(envPaths.data).toEqual("/windows/envPath/.local/share")
6198
expect(envPaths.config).toEqual("/windows/envPath/.config")
6299
expect(envPaths.runtime).toEqual("/tmp/envPath/runtime")
63100
})
64101
})
65102
describe("on other platforms", () => {
103+
let ORIGINAL_PLATFORM = ""
104+
105+
beforeAll(() => {
106+
ORIGINAL_PLATFORM = process.platform
107+
108+
Object.defineProperty(process, "platform", {
109+
value: "linux",
110+
})
111+
})
112+
66113
beforeEach(() => {
67114
jest.resetModules()
68115
jest.mock("env-paths", () => {
@@ -74,12 +121,20 @@ describe("getEnvPaths", () => {
74121
})
75122
})
76123

124+
afterAll(() => {
125+
// Restore old platform
126+
127+
Object.defineProperty(process, "platform", {
128+
value: ORIGINAL_PLATFORM,
129+
})
130+
})
131+
77132
it("should return the runtime using xdgBasedir if it exists", () => {
78133
jest.mock("xdg-basedir", () => ({
79134
runtime: "/tmp/runtime",
80135
}))
81136
const getEnvPaths = require("../../../src/node/util").getEnvPaths
82-
const envPaths = getEnvPaths("linux")
137+
const envPaths = getEnvPaths()
83138

84139
expect(envPaths.data).toEqual("/linux/envPath/.local/share")
85140
expect(envPaths.config).toEqual("/linux/envPath/.config")
@@ -89,7 +144,7 @@ describe("getEnvPaths", () => {
89144
it("should return the env paths using envPaths when xdgBasedir is undefined", () => {
90145
jest.mock("xdg-basedir", () => ({}))
91146
const getEnvPaths = require("../../../src/node/util").getEnvPaths
92-
const envPaths = getEnvPaths("linux")
147+
const envPaths = getEnvPaths()
93148

94149
expect(envPaths.data).toEqual("/linux/envPath/.local/share")
95150
expect(envPaths.config).toEqual("/linux/envPath/.config")
@@ -141,16 +196,16 @@ describe("isHashMatch", () => {
141196
const actual = await util.isHashMatch(password, _hash)
142197
expect(actual).toBe(false)
143198
})
144-
it("should return false if the hash doesn't start with a $", async () => {
199+
it("should return false and not throw an error if the hash doesn't start with a $", async () => {
145200
const password = "hellowpasssword"
146201
const _hash = "n2i$v=19$m=4096,t=3,p=1$EAoczTxVki21JDfIZpTUxg$rkXgyrW4RDGoDYrxBFD4H2DlSMEhP4h+Api1hXnGnFY"
202+
expect(async () => await util.isHashMatch(password, _hash)).not.toThrow()
147203
expect(await util.isHashMatch(password, _hash)).toBe(false)
148204
})
149-
it("should return false if the password and hash don't match", async () => {
205+
it("should reject the promise and throw if error", async () => {
150206
const password = "hellowpasssword"
151207
const _hash = "$ar2i"
152-
const actual = await util.isHashMatch(password, _hash)
153-
expect(actual).toBe(false)
208+
expect(async () => await util.isHashMatch(password, _hash)).rejects.toThrow()
154209
})
155210
})
156211

0 commit comments

Comments
 (0)