-
Notifications
You must be signed in to change notification settings - Fork 63
test: Testing cacheing CMM #163
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
seebees
merged 3 commits into
aws:master
from
seebees:testing-caching_materials_manter_node
Jul 24, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { createHash } from 'crypto' | ||
|
||
export const sha512 = async (...data: (Uint8Array|string)[]) => data | ||
.map(item => typeof item === 'string' ? Buffer.from(item) : item) | ||
.reduce((hash, item) => hash.update(item), createHash('sha512')) | ||
.digest() |
62 changes: 62 additions & 0 deletions
62
modules/caching-materials-manager-node/test/caching_materials_manager_node.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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 { NodeCachingMaterialsManager } from '../src/index' | ||
import { } from '@aws-crypto/cache-material' | ||
import { | ||
KeyringNode, | ||
NodeDefaultCryptographicMaterialsManager, | ||
NodeEncryptionMaterial, // eslint-disable-line no-unused-vars | ||
NodeDecryptionMaterial // eslint-disable-line no-unused-vars | ||
} from '@aws-crypto/material-management-node' | ||
|
||
describe('NodeCachingMaterialsManager', () => { | ||
it('constructor will decorate', () => { | ||
class TestKeyring extends KeyringNode { | ||
async _onEncrypt (): Promise<NodeEncryptionMaterial> { | ||
throw new Error('never') | ||
} | ||
async _onDecrypt (): Promise<NodeDecryptionMaterial> { | ||
throw new Error('never') | ||
} | ||
} | ||
|
||
const keyring = new TestKeyring() | ||
const cache = 'cache' as any | ||
const partition = 'partition' | ||
const maxAge = 10 | ||
const maxBytesEncrypted = 11 | ||
const maxMessagesEncrypted = 12 | ||
const test = new NodeCachingMaterialsManager({ | ||
backingMaterials: keyring, | ||
cache, | ||
partition, | ||
maxAge, | ||
maxBytesEncrypted, | ||
maxMessagesEncrypted | ||
}) | ||
|
||
expect(test._backingMaterialsManager).to.be.instanceOf(NodeDefaultCryptographicMaterialsManager) | ||
expect(test._cache).to.equal(cache) | ||
expect(test._partition).to.equal(partition) | ||
expect(test._maxAge).to.equal(maxAge) | ||
expect(test._maxBytesEncrypted).to.equal(maxBytesEncrypted) | ||
expect(test._maxMessagesEncrypted).to.equal(maxMessagesEncrypted) | ||
}) | ||
}) |
42 changes: 42 additions & 0 deletions
42
modules/caching-materials-manager-node/test/sha512.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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 { sha512 } from '../src/sha512' | ||
|
||
// sha512('asdf') | ||
const fixture = Buffer.from('QBsJ6rPAE9TKVJIruAK+yP1TGBkrCnXyAdizcnQpCA+zN1kavT5ERTuVRVW3oIEuEIHDm3QCk/dl6ucx9aZe0Q==', 'base64') | ||
|
||
describe('WebCryptoCachingMaterialsManager', () => { | ||
it('can hash a string', async () => { | ||
const test = await sha512('asdf') | ||
expect(test).to.deep.equal(fixture) | ||
}) | ||
|
||
it('can hash a Uint8Array', async () => { | ||
// the string 'asdf' as utf-8 encoded bytes | ||
const test = await sha512(Buffer.from([ 97, 115, 100, 102 ])) | ||
expect(test).to.deep.equal(fixture) | ||
}) | ||
|
||
it('can hash a mix of arguments', async () => { | ||
// the string 'asdf' as a mix of strings and binary | ||
const test = await sha512('a', new Uint8Array([115]), 'd', Buffer.from([102])) | ||
expect(test).to.deep.equal(fixture) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be base64(sha512('asdf'))?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are not wrong. I left the base64 off because the important part was the 'asdf'