Skip to content

Commit ea72904

Browse files
authored
test: Adding test for integration-node (#162)
Basic tests for integration-node
1 parent 9d10cf0 commit ea72904

7 files changed

+301
-11
lines changed

modules/integration-node/src/decrypt_materials_manager_node.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export function decryptMaterialsManagerNode (keyInfos: KeyInfoTuple[]) {
4949
return new MultiKeyringNode({ children })
5050
}
5151

52-
function keyringNode ([ info, key ]: KeyInfoTuple) {
52+
export function keyringNode ([ info, key ]: KeyInfoTuple) {
5353
if (info.type === 'aws-kms' && key.type === 'aws-kms') {
5454
return kmsKeyring(info, key)
5555
}
@@ -62,12 +62,12 @@ function keyringNode ([ info, key ]: KeyInfoTuple) {
6262
throw new Error('Unsupported keyring type')
6363
}
6464

65-
function kmsKeyring (_keyInfo: KmsKeyInfo, key: KMSKey) {
65+
export function kmsKeyring (_keyInfo: KmsKeyInfo, key: KMSKey) {
6666
const generatorKeyId = key['key-id']
6767
return new KmsKeyringNode({ generatorKeyId })
6868
}
6969

70-
function aesKeyring (keyInfo:AesKeyInfo, key: AESKey) {
70+
export function aesKeyring (keyInfo:AesKeyInfo, key: AESKey) {
7171
const keyName = key['key-id']
7272
const keyNamespace = keyInfo['provider-id']
7373
const { encoding, material } = key
@@ -76,7 +76,7 @@ function aesKeyring (keyInfo:AesKeyInfo, key: AESKey) {
7676
return new RawAesKeyringNode({ keyName, keyNamespace, unencryptedMasterKey, wrappingSuite })
7777
}
7878

79-
function rsaKeyring (keyInfo: RsaKeyInfo, key: RSAKey) {
79+
export function rsaKeyring (keyInfo: RsaKeyInfo, key: RSAKey) {
8080
const keyName = key['key-id']
8181
const keyNamespace = keyInfo['provider-id']
8282
const rsaKey = key.type === 'private'
@@ -86,7 +86,7 @@ function rsaKeyring (keyInfo: RsaKeyInfo, key: RSAKey) {
8686
return new RawRsaKeyringNode({ keyName, keyNamespace, rsaKey, padding })
8787
}
8888

89-
function rsaPadding (keyInfo: RsaKeyInfo) {
89+
export function rsaPadding (keyInfo: RsaKeyInfo) {
9090
const paddingAlgorithm = keyInfo['padding-algorithm']
9191
const paddingHash = keyInfo['padding-hash']
9292

modules/integration-node/src/get_decrypt_test_iterator.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
* limitations under the License.
1414
*/
1515

16-
import { Open } from 'unzipper'
16+
import {
17+
Open,
18+
File // eslint-disable-line no-unused-vars
19+
} from 'unzipper'
1720
import {
1821
DecryptManifestList, // eslint-disable-line no-unused-vars
1922
KeyList, // eslint-disable-line no-unused-vars
@@ -26,6 +29,11 @@ export async function getDecryptTestVectorIterator (vectorFile: string) {
2629
// @ts-ignore
2730
const filesMap = new Map(centralDirectory.files.map(file => [file.path, file]))
2831

32+
return _getDecryptTestVectorIterator(filesMap)
33+
}
34+
35+
/* Just a simple more testable function */
36+
export async function _getDecryptTestVectorIterator (filesMap: Map<string, File>) {
2937
const readUriOnce = (() => {
3038
const cache: Map<string, Buffer> = new Map()
3139
return async (uri: string) => {
@@ -49,7 +57,7 @@ export async function getDecryptTestVectorIterator (vectorFile: string) {
4957
const { plaintext: plaintextFile, ciphertext, 'master-keys': masterKeys } = testInfo
5058
const plainTextInfo = filesMap.get(testUri2Path(plaintextFile))
5159
const cipherInfo = filesMap.get(testUri2Path(ciphertext))
52-
if (!cipherInfo || !plainTextInfo) throw new Error(`no file for ${name}: ${ciphertext} | ${plaintextFile}`)
60+
if (!cipherInfo || !plainTextInfo) throw new Error(`no file for ${name}: ${testUri2Path(ciphertext)} | ${testUri2Path(plaintextFile)}`)
5361
const cipherStream = cipherInfo.stream()
5462
const plainTextStream = plainTextInfo.stream()
5563
const keysInfo = <KeyInfoTuple[]>masterKeys.map(keyInfo => {

modules/integration-node/src/get_encrypt_test_iterator.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ import { readFileSync } from 'fs'
2828
import got from 'got'
2929

3030
export async function getEncryptTestVectorIterator (manifestFile: string, keyFile: string) {
31-
const { tests, plaintexts }: EncryptManifestList = await getParsedJSON(manifestFile)
32-
const { keys }: KeyList = await getParsedJSON(keyFile)
31+
const [manifest, keys]: [EncryptManifestList, KeyList] = await Promise.all([
32+
getParsedJSON(manifestFile),
33+
getParsedJSON(keyFile)
34+
])
3335

36+
return _getEncryptTestVectorIterator(manifest, keys)
37+
}
38+
39+
/* Just a simple more testable function */
40+
export function _getEncryptTestVectorIterator ({ tests, plaintexts }: EncryptManifestList, { keys }: KeyList) {
3441
const plaintextBytes: {[name: string]: Buffer} = {}
3542

3643
Object

modules/integration-node/src/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export interface DecryptManifestList {
2424

2525
export interface EncryptManifestList {
2626
manifest: EncryptManifest
27-
client: Client
2827
keys: string
2928
plaintexts: {[name: string]: number}
3029
tests: {[testName: string]: EncryptTest}
@@ -68,7 +67,7 @@ interface RawKeyInfo extends KeyInfo {
6867
export interface RsaKeyInfo extends RawKeyInfo {
6968
'encryption-algorithm': 'rsa',
7069
'padding-algorithm': 'pkcs1'|'oaep-mgf1'
71-
'padding-hash': 'sha1'|'sha256'|'sha384'|'sha512'
70+
'padding-hash'?: 'sha1'|'sha256'|'sha384'|'sha512'
7271
}
7372

7473
export interface AesKeyInfo extends RawKeyInfo {
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is
6+
* located at
7+
*
8+
* http://aws.amazon.com/apache2.0/
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed on an
11+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12+
* implied. See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
/* eslint-env mocha */
17+
18+
import { expect } from 'chai'
19+
import 'mocha'
20+
import {
21+
kmsKeyring,
22+
aesKeyring,
23+
rsaKeyring,
24+
keyringNode
25+
} from '../src/index'
26+
import { KMSKey, KmsKeyInfo, AESKey, AesKeyInfo, RSAKey, RsaKeyInfo } from '../src/types' // eslint-disable-line no-unused-vars
27+
28+
const kmsKey: KMSKey = {
29+
'encrypt': true,
30+
'decrypt': true,
31+
'type': 'aws-kms',
32+
'key-id': 'arn:aws:kms:us-west-2:658956600833:key/b3537ef1-d8dc-4780-9f5a-55776cbb2f7f'
33+
}
34+
const kmsInfo: KmsKeyInfo = {
35+
'type': 'aws-kms',
36+
'key': 'us-west-2-decryptable'
37+
}
38+
const aesKey: AESKey = {
39+
'encrypt': true,
40+
'decrypt': true,
41+
'algorithm': 'aes',
42+
'type': 'symmetric',
43+
'bits': 128,
44+
'encoding': 'base64',
45+
'material': 'AAECAwQFBgcICRAREhMUFQ==',
46+
'key-id': 'aes-128'
47+
}
48+
const aesInfo: AesKeyInfo = {
49+
'type': 'raw',
50+
'key': 'aes-128',
51+
'provider-id': 'aws-raw-vectors-persistant',
52+
'encryption-algorithm': 'aes',
53+
'padding-algorithm': null
54+
}
55+
const rsaKey: RSAKey = {
56+
'encrypt': true,
57+
'decrypt': true,
58+
'algorithm': 'rsa',
59+
'type': 'private',
60+
'bits': 4096,
61+
'encoding': 'pem',
62+
'material': '-----BEGIN PRIVATE KEY-----\nMIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQCztGg1gQ8AjCzz\n1VX6StqtW//jBt2ZQBoApaBa7FmLmdr0YlKaeEKSrItGbvA9tBjgsKhrn8gxTGQc\nuxgM92651jRCbQZyjE6W8kodijhGMXsfKJLfgPp2/I7gZ3dqrSZkejFIYLFb/uF/\nTfAQzNyJUldYdeFojSUPqevMgSAusTgv7dXYt4BCO9mxMp35tgyp5k4vazKJVUgB\nTw87AAYZUGugmi94W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StiM6UCZB5PrO\nS8dfrO8ML+ki8Zqck8L1qhiNb5zkXtKExy4u+gNr8khGcT6vqqoSxOoH3mPRgOfL\nJnppne8wlwIf7Vq3H8ka6zPSXEHma999gZcmy9t7AoIBAGbQhiLl79j3a0wXMvZp\nVf5IVYgXFDnAbG2hb7a06bhAAIgyexcjzsC4C2+DWdgOgwHkuoPg+062QV8zauGh\nsJKaa6cHlvIpSJeg3NjD/nfJN3CYzCd0yCIm2Z9Ka6xI5iYhm+pGPNhIG4Na8deS\ngVL46yv1pc/o73VxfoGg5UzgN3xlp97Cva0sHEGguHr4W8Qr59xZw3wGQ4SLW35M\nF6qXVNKUh12GSMCPbZK2RXBWVKqqJmca+WzJoJ6DlsT2lQdFhXCus9L007xlDXxF\nC/hCmw1dEl+VaNo2Ou26W/zdwTKYhNlxBwsg4SB8nPNxXIsmlBBY54froFhriNfn\nx/0CggEAUzz+VMtjoEWw2HSHLOXrO4EmwJniNgiiwfX3DfZE4tMNZgqZwLkq67ns\nT0n3b0XfAOOkLgMZrUoOxPHkxFeyLLf7pAEJe7QNB+Qilw8e2zVqtiJrRk6uDIGJ\nSv+yM52zkImZAe2jOdU3KeUZxSMmb5vIoiPBm+tb2WupAg3YdpKn1/jWTpVmV/+G\nUtTLVE6YpAyFp1gMxhutE9vfIS94ek+vt03AoEOlltt6hqZfv3xmY8vGuAjlnj12\nzHaq+fhCRPsbsZkzJ9nIVdXYnNIEGtMGNnxax7tYRej/UXqyazbxHiJ0iPF4PeDn\ndzxtGxpeTBi+KhKlca8SlCdCqYwG6Q==\n-----END PRIVATE KEY-----',
63+
'key-id': 'rsa-4096-private'
64+
}
65+
const rsaInfo: RsaKeyInfo = {
66+
'type': 'raw',
67+
'key': 'rsa-4096-private',
68+
'provider-id': 'aws-raw-vectors-persistant',
69+
'encryption-algorithm': 'rsa',
70+
'padding-algorithm': 'pkcs1'
71+
}
72+
73+
describe('how to build keyrings', () => {
74+
it('kmsKeyring', () => {
75+
const test = kmsKeyring(kmsInfo, kmsKey)
76+
expect(test.generatorKeyId).to.equal(kmsKey['key-id'])
77+
})
78+
79+
it('aesKeyring', () => {
80+
const test = aesKeyring(aesInfo, aesKey)
81+
expect(test.keyName).to.equal(aesInfo.key)
82+
})
83+
84+
it('rsaKeyring', () => {
85+
const test = rsaKeyring(rsaInfo, rsaKey)
86+
expect(test.keyName).to.equal(rsaInfo.key)
87+
})
88+
89+
it('keyringNode: kmsKeyring', () => {
90+
const test: any = keyringNode([kmsInfo, kmsKey])
91+
expect(test.generatorKeyId).to.equal(kmsKey['key-id'])
92+
})
93+
94+
it('keyringNode: aesKeyring', () => {
95+
const test: any = keyringNode([aesInfo, aesKey])
96+
expect(test.keyName).to.equal(aesInfo.key)
97+
})
98+
99+
it('keyringNode: rsaKeyring', () => {
100+
const test: any = keyringNode([rsaInfo, rsaKey])
101+
expect(test.keyName).to.equal(rsaInfo.key)
102+
})
103+
})
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is
6+
* located at
7+
*
8+
* http://aws.amazon.com/apache2.0/
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed on an
11+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12+
* implied. See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
/* eslint-env mocha */
17+
18+
import { expect } from 'chai'
19+
import 'mocha'
20+
import {
21+
_getDecryptTestVectorIterator
22+
} from '../src/index'
23+
import { DecryptManifestList, KeyList } from '../src/types' // eslint-disable-line no-unused-vars
24+
25+
const keyList: KeyList = {
26+
'manifest': {
27+
'type': 'keys',
28+
'version': 3
29+
},
30+
'keys': {
31+
'us-west-2-decryptable': {
32+
'type': 'aws-kms',
33+
'key-id': 'arn:aws:kms:us-west-2:658956600833:alias/EncryptDecrypt',
34+
'encrypt': true,
35+
'decrypt': true
36+
}
37+
}
38+
}
39+
40+
const manifest:DecryptManifestList = {
41+
'manifest': {
42+
'type': 'awses-decrypt',
43+
'version': 1
44+
},
45+
'client': {
46+
'name': 'aws/aws-encryption-sdk-python',
47+
'version': '1.3.8'
48+
},
49+
'keys': 'file://keys.json',
50+
'tests': {
51+
'c17b05d0-915e-44cc-98a3-cc29b71aa42b': {
52+
'plaintext': 'file://plaintexts/small',
53+
'ciphertext': 'file://ciphertexts/460bd892-c137-4178-8201-4ab5ee5d3041',
54+
'master-keys': [
55+
{
56+
'type': 'aws-kms',
57+
'key': 'us-west-2-decryptable'
58+
}
59+
]
60+
}
61+
}
62+
}
63+
64+
const filesMap = new Map([
65+
[
66+
'manifest.json', {
67+
async buffer () {
68+
return Buffer.from(JSON.stringify(manifest))
69+
}
70+
} as any
71+
],
72+
[
73+
'keys.json', {
74+
async buffer () {
75+
return Buffer.from(JSON.stringify(keyList))
76+
}
77+
} as any
78+
],
79+
[
80+
'ciphertexts/460bd892-c137-4178-8201-4ab5ee5d3041', {
81+
stream () {
82+
return {} as any
83+
}
84+
} as any
85+
],
86+
[
87+
'plaintexts/small', {
88+
stream () {
89+
return {} as any
90+
}
91+
} as any
92+
]
93+
])
94+
95+
describe('_getDecryptTestVectorIterator', () => {
96+
it('returns a iterator that has a test', async () => {
97+
const testIterator = await _getDecryptTestVectorIterator(filesMap)
98+
const test = testIterator.next()
99+
expect(test.done).to.equal(false)
100+
expect(test.value.name).to.equal('c17b05d0-915e-44cc-98a3-cc29b71aa42b')
101+
})
102+
})
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. A copy of the License is
6+
* located at
7+
*
8+
* http://aws.amazon.com/apache2.0/
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed on an
11+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12+
* implied. See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
/* eslint-env mocha */
17+
18+
import { expect } from 'chai'
19+
import 'mocha'
20+
import {
21+
_getEncryptTestVectorIterator
22+
} from '../src/index'
23+
import { EncryptManifestList, KeyList } from '../src/types' // eslint-disable-line no-unused-vars
24+
25+
const manifiest: EncryptManifestList = {
26+
'manifest': {
27+
'type': 'awses-encrypt',
28+
'version': 1
29+
},
30+
'keys': 'file://0002-keys.v1.json',
31+
'plaintexts': {
32+
'small': 10240
33+
},
34+
'tests': {
35+
'0c9c3222-b8f6-4b5f-97bc-c2a97f5255b1': {
36+
'plaintext': 'small',
37+
'algorithm': '0014',
38+
'frame-size': 0,
39+
'encryption-context': {},
40+
'master-keys': [
41+
{
42+
'type': 'aws-kms',
43+
'key': 'us-west-2-decryptable'
44+
}
45+
]
46+
}
47+
}
48+
}
49+
50+
const keyList: KeyList = {
51+
'manifest': {
52+
'type': 'keys',
53+
'version': 3
54+
},
55+
'keys': { 'us-west-2-decryptable': {
56+
'type': 'aws-kms',
57+
'key-id': 'arn:aws:kms:us-west-2:658956600833:alias/EncryptDecrypt',
58+
'encrypt': true,
59+
'decrypt': true
60+
}
61+
}
62+
}
63+
64+
describe('_getEncryptTestVectorIterator', () => {
65+
it('returns a iterator that has a test', () => {
66+
const testIterator = _getEncryptTestVectorIterator(manifiest, keyList)
67+
const test = testIterator.next()
68+
expect(test.done).to.equal(false)
69+
expect(test.value.name).to.equal('0c9c3222-b8f6-4b5f-97bc-c2a97f5255b1')
70+
})
71+
})

0 commit comments

Comments
 (0)