-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix forwarding helpers: accept `date` option and use serverTime instead of local time by default
- Loading branch information
Showing
5 changed files
with
29 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ import { | |
getMatchingKey, | ||
generateSessionKeyForAlgorithm, | ||
generateSessionKey, | ||
getSHA256Fingerprints | ||
getSHA256Fingerprints, | ||
serverTime | ||
} from '../../lib'; | ||
|
||
describe('key utils', () => { | ||
|
@@ -39,7 +40,7 @@ describe('key utils', () => { | |
userIDs: [{ name: 'name', email: '[email protected]' }], | ||
format: 'object' | ||
}); | ||
const now = new Date(); | ||
const now = serverTime(); | ||
expect(Math.abs(+privateKey.getCreationTime() - +now) < 24 * 3600).to.be.true; | ||
}); | ||
|
||
|
@@ -48,7 +49,7 @@ describe('key utils', () => { | |
userIDs: [{ name: 'name', email: '[email protected]' }], | ||
format: 'object' | ||
}); | ||
const { selfCertification } = await privateKey.getPrimaryUser(); | ||
const { selfCertification } = await privateKey.getPrimaryUser(serverTime()); | ||
expect(selfCertification.preferredSymmetricAlgorithms).to.include(enums.symmetric.aes256); | ||
expect(selfCertification.preferredHashAlgorithms).to.include(enums.hash.sha256); | ||
expect(selfCertification.preferredCompressionAlgorithms).to.include(enums.compression.zlib); | ||
|
@@ -70,7 +71,7 @@ describe('key utils', () => { | |
}); | ||
|
||
it('isExpiredKey - it can correctly detect an expired key', async () => { | ||
const now = new Date(); | ||
const now = serverTime(); | ||
// key expires in one second | ||
const { privateKey: expiringKey } = await generateKey({ | ||
userIDs: [{ name: 'name', email: '[email protected]' }], | ||
|
@@ -93,7 +94,7 @@ describe('key utils', () => { | |
|
||
it('isRevokedKey - it can correctly detect a revoked key', async () => { | ||
const past = new Date(0); | ||
const now = new Date(); | ||
const now = serverTime(); | ||
|
||
const { privateKey: key, revocationCertificate } = await generateKey({ | ||
userIDs: [{ name: 'name', email: '[email protected]' }], | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { expect } from 'chai'; | ||
import { verifyMessage, signMessage, generateKey, readSignature, readMessage, decryptMessage, encryptMessage, readKey, ContextError } from '../../lib'; | ||
import { verifyMessage, signMessage, generateKey, readSignature, readMessage, decryptMessage, encryptMessage, readKey, ContextError, serverTime } from '../../lib'; | ||
import { VERIFICATION_STATUS } from '../../lib/constants'; | ||
|
||
// verification without passing context should fail | ||
|
@@ -233,7 +233,7 @@ describe('context', () => { | |
}); | ||
|
||
it('does not verify a message without context based on cutoff date (`expectFrom`)', async () => { | ||
const now = new Date(); | ||
const now = serverTime(); | ||
const nextHour = new Date(+now + (3600 * 1000)); | ||
const { privateKey, publicKey } = await generateKey({ | ||
userIDs: [{ name: 'name', email: '[email protected]' }], | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import { use as chaiUse } from 'chai'; | ||
import * as chaiAsPromised from 'chai-as-promised'; | ||
|
||
import { init } from '../lib'; | ||
import { init, updateServerTime } from '../lib'; | ||
|
||
chaiUse(chaiAsPromised); | ||
before(init); | ||
before(() => { | ||
// set server time in the future to spot functions that use local time unexpectedly | ||
const HOUR = 3600 * 1000; | ||
updateServerTime(new Date(Date.now() + HOUR)); | ||
init(); | ||
}); |