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

49 строки
1.7 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);
const result = (await verifyHealthCardIssuerKey(utils.loadJSONFromFile(filePath)));
2021-03-10 22:34:42 +03:00
return result.log.flatten(LogLevels.WARNING).map(item => item.code);
2021-03-03 18:42:47 +03:00
}
2021-03-11 22:10:21 +03:00
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: valid keys", async () => {
expect(await testKey('valid_keys.json')).toHaveLength(0);
});
2021-03-03 18:42:47 +03:00
test("Keys: wrong key identifier (kid)", async () => {
expect(await testKey('wrong_kid_key.json')).toContain(ErrorCode.INVALID_KEY_WRONG_KID);
2021-03-06 09:18:25 +03:00
});
2021-03-03 18:42:47 +03:00
test("Keys: wrong elliptic curve", async () => {
expect(await testKey('wrong_curve_key.json')).toContain(ErrorCode.INVALID_KEY_WRONG_ALG);
2021-03-06 09:18:25 +03:00
});
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_KEY_WRONG_USE);
2021-03-06 09:18:25 +03:00
});
2021-03-03 18:42:47 +03:00
test("Keys: wrong algorithm (alg)", async () => {
expect(await testKey('wrong_alg_key.json')).toContain(ErrorCode.INVALID_KEY_WRONG_ALG);
2021-03-06 09:18:25 +03:00
});
2021-03-03 18:42:47 +03:00
test("Keys: wrong key type (kty)", async () => {
expect(await testKey('wrong_kty_key.json')).toContain(ErrorCode.INVALID_KEY_WRONG_KTY);
2021-03-06 09:18:25 +03:00
});
2021-03-11 22:44:51 +03:00
test("Keys: private key", async () => {
expect(await testKey('private_key.json')).toContain(ErrorCode.INVALID_KEY_PRIVATE);
2021-03-11 22:44:51 +03:00
});