зеркало из
1
0
Форкнуть 0
health-cards-validation-SDK/tests/keys.test.ts

41 строка
1.4 KiB
TypeScript
Исходник Обычный вид История

2021-03-03 18:42:47 +03:00
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
2021-03-10 22:34:42 +03:00
2021-03-03 18:42:47 +03:00
import path from 'path';
2021-03-06 09:18:25 +03:00
import { ErrorCode } from '../src/error';
2021-03-10 22:34:42 +03:00
import { LogLevels } from '../src/logger';
import { verifyHealthCardIssuerKey } from '../src/shcKeyValidator';
import * as utils from '../src/utils';
2021-03-03 18:42:47 +03:00
const testdataDir = './testdata/';
2021-03-06 09:18:25 +03:00
async function testKey(fileName: string): Promise<ErrorCode[]> {
2021-03-03 18:42:47 +03:00
const filePath = path.join(testdataDir, fileName);
2021-03-10 22:34:42 +03:00
const result = (await verifyHealthCardIssuerKey({keys : [utils.loadJSONFromFile(filePath)]}));
return result.log.flatten(LogLevels.WARNING).map(item => item.code);
2021-03-03 18:42:47 +03:00
}
test("Keys: valid", async () => {
2021-03-06 09:18:25 +03:00
expect(await testKey('valid_key.json')).toHaveLength(0);
});
2021-03-03 18:42:47 +03:00
test("Keys: wrong key identifier (kid)", async () => {
2021-03-06 09:18:25 +03:00
expect(await testKey('wrong_kid_key.json')).toContain(ErrorCode.INVALID_WRONG_KID);
});
2021-03-03 18:42:47 +03:00
test("Keys: wrong elliptic curve", async () => {
2021-03-06 09:18:25 +03:00
expect(await testKey('wrong_curve_key.json')).toContain(ErrorCode.INVALID_WRONG_ALG);
});
2021-03-03 18:42:47 +03:00
2021-03-06 09:18:25 +03:00
test("Keys: wrong key use (use)", async () => {
expect(await testKey('wrong_use_key.json')).toContain(ErrorCode.INVALID_WRONG_USE);
});
2021-03-03 18:42:47 +03:00
test("Keys: wrong algorithm (alg)", async () => {
2021-03-06 09:18:25 +03:00
expect(await testKey('wrong_alg_key.json')).toContain(ErrorCode.INVALID_WRONG_ALG);
});
2021-03-03 18:42:47 +03:00
test("Keys: wrong key type (kty)", async () => {
2021-03-06 09:18:25 +03:00
expect(await testKey('wrong_kty_key.json')).toContain(ErrorCode.INVALID_WRONG_KTY);
});