Add unit tests for getExpirationTime Key method

This commit is contained in:
Thomas Oberndörfer 2014-02-06 12:28:36 +01:00
parent a595d683a9
commit b1e8c9ec52
2 changed files with 16 additions and 1 deletions

View File

@ -470,7 +470,7 @@ function getExpirationTime(keyPacket, selfCertificate) {
return new Date(keyPacket.created.getTime() + keyPacket.expirationTimeV3*24*3600*1000);
}
// check V4 expiration time
if (this.primaryKey.version == 4 && selfCertificate.keyNeverExpires === false) {
if (keyPacket.version == 4 && selfCertificate.keyNeverExpires === false) {
return new Date(keyPacket.created.getTime() + selfCertificate.keyExpirationTime*1000);
}
return null;

View File

@ -293,5 +293,20 @@ describe('Key', function() {
expect(status).to.equal(openpgp.enums.keyStatus.revoked);
done();
});
it('Method getExpirationTime V4 Key', function() {
var pubKey = openpgp.key.readArmored(twoKeys).keys[1];
expect(pubKey).to.exist;
expect(pubKey).to.be.an.instanceof(openpgp.key.Key);
expect(pubKey.getExpirationTime().toISOString()).to.be.equal('2018-11-26T10:58:29.000Z');
});
it('Method getExpirationTime V4 SubKey', function() {
var pubKey = openpgp.key.readArmored(twoKeys).keys[1];
expect(pubKey).to.exist;
expect(pubKey).to.be.an.instanceof(openpgp.key.Key);
expect(pubKey.subKeys[0].getExpirationTime().toISOString()).to.be.equal('2018-11-26T10:58:29.000Z');
});
});