Skip to content

Commit

Permalink
More robust handling for missing email
Browse files Browse the repository at this point in the history
  • Loading branch information
jehiah committed Jul 24, 2015
1 parent c1bf1ad commit 0692c37
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 2 additions & 0 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func testOptions() *Options {
o.CookieSecret = "foobar"
o.ClientID = "bazquux"
o.ClientSecret = "xyzzyplugh"
o.EmailDomains = []string{"*"}
return o
}

Expand All @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions providers/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package providers

import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
Expand Down Expand Up @@ -211,5 +210,5 @@ func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {
}
}

return "", errors.New("no email address found")
return "", nil
}
3 changes: 0 additions & 3 deletions providers/linkedin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package providers
import (
"errors"
"fmt"
"log"
"net/http"
"net/url"

Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 0692c37

Please sign in to comment.