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

source_test.go 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package auth_test
  4. import (
  5. "strings"
  6. "testing"
  7. auth_model "code.gitea.io/gitea/models/auth"
  8. "code.gitea.io/gitea/models/db"
  9. "code.gitea.io/gitea/models/unittest"
  10. "code.gitea.io/gitea/modules/json"
  11. "github.com/stretchr/testify/assert"
  12. "xorm.io/xorm/schemas"
  13. )
  14. type TestSource struct {
  15. Provider string
  16. ClientID string
  17. ClientSecret string
  18. OpenIDConnectAutoDiscoveryURL string
  19. IconURL string
  20. }
  21. // FromDB fills up a LDAPConfig from serialized format.
  22. func (source *TestSource) FromDB(bs []byte) error {
  23. return json.Unmarshal(bs, &source)
  24. }
  25. // ToDB exports a LDAPConfig to a serialized format.
  26. func (source *TestSource) ToDB() ([]byte, error) {
  27. return json.Marshal(source)
  28. }
  29. func TestDumpAuthSource(t *testing.T) {
  30. assert.NoError(t, unittest.PrepareTestDatabase())
  31. authSourceSchema, err := db.TableInfo(new(auth_model.Source))
  32. assert.NoError(t, err)
  33. auth_model.RegisterTypeConfig(auth_model.OAuth2, new(TestSource))
  34. auth_model.CreateSource(&auth_model.Source{
  35. Type: auth_model.OAuth2,
  36. Name: "TestSource",
  37. IsActive: false,
  38. Cfg: &TestSource{
  39. Provider: "ConvertibleSourceName",
  40. ClientID: "42",
  41. },
  42. })
  43. sb := new(strings.Builder)
  44. db.DumpTables([]*schemas.Table{authSourceSchema}, sb)
  45. assert.Contains(t, sb.String(), `"Provider":"ConvertibleSourceName"`)
  46. }