diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-04-08 12:13:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-08 04:13:34 +0000 |
commit | 074a3e05f665ad8c635a314f49080f8846e6d315 (patch) | |
tree | 24d4ec61b06beda2a720e333ce9db3c5292779ff /modules | |
parent | 0c7b0c5acaae911d3d3fefa1d8b394594c860620 (diff) | |
download | gitea-074a3e05f665ad8c635a314f49080f8846e6d315.tar.gz gitea-074a3e05f665ad8c635a314f49080f8846e6d315.zip |
Fix oauth2 builtin application logic (#30304)
Fix #29074 (allow to disable all builtin apps) and don't make the doctor
command remove the builtin apps.
By the way, rename refobject and joincond to camel case.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/setting/oauth2.go | 4 | ||||
-rw-r--r-- | modules/setting/oauth2_test.go | 18 |
2 files changed, 22 insertions, 0 deletions
diff --git a/modules/setting/oauth2.go b/modules/setting/oauth2.go index 1429a7585c..830472db32 100644 --- a/modules/setting/oauth2.go +++ b/modules/setting/oauth2.go @@ -118,6 +118,10 @@ func loadOAuth2From(rootCfg ConfigProvider) { return } + if sec.HasKey("DEFAULT_APPLICATIONS") && sec.Key("DEFAULT_APPLICATIONS").String() == "" { + OAuth2.DefaultApplications = nil + } + // Handle the rename of ENABLE to ENABLED deprecatedSetting(rootCfg, "oauth2", "ENABLE", "oauth2", "ENABLED", "v1.23.0") if sec.HasKey("ENABLE") && !sec.HasKey("ENABLED") { diff --git a/modules/setting/oauth2_test.go b/modules/setting/oauth2_test.go index d822198619..4403f35892 100644 --- a/modules/setting/oauth2_test.go +++ b/modules/setting/oauth2_test.go @@ -32,3 +32,21 @@ JWT_SECRET = BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB assert.Len(t, actual, 32) assert.EqualValues(t, expected, actual) } + +func TestOauth2DefaultApplications(t *testing.T) { + cfg, _ := NewConfigProviderFromData(``) + loadOAuth2From(cfg) + assert.Equal(t, []string{"git-credential-oauth", "git-credential-manager", "tea"}, OAuth2.DefaultApplications) + + cfg, _ = NewConfigProviderFromData(`[oauth2] +DEFAULT_APPLICATIONS = tea +`) + loadOAuth2From(cfg) + assert.Equal(t, []string{"tea"}, OAuth2.DefaultApplications) + + cfg, _ = NewConfigProviderFromData(`[oauth2] +DEFAULT_APPLICATIONS = +`) + loadOAuth2From(cfg) + assert.Nil(t, nil, OAuth2.DefaultApplications) +} |