Merge pull request #1 from gaarutyunov/systeminfo

Closes SystemInfo
This commit is contained in:
German Arutyunov 2021-05-13 01:38:18 +03:00 committed by GitHub
commit bccc0c9146
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 148 additions and 1 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "crypto-pro",
"version": "2.2.0",
"version": "2.2.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View 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
View 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;
}),
);
});

View 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');
});
});

View 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;
}),
);
});

View File

@ -10,3 +10,5 @@ export * from './createAttachedSignature';
export * from './addAttachedSignature';
export * from './createHash';
export * from './certificate';
export * from './getCspVersion';
export * from './getPluginVersion';