mirror of
				https://github.com/crypto-pro-web/crypto-pro-js.git
				synced 2025-10-31 06:13:22 +03:00 
			
		
		
		
	
						commit
						bccc0c9146
					
				
							
								
								
									
										2
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @ -1,6 +1,6 @@ | ||||
| { | ||||
|   "name": "crypto-pro", | ||||
|   "version": "2.2.0", | ||||
|   "version": "2.2.2", | ||||
|   "lockfileVersion": 1, | ||||
|   "requires": true, | ||||
|   "dependencies": { | ||||
|  | ||||
							
								
								
									
										26
									
								
								src/api/getCspVersion.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/api/getCspVersion.test.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| import 'cadesplugin'; | ||||
| import { getCspVersion } from './getCspVersion'; | ||||
| 
 | ||||
| const executionSteps = [Symbol('step 0'), Symbol('step 1'), Symbol('step 2')]; | ||||
| 
 | ||||
| // "any" because of using toString on the literal
 | ||||
| const executionFlow: any = { | ||||
|   [executionSteps[0]]: { | ||||
|     CSPVersion: jest.fn(() => executionSteps[1]), | ||||
|   }, | ||||
|   [executionSteps[1]]: { | ||||
|     toString: jest.fn(() => executionSteps[2]), | ||||
|   }, | ||||
|   [executionSteps[2]]: '4.0.9971', | ||||
| }; | ||||
| 
 | ||||
| window.cadesplugin.__defineExecutionFlow(executionFlow); | ||||
| window.cadesplugin.CreateObjectAsync.mockImplementation(() => executionSteps[0]); | ||||
| 
 | ||||
| describe('getCspVersion', () => { | ||||
|   test('returns information about CSP', async () => { | ||||
|     const cspVersion = await getCspVersion(); | ||||
| 
 | ||||
|     expect(cspVersion).toStrictEqual('4.0.9971'); | ||||
|   }); | ||||
| }); | ||||
							
								
								
									
										40
									
								
								src/api/getCspVersion.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								src/api/getCspVersion.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,40 @@ | ||||
| import { _afterPluginsLoaded } from '../helpers/_afterPluginsLoaded'; | ||||
| import { _extractMeaningfulErrorMessage } from '../helpers/_extractMeaningfulErrorMessage'; | ||||
| import { | ||||
|   __cadesAsyncToken__, | ||||
|   __createCadesPluginObject__, | ||||
|   _generateCadesFn, | ||||
| } from '../helpers/_generateCadesFn'; | ||||
| 
 | ||||
| /** | ||||
|  * Предоставляет информацию о системе | ||||
|  * | ||||
|  * @returns информацию о CSP | ||||
|  */ | ||||
| export const getCspVersion = _afterPluginsLoaded((): string => { | ||||
|   let cspVersion = null; | ||||
| 
 | ||||
|   return eval( | ||||
|     _generateCadesFn(function getCspVersion(): string { | ||||
|       let cadesAbout; | ||||
| 
 | ||||
|       try { | ||||
|         cadesAbout = | ||||
|           __cadesAsyncToken__ + __createCadesPluginObject__('CAdESCOM.About'); | ||||
| 
 | ||||
|         cspVersion = __cadesAsyncToken__ + cadesAbout.CSPVersion(); | ||||
| 
 | ||||
|         cspVersion = __cadesAsyncToken__ + cspVersion.toString(); | ||||
|       } catch (error) { | ||||
|         console.error(error); | ||||
| 
 | ||||
|         throw new Error( | ||||
|           _extractMeaningfulErrorMessage(error) || | ||||
|             'Ошибка при получении версии системы', | ||||
|         ); | ||||
|       } | ||||
| 
 | ||||
|       return cspVersion; | ||||
|     }), | ||||
|   ); | ||||
| }); | ||||
							
								
								
									
										35
									
								
								src/api/getPluginVersion.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/api/getPluginVersion.test.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | ||||
| import 'cadesplugin'; | ||||
| import { getPluginVersion } from './getPluginVersion'; | ||||
| 
 | ||||
| const executionSteps = [ | ||||
|   Symbol('step 0'), | ||||
|   Symbol('step 1'), | ||||
|   Symbol('step 2'), | ||||
|   Symbol('step 3'), | ||||
| ]; | ||||
| 
 | ||||
| // "any" because of using toString on the literal
 | ||||
| const executionFlow: any = { | ||||
|   [executionSteps[0]]: { | ||||
|     PluginVersion: executionSteps[1], | ||||
|     Version: executionSteps[2], | ||||
|   }, | ||||
|   [executionSteps[1]]: undefined, | ||||
|   [executionSteps[2]]: { | ||||
|     toString: jest.fn(() => executionSteps[3]), | ||||
|   }, | ||||
|   [executionSteps[3]]: '2.0.13771', | ||||
| }; | ||||
| 
 | ||||
| window.cadesplugin.__defineExecutionFlow(executionFlow); | ||||
| window.cadesplugin.CreateObjectAsync.mockImplementation( | ||||
|   () => executionSteps[0], | ||||
| ); | ||||
| 
 | ||||
| describe('getPluginVersion', () => { | ||||
|   test('returns information about plugin', async () => { | ||||
|     const pluginVersion = await getPluginVersion(); | ||||
| 
 | ||||
|     expect(pluginVersion).toStrictEqual('2.0.13771'); | ||||
|   }); | ||||
| }); | ||||
							
								
								
									
										44
									
								
								src/api/getPluginVersion.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/api/getPluginVersion.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,44 @@ | ||||
| import { _afterPluginsLoaded } from '../helpers/_afterPluginsLoaded'; | ||||
| import { | ||||
|   __cadesAsyncToken__, | ||||
|   __createCadesPluginObject__, | ||||
|   _generateCadesFn, | ||||
| } from '../helpers/_generateCadesFn'; | ||||
| import { _extractMeaningfulErrorMessage } from '../helpers/_extractMeaningfulErrorMessage'; | ||||
| 
 | ||||
| /** | ||||
|  * Предоставляет информацию о системе | ||||
|  * | ||||
|  * @returns информацию о плагине | ||||
|  */ | ||||
| export const getPluginVersion = _afterPluginsLoaded((): string => { | ||||
|   let cadesVersion = null; | ||||
| 
 | ||||
|   return eval( | ||||
|     _generateCadesFn(function getPluginVersion(): string { | ||||
|       let cadesAbout; | ||||
| 
 | ||||
|       try { | ||||
|         cadesAbout = | ||||
|           __cadesAsyncToken__ + __createCadesPluginObject__('CAdESCOM.About'); | ||||
| 
 | ||||
|         cadesVersion = __cadesAsyncToken__ + cadesAbout.PluginVersion; | ||||
| 
 | ||||
|         if (!cadesVersion) { | ||||
|           cadesVersion = __cadesAsyncToken__ + cadesAbout.Version; | ||||
|         } | ||||
| 
 | ||||
|         cadesVersion = __cadesAsyncToken__ + cadesVersion.toString(); | ||||
|       } catch (error) { | ||||
|         console.error(error); | ||||
| 
 | ||||
|         throw new Error( | ||||
|           _extractMeaningfulErrorMessage(error) || | ||||
|             'Ошибка при получении информации о плагине', | ||||
|         ); | ||||
|       } | ||||
| 
 | ||||
|       return cadesVersion; | ||||
|     }), | ||||
|   ); | ||||
| }); | ||||
| @ -10,3 +10,5 @@ export * from './createAttachedSignature'; | ||||
| export * from './addAttachedSignature'; | ||||
| export * from './createHash'; | ||||
| export * from './certificate'; | ||||
| export * from './getCspVersion'; | ||||
| export * from './getPluginVersion'; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 German Arutyunov
						German Arutyunov