MCPcopy Create free account
hub / github.com/gogs/gogs / usersUpdate

Function usersUpdate

internal/database/users_test.go:1029–1140  ·  view source on GitHub ↗
(t *testing.T, ctx context.Context, s *UsersStore)

Source from the content-addressed store, hash-verified

1027}
1028
1029func usersUpdate(t *testing.T, ctx context.Context, s *UsersStore) {
1030 const oldPassword = "Password"
1031 alice, err := s.Create(
1032 ctx,
1033 "alice",
1034 "alice@example.com",
1035 CreateUserOptions{
1036 FullName: "FullName",
1037 Password: oldPassword,
1038 LoginSource: 9,
1039 LoginName: "LoginName",
1040 Location: "Location",
1041 Website: "Website",
1042 Activated: false,
1043 Admin: false,
1044 },
1045 )
1046 require.NoError(t, err)
1047
1048 t.Run("update password", func(t *testing.T) {
1049 got := userutil.ValidatePassword(alice.Password, alice.Salt, oldPassword)
1050 require.True(t, got)
1051
1052 newPassword := "NewPassword"
1053 err = s.Update(ctx, alice.ID, UpdateUserOptions{Password: &newPassword})
1054 require.NoError(t, err)
1055 alice, err = s.GetByID(ctx, alice.ID)
1056 require.NoError(t, err)
1057
1058 got = userutil.ValidatePassword(alice.Password, alice.Salt, oldPassword)
1059 assert.False(t, got, "Old password should stop working")
1060
1061 got = userutil.ValidatePassword(alice.Password, alice.Salt, newPassword)
1062 assert.True(t, got, "New password should work")
1063 })
1064
1065 t.Run("update email but already used", func(t *testing.T) {
1066 bob, err := s.Create(
1067 ctx,
1068 "bob",
1069 "bob@example.com",
1070 CreateUserOptions{
1071 Activated: true,
1072 },
1073 )
1074 require.NoError(t, err)
1075
1076 got := s.Update(ctx, alice.ID, UpdateUserOptions{Email: &bob.Email})
1077 want := ErrEmailAlreadyUsed{args: errutil.Args{"email": bob.Email}}
1078 assert.Equal(t, want, got)
1079 })
1080
1081 loginSource := int64(1)
1082 maxRepoCreation := 99
1083 lastRepoVisibility := true
1084 overLimitStr := strings.Repeat("a", 2050)
1085 opts := UpdateUserOptions{
1086 LoginSource: &loginSource,

Callers

nothing calls this directly

Calls 4

ValidatePasswordFunction · 0.92
UpdateMethod · 0.65
GetByIDMethod · 0.65
CreateMethod · 0.45

Tested by

no test coverage detected