Skip to content
This repository was archived by the owner on Feb 25, 2019. It is now read-only.

Commit

Permalink
test(JWK): added tests for authenticated additionalData (aad)
Browse files Browse the repository at this point in the history
  • Loading branch information
EternalDeiwos committed Aug 21, 2017
1 parent 793b322 commit 68dd2dd
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions test/JWKSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ const ECPublicJWKNoKid = Object.assign({}, ECPublicJWK)
delete ECPublicJWKNoKid.kid

const plainTextData = 'data'
const plainTextAad = 'meta'
const encryptedData = {"iv":"RH9i_J861XN7qvgHYZ86ag","ciphertext":"qkrkiw","tag":"kqfdLgy8qopnzeKmC5JwQA"}
const encryptedDataWithAad = {"iv":"zrXJWOthT2tnFErPhWCrfw","ciphertext":"JWwKBg","tag":"txl7BQK4fxEP5cie2OQEZA","aad":"bWV0YQ"}
const signedData = 'MEQCIAIqNr8-7Pozi1D-cigvEKbkP5SpKezzEEDSqM9McIV1AiBd4gioW8njOpr29Ymrvjp46q7hA7lSOjAJpdi5TjHWsg'

/**
Expand Down Expand Up @@ -169,6 +171,19 @@ describe('JWK', () => {
data.should.haveOwnProperty('ciphertext')
data.should.haveOwnProperty('iv')
data.should.haveOwnProperty('tag')
data.should.not.haveOwnProperty('aad')
})
})

describe('with aad', () => {

it('should resolve encrypted data', () => {
return jwk.encrypt(plainTextData, plainTextAad).then(data => {
data.should.haveOwnProperty('ciphertext')
data.should.haveOwnProperty('iv')
data.should.haveOwnProperty('tag')
data.should.haveOwnProperty('aad')
})
})
})
})
Expand All @@ -182,12 +197,25 @@ describe('JWK', () => {

it('should return a promise', () => {
let { ciphertext, iv, tag } = encryptedData
return jwk.decrypt(ciphertext, iv, tag, Buffer.from('')).should.be.fulfilled
return jwk.decrypt(ciphertext, iv, tag).should.be.fulfilled
})

it('should resolve plain text data', () => {
let { ciphertext, iv, tag } = encryptedData
return jwk.decrypt(ciphertext, iv, tag, Buffer.from('')).should.eventually.equal(plainTextData)
return jwk.decrypt(ciphertext, iv, tag).should.eventually.equal(plainTextData)
})

describe('with aad', () => {

it('should reject if aad is omitted', () => {
let { ciphertext, iv, tag } = encryptedDataWithAad
return jwk.decrypt(ciphertext, iv, tag).should.be.rejected
})

it('should resolve plain text data', () => {
let { ciphertext, iv, tag, aad } = encryptedDataWithAad
return jwk.decrypt(ciphertext, iv, tag, aad).should.eventually.equal(plainTextData)
})
})
})
})

0 comments on commit 68dd2dd

Please sign in to comment.