-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new header to capture customattributes (#402)
- Loading branch information
1 parent
c70fcad
commit 4604974
Showing
7 changed files
with
103 additions
and
58 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 |
---|---|---|
|
@@ -34,13 +34,14 @@ func TestMetadataHeaders(t *testing.T) { | |
"env", | ||
} | ||
authContext := &auth.Context{ | ||
Context: h, | ||
ClientID: "clientid", | ||
AccessToken: "accesstoken", | ||
Application: "application", | ||
APIProducts: []string{"prod1", "prod2"}, | ||
DeveloperEmail: "[email protected]", | ||
Scopes: []string{"scope1", "scope2"}, | ||
Context: h, | ||
ClientID: "clientid", | ||
AccessToken: "accesstoken", | ||
Application: "application", | ||
APIProducts: []string{"prod1", "prod2"}, | ||
DeveloperEmail: "[email protected]", | ||
Scopes: []string{"scope1", "scope2"}, | ||
CustomAttributes: "{\"tier\":\"standard\"}", | ||
} | ||
api := "api" | ||
opts = makeMetadataHeaders(api, authContext, true) | ||
|
@@ -61,6 +62,7 @@ func TestMetadataHeaders(t *testing.T) { | |
equal(headerApplication, authContext.Application) | ||
equal(headerClientID, authContext.ClientID) | ||
equal(headerDeveloperEmail, authContext.DeveloperEmail) | ||
equal(headerCustomAttributes, authContext.CustomAttributes) | ||
equal(headerEnvironment, authContext.Environment()) | ||
equal(headerOrganization, authContext.Organization()) | ||
equal(headerScope, strings.Join(authContext.Scopes, " ")) | ||
|
@@ -75,6 +77,35 @@ func TestMetadataHeaders(t *testing.T) { | |
} | ||
} | ||
|
||
func TestCustomAttributeMetadata(t *testing.T) { | ||
h := &multitenantContext{ | ||
&Handler{ | ||
orgName: "org", | ||
envName: "*", | ||
isMultitenant: true, | ||
}, | ||
"env", | ||
} | ||
ac := &auth.Context{ | ||
Context: h, | ||
ClientID: "clientid", | ||
AccessToken: "accesstoken", | ||
Application: "application", | ||
APIProducts: []string{"prod1", "prod2"}, | ||
DeveloperEmail: "[email protected]", | ||
Scopes: []string{"scope1", "scope2"}, | ||
} | ||
|
||
// Call the function with authorized set to true | ||
headers := makeMetadataHeaders("api", ac, true) | ||
|
||
// Verify that the CustomAttributes header is not included in the headers | ||
for _, h := range headers { | ||
if h.Header.Key == headerCustomAttributes { | ||
t.Errorf("Expected CustomAttributes header to not be included, but found it with value %s", h.Header.Value) | ||
} | ||
} | ||
} | ||
func TestMetadataHeadersExceptions(t *testing.T) { | ||
opts := makeMetadataHeaders("api", nil, true) | ||
if opts != nil { | ||
|
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 |
---|---|---|
|
@@ -33,13 +33,14 @@ func TestEncodeMetadata(t *testing.T) { | |
"env", | ||
} | ||
authContext := &auth.Context{ | ||
Context: h, | ||
ClientID: "clientid", | ||
AccessToken: "accesstoken", | ||
Application: "application", | ||
APIProducts: []string{"prod1", "prod2"}, | ||
DeveloperEmail: "[email protected]", | ||
Scopes: []string{"scope1", "scope2"}, | ||
Context: h, | ||
ClientID: "clientid", | ||
AccessToken: "accesstoken", | ||
Application: "application", | ||
APIProducts: []string{"prod1", "prod2"}, | ||
DeveloperEmail: "[email protected]", | ||
Scopes: []string{"scope1", "scope2"}, | ||
CustomAttributes: "{\"tier\":\"standard\"}", | ||
} | ||
api := "api" | ||
metadata := encodeExtAuthzMetadata(api, authContext, true) | ||
|
@@ -63,6 +64,7 @@ func TestEncodeMetadata(t *testing.T) { | |
equal(headerEnvironment, authContext.Environment()) | ||
equal(headerOrganization, authContext.Organization()) | ||
equal(headerScope, strings.Join(authContext.Scopes, " ")) | ||
equal(headerCustomAttributes, authContext.CustomAttributes) | ||
|
||
api2, ac2 := h.decodeExtAuthzMetadata(metadata.GetFields()) | ||
if api != api2 { | ||
|
@@ -86,13 +88,14 @@ func TestEncodeMetadataAuthorizedField(t *testing.T) { | |
envName: "env", | ||
} | ||
authContext := &auth.Context{ | ||
Context: h, | ||
ClientID: "clientid", | ||
AccessToken: "accesstoken", | ||
Application: "application", | ||
APIProducts: []string{"prod1", "prod2"}, | ||
DeveloperEmail: "[email protected]", | ||
Scopes: []string{"scope1", "scope2"}, | ||
Context: h, | ||
ClientID: "clientid", | ||
AccessToken: "accesstoken", | ||
Application: "application", | ||
APIProducts: []string{"prod1", "prod2"}, | ||
DeveloperEmail: "[email protected]", | ||
Scopes: []string{"scope1", "scope2"}, | ||
CustomAttributes: "", | ||
} | ||
|
||
metadata := encodeExtAuthzMetadata("api", authContext, true) | ||
|