Files
homebox/backend/pkgs/hasher/password_test.go
Matt Kilgore f000e14f07 Update passwords to use Argon2ID (#695)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2025-06-05 10:19:05 -04:00

68 lines
1.7 KiB
Go

package hasher
import (
"testing"
)
func TestHashPassword(t *testing.T) {
t.Parallel()
type args struct {
password string
invalidInputs []string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "letters_and_numbers",
args: args{
password: "password123456788",
invalidInputs: []string{"testPassword", "AnotherBadPassword", "ThisShouldNeverWork", "1234567890"},
},
},
{
name: "letters_number_and_special",
args: args{
password: "!2afj3214pofajip3142j;fa",
invalidInputs: []string{"testPassword", "AnotherBadPassword", "ThisShouldNeverWork", "1234567890"},
},
},
{
name: "extra_long_password",
args: args{
password: "this_is_a_very_long_password_that_should_be_hashed_properly_and_still_work_with_the_check_function",
invalidInputs: []string{"testPassword", "AnotherBadPassword", "ThisShouldNeverWork", "1234567890"},
},
},
{
name: "empty_password",
args: args{
password: "",
invalidInputs: []string{"testPassword", "AnotherBadPassword", "ThisShouldNeverWork", "1234567890"},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := HashPassword(tt.args.password)
if (err != nil) != tt.wantErr {
t.Errorf("HashPassword() error = %v, wantErr %v", err, tt.wantErr)
return
}
check, _ := CheckPasswordHash(tt.args.password, got)
if !check {
t.Errorf("CheckPasswordHash() failed to validate password=%v against hash=%v", tt.args.password, got)
}
for _, invalid := range tt.args.invalidInputs {
check, _ := CheckPasswordHash(invalid, got)
if check {
t.Errorf("CheckPasswordHash() improperly validated password=%v against hash=%v", invalid, got)
}
}
})
}
}