1
0
Fork 0
forked from forgejo/forgejo

[TESTS] coverage for SignInOAuthCallback

(cherry picked from commit f8e1619b99)
This commit is contained in:
Earl Warren 2023-06-27 15:00:15 +02:00
parent d386b212c4
commit 46d8bc9bdf
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
2 changed files with 60 additions and 0 deletions

View file

@ -40,6 +40,8 @@ import (
"code.gitea.io/gitea/tests"
"github.com/PuerkitoBio/goquery"
"github.com/markbates/goth"
"github.com/markbates/goth/gothic"
goth_gitlab "github.com/markbates/goth/providers/gitlab"
"github.com/stretchr/testify/assert"
"github.com/xeipuuv/gojsonschema"
@ -244,6 +246,14 @@ func getUserToken(t testing.TB, userName string, scope ...auth.AccessTokenScope)
return getTokenForLoggedInUser(t, loginUser(t, userName), scope...)
}
func mockCompleteUserAuth(mock func(res http.ResponseWriter, req *http.Request) (goth.User, error)) func() {
old := gothic.CompleteUserAuth
gothic.CompleteUserAuth = mock
return func() {
gothic.CompleteUserAuth = old
}
}
func addAuthSource(t *testing.T, payload map[string]string) *auth.Source {
session := loginUser(t, "user1")
payload["_csrf"] = GetCSRF(t, session, "/admin/auths/new")