aboutsummaryrefslogtreecommitdiff
path: root/internal/userutil/userutil_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/userutil/userutil_test.go')
-rw-r--r--internal/userutil/userutil_test.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/internal/userutil/userutil_test.go b/internal/userutil/userutil_test.go
index e90c9235..10ffa12a 100644
--- a/internal/userutil/userutil_test.go
+++ b/internal/userutil/userutil_test.go
@@ -77,3 +77,79 @@ func TestGenerateRandomAvatar(t *testing.T) {
got := osutil.IsFile(CustomAvatarPath(1))
assert.True(t, got)
}
+
+func TestEncodePassword(t *testing.T) {
+ want := EncodePassword("123456", "rands")
+ tests := []struct {
+ name string
+ password string
+ rands string
+ wantEqual bool
+ }{
+ {
+ name: "correct",
+ password: "123456",
+ rands: "rands",
+ wantEqual: true,
+ },
+
+ {
+ name: "wrong password",
+ password: "111333",
+ rands: "rands",
+ wantEqual: false,
+ },
+ {
+ name: "wrong salt",
+ password: "111333",
+ rands: "salt",
+ wantEqual: false,
+ },
+ }
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ got := EncodePassword(test.password, test.rands)
+ if test.wantEqual {
+ assert.Equal(t, want, got)
+ } else {
+ assert.NotEqual(t, want, got)
+ }
+ })
+ }
+}
+
+func TestValidatePassword(t *testing.T) {
+ want := EncodePassword("123456", "rands")
+ tests := []struct {
+ name string
+ password string
+ rands string
+ wantEqual bool
+ }{
+ {
+ name: "correct",
+ password: "123456",
+ rands: "rands",
+ wantEqual: true,
+ },
+
+ {
+ name: "wrong password",
+ password: "111333",
+ rands: "rands",
+ wantEqual: false,
+ },
+ {
+ name: "wrong salt",
+ password: "111333",
+ rands: "salt",
+ wantEqual: false,
+ },
+ }
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ got := ValidatePassword(want, test.rands, test.password)
+ assert.Equal(t, test.wantEqual, got)
+ })
+ }
+}