/
gcfbackend_test.go
69 lines (57 loc) · 1.78 KB
/
gcfbackend_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
package gcfbackend
import (
"fmt"
"testing"
"github.com/aiteung/atdb"
"github.com/whatsauth/watoken"
"go.mongodb.org/mongo-driver/bson"
)
// func TestUpdateGetData(t *testing.T) {
// mconn := SetConnection("MONGOSTRING", "healhero_db")
// datagedung := GetAllBangunanLineString(mconn, "healhero_db")
// fmt.Println(datagedung)
// }
func TestGeneratePasswordHash(t *testing.T) {
password := "riziq"
hash, _ := HashPassword(password) // ignore error for the sake of simplicity
fmt.Println("Password:", password)
fmt.Println("Hash: ", hash)
match := CheckPasswordHash(password, hash)
fmt.Println("Match: ", match)
}
func TestGeneratePrivateKeyPaseto(t *testing.T) {
privateKey, publicKey := watoken.GenerateKey()
fmt.Println(privateKey)
fmt.Println(publicKey)
hasil, err := watoken.Encode("coba", privateKey)
fmt.Println(hasil, err)
}
func TestHashFunction(t *testing.T) {
mconn := SetConnection("MONGOSTRING", "hppinjam")
var userdata User
userdata.Username = "coba"
userdata.Password = "riziq"
filter := bson.M{"username": userdata.Username}
res := atdb.GetOneDoc[User](mconn, "user", filter)
fmt.Println("Mongo User Result: ", res)
hash, _ := HashPassword(userdata.Password)
fmt.Println("Hash Password : ", hash)
match := CheckPasswordHash(userdata.Password, res.Password)
fmt.Println("Match: ", match)
}
func TestIsPasswordValid(t *testing.T) {
mconn := SetConnection("MONGOSTRING", "hppinjam")
var userdata User
userdata.Username = "coba"
userdata.Password = "riziq"
anu := IsPasswordValid(mconn, "user", userdata)
fmt.Println(anu)
}
func TestInsertUser(t *testing.T) {
mconn := SetConnection("MONGOSTRING", "hppinjam")
var userdata User
userdata.Username = "coba"
userdata.Password = "riziq"
nama := InsertUser(mconn, "user", userdata)
fmt.Println(nama)
}