mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2024-11-28 09:08:44 +02:00
More robust handling for missing email
This commit is contained in:
parent
c1bf1ad167
commit
0692c3763f
@ -15,6 +15,7 @@ func testOptions() *Options {
|
||||
o.CookieSecret = "foobar"
|
||||
o.ClientID = "bazquux"
|
||||
o.ClientSecret = "xyzzyplugh"
|
||||
o.EmailDomains = []string{"*"}
|
||||
return o
|
||||
}
|
||||
|
||||
@ -27,6 +28,7 @@ func errorMsg(msgs []string) string {
|
||||
|
||||
func TestNewOptions(t *testing.T) {
|
||||
o := NewOptions()
|
||||
o.EmailDomains = []string{"*"}
|
||||
err := o.Validate()
|
||||
assert.NotEqual(t, nil, err)
|
||||
|
||||
|
@ -2,7 +2,6 @@ package providers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@ -211,5 +210,5 @@ func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
return "", errors.New("no email address found")
|
||||
return "", nil
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package providers
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
@ -60,13 +59,11 @@ func (p *LinkedInProvider) GetEmailAddress(s *SessionState) (string, error) {
|
||||
|
||||
json, err := api.Request(req)
|
||||
if err != nil {
|
||||
log.Printf("failed making request %s", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
email, err := json.String()
|
||||
if err != nil {
|
||||
log.Printf("failed making request %s", err)
|
||||
return "", err
|
||||
}
|
||||
return email, nil
|
||||
|
@ -71,9 +71,11 @@ func newValidatorImpl(domains []string, usersFile string,
|
||||
domains[i] = fmt.Sprintf("@%s", strings.ToLower(domain))
|
||||
}
|
||||
|
||||
validator := func(email string) bool {
|
||||
validator := func(email string) (valid bool) {
|
||||
if email == "" {
|
||||
return
|
||||
}
|
||||
email = strings.ToLower(email)
|
||||
valid := false
|
||||
for _, domain := range domains {
|
||||
valid = valid || strings.HasSuffix(email, domain)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user