1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2024-11-24 08:52:25 +02:00

More robust handling for missing email

This commit is contained in:
Jehiah Czebotar 2015-07-24 16:23:19 -04:00
parent c1bf1ad167
commit 0692c3763f
4 changed files with 7 additions and 7 deletions

View File

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

View File

@ -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
} }

View File

@ -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

View File

@ -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)
} }