userutil_test.go 984 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2022 The Gogs 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 userutil
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. "gogs.io/gogs/internal/conf"
  9. "gogs.io/gogs/internal/tool"
  10. )
  11. func TestDashboardURLPath(t *testing.T) {
  12. t.Run("user", func(t *testing.T) {
  13. got := DashboardURLPath("alice", false)
  14. want := "/"
  15. assert.Equal(t, want, got)
  16. })
  17. t.Run("organization", func(t *testing.T) {
  18. got := DashboardURLPath("acme", true)
  19. want := "/org/acme/dashboard/"
  20. assert.Equal(t, want, got)
  21. })
  22. }
  23. func TestGenerateActivateCode(t *testing.T) {
  24. conf.SetMockAuth(t,
  25. conf.AuthOpts{
  26. ActivateCodeLives: 10,
  27. },
  28. )
  29. code := GenerateActivateCode(1, "[email protected]", "Alice", "123456", "rands")
  30. got := tool.VerifyTimeLimitCode("[email protected]", conf.Auth.ActivateCodeLives, code[:tool.TIME_LIMIT_CODE_LENGTH])
  31. assert.True(t, got)
  32. }