[#3364] added mailcow OAuth2 provider

Co-authored-by: thisni1s <nils@jn2p.de>
This commit is contained in:
Gani Georgiev
2023-10-14 14:46:01 +03:00
parent 69983bff5e
commit 01e33c07fe
45 changed files with 3332 additions and 3219 deletions
+7
View File
@@ -64,6 +64,7 @@ type Settings struct {
VKAuth AuthProviderConfig `form:"vkAuth" json:"vkAuth"`
YandexAuth AuthProviderConfig `form:"yandexAuth" json:"yandexAuth"`
PatreonAuth AuthProviderConfig `form:"patreonAuth" json:"patreonAuth"`
MailcowAuth AuthProviderConfig `form:"mailcowAuth" json:"mailcowAuth"`
}
// New creates and returns a new default Settings instance.
@@ -191,6 +192,9 @@ func New() *Settings {
PatreonAuth: AuthProviderConfig{
Enabled: false,
},
MailcowAuth: AuthProviderConfig{
Enabled: false,
},
}
}
@@ -235,6 +239,7 @@ func (s *Settings) Validate() error {
validation.Field(&s.VKAuth),
validation.Field(&s.YandexAuth),
validation.Field(&s.PatreonAuth),
validation.Field(&s.MailcowAuth),
)
}
@@ -302,6 +307,7 @@ func (s *Settings) RedactClone() (*Settings, error) {
&clone.VKAuth.ClientSecret,
&clone.YandexAuth.ClientSecret,
&clone.PatreonAuth.ClientSecret,
&clone.MailcowAuth.ClientSecret,
}
// mask all sensitive fields
@@ -343,6 +349,7 @@ func (s *Settings) NamedAuthProviderConfigs() map[string]AuthProviderConfig {
auth.NameVK: s.VKAuth,
auth.NameYandex: s.YandexAuth,
auth.NamePatreon: s.PatreonAuth,
auth.NameMailcow: s.MailcowAuth,
}
}
+8
View File
@@ -75,6 +75,8 @@ func TestSettingsValidate(t *testing.T) {
s.YandexAuth.ClientId = ""
s.PatreonAuth.Enabled = true
s.PatreonAuth.ClientId = ""
s.MailcowAuth.Enabled = true
s.MailcowAuth.ClientId = ""
// check if Validate() is triggering the members validate methods.
err := s.Validate()
@@ -117,6 +119,7 @@ func TestSettingsValidate(t *testing.T) {
`"vkAuth":{`,
`"yandexAuth":{`,
`"patreonAuth":{`,
`"mailcowAuth":{`,
}
errBytes, _ := json.Marshal(err)
@@ -192,6 +195,8 @@ func TestSettingsMerge(t *testing.T) {
s2.YandexAuth.ClientId = "yandex_test"
s2.PatreonAuth.Enabled = true
s2.PatreonAuth.ClientId = "patreon_test"
s2.MailcowAuth.Enabled = true
s2.MailcowAuth.ClientId = "mailcow_test"
if err := s1.Merge(s2); err != nil {
t.Fatal(err)
@@ -283,6 +288,7 @@ func TestSettingsRedactClone(t *testing.T) {
s1.VKAuth.ClientSecret = testSecret
s1.YandexAuth.ClientSecret = testSecret
s1.PatreonAuth.ClientSecret = testSecret
s1.MailcowAuth.ClientSecret = testSecret
s1Bytes, err := json.Marshal(s1)
if err != nil {
@@ -342,6 +348,7 @@ func TestNamedAuthProviderConfigs(t *testing.T) {
s.VKAuth.ClientId = "vk_test"
s.YandexAuth.ClientId = "yandex_test"
s.PatreonAuth.ClientId = "patreon_test"
s.MailcowAuth.ClientId = "mailcow_test"
result := s.NamedAuthProviderConfigs()
@@ -374,6 +381,7 @@ func TestNamedAuthProviderConfigs(t *testing.T) {
`"vk":{"enabled":false,"clientId":"vk_test"`,
`"yandex":{"enabled":false,"clientId":"yandex_test"`,
`"patreon":{"enabled":false,"clientId":"patreon_test"`,
`"mailcow":{"enabled":false,"clientId":"mailcow_test"`,
}
for _, p := range expectedParts {
if !strings.Contains(encodedStr, p) {