mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-11-04 00:11:04 +00:00 
			
		
		
		
	[GITEA] oauth2: use link_account page when email/username is missing (#1757)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/1757 Co-authored-by: Antonin Delpeuch <antonin@delpeuch.eu> Co-committed-by: Antonin Delpeuch <antonin@delpeuch.eu>
This commit is contained in:
		
					parent
					
						
							
								90a648bc29
							
						
					
				
			
			
				commit
				
					
						0f6e0f9035
					
				
			
		
					 2 changed files with 39 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -469,3 +469,30 @@ func TestSignInOAuthCallbackSignIn(t *testing.T) {
 | 
			
		|||
	userAfterLogin := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userGitLab.ID})
 | 
			
		||||
	assert.Greater(t, userAfterLogin.LastLoginUnix, userGitLab.LastLoginUnix)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestSignUpViaOAuthWithMissingFields(t *testing.T) {
 | 
			
		||||
	defer tests.PrepareTestEnv(t)()
 | 
			
		||||
	// enable auto-creation of accounts via OAuth2
 | 
			
		||||
	enableAutoRegistration := setting.OAuth2Client.EnableAutoRegistration
 | 
			
		||||
	setting.OAuth2Client.EnableAutoRegistration = true
 | 
			
		||||
	defer func() {
 | 
			
		||||
		setting.OAuth2Client.EnableAutoRegistration = enableAutoRegistration
 | 
			
		||||
	}()
 | 
			
		||||
 | 
			
		||||
	// OAuth2 authentication source GitLab
 | 
			
		||||
	gitlabName := "gitlab"
 | 
			
		||||
	addAuthSource(t, authSourcePayloadGitLabCustom(gitlabName))
 | 
			
		||||
	userGitLabUserID := "5678"
 | 
			
		||||
 | 
			
		||||
	// The Goth User returned by the oauth2 integration is missing
 | 
			
		||||
	// an email address, so we won't be able to automatically create a local account for it.
 | 
			
		||||
	defer mockCompleteUserAuth(func(res http.ResponseWriter, req *http.Request) (goth.User, error) {
 | 
			
		||||
		return goth.User{
 | 
			
		||||
			Provider: gitlabName,
 | 
			
		||||
			UserID:   userGitLabUserID,
 | 
			
		||||
		}, nil
 | 
			
		||||
	})()
 | 
			
		||||
	req := NewRequest(t, "GET", fmt.Sprintf("/user/oauth2/%s/callback?code=XYZ&state=XYZ", gitlabName))
 | 
			
		||||
	resp := MakeRequest(t, req, http.StatusSeeOther)
 | 
			
		||||
	assert.Equal(t, test.RedirectURL(resp), "/user/link_account")
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue