From 9d07dd27ad1d7c793fca4a1cd48736b4510c09b9 Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Wed, 23 Oct 2024 20:28:52 +0200 Subject: [PATCH] Add unit test for makePassword. --- galenectl/galenectl_test.go | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 galenectl/galenectl_test.go diff --git a/galenectl/galenectl_test.go b/galenectl/galenectl_test.go new file mode 100644 index 0000000..cb9431a --- /dev/null +++ b/galenectl/galenectl_test.go @@ -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") + } +}