forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OAuth: Support JMES path lookup when retrieving user email (grafana#1…
…4683) Add support for fetching e-mail with JMES path Signed-off-by: Bob Shannon <bobs@dropbox.com>
- Loading branch information
1 parent
35b74a9
commit 056dbc7
Showing
7 changed files
with
144 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package social | ||
|
||
import ( | ||
"github.com/grafana/grafana/pkg/infra/log" | ||
. "github.com/smartystreets/goconvey/convey" | ||
"testing" | ||
) | ||
|
||
func TestSearchJSONForEmail(t *testing.T) { | ||
Convey("Given a generic OAuth provider", t, func() { | ||
provider := SocialGenericOAuth{ | ||
SocialBase: &SocialBase{ | ||
log: log.New("generic_oauth_test"), | ||
}, | ||
} | ||
|
||
tests := []struct { | ||
Name string | ||
UserInfoJSONResponse []byte | ||
EmailAttributePath string | ||
ExpectedResult string | ||
}{ | ||
{ | ||
Name: "Given an invalid user info JSON response", | ||
UserInfoJSONResponse: []byte("{"), | ||
EmailAttributePath: "attributes.email", | ||
ExpectedResult: "", | ||
}, | ||
{ | ||
Name: "Given an empty user info JSON response and empty JMES path", | ||
UserInfoJSONResponse: []byte{}, | ||
EmailAttributePath: "", | ||
ExpectedResult: "", | ||
}, | ||
{ | ||
Name: "Given an empty user info JSON response and valid JMES path", | ||
UserInfoJSONResponse: []byte{}, | ||
EmailAttributePath: "attributes.email", | ||
ExpectedResult: "", | ||
}, | ||
{ | ||
Name: "Given a simple user info JSON response and valid JMES path", | ||
UserInfoJSONResponse: []byte(`{ | ||
"attributes": { | ||
"email": "grafana@localhost" | ||
} | ||
}`), | ||
EmailAttributePath: "attributes.email", | ||
ExpectedResult: "grafana@localhost", | ||
}, | ||
{ | ||
Name: "Given a user info JSON response with e-mails array and valid JMES path", | ||
UserInfoJSONResponse: []byte(`{ | ||
"attributes": { | ||
"emails": ["grafana@localhost", "admin@localhost"] | ||
} | ||
}`), | ||
EmailAttributePath: "attributes.emails[0]", | ||
ExpectedResult: "grafana@localhost", | ||
}, | ||
{ | ||
Name: "Given a nested user info JSON response and valid JMES path", | ||
UserInfoJSONResponse: []byte(`{ | ||
"identities": [ | ||
{ | ||
"userId": "grafana@localhost" | ||
}, | ||
{ | ||
"userId": "admin@localhost" | ||
} | ||
] | ||
}`), | ||
EmailAttributePath: "identities[0].userId", | ||
ExpectedResult: "grafana@localhost", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
provider.emailAttributePath = test.EmailAttributePath | ||
Convey(test.Name, func() { | ||
actualResult := provider.searchJSONForEmail(test.UserInfoJSONResponse) | ||
So(actualResult, ShouldEqual, test.ExpectedResult) | ||
}) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters