From 3ad9ea1a336d684b6af90a16241ae13518339b65 Mon Sep 17 00:00:00 2001 From: Jared Scheib Date: Mon, 7 May 2018 11:27:00 -0700 Subject: [PATCH 1/2] partial revert(43c5afe7) to fix GitHub Enterprise via Generic Oauth The above commit was over-applied in #3168 to Generic Oauth in addition to GitHub Oauth based on an assumption. It should only have been applied to GitHub-specific OAuth. This over-application introduced a bug where GitHub Enterprise did not work anymore. --- oauth2/generic.go | 24 +----------------------- oauth2/generic_test.go | 4 +--- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/oauth2/generic.go b/oauth2/generic.go index 54b4392fc..c53c98c87 100644 --- a/oauth2/generic.go +++ b/oauth2/generic.go @@ -165,28 +165,6 @@ type UserEmail struct { Verified *bool `json:"verified,omitempty"` } -// GetPrimary returns if the email is the primary email. -// If primary is not present, all emails are considered the primary. -func (u *UserEmail) GetPrimary() bool { - if u == nil { - return false - } else if u.Primary == nil { - return true - } - return *u.Primary -} - -// GetVerified returns if the email has been verified. -// If verified is not present, all emails are considered verified. -func (u *UserEmail) GetVerified() bool { - if u == nil { - return false - } else if u.Verified == nil { - return true - } - return *u.Verified -} - // getPrimaryEmail gets the private email account for the authenticated user. func (g *Generic) getPrimaryEmail(client *http.Client) (string, error) { emailsEndpoint := g.APIURL + "/emails" @@ -211,7 +189,7 @@ func (g *Generic) getPrimaryEmail(client *http.Client) (string, error) { func (g *Generic) primaryEmail(emails []*UserEmail) (string, error) { for _, m := range emails { - if m != nil && m.GetPrimary() && m.GetVerified() && m.Email != nil { + if m != nil && m.Primary != nil && m.Verified != nil && m.Email != nil { return *m.Email, nil } } diff --git a/oauth2/generic_test.go b/oauth2/generic_test.go index 33e54c5de..89bfc8818 100644 --- a/oauth2/generic_test.go +++ b/oauth2/generic_test.go @@ -155,9 +155,7 @@ func TestGenericPrincipalIDDomain(t *testing.T) { Primary bool `json:"primary"` Verified bool `json:"verified"` }{ - {"mcfly@example.com", false, true}, - {"martymcspelledwrong@example.com", false, false}, - {"martymcfly@pinheads.rok", true, true}, + {"martymcfly@pinheads.rok", true, false}, } mockAPI := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { if r.URL.Path == "/" { From 2b78e08760f27d0aca8f541449a8f44d2c9d6188 Mon Sep 17 00:00:00 2001 From: Jared Scheib Date: Mon, 7 May 2018 11:40:02 -0700 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e71ae6661..41c90ff45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ 1. [#3353](https://github.com/influxdata/chronograf/pull/3353): Display y-axis label on initial graph load 1. [#3352](https://github.com/influxdata/chronograf/pull/3352): Fix not being able to change the source in the CEO display 1. [#3357](https://github.com/influxdata/chronograf/pull/3357): Fix only the selected template variable value getting loaded +1. [#3389](https://github.com/influxdata/chronograf/pull/3389): Fix Generic OAuth bug for GitHub Enterprise where the principal was incorrectly being checked for email being Primary and Verified ## v1.4.4.1 [2018-04-16]