MCPcopy Create free account
hub / github.com/dnote/dnote / TestUserResetPasswordCmd

Function TestUserResetPasswordCmd

pkg/server/cmd/user_test.go:77–111  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

75}
76
77func TestUserResetPasswordCmd(t *testing.T) {
78 tmpDB := t.TempDir() + "/test.db"
79
80 // Create a user first
81 db := testutils.InitDB(tmpDB)
82 user := testutils.SetupUserData(db, "test@example.com", "oldpassword123")
83 oldPasswordHash := user.Password.String
84 sqlDB, _ := db.DB()
85 sqlDB.Close()
86
87 // Reset password
88 userResetPasswordCmd([]string{"--dbPath", tmpDB, "--email", "test@example.com", "--password", "newpassword123"})
89
90 // Verify password was changed
91 db2 := testutils.InitDB(tmpDB)
92 defer func() {
93 sqlDB2, _ := db2.DB()
94 sqlDB2.Close()
95 }()
96
97 var updatedUser database.User
98 testutils.MustExec(t, db2.Where("email = ?", "test@example.com").First(&updatedUser), "finding user")
99
100 // Verify password hash changed
101 assert.Equal(t, updatedUser.Password.String != oldPasswordHash, true, "password hash should be different")
102 assert.Equal(t, len(updatedUser.Password.String) > 0, true, "password should be set")
103
104 // Verify new password works
105 err := bcrypt.CompareHashAndPassword([]byte(updatedUser.Password.String), []byte("newpassword123"))
106 assert.Equal(t, err, nil, "new password should match")
107
108 // Verify old password doesn't work
109 err = bcrypt.CompareHashAndPassword([]byte(updatedUser.Password.String), []byte("oldpassword123"))
110 assert.Equal(t, err != nil, true, "old password should not match")
111}
112
113func TestUserListCmd(t *testing.T) {
114 t.Run("multiple users", func(t *testing.T) {

Callers

nothing calls this directly

Calls 6

InitDBFunction · 0.92
SetupUserDataFunction · 0.92
MustExecFunction · 0.92
EqualFunction · 0.92
userResetPasswordCmdFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected