[#3323] added Patreon OAuth2 provider
Co-authored-by: GHOST <ghostdevbusiness@gmail.com>
This commit is contained in:
@@ -63,6 +63,7 @@ type Settings struct {
|
||||
InstagramAuth AuthProviderConfig `form:"instagramAuth" json:"instagramAuth"`
|
||||
VKAuth AuthProviderConfig `form:"vkAuth" json:"vkAuth"`
|
||||
YandexAuth AuthProviderConfig `form:"yandexAuth" json:"yandexAuth"`
|
||||
PatreonAuth AuthProviderConfig `form:"patreonAuth" json:"patreonAuth"`
|
||||
}
|
||||
|
||||
// New creates and returns a new default Settings instance.
|
||||
@@ -187,6 +188,9 @@ func New() *Settings {
|
||||
YandexAuth: AuthProviderConfig{
|
||||
Enabled: false,
|
||||
},
|
||||
PatreonAuth: AuthProviderConfig{
|
||||
Enabled: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,6 +234,7 @@ func (s *Settings) Validate() error {
|
||||
validation.Field(&s.InstagramAuth),
|
||||
validation.Field(&s.VKAuth),
|
||||
validation.Field(&s.YandexAuth),
|
||||
validation.Field(&s.PatreonAuth),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -296,6 +301,7 @@ func (s *Settings) RedactClone() (*Settings, error) {
|
||||
&clone.InstagramAuth.ClientSecret,
|
||||
&clone.VKAuth.ClientSecret,
|
||||
&clone.YandexAuth.ClientSecret,
|
||||
&clone.PatreonAuth.ClientSecret,
|
||||
}
|
||||
|
||||
// mask all sensitive fields
|
||||
@@ -336,6 +342,7 @@ func (s *Settings) NamedAuthProviderConfigs() map[string]AuthProviderConfig {
|
||||
auth.NameInstagram: s.InstagramAuth,
|
||||
auth.NameVK: s.VKAuth,
|
||||
auth.NameYandex: s.YandexAuth,
|
||||
auth.NamePatreon: s.PatreonAuth,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,8 @@ func TestSettingsValidate(t *testing.T) {
|
||||
s.VKAuth.ClientId = ""
|
||||
s.YandexAuth.Enabled = true
|
||||
s.YandexAuth.ClientId = ""
|
||||
s.PatreonAuth.Enabled = true
|
||||
s.PatreonAuth.ClientId = ""
|
||||
|
||||
// check if Validate() is triggering the members validate methods.
|
||||
err := s.Validate()
|
||||
@@ -114,6 +116,7 @@ func TestSettingsValidate(t *testing.T) {
|
||||
`"instagramAuth":{`,
|
||||
`"vkAuth":{`,
|
||||
`"yandexAuth":{`,
|
||||
`"patreonAuth":{`,
|
||||
}
|
||||
|
||||
errBytes, _ := json.Marshal(err)
|
||||
@@ -187,6 +190,8 @@ func TestSettingsMerge(t *testing.T) {
|
||||
s2.VKAuth.ClientId = "vk_test"
|
||||
s2.YandexAuth.Enabled = true
|
||||
s2.YandexAuth.ClientId = "yandex_test"
|
||||
s2.PatreonAuth.Enabled = true
|
||||
s2.PatreonAuth.ClientId = "patreon_test"
|
||||
|
||||
if err := s1.Merge(s2); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -277,6 +282,7 @@ func TestSettingsRedactClone(t *testing.T) {
|
||||
s1.InstagramAuth.ClientSecret = testSecret
|
||||
s1.VKAuth.ClientSecret = testSecret
|
||||
s1.YandexAuth.ClientSecret = testSecret
|
||||
s1.PatreonAuth.ClientSecret = testSecret
|
||||
|
||||
s1Bytes, err := json.Marshal(s1)
|
||||
if err != nil {
|
||||
@@ -335,6 +341,7 @@ func TestNamedAuthProviderConfigs(t *testing.T) {
|
||||
s.InstagramAuth.ClientId = "instagram_test"
|
||||
s.VKAuth.ClientId = "vk_test"
|
||||
s.YandexAuth.ClientId = "yandex_test"
|
||||
s.PatreonAuth.ClientId = "patreon_test"
|
||||
|
||||
result := s.NamedAuthProviderConfigs()
|
||||
|
||||
@@ -366,6 +373,7 @@ func TestNamedAuthProviderConfigs(t *testing.T) {
|
||||
`"instagram":{"enabled":false,"clientId":"instagram_test"`,
|
||||
`"vk":{"enabled":false,"clientId":"vk_test"`,
|
||||
`"yandex":{"enabled":false,"clientId":"yandex_test"`,
|
||||
`"patreon":{"enabled":false,"clientId":"patreon_test"`,
|
||||
}
|
||||
for _, p := range expectedParts {
|
||||
if !strings.Contains(encodedStr, p) {
|
||||
|
||||
Reference in New Issue
Block a user