| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2752d95 commit 723469a
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,10 +1,6 @@ | |||
| 1 | 1 | #!/usr/bin/env bash | |
| 2 | 2 | set -euo pipefail | |
| 3 | 3 | ||
| 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 | - | ||
| 8 | 4 | main() { | |
| 9 | 5 | cd "$(dirname "${0}")/../.." | |
| 10 | 6 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,9 +18,6 @@ detect_arch() { | |||
| 18 | 18 | } | |
| 19 | 19 | ||
| 20 | 20 | 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 | ||
| 24 | 21 | ||
| 25 | 22 | main() { | |
| 26 | 23 | # Grabs the major version of node from $npm_config_user_agent which looks like | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -82,7 +82,7 @@ | |||
| 82 | 82 | }, | |
| 83 | 83 | "dependencies": { | |
| 84 | 84 | "@coder/logger": "1.1.16", | |
| 85 | - "argon2": "^0.28.0", | ||
| 85 | + "@node-rs/argon2": "^1.0.5", | ||
| 86 | 86 | "compression": "^1.7.4", | |
| 87 | 87 | "cookie-parser": "^1.4.5", | |
| 88 | 88 | "env-paths": "^2.2.0", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | import { logger } from "@coder/logger" | |
| 2 | - import * as argon2 from "argon2" | ||
| 2 | + import * as argon2 from "@node-rs/argon2" | ||
| 3 | 3 | import * as cp from "child_process" | |
| 4 | 4 | import * as crypto from "crypto" | |
| 5 | 5 | import envPaths from "env-paths" | |
@@ -58,10 +58,10 @@ export const paths = getEnvPaths() | |||
| 58 | 58 | * On MacOS this function gets the standard XDG directories instead of using the native macOS | |
| 59 | 59 | * ones. Most CLIs do this as in practice only GUI apps use the standard macOS directories. | |
| 60 | 60 | */ | |
| 61 | - export function getEnvPaths(): Paths { | ||
| 61 | + export function getEnvPaths(platform = process.platform): Paths { | ||
| 62 | 62 | const paths = envPaths("code-server", { suffix: "" }) | |
| 63 | 63 | const append = (p: string): string => path.join(p, "code-server") | |
| 64 | - switch (process.platform) { | ||
| 64 | + switch (platform) { | ||
| 65 | 65 | case "darwin": | |
| 66 | 66 | return { | |
| 67 | 67 | // envPaths uses native directories so force Darwin to use the XDG spec | |
@@ -175,7 +175,8 @@ export const isHashMatch = async (password: string, hash: string) => { | |||
| 175 | 175 | try { | |
| 176 | 176 | return await argon2.verify(hash, password) | |
| 177 | 177 | } catch (error: any) { | |
| 178 | - throw new Error(error) | ||
| 178 | + logger.error(error) | ||
| 179 | + return false | ||
| 179 | 180 | } | |
| 180 | 181 | } | |
| 181 | 182 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,6 @@ | |||
| 24 | 24 | "typescript": "^4.0.5" | |
| 25 | 25 | }, | |
| 26 | 26 | "scripts": { | |
| 27 | - "build": "tsc extension.ts" | ||
| 27 | + "build": "tsc" | ||
| 28 | 28 | } | |
| 29 | 29 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,9 @@ | |||
| 4 | 4 | "module": "commonjs", | |
| 5 | 5 | "outDir": ".", | |
| 6 | 6 | "strict": true, | |
| 7 | - "baseUrl": "./" | ||
| 7 | + "baseUrl": "./", | ||
| 8 | + "skipLibCheck": true | ||
| 8 | 9 | }, | |
| 9 | - "include": ["./extension.ts"] | ||
| 10 | + "include": ["./extension.ts"], | ||
| 11 | + "exclude": ["node_modules"] | ||
| 10 | 12 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,6 @@ | |||
| 8 | 8 | "@types/node-fetch": "^2.5.8", | |
| 9 | 9 | "@types/supertest": "^2.0.11", | |
| 10 | 10 | "@types/wtfnode": "^0.7.0", | |
| 11 | - "argon2": "^0.28.0", | ||
| 12 | 11 | "jest": "^27.3.1", | |
| 13 | 12 | "jest-fetch-mock": "^3.0.3", | |
| 14 | 13 | "jsdom": "^16.4.0", | |
@@ -20,7 +19,6 @@ | |||
| 20 | 19 | }, | |
| 21 | 20 | "resolutions": { | |
| 22 | 21 | "ansi-regex": "^5.0.1", | |
| 23 | - "argon2/@mapbox/node-pre-gyp/tar": "^6.1.9", | ||
| 24 | 22 | "set-value": "^4.0.1", | |
| 25 | 23 | "tmpl": "^1.0.5", | |
| 26 | 24 | "path-parse": "^1.0.7", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,16 +7,6 @@ import * as util from "../../../src/node/util" | |||
| 7 | 7 | ||
| 8 | 8 | describe("getEnvPaths", () => { | |
| 9 | 9 | 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 | - | ||
| 20 | 10 | beforeEach(() => { | |
| 21 | 11 | jest.resetModules() | |
| 22 | 12 | jest.mock("env-paths", () => { | |
@@ -27,23 +17,14 @@ describe("getEnvPaths", () => { | |||
| 27 | 17 | }) | |
| 28 | 18 | }) | |
| 29 | 19 | }) | |
| 30 | - | ||
| 31 | - afterAll(() => { | ||
| 32 | - // Restore old platform | ||
| 33 | - | ||
| 34 | - Object.defineProperty(process, "platform", { | ||
| 35 | - value: ORIGINAL_PLATFORM, | ||
| 36 | - }) | ||
| 37 | - }) | ||
| 38 | - | ||
| 39 | 20 | it("should return the env paths using xdgBasedir", () => { | |
| 40 | 21 | jest.mock("xdg-basedir", () => ({ | |
| 41 | 22 | data: "/home/usr/.local/share", | |
| 42 | 23 | config: "/home/usr/.config", | |
| 43 | 24 | runtime: "/tmp/runtime", | |
| 44 | 25 | })) | |
| 45 | 26 | const getEnvPaths = require("../../../src/node/util").getEnvPaths | |
| 46 | - const envPaths = getEnvPaths() | ||
| 27 | + const envPaths = getEnvPaths("darwin") | ||
| 47 | 28 | ||
| 48 | 29 | expect(envPaths.data).toEqual("/home/usr/.local/share/code-server") | |
| 49 | 30 | expect(envPaths.config).toEqual("/home/usr/.config/code-server") | |
@@ -53,24 +34,14 @@ describe("getEnvPaths", () => { | |||
| 53 | 34 | it("should return the env paths using envPaths when xdgBasedir is undefined", () => { | |
| 54 | 35 | jest.mock("xdg-basedir", () => ({})) | |
| 55 | 36 | const getEnvPaths = require("../../../src/node/util").getEnvPaths | |
| 56 | - const envPaths = getEnvPaths() | ||
| 37 | + const envPaths = getEnvPaths("darwin") | ||
| 57 | 38 | ||
| 58 | 39 | expect(envPaths.data).toEqual("/home/envPath/.local/share") | |
| 59 | 40 | expect(envPaths.config).toEqual("/home/envPath/.config") | |
| 60 | 41 | expect(envPaths.runtime).toEqual("/tmp/envPath/runtime") | |
| 61 | 42 | }) | |
| 62 | 43 | }) | |
| 63 | 44 | 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 | - | ||
| 74 | 45 | beforeEach(() => { | |
| 75 | 46 | jest.resetModules() | |
| 76 | 47 | jest.mock("env-paths", () => { | |
@@ -82,34 +53,16 @@ describe("getEnvPaths", () => { | |||
| 82 | 53 | }) | |
| 83 | 54 | }) | |
| 84 | 55 | ||
| 85 | - afterAll(() => { | ||
| 86 | - // Restore old platform | ||
| 87 | - | ||
| 88 | - Object.defineProperty(process, "platform", { | ||
| 89 | - value: ORIGINAL_PLATFORM, | ||
| 90 | - }) | ||
| 91 | - }) | ||
| 92 | - | ||
| 93 | 56 | it("should return the env paths using envPaths", () => { | |
| 94 | 57 | const getEnvPaths = require("../../../src/node/util").getEnvPaths | |
| 95 | - const envPaths = getEnvPaths() | ||
| 58 | + const envPaths = getEnvPaths("win32") | ||
| 96 | 59 | ||
| 97 | 60 | expect(envPaths.data).toEqual("/windows/envPath/.local/share") | |
| 98 | 61 | expect(envPaths.config).toEqual("/windows/envPath/.config") | |
| 99 | 62 | expect(envPaths.runtime).toEqual("/tmp/envPath/runtime") | |
| 100 | 63 | }) | |
| 101 | 64 | }) | |
| 102 | 65 | 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 | - | ||
| 113 | 66 | beforeEach(() => { | |
| 114 | 67 | jest.resetModules() | |
| 115 | 68 | jest.mock("env-paths", () => { | |
@@ -121,20 +74,12 @@ describe("getEnvPaths", () => { | |||
| 121 | 74 | }) | |
| 122 | 75 | }) | |
| 123 | 76 | ||
| 124 | - afterAll(() => { | ||
| 125 | - // Restore old platform | ||
| 126 | - | ||
| 127 | - Object.defineProperty(process, "platform", { | ||
| 128 | - value: ORIGINAL_PLATFORM, | ||
| 129 | - }) | ||
| 130 | - }) | ||
| 131 | - | ||
| 132 | 77 | it("should return the runtime using xdgBasedir if it exists", () => { | |
| 133 | 78 | jest.mock("xdg-basedir", () => ({ | |
| 134 | 79 | runtime: "/tmp/runtime", | |
| 135 | 80 | })) | |
| 136 | 81 | const getEnvPaths = require("../../../src/node/util").getEnvPaths | |
| 137 | - const envPaths = getEnvPaths() | ||
| 82 | + const envPaths = getEnvPaths("linux") | ||
| 138 | 83 | ||
| 139 | 84 | expect(envPaths.data).toEqual("/linux/envPath/.local/share") | |
| 140 | 85 | expect(envPaths.config).toEqual("/linux/envPath/.config") | |
@@ -144,7 +89,7 @@ describe("getEnvPaths", () => { | |||
| 144 | 89 | it("should return the env paths using envPaths when xdgBasedir is undefined", () => { | |
| 145 | 90 | jest.mock("xdg-basedir", () => ({})) | |
| 146 | 91 | const getEnvPaths = require("../../../src/node/util").getEnvPaths | |
| 147 | - const envPaths = getEnvPaths() | ||
| 92 | + const envPaths = getEnvPaths("linux") | ||
| 148 | 93 | ||
| 149 | 94 | expect(envPaths.data).toEqual("/linux/envPath/.local/share") | |
| 150 | 95 | expect(envPaths.config).toEqual("/linux/envPath/.config") | |
@@ -192,16 +137,16 @@ describe("isHashMatch", () => { | |||
| 192 | 137 | const actual = await util.isHashMatch(password, _hash) | |
| 193 | 138 | expect(actual).toBe(false) | |
| 194 | 139 | }) | |
| 195 | - it("should return false and not throw an error if the hash doesn't start with a $", async () => { | ||
| 140 | + it("should return false if the hash doesn't start with a $", async () => { | ||
| 196 | 141 | const password = "hellowpasssword" | |
| 197 | 142 | const _hash = "n2i$v=19$m=4096,t=3,p=1$EAoczTxVki21JDfIZpTUxg$rkXgyrW4RDGoDYrxBFD4H2DlSMEhP4h+Api1hXnGnFY" | |
| 198 | - expect(async () => await util.isHashMatch(password, _hash)).not.toThrow() | ||
| 199 | 143 | expect(await util.isHashMatch(password, _hash)).toBe(false) | |
| 200 | 144 | }) | |
| 201 | - it("should reject the promise and throw if error", async () => { | ||
| 145 | + it("should return false if the password and hash don't match", async () => { | ||
| 202 | 146 | const password = "hellowpasssword" | |
| 203 | 147 | const _hash = "$ar2i" | |
| 204 | - expect(async () => await util.isHashMatch(password, _hash)).rejects.toThrow() | ||
| 148 | + const actual = await util.isHashMatch(password, _hash) | ||
| 149 | + expect(actual).toBe(false) | ||
| 205 | 150 | }) | |
| 206 | 151 | }) | |
| 207 | 152 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments