Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

user_openid_test.go 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 models
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestGetUserOpenIDs(t *testing.T) {
  10. assert.NoError(t, PrepareTestDatabase())
  11. oids, err := GetUserOpenIDs(int64(1))
  12. if assert.NoError(t, err) && assert.Len(t, oids, 2) {
  13. assert.Equal(t, oids[0].URI, "https://user1.domain1.tld/")
  14. assert.False(t, oids[0].Show)
  15. assert.Equal(t, oids[1].URI, "http://user1.domain2.tld/")
  16. assert.True(t, oids[1].Show)
  17. }
  18. oids, err = GetUserOpenIDs(int64(2))
  19. if assert.NoError(t, err) && assert.Len(t, oids, 1) {
  20. assert.Equal(t, oids[0].URI, "https://domain1.tld/user2/")
  21. assert.True(t, oids[0].Show)
  22. }
  23. }
  24. func TestGetUserByOpenID(t *testing.T) {
  25. assert.NoError(t, PrepareTestDatabase())
  26. user, err := GetUserByOpenID("https://unknown")
  27. if assert.Error(t, err) {
  28. assert.True(t, IsErrUserNotExist(err))
  29. }
  30. user, err = GetUserByOpenID("https://user1.domain1.tld")
  31. if assert.NoError(t, err) {
  32. assert.Equal(t, user.ID, int64(1))
  33. }
  34. user, err = GetUserByOpenID("https://domain1.tld/user2/")
  35. if assert.NoError(t, err) {
  36. assert.Equal(t, user.ID, int64(2))
  37. }
  38. }
  39. func TestToggleUserOpenIDVisibility(t *testing.T) {
  40. assert.NoError(t, PrepareTestDatabase())
  41. oids, err := GetUserOpenIDs(int64(2))
  42. if !assert.NoError(t, err) || !assert.Len(t, oids, 1) {
  43. return
  44. }
  45. assert.True(t, oids[0].Show)
  46. err = ToggleUserOpenIDVisibility(oids[0].ID)
  47. if !assert.NoError(t, err) {
  48. return
  49. }
  50. oids, err = GetUserOpenIDs(int64(2))
  51. if !assert.NoError(t, err) || !assert.Len(t, oids, 1) {
  52. return
  53. }
  54. assert.False(t, oids[0].Show)
  55. err = ToggleUserOpenIDVisibility(oids[0].ID)
  56. if !assert.NoError(t, err) {
  57. return
  58. }
  59. oids, err = GetUserOpenIDs(int64(2))
  60. if !assert.NoError(t, err) {
  61. return
  62. }
  63. if assert.Len(t, oids, 1) {
  64. assert.True(t, oids[0].Show)
  65. }
  66. }