De-duplicate code in GetLoginURL of in logingov provider
Also add unit test to ensure logingov specific logic is applied.
This commit is contained in:
		
							parent
							
								
									fde09bea4e
								
							
						
					
					
						commit
						9a64e67d5b
					
				|  | @ -225,19 +225,11 @@ func (p *LoginGovProvider) Redeem(ctx context.Context, redirectURL, code string) | ||||||
| 
 | 
 | ||||||
| // GetLoginURL overrides GetLoginURL to add login.gov parameters
 | // GetLoginURL overrides GetLoginURL to add login.gov parameters
 | ||||||
| func (p *LoginGovProvider) GetLoginURL(redirectURI, state string) string { | func (p *LoginGovProvider) GetLoginURL(redirectURI, state string) string { | ||||||
| 	a := *p.LoginURL | 	a, params := DefaultGetLoginURL(p.ProviderData, redirectURI, state) | ||||||
| 	params, _ := url.ParseQuery(a.RawQuery) | 	if p.AcrValues == "" { | ||||||
| 	params.Set("redirect_uri", redirectURI) | 		acr := "http://idmanagement.gov/ns/assurance/loa/1" | ||||||
| 	params.Set("approval_prompt", p.ApprovalPrompt) |  | ||||||
| 	params.Add("scope", p.Scope) |  | ||||||
| 	params.Set("client_id", p.ClientID) |  | ||||||
| 	params.Set("response_type", "code") |  | ||||||
| 	params.Add("state", state) |  | ||||||
| 	acr := p.AcrValues |  | ||||||
| 	if acr == "" { |  | ||||||
| 		acr = "http://idmanagement.gov/ns/assurance/loa/1" |  | ||||||
| 	} |  | ||||||
| 		params.Add("acr_values", acr) | 		params.Add("acr_values", acr) | ||||||
|  | 	} | ||||||
| 	params.Add("nonce", p.Nonce) | 	params.Add("nonce", p.Nonce) | ||||||
| 	a.RawQuery = params.Encode() | 	a.RawQuery = params.Encode() | ||||||
| 	return a.String() | 	return a.String() | ||||||
|  |  | ||||||
|  | @ -289,3 +289,10 @@ func TestLoginGovProviderBadNonce(t *testing.T) { | ||||||
| 	// The "badfakenonce" in the idtoken above should cause this to error out
 | 	// The "badfakenonce" in the idtoken above should cause this to error out
 | ||||||
| 	assert.Error(t, err) | 	assert.Error(t, err) | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func TestLoginGovProviderGetLoginURL(t *testing.T) { | ||||||
|  | 	p, _, _ := newLoginGovProvider() | ||||||
|  | 	result := p.GetLoginURL("http://redirect/", "") | ||||||
|  | 	assert.Contains(t, result, "acr_values="+url.QueryEscape("http://idmanagement.gov/ns/assurance/loa/1")) | ||||||
|  | 	assert.Contains(t, result, "nonce=fakenonce") | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue