Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Defines TransitProvider#renew for decrypting ciphertext.
Browse files Browse the repository at this point in the history
  • Loading branch information
onefrankguy committed Sep 30, 2016
1 parent f47202e commit d06b7cc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/providers/transit.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ class TransitProvider {
return this._decrypt();
}

/**
* Decrypt the ciphertext
*
* @return {Promise} - Resolves with decrypted ciphertext; rejects with an Error if decryption fails
*/
renew() {
return this._decrypt();
}

/**
* Decrypt the ciphertext using Vault's /transit/decrypt/ API
*
Expand Down
36 changes: 36 additions & 0 deletions test/provider-transit.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,40 @@ describe('Provider/Transit', function () {
.catch(done);
});
});

describe('TransitProvider#renew', function () {
it('calls Vault every time when renewing', function (done) {
const transit = new TransitProvider('KEY', 'TOKEN', {ciphertext: 'CTEXT'});

localVaultMock.post('/v1/transit/decrypt/KEY', {
ciphertext: 'CTEXT'
})
.reply(STATUS_CODES.OK, {
plaintext: 'PTEXT'
})
.post('/v1/transit/decrypt/KEY', {
ciphertext: 'CTEXT'
})
.reply(STATUS_CODES.OK, {
plaintext: 'PTEXT'
});

transit.renew()
.then((retrievedPlaintext) => {
should(retrievedPlaintext).eql({
plaintext: 'PTEXT'
});
})
.then(() => transit.renew())
.then((renewedPlaintext) => {
should(renewedPlaintext).eql({
plaintext: 'PTEXT'
});

localVaultMock.done();
done();
})
.catch(done);
});
});
});

0 comments on commit d06b7cc

Please sign in to comment.