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.CookieSecret = "foobar"
|
||||||
o.ClientID = "bazquux"
|
o.ClientID = "bazquux"
|
||||||
o.ClientSecret = "xyzzyplugh"
|
o.ClientSecret = "xyzzyplugh"
|
||||||
|
o.EmailDomains = []string{"*"}
|
||||||
return o
|
return o
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +28,7 @@ func errorMsg(msgs []string) string {
|
|||||||
|
|
||||||
func TestNewOptions(t *testing.T) {
|
func TestNewOptions(t *testing.T) {
|
||||||
o := NewOptions()
|
o := NewOptions()
|
||||||
|
o.EmailDomains = []string{"*"}
|
||||||
err := o.Validate()
|
err := o.Validate()
|
||||||
assert.NotEqual(t, nil, err)
|
assert.NotEqual(t, nil, err)
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package providers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"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 (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
@ -60,13 +59,11 @@ func (p *LinkedInProvider) GetEmailAddress(s *SessionState) (string, error) {
|
|||||||
|
|
||||||
json, err := api.Request(req)
|
json, err := api.Request(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed making request %s", err)
|
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
email, err := json.String()
|
email, err := json.String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed making request %s", err)
|
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
return email, nil
|
return email, nil
|
||||||
|
@ -71,9 +71,11 @@ func newValidatorImpl(domains []string, usersFile string,
|
|||||||
domains[i] = fmt.Sprintf("@%s", strings.ToLower(domain))
|
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)
|
email = strings.ToLower(email)
|
||||||
valid := false
|
|
||||||
for _, domain := range domains {
|
for _, domain := range domains {
|
||||||
valid = valid || strings.HasSuffix(email, domain)
|
valid = valid || strings.HasSuffix(email, domain)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user