Created
May 2, 2019 20:29
-
-
Save codebudo/09d2b91b03ba3293f293d739ef6031fe to your computer and use it in GitHub Desktop.
Kinda pseudocode test describing the use of beforeEach to create input data for a test.
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
/* eslint-env node, mocha */ | |
const should = require('should'); | |
describe('Some encrypt/decrypt test', function(){ | |
const passphrase = 'good passphrases are long'; | |
const passphraseIV = Buffer.from('AAAAAAAAAAAAAAAAAAAAAA==', 'base64'); | |
let fileBlob = 'start'; | |
let ciphertext = null; | |
let nock = require('nock'); | |
// 'after' does not need to respect top-down ordering | |
after( function(){ | |
nock.enableNetConnect(); | |
}) | |
beforeEach( function(){ | |
return new Promise( async function(accept){ | |
// expand fileBlob size | |
while( fileBlob.length < 5 * 16 * 1024 ){ | |
fileBlob += '0'; | |
} | |
fileBlob += 'end'; | |
nock.cleanAll(); | |
nock.disableNetConnect(); | |
// generate key from passphrase | |
let key = await keyDerivationFunction(passphrase, passphraseIV); | |
let ciphertext = await encryptFunction(key, fileBlob); | |
}); | |
}); // end before | |
it('should decrypt a blob in memory', async function(done){ | |
let plaintext = await decryptFunction(key, ciphertext) | |
.catch( (err) => { | |
done(err); | |
}); | |
plaintext.should.equal(fileBlob); | |
done(); | |
}); | |
// disabled test | |
xit('should decrypt a blob to stream', function(done){ | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment