本站源代码
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

65 行
1.3KB

  1. // Copyright 2018 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 auth
  5. import (
  6. "testing"
  7. "code.gitea.io/gitea/modules/setting"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestRegisterForm_IsDomainWhiteList_Empty(t *testing.T) {
  11. _ = setting.Service
  12. setting.Service.EmailDomainWhitelist = []string{}
  13. form := RegisterForm{}
  14. assert.True(t, form.IsEmailDomainWhitelisted())
  15. }
  16. func TestRegisterForm_IsDomainWhiteList_InvalidEmail(t *testing.T) {
  17. _ = setting.Service
  18. setting.Service.EmailDomainWhitelist = []string{"gitea.io"}
  19. tt := []struct {
  20. email string
  21. }{
  22. {"securitygieqqq"},
  23. {"hdudhdd"},
  24. }
  25. for _, v := range tt {
  26. form := RegisterForm{Email: v.email}
  27. assert.False(t, form.IsEmailDomainWhitelisted())
  28. }
  29. }
  30. func TestRegisterForm_IsDomainWhiteList_ValidEmail(t *testing.T) {
  31. _ = setting.Service
  32. setting.Service.EmailDomainWhitelist = []string{"gitea.io"}
  33. tt := []struct {
  34. email string
  35. valid bool
  36. }{
  37. {"security@gitea.io", true},
  38. {"security@gITea.io", true},
  39. {"hdudhdd", false},
  40. {"seee@example.com", false},
  41. }
  42. for _, v := range tt {
  43. form := RegisterForm{Email: v.email}
  44. assert.Equal(t, v.valid, form.IsEmailDomainWhitelisted())
  45. }
  46. }
上海开阖软件有限公司 沪ICP备12045867号-1