mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-26 03:33:58 -05:00
Merge pull request #1389 from hedgedoc/fix/publicId
This commit is contained in:
commit
2dc8fc2b66
2 changed files with 23 additions and 1 deletions
22
src/notes/utils.spec.ts
Normal file
22
src/notes/utils.spec.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { randomBytes } from 'crypto';
|
||||
import { generatePublicId } from './utils';
|
||||
jest.mock('crypto');
|
||||
|
||||
it('generatePublicId', () => {
|
||||
const random128bitBuffer = Buffer.from([
|
||||
0xe1, 0x75, 0x86, 0xb7, 0xc3, 0xfb, 0x03, 0xa9, 0x26, 0x9f, 0xc9, 0xd6,
|
||||
0x8c, 0x2d, 0x7b, 0x7b,
|
||||
]);
|
||||
const mockRandomBytes = randomBytes as jest.MockedFunction<
|
||||
typeof randomBytes
|
||||
>;
|
||||
mockRandomBytes.mockImplementationOnce((_) => random128bitBuffer);
|
||||
|
||||
expect(generatePublicId()).toEqual('w5trddy3zc1tj9mzs7b8rbbvfc');
|
||||
});
|
|
@ -12,6 +12,6 @@ import { randomBytes } from 'crypto';
|
|||
* This is a randomly generated 128-bit value encoded with base32-encode using the crockford variant and converted to lowercase.
|
||||
*/
|
||||
export function generatePublicId(): string {
|
||||
const randomId = randomBytes(128);
|
||||
const randomId = randomBytes(16);
|
||||
return base32Encode(randomId, 'Crockford').toLowerCase();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue