From 9e61907d516b1d3d7416d542faa3e71fdc78c13f Mon Sep 17 00:00:00 2001 From: Jon Lundy Date: Wed, 7 Dec 2022 17:04:46 -0700 Subject: [PATCH] tests: add some more testing around IsPreferred --- pkg/argon2/argon2_test.go | 16 ++++++++++++++++ pkg/scrypt/scrypt_test.go | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/pkg/argon2/argon2_test.go b/pkg/argon2/argon2_test.go index f4b7c91..f65e27e 100644 --- a/pkg/argon2/argon2_test.go +++ b/pkg/argon2/argon2_test.go @@ -8,6 +8,7 @@ import ( "github.com/sour-is/go-passwd" "github.com/sour-is/go-passwd/pkg/argon2" + "github.com/sour-is/go-passwd/pkg/unix" ) func TestPasswdHash(t *testing.T) { @@ -38,3 +39,18 @@ func TestPasswdHash(t *testing.T) { }) } } + +func TestPasswdIsPreferred(t *testing.T) { + is := is.New(t) + + pass := passwd.New(argon2.Argon2i, &unix.MD5{}) + + ok := pass.IsPreferred("$argon2i$v=19,m=32768,t=3,p=4$LdaB2Z4EI4lwpxTc78QUFw$VhlPSK0tdF226QCLC24IIrmQcMBmg47Ik9h/Yq6htFI") + is.True(ok) + + ok = pass.IsPreferred("$argon2i$v=19,m=1024,t=2,p=4$LdaB2Z4EI4lwpxTc78QUFw$VhlPSK0tdF226QCLC24IIrmQcMBmg47Ik9h/Yq6htFI") + is.True(!ok) + + ok = pass.IsPreferred("$1$76a2173be6393254e72ffa4d6df1030a") + is.True(!ok) +} diff --git a/pkg/scrypt/scrypt_test.go b/pkg/scrypt/scrypt_test.go index fbbbb83..9527840 100644 --- a/pkg/scrypt/scrypt_test.go +++ b/pkg/scrypt/scrypt_test.go @@ -8,6 +8,7 @@ import ( "github.com/sour-is/go-passwd" "github.com/sour-is/go-passwd/pkg/scrypt" + "github.com/sour-is/go-passwd/pkg/unix" ) func TestPasswdHash(t *testing.T) { @@ -38,3 +39,21 @@ func TestPasswdHash(t *testing.T) { }) } } + +func TestPasswdIsPreferred(t *testing.T) { + is := is.New(t) + + pass := passwd.New(scrypt.Scrypt2, &unix.MD5{}) + + ok := pass.IsPreferred("16384$8$1$b97ed09792dd74b71dcb7fc8caf04a89$0b5cda82b17298ec4bf6d2139f7ea8587d8478fcc68c09e2506a7cf08b2817c0") + is.True(!ok) + + ok = pass.IsPreferred("$s2$16384$8$1$iEdwbgXyKa5GNGNW/0NsOA$9YN/hzbskVVDZ887ppqv5su0n8SxVXwDB/rhVhAc9xQ") + is.True(ok) + + ok = pass.IsPreferred("$s2$16384$7$1$iEdwbgXyKa5GNGNW/0NsOA$9YN/hzbskVVDZ887ppqv5su0n8SxVXwDB/rhVhAc9xQ") + is.True(!ok) + + ok = pass.IsPreferred("$1$76a2173be6393254e72ffa4d6df1030a") + is.True(!ok) +}