mirror of
https://github.com/jech/galene.git
synced 2024-12-22 15:25:48 +01:00
Add unit test for makePassword.
This commit is contained in:
parent
3f24625fe0
commit
9d07dd27ad
1 changed files with 40 additions and 0 deletions
40
galenectl/galenectl_test.go
Normal file
40
galenectl/galenectl_test.go
Normal file
|
@ -0,0 +1,40 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/jech/galene/group"
|
||||
)
|
||||
|
||||
func TestMakePassword(t *testing.T) {
|
||||
doit := func(pw group.Password) {
|
||||
ok, _ := pw.Match("secret")
|
||||
if !ok {
|
||||
t.Errorf("%v didn't match", pw)
|
||||
}
|
||||
ok, _ = pw.Match("notsecret")
|
||||
if ok {
|
||||
t.Errorf("%v did match", pw)
|
||||
}
|
||||
}
|
||||
pw, err := makePassword("secret", "pbkdf2", 4096, 32, 8, 0)
|
||||
if err != nil {
|
||||
t.Errorf("PBKDF2: %v", err)
|
||||
}
|
||||
doit(pw)
|
||||
|
||||
pw, err = makePassword("secret", "bcrypt", 0, 0, 0, 10)
|
||||
if err != nil {
|
||||
t.Errorf("bcrypt: %v", err)
|
||||
}
|
||||
doit(pw)
|
||||
|
||||
pw, err = makePassword("", "wildcard", 0, 0, 0, 0)
|
||||
if err != nil {
|
||||
t.Errorf("Wildcard: %v", err)
|
||||
}
|
||||
ok, _ := pw.Match("notsecretatall")
|
||||
if !ok {
|
||||
t.Errorf("Wildcard didn't match")
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue