From 059dcbfdbdd9db8ddd257e89d7957c56b924386a Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 23 Dec 2015 00:08:51 -0800 Subject: [PATCH] Ignore spaces in authorized emails list adding enterprise github provider print the error stack trace point to my fork in oauthproxy.go addint pointers to ruta-goomba fork in mulitple files change api endpoint replace hard-coded github api endpoint with variables resetting fall through github urls to point to github.com fix malformed url remove pointers to fork files removing comment changes and cookie error output changes replace spacing changes --- providers/github.go | 6 +++--- validator.go | 3 ++- validator_test.go | 13 +++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/providers/github.go b/providers/github.go index cf0cfcbe2..124eebeea 100644 --- a/providers/github.go +++ b/providers/github.go @@ -63,7 +63,7 @@ func (p *GitHubProvider) hasOrg(accessToken string) (bool, error) { "limit": {"100"}, } - endpoint := "https://api.github.com/user/orgs?" + params.Encode() + endpoint := p.ValidateURL.Scheme + "://" + p.ValidateURL.Host + "/user/orgs?" + params.Encode() req, _ := http.NewRequest("GET", endpoint, nil) req.Header.Set("Accept", "application/vnd.github.v3+json") resp, err := http.DefaultClient.Do(req) @@ -113,7 +113,7 @@ func (p *GitHubProvider) hasOrgAndTeam(accessToken string) (bool, error) { "limit": {"100"}, } - endpoint := "https://api.github.com/user/teams?" + params.Encode() + endpoint := p.ValidateURL.Scheme + "://" + p.ValidateURL.Host + "/user/teams?" + params.Encode() req, _ := http.NewRequest("GET", endpoint, nil) req.Header.Set("Accept", "application/vnd.github.v3+json") resp, err := http.DefaultClient.Do(req) @@ -183,7 +183,7 @@ func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) { params := url.Values{ "access_token": {s.AccessToken}, } - endpoint := "https://api.github.com/user/emails?" + params.Encode() + endpoint := p.ValidateURL.Scheme + "://" + p.ValidateURL.Host + p.ValidateURL.Path + "?" + params.Encode() resp, err := http.DefaultClient.Get(endpoint) if err != nil { return "", err diff --git a/validator.go b/validator.go index e3c0a542b..1b0492369 100644 --- a/validator.go +++ b/validator.go @@ -53,7 +53,8 @@ func (um *UserMap) LoadAuthenticatedEmailsFile() { } updated := make(map[string]bool) for _, r := range records { - updated[strings.ToLower(r[0])] = true + address := strings.ToLower(strings.TrimSpace(r[0])) + updated[address] = true } atomic.StorePointer(&um.m, unsafe.Pointer(&updated)) } diff --git a/validator_test.go b/validator_test.go index 0bf0a08fc..b87d419b8 100644 --- a/validator_test.go +++ b/validator_test.go @@ -147,3 +147,16 @@ func TestValidatorComparisonsAreCaseInsensitive(t *testing.T) { t.Error("validated domains are not lower-cased") } } + +func TestValidatorIgnoreSpacesInAuthEmails(t *testing.T) { + vt := NewValidatorTest(t) + defer vt.TearDown() + + vt.WriteEmails(t, []string{" foo.bar@example.com "}) + domains := []string(nil) + validator := vt.NewValidator(domains, nil) + + if !validator("foo.bar@example.com") { + t.Error("email should validate") + } +}