mirror of
				https://github.com/crypto-pro-web/crypto-pro-js.git
				synced 2025-10-31 06:13:22 +03:00 
			
		
		
		
	Добавил тесты для создания присоединенной подписи
This commit is contained in:
		
							parent
							
								
									e4d93c64dd
								
							
						
					
					
						commit
						cfd244df02
					
				| @ -1,2 +1,3 @@ | ||||
| // suppress logging errors to stdout while running tests
 | ||||
| window.console.error = jest.fn(); | ||||
| window.console.warn = jest.fn(); | ||||
							
								
								
									
										76
									
								
								src/api/createAttachedSignature.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								src/api/createAttachedSignature.test.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,76 @@ | ||||
| import 'cadesplugin'; | ||||
| import { rawCertificates, parsedCertificates } from '../__mocks__/certificates'; | ||||
| import { createAttachedSignature } from './createAttachedSignature'; | ||||
| import { _getCadesCert } from '../helpers/_getCadesCert'; | ||||
| 
 | ||||
| const [rawCertificateMock] = rawCertificates; | ||||
| const [parsedCertificateMock] = parsedCertificates; | ||||
| 
 | ||||
| jest.mock('../helpers/_getCadesCert', () => ({ _getCadesCert: jest.fn(() => rawCertificateMock) })); | ||||
| 
 | ||||
| beforeEach(() => { | ||||
|   (_getCadesCert as jest.Mock).mockClear(); | ||||
| }); | ||||
| 
 | ||||
| const executionSteps = [Symbol('step 0'), Symbol('step 1'), Symbol('step 2'), Symbol('step 3'), Symbol('step 4')]; | ||||
| 
 | ||||
| const executionFlow = { | ||||
|   [executionSteps[0]]: { | ||||
|     propset_Name: jest.fn(), | ||||
|     propset_Value: jest.fn(), | ||||
|   }, | ||||
|   [executionSteps[1]]: { | ||||
|     propset_ContentEncoding: jest.fn(), | ||||
|     propset_Content: jest.fn(), | ||||
|     SignCades: jest.fn(() => executionSteps[4]), | ||||
|   }, | ||||
|   [executionSteps[2]]: { | ||||
|     propset_Certificate: jest.fn(), | ||||
|     AuthenticatedAttributes2: executionSteps[3], | ||||
|     propset_Options: jest.fn(), | ||||
|   }, | ||||
|   [executionSteps[3]]: { | ||||
|     Add: jest.fn(), | ||||
|   }, | ||||
|   [executionSteps[4]]: 'signature', | ||||
| }; | ||||
| 
 | ||||
| window.cadesplugin.__defineExecutionFlow(executionFlow); | ||||
| window.cadesplugin.CreateObjectAsync.mockImplementation((object) => { | ||||
|   switch (object) { | ||||
|     case 'CADESCOM.CPAttribute': | ||||
|       return executionSteps[0]; | ||||
|     case 'CAdESCOM.CadesSignedData': | ||||
|       return executionSteps[1]; | ||||
|     case 'CAdESCOM.CPSigner': | ||||
|       return executionSteps[2]; | ||||
|   } | ||||
| }); | ||||
| 
 | ||||
| describe('createAttachedSignature', () => { | ||||
|   test('uses Buffer to encrypt the message', async () => { | ||||
|     const originalBufferFrom = (window as any).Buffer.from; | ||||
| 
 | ||||
|     (window as any).Buffer.from = jest.fn(() => ({ | ||||
|       toString: jest.fn(), | ||||
|     })); | ||||
| 
 | ||||
|     await createAttachedSignature(parsedCertificateMock.thumbprint, 'message'); | ||||
| 
 | ||||
|     expect((window as any).Buffer.from).toHaveBeenCalledTimes(1); | ||||
| 
 | ||||
|     (window as any).Buffer.from = originalBufferFrom; | ||||
|   }); | ||||
| 
 | ||||
|   test('uses specified certificate', async () => { | ||||
|     await createAttachedSignature(parsedCertificateMock.thumbprint, 'message'); | ||||
| 
 | ||||
|     expect(_getCadesCert).toHaveBeenCalledWith(parsedCertificateMock.thumbprint); | ||||
|   }); | ||||
| 
 | ||||
|   test('returns signature', async () => { | ||||
|     const signature = await createAttachedSignature(parsedCertificateMock.thumbprint, 'message'); | ||||
| 
 | ||||
|     expect(signature).toEqual('signature'); | ||||
|   }); | ||||
| }); | ||||
| @ -1,4 +1,5 @@ | ||||
| import 'cadesplugin'; | ||||
| import 'console-mock'; | ||||
| import { rawCertificates, parsedCertificates } from '../__mocks__/certificates'; | ||||
| import { createSignature } from './createSignature'; | ||||
| import { _getCadesCert } from '../helpers/_getCadesCert'; | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| import 'cadesplugin'; | ||||
| import 'console-error'; | ||||
| import 'console-mock'; | ||||
| import { isValidSystemSetup } from './isValidSystemSetup'; | ||||
| import { getSystemInfo } from './getSystemInfo'; | ||||
| import { _isSupportedCadesVersion } from '../helpers/_isSupportedCadesVersion'; | ||||
|  | ||||
| @ -1,5 +1,5 @@ | ||||
| import 'cadesplugin'; | ||||
| import 'console-error'; | ||||
| import 'console-mock'; | ||||
| import { _afterPluginsLoaded } from './_afterPluginsLoaded'; | ||||
| 
 | ||||
| const cadesPluginMock = window.cadesplugin; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 vgoma
						vgoma