github.com/webx-top/com@v1.2.12/password_test.go (about) 1 package com 2 3 import ( 4 "crypto/sha1" 5 "fmt" 6 "testing" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestMakePassword(t *testing.T) { 12 hashed := MakePassword(`github.com/webx-top/com`, ``) 13 fmt.Println(`hashed`, hashed, len(hashed)) 14 if CheckPassword(`github.com/webx-top/com`, hashed, ``) == false { 15 t.Errorf(`The passwords do not match`) 16 } 17 salt := Salt() 18 fmt.Println(`salt:`, salt) 19 hashed = MakePassword(`github.com/webx-top/com`, salt, 2, 4, 6, 8, 13, 19, 32) 20 fmt.Println(`hashed`, hashed, len(hashed)) 21 if CheckPassword(`github.com/webx-top/com`, hashed, salt, 2, 4, 6, 8, 13, 19, 32) == false { 22 t.Errorf(`The passwords do not match`) 23 } 24 salt = Salt() 25 hashed = MakePassword(`github.com/webx-top/com`, salt, 13) 26 fmt.Println(`hashed`, hashed, len(hashed)) 27 if CheckPassword(`github.com/webx-top/com`, hashed, salt, 13) == false { 28 t.Errorf(`The passwords do not match`) 29 } 30 salt = `github.com/webx-top/com` 31 dk := PBKDF2Key([]byte("some password"), []byte(salt), 4096, 32, sha1.New) 32 fmt.Println(`PBKDF2:`, string(dk)) 33 } 34 35 func TestAbsURL(t *testing.T) { 36 pageURL := AbsURL(`https://www.coscms.com/system/download/index`, `../download2/index`) 37 assert.Equal(t, `https://www.coscms.com/system/download2/index`, pageURL) 38 39 pageURL = AbsURL(`https://www.coscms.com/system/download/index`, `../../system2/download2/index`) 40 assert.Equal(t, `https://www.coscms.com/system2/download2/index`, pageURL) 41 42 pageURL = AbsURL(`https://www.coscms.com/system/download/index`, `/payment/index/index`) 43 assert.Equal(t, `https://www.coscms.com/payment/index/index`, pageURL) 44 45 pageURL = AbsURL(`https://www.coscms.com/system/download/index`, `./payment/index/index`) 46 assert.Equal(t, `https://www.coscms.com/system/download/payment/index/index`, pageURL) 47 48 fmt.Println(`SelfDir:`, SelfDir()) 49 fmt.Println(`SelfPath:`, SelfPath()) 50 }