Skip to content

Commit bad0642

Browse files
reword and add test
1 parent 3950fd9 commit bad0642

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

__tests__/core/totp.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2020-present, Elastic NV
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
*/
25+
26+
import { createTOTP } from '../../src/core/totp';
27+
28+
describe('TOTP', () => {
29+
it('generate one time token', () => {
30+
const totp = createTOTP({ secret: "FLIIOLP3IR3W" });
31+
expect(totp.generate().length).toBe(6);
32+
expect(totp.toString()).toEqual('otpauth://totp/SyntheticsTOTP?secret=FLIIOLP3IR3Q&algorithm=SHA1&digits=6&period=30')
33+
});
34+
});
35+
36+
37+

src/core/totp.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ import { TOTP } from "otpauth";
2727

2828
type TOTPOptions = {
2929
/**
30-
* Service provider name.
30+
* Provider or Service the secret is associated with
3131
*/
3232
issuer?: string
3333
/**
3434
* Account Identifier.
35+
* @default 'SyntheticsTOTP'
3536
*/
3637
label?: string
3738
/**
@@ -48,17 +49,17 @@ type TOTPOptions = {
4849
*/
4950
algorithm?: string
5051
/**
51-
* Length of the generated token.
52+
* Number of digits in the generated token.
5253
* @default 6
5354
*/
5455
digits?: number
5556
/**
56-
* Interval in seconds for which the token is valid.
57+
* Validity period in seconds for the token.
5758
* @default 30
5859
*/
5960
period?: number
6061
};
6162

6263
export function createTOTP(options: TOTPOptions) {
63-
return new TOTP({ ...options });
64+
return new TOTP({ label: "SyntheticsTOTP", ...options });
6465
}

0 commit comments

Comments
 (0)