Skip to content

Commit bb3c215

Browse files
committed
use crypto to generate secure random number
1 parent 57b6dc2 commit bb3c215

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/backend/src/graphql/__tests__/queries/tiles/get-table-connections.itest.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import crypto from 'crypto'
12
import { beforeEach, describe, expect, it } from 'vitest'
23

34
import getTableConnections from '@/graphql/queries/tiles/get-table-connections'
@@ -15,7 +16,9 @@ interface TablePipeCountObj {
1516
}
1617

1718
function getRandNum() {
18-
return Math.floor(Math.random() * 5) + 1
19+
const array = new Uint32Array(1)
20+
crypto.getRandomValues(array)
21+
return Math.floor((array[0] / (0xffffffff + 1)) * 5) + 1
1922
}
2023

2124
describe('get table connections query', () => {
@@ -46,8 +49,7 @@ describe('get table connections query', () => {
4649
const res = await generateMockTable({ userId: context.currentUser.id })
4750
const { id: tableId } = res.table
4851

49-
const numFlows = Math.floor(Math.random() * 5) + 1
50-
const numSteps = Math.floor(Math.random() * 5) + 1
52+
const [numFlows, numSteps] = [getRandNum(), getRandNum()]
5153
tablePipeCount[tableId] = numFlows
5254

5355
for (let i = 0; i < numFlows; i++) {

0 commit comments

Comments
 (0)