-
Notifications
You must be signed in to change notification settings - Fork 0
/
hrm_test.go
112 lines (95 loc) · 2.82 KB
/
hrm_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package PasetoprojectBackend
import (
"fmt"
"github.com/whatsauth/watoken"
"testing"
)
var privatekey = "privatekey"
var publickeyb = "publickey"
var encode = "encode"
func TestGenerateKeyPASETO(t *testing.T) {
privateKey, publicKey := watoken.GenerateKey()
fmt.Println(privateKey)
fmt.Println(publicKey)
hasil, err := watoken.Encode("asoy", privateKey)
fmt.Println(hasil, err)
}
func TestHashPass(t *testing.T) {
password := "cihuypass"
Hashedpass, err := HashPass(password)
fmt.Println("error : ", err)
fmt.Println("Hash : ", Hashedpass)
}
func TestHashFunc(t *testing.T) {
conn := MongoCreateConnection("MONGOSTRING", "HRMApp")
userdata := new(User)
userdata.Username = "cihuy"
userdata.Password = "cihuypass"
data := GetOneUser(conn, "user", User{
Username: userdata.Username,
Password: userdata.Password,
})
fmt.Printf("%+v", data)
fmt.Println(" ")
hashpass, _ := HashPass(userdata.Password)
fmt.Println("Hasil hash : ", hashpass)
compared := CompareHashPass(userdata.Password, data.Password)
fmt.Println("result : ", compared)
}
func TestTokenEncoder(t *testing.T) {
conn := MongoCreateConnection("MONGOSTR", "HRMApp")
privateKey, publicKey := watoken.GenerateKey()
userdata := new(User)
userdata.Username = "cihuy"
userdata.Password = "cihuypass"
data := GetOneUser(conn, "user", User{
Username: userdata.Username,
Password: userdata.Password,
})
fmt.Println("Private Key : ", privateKey)
fmt.Println("Public Key : ", publicKey)
fmt.Printf("%+v", data)
fmt.Println(" ")
encode := TokenEncoder(data.Username, privateKey)
fmt.Printf("%+v", encode)
}
func TestInsertUserdata(t *testing.T) {
conn := MongoCreateConnection("MONGOSTRING", "HRMApp")
password, err := HashPass("rofiganteng")
fmt.Println("err", err)
data := InsertUserdata(conn, "rofi", "role", password)
fmt.Println(data)
}
func TestDecodeToken(t *testing.T) {
deco := watoken.DecodeGetId("public",
"token")
fmt.Println(deco)
}
func TestCompareUsername(t *testing.T) {
conn := MongoCreateConnection("MONGOSTRING", "HRMApp")
deco := watoken.DecodeGetId("public",
"token")
compare := CompareUsername(conn, "user", deco)
fmt.Println(compare)
}
func TestEncodeWithRole(t *testing.T) {
privateKey, publicKey := watoken.GenerateKey()
role := "admin"
username := "cihuy"
encoder, err := EncodeWithRole(role, username, privateKey)
fmt.Println(" error :", err)
fmt.Println("Private :", privateKey)
fmt.Println("Public :", publicKey)
fmt.Println("encode: ", encoder)
}
func TestDecoder2(t *testing.T) {
pay, err := Decoder(publickeyb, encode)
user, _ := DecodeGetUser(publickeyb, encode)
role, _ := DecodeGetRole(publickeyb, encode)
use, ro := DecodeGetRoleandUser(publickeyb, encode)
fmt.Println("user :", user)
fmt.Println("role :", role)
fmt.Println("user and role :", use, ro)
fmt.Println("err : ", err)
fmt.Println("payload : ", pay)
}