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.
61 lines
1.4 KiB
61 lines
1.4 KiB
5 years ago
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||
9 years ago
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
3 years ago
|
package auth
|
||
9 years ago
|
|
||
|
import (
|
||
3 years ago
|
"strings"
|
||
9 years ago
|
"testing"
|
||
|
|
||
3 years ago
|
"code.gitea.io/gitea/models/db"
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
3 years ago
|
"code.gitea.io/gitea/modules/json"
|
||
5 years ago
|
|
||
8 years ago
|
"github.com/stretchr/testify/assert"
|
||
3 years ago
|
"xorm.io/xorm/schemas"
|
||
9 years ago
|
)
|
||
|
|
||
3 years ago
|
type TestSource struct {
|
||
|
Provider string
|
||
|
ClientID string
|
||
|
ClientSecret string
|
||
|
OpenIDConnectAutoDiscoveryURL string
|
||
|
IconURL string
|
||
|
}
|
||
|
|
||
|
// FromDB fills up a LDAPConfig from serialized format.
|
||
|
func (source *TestSource) FromDB(bs []byte) error {
|
||
|
return json.Unmarshal(bs, &source)
|
||
|
}
|
||
|
|
||
|
// ToDB exports a LDAPConfig to a serialized format.
|
||
|
func (source *TestSource) ToDB() ([]byte, error) {
|
||
|
return json.Marshal(source)
|
||
|
}
|
||
|
|
||
3 years ago
|
func TestDumpAuthSource(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
3 years ago
|
|
||
3 years ago
|
authSourceSchema, err := db.TableInfo(new(Source))
|
||
3 years ago
|
assert.NoError(t, err)
|
||
|
|
||
3 years ago
|
RegisterTypeConfig(OAuth2, new(TestSource))
|
||
3 years ago
|
|
||
3 years ago
|
CreateSource(&Source{
|
||
|
Type: OAuth2,
|
||
3 years ago
|
Name: "TestSource",
|
||
|
IsActive: false,
|
||
|
Cfg: &TestSource{
|
||
|
Provider: "ConvertibleSourceName",
|
||
|
ClientID: "42",
|
||
|
},
|
||
|
})
|
||
|
|
||
|
sb := new(strings.Builder)
|
||
|
|
||
3 years ago
|
db.DumpTables([]*schemas.Table{authSourceSchema}, sb)
|
||
3 years ago
|
|
||
|
assert.Contains(t, sb.String(), `"Provider":"ConvertibleSourceName"`)
|
||
|
}
|