44package auth
55
66import (
7+ "html/template"
78 "net/http"
89 "net/http/httptest"
910 "net/url"
@@ -67,29 +68,29 @@ func TestWebAuthOAuth2(t *testing.T) {
6768 defer test .MockVariableValue (& setting .OAuth2Client .EnableAutoRegistration , true )()
6869
6970 _ = oauth2 .Init (t .Context ())
70- addOAuth2Source (t , "dummy- auth- source" , oauth2.Source {})
71+ addOAuth2Source (t , "dummy+ auth's source" , oauth2.Source {})
7172
7273 t .Run ("OAuth2MissingField" , func (t * testing.T ) {
7374 defer test .MockVariableValue (& gothic .CompleteUserAuth , func (res http.ResponseWriter , req * http.Request ) (goth.User , error ) {
74- return goth.User {Provider : "dummy- auth- source" , UserID : "dummy-user" }, nil
75+ return goth.User {Provider : "dummy+ auth's source" , UserID : "dummy-user" }, nil
7576 })()
7677 mockOpt := contexttest.MockContextOption {SessionStore : session .NewMockMemStore ("dummy-sid" )}
77- ctx , resp := contexttest .MockContext (t , "/user/oauth2/dummy-auth-source /callback?code=dummy-code" , mockOpt )
78- ctx .SetPathParam ("provider" , "dummy- auth-source " )
78+ ctx , resp := contexttest .MockContext (t , "/user/oauth2/.... /callback?code=dummy-code" , mockOpt )
79+ ctx .SetPathParamRaw ("provider" , "dummy+ auth%27s%20source " )
7980 SignInOAuthCallback (ctx )
8081 assert .Equal (t , http .StatusSeeOther , resp .Code )
8182 assert .Equal (t , "/user/link_account" , test .RedirectURL (resp ))
8283
8384 // then the user will be redirected to the link account page, and see a message about the missing fields
8485 ctx , _ = contexttest .MockContext (t , "/user/link_account" , mockOpt )
8586 LinkAccount (ctx )
86- assert .EqualValues (t , "auth.oauth_callback_unable_auto_reg:dummy- auth- source,email" , ctx .Data ["AutoRegistrationFailedPrompt" ])
87+ assert .Equal (t , template . HTML ( "auth.oauth_callback_unable_auto_reg:dummy+ auth's source,email" ) , ctx .Data ["AutoRegistrationFailedPrompt" ])
8788 })
8889
8990 t .Run ("OAuth2CallbackError" , func (t * testing.T ) {
9091 mockOpt := contexttest.MockContextOption {SessionStore : session .NewMockMemStore ("dummy-sid" )}
91- ctx , resp := contexttest .MockContext (t , "/user/oauth2/dummy-auth-source /callback" , mockOpt )
92- ctx .SetPathParam ("provider" , "dummy- auth-source " )
92+ ctx , resp := contexttest .MockContext (t , "/user/oauth2/..... /callback" , mockOpt )
93+ ctx .SetPathParamRaw ("provider" , "dummy+ auth%27s%20source " )
9394 SignInOAuthCallback (ctx )
9495 assert .Equal (t , http .StatusSeeOther , resp .Code )
9596 assert .Equal (t , "/user/login" , test .RedirectURL (resp ))
@@ -112,8 +113,8 @@ func TestWebAuthOAuth2(t *testing.T) {
112113 assert .Equal (t , expectedRedirect , test .RedirectURL (resp ))
113114 }
114115 }
115- testSignIn (t , "/user/login" , http .StatusSeeOther , "/user/oauth2/dummy- auth-source " )
116- testSignIn (t , "/user/login?redirect_to=/" , http .StatusSeeOther , "/user/oauth2/dummy- auth-source ?redirect_to=%2F" )
116+ testSignIn (t , "/user/login" , http .StatusSeeOther , "/user/oauth2/dummy+ auth%27s%20source " )
117+ testSignIn (t , "/user/login?redirect_to=/" , http .StatusSeeOther , "/user/oauth2/dummy+ auth%27s%20source ?redirect_to=%2F" )
117118
118119 * enablePassword , * enableOpenID , * enablePasskey = true , false , false
119120 testSignIn (t , "/user/login" , http .StatusOK , "" )
0 commit comments