-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move issue tests to independent files (#203)
- Loading branch information
Showing
8 changed files
with
102 additions
and
113 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
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Authenticator as AuthenticatorDefault } from '@otplib/core'; | ||
import { createDigest, createRandomBytes } from '@otplib/plugin-crypto'; | ||
import { keyDecoder, keyEncoder } from '@otplib/plugin-thirty-two'; | ||
|
||
const secret = 'KVKFKRCPNZQUYMLXOVYDSQKJKZDTSRLD'; | ||
const code = '123456'; | ||
|
||
function runTestIssue136(name, Authenticator) { | ||
const authenticator = new Authenticator(); | ||
|
||
test(`#136 - [${name}] option is reset if set via options setter`, async () => { | ||
expect.assertions(1); | ||
|
||
const instance = authenticator.create(); | ||
|
||
instance.options = { | ||
createDigest, | ||
createRandomBytes, | ||
keyEncoder, | ||
keyDecoder | ||
}; | ||
|
||
try { | ||
await instance.check(code, secret); | ||
instance.resetOptions(); | ||
await instance.check(code, secret); | ||
} catch (err) { | ||
expect(err).not.toBeUndefined(); | ||
} | ||
}); | ||
|
||
test(`#136 - [${name}] allow setting of persistent options via constructor / create`, async () => { | ||
expect.assertions(0); | ||
|
||
// @ts-ignore | ||
const instance = authenticator.create({ | ||
createDigest, | ||
createRandomBytes, | ||
keyEncoder, | ||
keyDecoder | ||
}); | ||
|
||
try { | ||
await instance.check(code, secret); | ||
instance.resetOptions(); | ||
await instance.check(code, secret); | ||
} catch (err) { | ||
expect(err).toBeUndefined(); | ||
} | ||
}); | ||
} | ||
|
||
runTestIssue136('Authenticator', AuthenticatorDefault); |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { authenticator as authenticatorDefault } from '@otplib/preset-default'; | ||
import { authenticator as authenticatorAsync } from '@otplib/preset-default-async'; | ||
import { authenticator as authenticatorBrowser } from '@otplib/preset-browser'; | ||
|
||
function runTestIssue7(name, authenticator) { | ||
test(`[${name}] sample 1`, async () => { | ||
authenticator.resetOptions(); | ||
const secret = 'xbja vgc6 gv4i i4qq h5ct 6stz ytcp ksiz'.replace(/ /g, ''); | ||
|
||
authenticator.options = { epoch: 1507953809 * 1000 }; | ||
const result = await authenticator.generate(secret); | ||
|
||
expect(result).toBe('849140'); | ||
}); | ||
|
||
test(`[${name}] sample 2`, async () => { | ||
authenticator.resetOptions(); | ||
const secret = 'SVT52XEZE2TWC2MU'; | ||
|
||
authenticator.options = { epoch: 1507908269 * 1000 }; | ||
const result = await authenticator.generate(secret); | ||
|
||
expect(result).toBe('334156'); | ||
}); | ||
} | ||
|
||
runTestIssue7('preset-default', authenticatorDefault); | ||
runTestIssue7('preset-default-async', authenticatorAsync); | ||
runTestIssue7('preset-browser', authenticatorBrowser); |
This file was deleted.
Oops, something went wrong.
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