-
Notifications
You must be signed in to change notification settings - Fork 0
/
security_test.go
97 lines (89 loc) · 2.65 KB
/
security_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package oauth
import (
"testing"
)
var _sutRC4, _sutSHA256 *TokenProvider
func init() {
_sutRC4 = NewTokenProvider(NewRC4TokenSecurityProvider([]byte("testkey")))
_sutSHA256 = NewTokenProvider(NewSHA256RC4TokenSecurityProvider([]byte("testkey")))
}
func TestCrypt(t *testing.T) {
var token string = `{"CreationDate":"2016-12-14","Expiration":"1000"}`
result, err := _sutRC4.crypt([]byte(token))
if err != nil {
t.Fatalf("Error %s", err.Error())
}
t.Logf("Base64 Token : %v", result)
}
func TestDecrypt(t *testing.T) {
var token string = `{"CreationDate":"2016-12-14","Expiration":"1000"}`
var bToken []byte = []byte(token)
t.Logf("Base64 Token : %v", bToken)
result, err := _sutRC4.crypt([]byte(token))
if err != nil {
t.Fatalf("Error %s", err.Error())
}
t.Logf("Base64 Token : %v", result)
decrypt, err := _sutRC4.decrypt(result)
if err != nil {
t.Fatalf("Error %s", err.Error())
}
t.Logf("Base64 Token Decrypted: %v", decrypt)
t.Logf("Base64 Token Decrypted: %s", decrypt)
for i := range bToken {
if bToken[i] != decrypt[i] {
t.Fatalf("Error in decryption")
}
}
}
func TestCryptSHA256(t *testing.T) {
var token string = `{"CreationDate":"2016-12-14","Expiration":"1000"}`
result, err := _sutSHA256.crypt([]byte(token))
if err != nil {
t.Fatalf("Error %s", err.Error())
}
t.Logf("Base64 Token : %v", result)
}
func TestDecryptSHA256(t *testing.T) {
var token string = `{"CreationDate":"2016-12-14","Expiration":"1000"}`
var bToken []byte = []byte(token)
t.Logf("Base64 Token : %v", bToken)
result, err := _sutSHA256.crypt([]byte(token))
if err != nil {
t.Fatalf("Error %s", err.Error())
}
t.Logf("Base64 Token : %v", result)
decrypt, err := _sutSHA256.decrypt(result)
if err != nil {
t.Fatalf("Error %s", err.Error())
}
t.Logf("Base64 Token Decrypted: %v", decrypt)
t.Logf("Base64 Token Decrypted: %s", decrypt)
for i := range bToken {
if bToken[i] != decrypt[i] {
t.Fatalf("Error in decryption")
}
}
}
func TestDecryptSHA256_LongKey(t *testing.T) {
sutSHA256 := NewTokenProvider(NewSHA256RC4TokenSecurityProvider([]byte("518baffa-b290-4c01-a150-1980f5b06a01")))
var token string = `{"CreationDate":"2016-12-14","Expiration":"1000"}`
var bToken []byte = []byte(token)
t.Logf("Base64 Token : %v", bToken)
result, err := sutSHA256.crypt([]byte(token))
if err != nil {
t.Fatalf("Error %s", err.Error())
}
t.Logf("Base64 Token : %v", result)
decrypt, err := sutSHA256.decrypt(result)
if err != nil {
t.Fatalf("Error %s", err.Error())
}
t.Logf("Base64 Token Decrypted: %v", decrypt)
t.Logf("Base64 Token Decrypted: %s", decrypt)
for i := range bToken {
if bToken[i] != decrypt[i] {
t.Fatalf("Error in decryption")
}
}
}