0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-17 22:04:19 -05:00

refactor(test): use secure random method in integration test util (#6139)

This commit is contained in:
Charles Zhao 2024-06-29 18:39:45 +08:00 committed by GitHub
parent e548eeaa15
commit 97b8201a57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,4 @@
import crypto from 'node:crypto'; import crypto, { randomInt } from 'node:crypto';
import path from 'node:path'; import path from 'node:path';
import { generateStandardId } from '@logto/shared'; import { generateStandardId } from '@logto/shared';
@ -37,10 +37,8 @@ export const generatePhone = (isE164?: boolean) => {
'232', '232',
]; ];
const centralOfficeCode = const centralOfficeCode =
validCentralOfficeCodes[Math.floor(Math.random() * validCentralOfficeCodes.length)] ?? '205'; validCentralOfficeCodes[randomInt(0, validCentralOfficeCodes.length)] ?? '205';
const phoneNumber = Math.floor(Math.random() * 10_000) const phoneNumber = randomInt(0, 10_000).toString().padStart(4, '0');
.toString()
.padStart(4, '0');
return plus + countryAndAreaCode + centralOfficeCode + phoneNumber; return plus + countryAndAreaCode + centralOfficeCode + phoneNumber;
}; };