forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix oauth2 builtin application logic (go-gitea#30304)
Fix go-gitea#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.
- Loading branch information
1 parent
0c7b0c5
commit 074a3e0
Showing
6 changed files
with
107 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package doctor | ||
|
||
import ( | ||
"slices" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models/auth" | ||
"code.gitea.io/gitea/models/db" | ||
"code.gitea.io/gitea/models/unittest" | ||
"code.gitea.io/gitea/models/user" | ||
"code.gitea.io/gitea/modules/log" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConsistencyCheck(t *testing.T) { | ||
checks := prepareDBConsistencyChecks() | ||
idx := slices.IndexFunc(checks, func(check consistencyCheck) bool { | ||
return check.Name == "Orphaned OAuth2Application without existing User" | ||
}) | ||
if !assert.NotEqual(t, -1, idx) { | ||
return | ||
} | ||
|
||
_ = db.TruncateBeans(db.DefaultContext, &auth.OAuth2Application{}, &user.User{}) | ||
_ = db.TruncateBeans(db.DefaultContext, &auth.OAuth2Application{}, &auth.OAuth2Application{}) | ||
|
||
err := db.Insert(db.DefaultContext, &user.User{ID: 1}) | ||
assert.NoError(t, err) | ||
err = db.Insert(db.DefaultContext, &auth.OAuth2Application{Name: "test-oauth2-app-1", ClientID: "client-id-1"}) | ||
assert.NoError(t, err) | ||
err = db.Insert(db.DefaultContext, &auth.OAuth2Application{Name: "test-oauth2-app-2", ClientID: "client-id-2", UID: 1}) | ||
assert.NoError(t, err) | ||
err = db.Insert(db.DefaultContext, &auth.OAuth2Application{Name: "test-oauth2-app-3", ClientID: "client-id-3", UID: 99999999}) | ||
assert.NoError(t, err) | ||
|
||
unittest.AssertExistsAndLoadBean(t, &auth.OAuth2Application{ClientID: "client-id-1"}) | ||
unittest.AssertExistsAndLoadBean(t, &auth.OAuth2Application{ClientID: "client-id-2"}) | ||
unittest.AssertExistsAndLoadBean(t, &auth.OAuth2Application{ClientID: "client-id-3"}) | ||
|
||
oauth2AppCheck := checks[idx] | ||
err = oauth2AppCheck.Run(db.DefaultContext, log.GetManager().GetLogger(log.DEFAULT), true) | ||
assert.NoError(t, err) | ||
|
||
unittest.AssertExistsAndLoadBean(t, &auth.OAuth2Application{ClientID: "client-id-1"}) | ||
unittest.AssertExistsAndLoadBean(t, &auth.OAuth2Application{ClientID: "client-id-2"}) | ||
unittest.AssertNotExistsBean(t, &auth.OAuth2Application{ClientID: "client-id-3"}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package doctor | ||
|
||
import ( | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models/unittest" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
unittest.MainTest(m) | ||
} |