You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

users_test.go 1.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package admin
  5. import (
  6. "testing"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/auth"
  9. "code.gitea.io/gitea/modules/test"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestNewUserPost_MustChangePassword(t *testing.T) {
  13. models.PrepareTestEnv(t)
  14. ctx := test.MockContext(t, "admin/users/new")
  15. u := models.AssertExistsAndLoadBean(t, &models.User{
  16. IsAdmin: true,
  17. ID: 2,
  18. }).(*models.User)
  19. ctx.User = u
  20. username := "gitea"
  21. email := "gitea@gitea.io"
  22. form := auth.AdminCreateUserForm{
  23. LoginType: "local",
  24. LoginName: "local",
  25. UserName: username,
  26. Email: email,
  27. Password: "xxxxxxxx",
  28. SendNotify: false,
  29. }
  30. NewUserPost(ctx, form)
  31. assert.NotEmpty(t, ctx.Flash.SuccessMsg)
  32. u, err := models.GetUserByName(username)
  33. assert.NoError(t, err)
  34. assert.Equal(t, username, u.Name)
  35. assert.Equal(t, email, u.Email)
  36. assert.True(t, u.MustChangePassword)
  37. }