diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-09-18 07:32:56 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-17 23:32:56 +0000 |
commit | 8531ca08372dd4a4739564dec17766fffe34a385 (patch) | |
tree | a6c05c2083d71230bab7768d205e7fbfedcebd4c /routers/api | |
parent | 47b878858ada27fc4c74eeadcc1e467d2da90e04 (diff) | |
download | gitea-8531ca08372dd4a4739564dec17766fffe34a385.tar.gz gitea-8531ca08372dd4a4739564dec17766fffe34a385.zip |
Make SSPI auth mockable (#27036)
Before, the SSPI auth is only complied for Windows, it's difficult to
test and it breaks a lot.
Now, make the SSPI auth mockable and testable.
Diffstat (limited to 'routers/api')
-rw-r--r-- | routers/api/v1/api.go | 5 | ||||
-rw-r--r-- | routers/api/v1/auth.go | 10 | ||||
-rw-r--r-- | routers/api/v1/auth_windows.go | 19 |
3 files changed, 4 insertions, 30 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index ca74a23a4b..d58e39920b 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -705,7 +705,10 @@ func buildAuthGroup() *auth.Group { if setting.Service.EnableReverseProxyAuthAPI { group.Add(&auth.ReverseProxy{}) } - specialAdd(group) + + if setting.IsWindows && auth_model.IsSSPIEnabled() { + group.Add(&auth.SSPI{}) // it MUST be the last, see the comment of SSPI + } return group } diff --git a/routers/api/v1/auth.go b/routers/api/v1/auth.go deleted file mode 100644 index e44271ba14..0000000000 --- a/routers/api/v1/auth.go +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2022 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -//go:build !windows - -package v1 - -import auth_service "code.gitea.io/gitea/services/auth" - -func specialAdd(group *auth_service.Group) {} diff --git a/routers/api/v1/auth_windows.go b/routers/api/v1/auth_windows.go deleted file mode 100644 index 3514e21baa..0000000000 --- a/routers/api/v1/auth_windows.go +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2022 The Gitea Authors. All rights reserved. -// SPDX-License-Identifier: MIT - -package v1 - -import ( - "code.gitea.io/gitea/models/auth" - auth_service "code.gitea.io/gitea/services/auth" -) - -// specialAdd registers the SSPI auth method as the last method in the list. -// The SSPI plugin is expected to be executed last, as it returns 401 status code if negotiation -// fails (or if negotiation should continue), which would prevent other authentication methods -// to execute at all. -func specialAdd(group *auth_service.Group) { - if auth.IsSSPIEnabled() { - group.Add(&auth_service.SSPI{}) - } -} |