mirror of
https://github.com/crypto-pro-web/crypto-pro-js.git
synced 2024-11-23 16:44:59 +03:00
Добавил тесты для создания хеша
This commit is contained in:
parent
bdcb3d7542
commit
56e5e2ff17
@ -49,17 +49,17 @@ window.cadesplugin.CreateObjectAsync.mockImplementation((object) => {
|
||||
|
||||
describe('createAttachedSignature', () => {
|
||||
test('uses Buffer to encrypt the message', async () => {
|
||||
const originalBufferFrom = (window as any).Buffer.from;
|
||||
const originalBufferFrom = global.Buffer.from;
|
||||
|
||||
(window as any).Buffer.from = jest.fn(() => ({
|
||||
(global.Buffer.from as jest.Mock) = jest.fn(() => ({
|
||||
toString: jest.fn(),
|
||||
}));
|
||||
|
||||
await createAttachedSignature(parsedCertificateMock.thumbprint, 'message');
|
||||
|
||||
expect((window as any).Buffer.from).toHaveBeenCalledTimes(1);
|
||||
expect(global.Buffer.from).toHaveBeenCalledTimes(1);
|
||||
|
||||
(window as any).Buffer.from = originalBufferFrom;
|
||||
global.Buffer.from = originalBufferFrom;
|
||||
});
|
||||
|
||||
test('uses specified certificate', async () => {
|
||||
|
44
src/api/createHash.test.ts
Normal file
44
src/api/createHash.test.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import 'cadesplugin';
|
||||
import { createHash } from './createHash';
|
||||
|
||||
const executionSteps = [Symbol('step 0'), Symbol('step 1')];
|
||||
|
||||
const executionFlow = {
|
||||
[executionSteps[0]]: {
|
||||
propset_Algorithm: jest.fn(),
|
||||
propset_DataEncoding: jest.fn(),
|
||||
Hash: jest.fn(),
|
||||
Value: executionSteps[1],
|
||||
},
|
||||
[executionSteps[1]]: 'hash',
|
||||
};
|
||||
|
||||
window.cadesplugin.__defineExecutionFlow(executionFlow);
|
||||
window.cadesplugin.CreateObjectAsync.mockImplementation((object) => {
|
||||
switch (object) {
|
||||
case 'CAdESCOM.HashedData':
|
||||
return executionSteps[0];
|
||||
}
|
||||
});
|
||||
|
||||
describe('createHash', () => {
|
||||
test('uses Buffer to encrypt the message', async () => {
|
||||
const originalBufferFrom = global.Buffer.from;
|
||||
|
||||
(global.Buffer.from as jest.Mock) = jest.fn(() => ({
|
||||
toString: jest.fn(),
|
||||
}));
|
||||
|
||||
await createHash('message');
|
||||
|
||||
expect(global.Buffer.from).toHaveBeenCalledTimes(1);
|
||||
|
||||
global.Buffer.from = originalBufferFrom;
|
||||
});
|
||||
|
||||
test('returns created hash', async () => {
|
||||
const hash = await createHash('message');
|
||||
|
||||
expect(hash).toEqual('hash');
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user