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.
60 lines
1.4 KiB
60 lines
1.4 KiB
5 years ago
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||
8 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 login
|
||
8 years ago
|
|
||
|
import (
|
||
3 years ago
|
"strings"
|
||
8 years ago
|
"testing"
|
||
|
|
||
3 years ago
|
"code.gitea.io/gitea/models/db"
|
||
|
"code.gitea.io/gitea/modules/json"
|
||
5 years ago
|
|
||
8 years ago
|
"github.com/stretchr/testify/assert"
|
||
3 years ago
|
"xorm.io/xorm/schemas"
|
||
8 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)
|
||
|
}
|
||
|
|
||
|
func TestDumpLoginSource(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, db.PrepareTestDatabase())
|
||
3 years ago
|
|
||
3 years ago
|
loginSourceSchema, 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{loginSourceSchema}, sb)
|
||
3 years ago
|
|
||
|
assert.Contains(t, sb.String(), `"Provider":"ConvertibleSourceName"`)
|
||
|
}
|