Skip to content

Commit

Permalink
cleaned up tests by using async and await
Browse files Browse the repository at this point in the history
  • Loading branch information
erdtman committed Nov 2, 2021
1 parent e723ddd commit c7f2357
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 277 deletions.
37 changes: 17 additions & 20 deletions test/sign-performance-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const base64url = require('base64url');
const cbor = require('cbor');
const jsonfile = require('jsonfile');

test('create and verify really huge payload', (t) => {
test('create and verify really huge payload', async (t) => {
// uses the keys from here but it has nothing to do with the test
const example = jsonfile.readFileSync('test/Examples/sign-tests/ecdsa-01.json');

const BIG_LENGHT = 100 * 1000;
const p = example.input.sign.protected;
const u = example.input.sign.unprotected;
const signers = [{
Expand All @@ -21,7 +21,7 @@ test('create and verify really huge payload', (t) => {
u: example.input.sign.signers[0].unprotected,
p: example.input.sign.signers[0].protected
}];
const plaintext = Buffer.from('a'.repeat(100 * 1000));
const plaintext = Buffer.from('a'.repeat(BIG_LENGHT));

const verifier = {
key: {
Expand All @@ -31,24 +31,21 @@ test('create and verify really huge payload', (t) => {
}
};

return cose.sign.create(
const buf = await cose.sign.create(
{ p: p, u: u },
plaintext,
signers
)
.then((buf) => {
t.true(Buffer.isBuffer(buf));
t.true(buf.length > 0);
return cbor.decodeFirst(buf)
.then(actual => {
t.is(actual.value[2].length, 100 * 1000);
})
.then(() => buf);
})
.then(buf => cose.sign.verify(buf, verifier))
.then(buf => {
t.true(Buffer.isBuffer(buf));
t.true(buf.length > 0);
t.is(buf.toString('utf8'), plaintext.toString('utf8'));
});
);

t.true(Buffer.isBuffer(buf));
t.true(buf.length > 0);

const actual = await cbor.decodeFirst(buf);
t.is(actual.value[2].length, BIG_LENGHT);

const verifiedBuf = await cose.sign.verify(buf, verifier);

t.true(Buffer.isBuffer(verifiedBuf));
t.true(verifiedBuf.length > 0);
t.is(verifiedBuf.toString('utf8'), plaintext.toString('utf8'));
});
Loading

0 comments on commit c7f2357

Please sign in to comment.