-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsaaspass_test.go
56 lines (49 loc) · 1.22 KB
/
saaspass_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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package saaspass
import (
"crypto/rand"
"fmt"
"io"
"testing"
)
// Generate a dummy session id to use in generating qr codes
func NewSessionID() (string, error) {
uuid := make([]byte, 16)
n, err := io.ReadFull(rand.Reader, uuid)
if n != len(uuid) || err != nil {
return "", err
}
uuid[8] = uuid[8]&^0xc0 | 0x80
uuid[6] = uuid[6]&^0xf0 | 0x40
return fmt.Sprintf("%x0%x1%x2%x3%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:]), nil
}
func TestCredentials(t *testing.T) {
cr := new(APICredentials).SetCredentials()
if cr == (APICredentials{}) {
t.Fatalf("No ENV")
}
}
func TestAuthentication(t *testing.T) {
m := new(APICredentials).SetCredentials()
au := new(AuthToken).GetAuth(m)
if au == (AuthToken{}) {
t.Fatalf("Falls Over No Auth")
}
}
func TestOTP(t *testing.T) {
apr := new(AuthPair).GeneratePair()
_, err := apr.CheckOTP("[email protected]", "239144")
if err != nil {
fmt.Println(err)
}
}
func TestBarcode(t *testing.T) {
sess, _ := NewSessionID()
apr := new(AuthPair).GeneratePair()
if apr.CheckTokenLife() {
bcd := &BarCode{Session: sess, CodeType: "ILBT", User: "[email protected]"}
_, err := apr.GetBarCodeImage(bcd)
if err != nil {
t.Fatalf("BarCode generation failed")
}
}
}