mirror of
https://github.com/laurent22/joplin.git
synced 2026-10-25 02:47:28 +00:00
Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
This commit is contained in:
1 parent
9f84bda5db
commit
9e4ca948be
36 files changed
+3093
-1821
No files matched your search
@@ -235,6 +235,33 @@ export async function testFilePerformance(method: EncryptionMethod, dataSize: nu
|
||||
}
|
||||
}
|
||||
|
||||
const checkRandomBytes = async () => {
|
||||
const length = 100;
|
||||
const randomBytes = await shim.randomBytes(length);
|
||||
const errorPrefix = `shim.randomBytes(${length}) test failed`;
|
||||
|
||||
if (randomBytes.length !== length) {
|
||||
throw new Error(`${errorPrefix}: unexpected length ${randomBytes.length}`);
|
||||
}
|
||||
|
||||
let sum = 0;
|
||||
for (const b of randomBytes) {
|
||||
sum += b;
|
||||
|
||||
if (!Number.isInteger(b)) {
|
||||
throw new Error(`${errorPrefix}: Generated byte is not an integer: ${b}`);
|
||||
}
|
||||
if (b < 0 || b > 255) {
|
||||
throw new Error(`${errorPrefix}: Byte out of range: ${b}`);
|
||||
}
|
||||
}
|
||||
|
||||
// It's extremely unlikely that all 100 bytes will all be zero by chance:
|
||||
if (sum === 0) {
|
||||
throw new Error('randomBytes test failed: Did not generate a non-zero byte.');
|
||||
}
|
||||
};
|
||||
|
||||
// cSpell:disable
|
||||
|
||||
// Data generated on desktop, using node:crypto in packages/lib/services/e2ee/crypto.ts
|
||||
@@ -278,6 +305,9 @@ export const runIntegrationTests = async (silent = false, testPerformance = fals
|
||||
log('Testing bufferToString...');
|
||||
checkBufferToString();
|
||||
|
||||
log('Testing shim.randomBytes...');
|
||||
await checkRandomBytes();
|
||||
|
||||
log('Decrypting using known data...');
|
||||
for (const testLabel in decryptTestData) {
|
||||
log(`Running decrypt test data case ${testLabel}...`);
|
||||
|
||||
Reference in new issue
Block a user