Skip to content

fix: Add tests for signature info #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions modules/serialize/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
51 changes: 51 additions & 0 deletions modules/serialize/test/signature_info.test.ts
Original file line number Diff line number Diff line change
@@ -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()
})
})