fix: should check if email is verified

This commit is contained in:
Carlos Alexandro Becker 2019-03-11 14:52:08 -03:00
parent 056089bbcc
commit b49aeb222b
No known key found for this signature in database
GPG Key ID: E61E2F7DC14AB940
2 changed files with 6 additions and 6 deletions

View File

@ -203,7 +203,7 @@ func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {
var emails []struct {
Email string `json:"email"`
Primary bool `json:"primary"`
Verified bool `json:"verified"`
}
// if we require an Org or Team, check that first
@ -248,7 +248,7 @@ func (p *GitHubProvider) GetEmailAddress(s *SessionState) (string, error) {
}
for _, email := range emails {
if email.Primary {
if email.Verified {
return email.Email, nil
}
}

View File

@ -97,7 +97,7 @@ func TestGitHubProviderOverrides(t *testing.T) {
}
func TestGitHubProviderGetEmailAddress(t *testing.T) {
b := testGitHubBackend([]string{`[ {"email": "michael.bland@gsa.gov", "primary": true} ]`})
b := testGitHubBackend([]string{`[ {"email": "michael.bland@gsa.gov", "verified": true} ]`})
defer b.Close()
bURL, _ := url.Parse(b.URL)
@ -111,8 +111,8 @@ func TestGitHubProviderGetEmailAddress(t *testing.T) {
func TestGitHubProviderGetEmailAddressWithOrg(t *testing.T) {
b := testGitHubBackend([]string{
`[ {"email": "michael.bland@gsa.gov", "primary": true, "login":"testorg"} ]`,
`[ {"email": "michael.bland1@gsa.gov", "primary": true, "login":"testorg1"} ]`,
`[ {"email": "michael.bland@gsa.gov", "verified": true, "login":"testorg"} ]`,
`[ {"email": "michael.bland1@gsa.gov", "verified": true, "login":"testorg1"} ]`,
`[ ]`,
})
defer b.Close()