Skip to content

Commit 1904941

Browse files
authored
Add test to ensure that dumping of login sources remains correct (#16847)
#16831 has occurred because of a missed regression. This PR adds a simple test to try to prevent this occuring again. Signed-off-by: Andrew Thornton <[email protected]>
1 parent 88abb0d commit 1904941

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

models/models_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
package models
66

77
import (
8+
"encoding/json"
89
"io/ioutil"
910
"os"
1011
"path/filepath"
12+
"strings"
1113
"testing"
1214

1315
"code.gitea.io/gitea/modules/setting"
16+
"xorm.io/xorm/schemas"
1417

1518
"github.com/stretchr/testify/assert"
1619
)
@@ -32,3 +35,46 @@ func TestDumpDatabase(t *testing.T) {
3235
assert.NoError(t, DumpDatabase(filepath.Join(dir, dbType+".sql"), dbType))
3336
}
3437
}
38+
39+
type TestSource struct {
40+
Provider string
41+
ClientID string
42+
ClientSecret string
43+
OpenIDConnectAutoDiscoveryURL string
44+
IconURL string
45+
}
46+
47+
// FromDB fills up a LDAPConfig from serialized format.
48+
func (source *TestSource) FromDB(bs []byte) error {
49+
return json.Unmarshal(bs, &source)
50+
}
51+
52+
// ToDB exports a LDAPConfig to a serialized format.
53+
func (source *TestSource) ToDB() ([]byte, error) {
54+
return json.Marshal(source)
55+
}
56+
57+
func TestDumpLoginSource(t *testing.T) {
58+
assert.NoError(t, PrepareTestDatabase())
59+
60+
loginSourceSchema, err := x.TableInfo(new(LoginSource))
61+
assert.NoError(t, err)
62+
63+
RegisterLoginTypeConfig(LoginOAuth2, new(TestSource))
64+
65+
CreateLoginSource(&LoginSource{
66+
Type: LoginOAuth2,
67+
Name: "TestSource",
68+
IsActive: false,
69+
Cfg: &TestSource{
70+
Provider: "ConvertibleSourceName",
71+
ClientID: "42",
72+
},
73+
})
74+
75+
sb := new(strings.Builder)
76+
77+
x.DumpTables([]*schemas.Table{loginSourceSchema}, sb)
78+
79+
assert.Contains(t, sb.String(), `"Provider":"ConvertibleSourceName"`)
80+
}

0 commit comments

Comments
 (0)