From 0692c3763f1b5023ca8c37c539d1b4ed23a4aa10 Mon Sep 17 00:00:00 2001 From: Jehiah Czebotar Date: Fri, 24 Jul 2015 16:23:19 -0400 Subject: [PATCH] More robust handling for missing email --- options_test.go | 2 ++ providers/github.go | 3 +-- providers/linkedin.go | 3 --- validator.go | 6 ++++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/options_test.go b/options_test.go index 8d8fdf87..3b2f19f0 100644 --- a/options_test.go +++ b/options_test.go @@ -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) diff --git a/providers/github.go b/providers/github.go index a76d7550..c9b490f3 100644 --- a/providers/github.go +++ b/providers/github.go @@ -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 } diff --git a/providers/linkedin.go b/providers/linkedin.go index 78ad3c9c..21512297 100644 --- a/providers/linkedin.go +++ b/providers/linkedin.go @@ -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 diff --git a/validator.go b/validator.go index 396e6055..e3c0a542 100644 --- a/validator.go +++ b/validator.go @@ -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) }