-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtotp_test.go
26 lines (23 loc) · 3.21 KB
/
totp_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//
// totp_test.go
// Copyright (C) 2016 tinyproxy <[email protected]>
//
// Distributed under terms of the MIT license.
//
package gootp
import "testing"
func TestTOTP(t *testing.T) {
secret := []byte("it works")
digits := 6
x := 30
totp := NewTOTP(secret, digits, x)
timestamps := []int64{1464624399, 1464624400, 1464624401, 1464624402, 1464624403, 1464624404, 1464624405, 1464624406, 1464624407, 1464624408, 1464624409, 1464624410, 1464624411, 1464624412, 1464624413, 1464624414, 1464624415, 1464624416, 1464624417, 1464624418, 1464624419, 1464624420, 1464624421, 1464624422, 1464624423, 1464624424, 1464624425, 1464624426, 1464624427, 1464624428, 1464624429, 1464624430, 1464624431, 1464624432, 1464624433, 1464624434, 1464624435, 1464624436, 1464624437, 1464624438, 1464624439, 1464624440, 1464624441, 1464624442, 1464624443, 1464624444, 1464624445, 1464624446, 1464624447, 1464624448, 1464624449, 1464624450, 1464624451, 1464624452, 1464624453, 1464624454, 1464624455, 1464624456, 1464624457, 1464624458, 1464624459, 1464624460, 1464624461, 1464624462, 1464624463, 1464624464, 1464624465, 1464624466, 1464624467, 1464624468, 1464624469, 1464624470, 1464624471, 1464624472, 1464624473, 1464624474, 1464624475, 1464624476, 1464624477, 1464624478, 1464624479, 1464624480, 1464624481, 1464624482, 1464624483, 1464624484, 1464624485, 1464624486, 1464624487, 1464624488, 1464624489, 1464624490, 1464624491, 1464624492, 1464624493, 1464624494, 1464624495, 1464624496, 1464624497, 1464624498, 1464624499, 1464624500, 1464624501, 1464624502, 1464624503, 1464624504, 1464624505, 1464624506, 1464624507, 1464624508, 1464624509, 1464624510, 1464624511, 1464624512, 1464624513, 1464624514, 1464624515, 1464624516, 1464624517, 1464624518, 1464624519, 1464624520, 1464624521, 1464624522, 1464624523, 1464624524, 1464624525, 1464624526}
codes := []string{"772642", "772642", "772642", "772642", "772642", "772642", "772642", "772642", "772642", "772642", "772642", "772642", "772642", "772642", "772642", "772642", "772642", "772642", "772642", "772642", "772642", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "057177", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "258213", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "127445", "306063", "306063", "306063", "306063", "306063", "306063", "306063", "306063", "306063", "306063", "306063", "306063", "306063", "306063", "306063", "306063", "306063"}
for index, timestamp := range timestamps {
realCode := totp.At(timestamp)
if realCode != codes[index] {
t.Error("fail")
return
}
}
}