-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
65 additions
and
133 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 |
---|---|---|
@@ -1,9 +1,34 @@ | ||
module Test.TOTP where | ||
|
||
import Chronos | ||
import Data.Maybe (fromJust) | ||
import OTP | ||
import Test.Tasty | ||
import Test.Tasty.HUnit | ||
import Torsor (scale) | ||
|
||
spec :: TestTree | ||
spec = | ||
testGroup | ||
"TOTP" | ||
[] | ||
[ testCase "TOTP counter from time" testTOTPCounterFromTime | ||
] | ||
|
||
testTOTPCounterFromTime :: Assertion | ||
testTOTPCounterFromTime = do | ||
let dtf = DatetimeFormat (Just '-') (Just ' ') (Just ':') | ||
let decode txt = datetimeToTime $ fromJust $ Chronos.decode_YmdHMS dtf txt | ||
assertEqual | ||
"Correct counter from date" | ||
(totpCounter (decode "2010-10-10 00:00:00") (scale 30 second)) | ||
42888960 | ||
|
||
assertEqual | ||
"Correct counter from date" | ||
(totpCounter (decode "2010-10-10 00:00:30") (scale 30 second)) | ||
42888961 | ||
|
||
assertEqual | ||
"Correct counter from date" | ||
(totpCounter (decode "2010-10-10 00:01:00") (scale 30 second)) | ||
42888962 |