Ensure claim extractor does not attempt profile call when URL is empty

This commit is contained in:
Joel Speed
2022-02-19 15:33:30 +00:00
parent 07aba7db09
commit 25ef843115
3 changed files with 20 additions and 1 deletions
+1 -1
View File
@@ -86,7 +86,7 @@ func (c *claimExtractor) GetClaim(claim string) (interface{}, bool, error) {
// loadProfileClaims will fetch the profileURL using the provided headers as
// authentication.
func (c *claimExtractor) loadProfileClaims() (*simplejson.Json, error) {
if c.profileURL == nil || c.requestHeaders == nil {
if c.profileURL == nil || c.profileURL.String() == "" || c.requestHeaders == nil {
// When no profileURL is set, we return a non-empty map so that
// we don't attempt to populate the profile claims again.
// If there are no headers, the request would be unauthorized so we also skip
@@ -259,6 +259,24 @@ var _ = Describe("Claim Extractor Suite", func() {
Expect(counter).To(BeEquivalentTo(1))
})
It("GetClaim should not return an error with a non-nil empty ProfileURL", func() {
claims, serverClose, err := newTestClaimExtractor(testClaimExtractorOpts{
idTokenPayload: "{}",
profileRequestHeaders: newAuthorizedHeader(),
})
Expect(err).ToNot(HaveOccurred())
if serverClose != nil {
defer serverClose()
}
// Set the ProfileURL to be empty, but not nil
claims.(*claimExtractor).profileURL = &url.URL{}
value, exists, err := claims.GetClaim("user")
Expect(err).ToNot(HaveOccurred())
Expect(exists).To(BeFalse())
Expect(value).To(BeNil())
})
type getClaimIntoTableInput struct {
testClaimExtractorOpts
into interface{}