From a4484723fafc464bf2abc35be8eb8ae11a008511 Mon Sep 17 00:00:00 2001 From: seebees Date: Wed, 3 Jul 2019 16:10:29 -0700 Subject: [PATCH 1/2] fix: Add tests for signature info --- modules/serialize/test/fixtures.ts | 8 +++ modules/serialize/test/signature_info.test.ts | 51 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 modules/serialize/test/signature_info.test.ts diff --git a/modules/serialize/test/fixtures.ts b/modules/serialize/test/fixtures.ts index ecadcb200..9ed8d90c1 100644 --- a/modules/serialize/test/fixtures.ts +++ b/modules/serialize/test/fixtures.ts @@ -68,3 +68,11 @@ export function headerAuthIV () { export function encryptedDataKey () { return new Uint8Array([ 0, 2, 0, 12, 194, 189, 32, 43, 32, 194, 188, 32, 61, 32, 194, 190, 0, 8, 102, 105, 114, 115, 116, 75, 101, 121, 0, 5, 1, 2, 3, 4, 5, 0, 12, 194, 189, 32, 43, 32, 194, 188, 32, 61, 32, 194, 190, 0, 9, 115, 101, 99, 111, 110, 100, 75, 101, 121, 0, 5, 6, 7, 8, 9, 0 ]) } + +export function ecdsaP256Signature() { + return new Uint8Array([48, 68, 2, 32, 22, 77, 187, 192, 175, 104, 2, 240, 55, 2, 6, 138, 103, 148, 214, 240, 244, 65, 224, 254, 60, 52, 218, 22, 250, 245, 216, 228, 151, 151, 220, 234, 2, 32, 125, 9, 97, 8, 132, 123, 79, 193, 216, 207, 214, 0, 73, 183, 149, 173, 26, 173, 251, 132, 140, 139, 44, 122, 11, 50, 163, 105, 138, 221, 223, 29]) +} + +export function ecdsaP256SignatureInfo() { + return new Uint8Array([0, 70, 48, 68, 2, 32, 22, 77, 187, 192, 175, 104, 2, 240, 55, 2, 6, 138, 103, 148, 214, 240, 244, 65, 224, 254, 60, 52, 218, 22, 250, 245, 216, 228, 151, 151, 220, 234, 2, 32, 125, 9, 97, 8, 132, 123, 79, 193, 216, 207, 214, 0, 73, 183, 149, 173, 26, 173, 251, 132, 140, 139, 44, 122, 11, 50, 163, 105, 138, 221, 223, 29]) +} \ No newline at end of file diff --git a/modules/serialize/test/signature_info.test.ts b/modules/serialize/test/signature_info.test.ts new file mode 100644 index 000000000..d73f408a1 --- /dev/null +++ b/modules/serialize/test/signature_info.test.ts @@ -0,0 +1,51 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use + * this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0/ + * + * or in the "license" file accompanying this file. This file is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* eslint-env mocha */ + +import { expect } from 'chai' +import 'mocha' +import { serializeSignatureInfo, deserializeSignature } from '../src/signature_info' +import * as fixtures from './fixtures' + +describe('serializeSignatureInfo', () => { + it('returns signature info', () => { + const test = serializeSignatureInfo(fixtures.ecdsaP256Signature()) + expect(test).to.deep.equal(fixtures.ecdsaP256SignatureInfo()) + }) +}) + +describe('deserializeSignature', () => { + it('returns the signature', () => { + const test = deserializeSignature(fixtures.ecdsaP256SignatureInfo()) + expect(test).to.deep.equal(fixtures.ecdsaP256Signature()) + }) + + it('Precondition: There must be information for a signature.', () => { + expect(() => deserializeSignature({} as any)).to.throw() + }) + + it('Precondition: The signature length must be positive.', () => { + const badInfo = fixtures.ecdsaP256SignatureInfo() + badInfo[1] = 0 + expect(() => deserializeSignature(badInfo)).to.throw() + }) + + it('Precondition: The data must match the serialized length.', () => { + const badInfo = fixtures.ecdsaP256SignatureInfo() + badInfo[1] = badInfo[1] + 1 + expect(() => deserializeSignature(badInfo)).to.throw() + }) +}) From 8625eea0674b4076aaddf8aa077a722db594e1cd Mon Sep 17 00:00:00 2001 From: seebees Date: Mon, 8 Jul 2019 16:31:16 -0700 Subject: [PATCH 2/2] lint --- modules/serialize/test/fixtures.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/serialize/test/fixtures.ts b/modules/serialize/test/fixtures.ts index 9ed8d90c1..72aa8854e 100644 --- a/modules/serialize/test/fixtures.ts +++ b/modules/serialize/test/fixtures.ts @@ -69,10 +69,10 @@ export function encryptedDataKey () { return new Uint8Array([ 0, 2, 0, 12, 194, 189, 32, 43, 32, 194, 188, 32, 61, 32, 194, 190, 0, 8, 102, 105, 114, 115, 116, 75, 101, 121, 0, 5, 1, 2, 3, 4, 5, 0, 12, 194, 189, 32, 43, 32, 194, 188, 32, 61, 32, 194, 190, 0, 9, 115, 101, 99, 111, 110, 100, 75, 101, 121, 0, 5, 6, 7, 8, 9, 0 ]) } -export function ecdsaP256Signature() { +export function ecdsaP256Signature () { return new Uint8Array([48, 68, 2, 32, 22, 77, 187, 192, 175, 104, 2, 240, 55, 2, 6, 138, 103, 148, 214, 240, 244, 65, 224, 254, 60, 52, 218, 22, 250, 245, 216, 228, 151, 151, 220, 234, 2, 32, 125, 9, 97, 8, 132, 123, 79, 193, 216, 207, 214, 0, 73, 183, 149, 173, 26, 173, 251, 132, 140, 139, 44, 122, 11, 50, 163, 105, 138, 221, 223, 29]) } -export function ecdsaP256SignatureInfo() { +export function ecdsaP256SignatureInfo () { return new Uint8Array([0, 70, 48, 68, 2, 32, 22, 77, 187, 192, 175, 104, 2, 240, 55, 2, 6, 138, 103, 148, 214, 240, 244, 65, 224, 254, 60, 52, 218, 22, 250, 245, 216, 228, 151, 151, 220, 234, 2, 32, 125, 9, 97, 8, 132, 123, 79, 193, 216, 207, 214, 0, 73, 183, 149, 173, 26, 173, 251, 132, 140, 139, 44, 122, 11, 50, 163, 105, 138, 221, 223, 29]) -} \ No newline at end of file +}