Skip to content

Commit 513b957

Browse files
authored
use latest arena-core (#133)
* use latest arena-core * fixed tests * fixing tests * update dependencies * updated yarn * update yarn * fixed tests * fixed tests * fixed tests
1 parent 270fe0d commit 513b957

13 files changed

Lines changed: 1234 additions & 1263 deletions

File tree

.yarn/install-state.gz

-1.15 KB
Binary file not shown.

.yarn/releases/yarn-4.12.0.cjs

Lines changed: 0 additions & 942 deletions
This file was deleted.

.yarn/releases/yarn-4.13.0.cjs

Lines changed: 940 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ npmScopes:
66
npmAuthToken: "${NPM_TOKEN}"
77
npmRegistryServer: "https://npm.pkg.github.com"
88

9-
yarnPath: .yarn/releases/yarn-4.12.0.cjs
9+
yarnPath: .yarn/releases/yarn-4.13.0.cjs

jest.config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

jest.config.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { Config } from 'jest'
2+
3+
const config: Config = {
4+
roots: ['<rootDir>/dist/'],
5+
testEnvironment: 'node',
6+
verbose: true,
7+
transform: { '^.+\\.[jt]s$': 'ts-jest' },
8+
transformIgnorePatterns: ['/node_modules/(?!(change-case|uuid|otplib|@otplib|@scure/base|@noble)/)'],
9+
}
10+
11+
export default config

package.json

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
"name": "OpenForis",
55
"email": "openforis.arena@gmail.com"
66
},
7-
"version": "1.2.23",
7+
"version": "1.2.24",
88
"description": "",
99
"main": "dist/index.js",
1010
"types": "dist/index.d.ts",
1111
"devDependencies": {
12+
"@eslint/js": "^10.0.1",
1213
"@machinomy/types-node-db-migrate": "^0.0.2",
1314
"@types/bcryptjs": "^3.0.0",
1415
"@types/compression": "^1.8.1",
@@ -22,12 +23,12 @@
2223
"@types/passport": "^1.0.17",
2324
"@types/passport-jwt": "^4.0.1",
2425
"@types/passport-local": "^1.0.38",
25-
"@types/supertest": "^6.0.3",
26-
"@typescript-eslint/eslint-plugin": "^8.57.1",
27-
"@typescript-eslint/parser": "^8.57.1",
26+
"@types/supertest": "^7.2.0",
27+
"@typescript-eslint/eslint-plugin": "^8.57.2",
28+
"@typescript-eslint/parser": "^8.57.2",
2829
"copyfiles": "^2.4.1",
2930
"dotenv": "^17.3.1",
30-
"eslint": "^9.39.4",
31+
"eslint": "^10.1.0",
3132
"husky": "9.1.7",
3233
"jest": "^30.3.0",
3334
"lint-staged": "^16.4.0",
@@ -37,12 +38,12 @@
3738
"supertest": "^7.2.2",
3839
"ts-jest": "^29.4.6",
3940
"ts-node": "^10.9.2",
40-
"typescript": "^5.9.3",
41-
"typescript-eslint": "^8.57.1"
41+
"typescript": "^6.0.2",
42+
"typescript-eslint": "^8.57.2"
4243
},
4344
"dependencies": {
4445
"@godaddy/terminus": "^4.12.1",
45-
"@openforis/arena-core": "^1.0.94",
46+
"@openforis/arena-core": "^1.0.95",
4647
"bcryptjs": "^3.0.3",
4748
"compression": "^1.8.1",
4849
"cookie-parser": "^1.4.7",
@@ -54,7 +55,7 @@
5455
"jsonwebtoken": "^9.0.3",
5556
"lodash.throttle": "^4.1.1",
5657
"log4js": "^6.9.1",
57-
"otplib": "^12.0.1",
58+
"otplib": "^13.4.0",
5859
"passport": "^0.7.0",
5960
"passport-jwt": "^4.0.1",
6061
"passport-local": "^1.0.0",
@@ -93,7 +94,7 @@
9394
"url": "https://github.com/openforis/arena-server/issues"
9495
},
9596
"homepage": "https://github.com/openforis/arena-server#readme",
96-
"packageManager": "yarn@4.12.0",
97+
"packageManager": "yarn@4.13.0",
9798
"publishConfig": {
9899
"registry": "https://npm.pkg.github.com"
99100
}

src/job/jobRegistry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class JobRegistry extends Map<string, JobConstructor> {
99
JobRegistry.instance = new Map<string, JobConstructor>()
1010

1111
if (ProcessEnv.nodeEnv === NodeEnv.test) {
12-
const { SimpleJob, SimpleJobWithJobs } = await import('./tests/testJobs')
12+
const { SimpleJob, SimpleJobWithJobs } = await import('./tests/testJobs.js')
1313
JobRegistry.instance.set(SimpleJob.type, SimpleJob)
1414
JobRegistry.instance.set(SimpleJobWithJobs.type, SimpleJobWithJobs)
1515
}

src/service/user2FA/user2FAService.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { authenticator } from 'otplib'
1+
import { generateSecret as generateOtpSecret, generateURI, verifySync } from 'otplib'
22
import * as crypto from 'node:crypto'
33
import bcrypt from 'bcryptjs'
44

@@ -100,9 +100,13 @@ const generateSecret = async (options: {
100100
}): Promise<{ secret: string; otpAuthUrl: string }> => {
101101
const { userEmail, deviceName } = options
102102

103-
const secret = authenticator.generateSecret()
103+
const secret = generateOtpSecret()
104104
const accountName = `${deviceName} - ${userEmail}`
105-
const otpAuthUrl = authenticator.keyuri(accountName, ArenaServerConstants.appId, secret)
105+
const otpAuthUrl = generateURI({
106+
issuer: ArenaServerConstants.appId,
107+
label: accountName,
108+
secret,
109+
})
106110

107111
return { secret, otpAuthUrl }
108112
}
@@ -124,11 +128,13 @@ const generateBackupCodes = (): string[] => {
124128
*/
125129
const verifyToken = (options: { secret: string; token: string }): boolean => {
126130
const { secret, token } = options
127-
128-
// Set window to allow for clock skew (2 time steps before and after)
129-
authenticator.options = { window: 2 }
130-
131-
return authenticator.verify({ token, secret })
131+
const result = verifySync({
132+
secret,
133+
token,
134+
// Allow for clock skew: 2 TOTP windows on either side of current time.
135+
epochTolerance: 60,
136+
})
137+
return result.valid
132138
}
133139

134140
const to2FADeviceForClient = (device: User2FADevice): User2FADeviceForClient => {

src/service/userTempAuthToken/create.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { v4 as uuidv4 } from 'uuid'
1+
import * as crypto from 'node:crypto'
22

33
import { BaseProtocol, DB } from '../../db'
44
import { UserTempAuthTokenForClient, UserTempAuthTokenStored } from '../../model'
@@ -24,7 +24,7 @@ export const create = async (
2424
const now = new Date()
2525
const expiresAt = new Date(now.getTime() + expirationMinutes * 60 * 1000)
2626

27-
const token = uuidv4()
27+
const token = crypto.randomUUID()
2828
const tokenHash = hashToken(token)
2929

3030
const tempAuthToken: UserTempAuthTokenStored = {

0 commit comments

Comments
 (0)