2022-12-07 14:19:04 -07:00
|
|
|
package unix_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/matryer/is"
|
|
|
|
|
|
|
|
"github.com/sour-is/go-passwd"
|
|
|
|
"github.com/sour-is/go-passwd/pkg/unix"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPasswdHash(t *testing.T) {
|
|
|
|
type testCase struct {
|
2022-12-10 08:58:08 -07:00
|
|
|
pass, hash []byte
|
2022-12-07 14:19:04 -07:00
|
|
|
}
|
2022-12-09 10:05:39 -07:00
|
|
|
|
2022-12-07 14:19:04 -07:00
|
|
|
tests := []testCase{
|
2022-12-10 08:58:08 -07:00
|
|
|
{[]byte("passwd"), []byte("$1$76a2173be6393254e72ffa4d6df1030a")},
|
|
|
|
{[]byte("passwd"), []byte("$2a$10$GkJwB.nOaaeAvRGgyl2TI.kruM8e.iIo.OozgdslegpNlC/vIFKRq")},
|
2022-12-07 14:19:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
is := is.New(t)
|
|
|
|
// Generate additional test cases for each algo.
|
|
|
|
for _, algo := range unix.All {
|
2022-12-10 08:58:08 -07:00
|
|
|
hash, err := algo.Passwd([]byte("passwd"), nil)
|
2022-12-07 14:19:04 -07:00
|
|
|
is.NoErr(err)
|
2022-12-10 08:58:08 -07:00
|
|
|
tests = append(tests, testCase{[]byte("passwd"), hash})
|
2022-12-07 14:19:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pass := passwd.New(unix.All...)
|
|
|
|
|
|
|
|
for i, tt := range tests {
|
|
|
|
t.Run(fmt.Sprint("Test-", i), func(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
|
|
|
|
hash, err := pass.Passwd(tt.pass, tt.hash)
|
2022-12-10 08:58:08 -07:00
|
|
|
is.Equal(string(hash), string(tt.hash))
|
2022-12-07 14:19:04 -07:00
|
|
|
is.NoErr(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|