Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions token/claimBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,11 @@ type remoteClaimBuilder struct {

func (rc *remoteClaimBuilder) AddClaims(ctx context.Context, r *Request, target map[string]interface{}) error {
rCopy := Request{
Metadata: make(map[string]interface{}),
PathValues: make(map[string]interface{}),
Metadata: make(map[string]interface{}),
PathWildCards: make(map[string]interface{}),
}

maps.Copy(rCopy.Metadata, r.Metadata)
maps.Copy(rCopy.PathValues, r.PathValues)
maps.Copy(rCopy.PathWildCards, r.PathWildCards)
if len(rc.extra) > 0 {
rCopy.Metadata = make(map[string]interface{}, len(r.Metadata)+len(rc.extra))
for k, v := range r.Metadata {
Expand Down
2 changes: 1 addition & 1 deletion token/claimBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ func (suite *NewClaimBuildersTestSuite) TestFull() {

actual := make(map[string]interface{})
suite.NoError(
builder.AddClaims(context.Background(), &Request{Claims: map[string]interface{}{"request": 123}, PathValues: make(map[string]interface{})}, actual),
builder.AddClaims(context.Background(), &Request{Claims: map[string]interface{}{"request": 123}, PathWildCards: make(map[string]interface{})}, actual),
)

suite.Equal(
Expand Down
14 changes: 7 additions & 7 deletions token/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type Request struct {
// metadata is available to lower levels of infrastructure used by the Factory.
Metadata map[string]interface{}

// PathValues holds non-claim information about the request, usually garnered from the original HTTP request. This
// PathValues is available to remote claim builders.
PathValues map[string]interface{}
// PathWildCards holds non-claim information about the request, usually garnered from the original HTTP request. This
// PathWildCards is available to remote claim builders
PathWildCards map[string]any

// TLS represents the state of any underlying TLS connection.
// For non-tls connections, this field is unset.
Expand All @@ -46,10 +46,10 @@ type Request struct {
// NewRequest returns an empty, fully initialized token Request
func NewRequest() *Request {
return &Request{
Logger: sallust.Default(),
Claims: make(map[string]interface{}),
Metadata: make(map[string]interface{}),
PathValues: make(map[string]interface{}),
Logger: sallust.Default(),
Claims: make(map[string]interface{}),
Metadata: make(map[string]interface{}),
PathWildCards: make(map[string]interface{}),
}
}

Expand Down
6 changes: 3 additions & 3 deletions token/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ type Options struct {
// Metadata describes non-claim data, which can be statically configured or supplied via a request
Metadata []Value

// PathValues holds non-claim information about the request, usually garnered from the original HTTP request. This
// PathValues is available to remote claim builders.
PathValues []Value
// PathWildCards holds non-claim information about the request, usually garnered from the original HTTP request. This
// PathWildCards is available to remote claim builders.
PathWildCards []Value

// PartnerID is the optional partner id configuration. If unset, no partner id processing is
// performed, though a partner id may still be configured as part of the claims.
Expand Down
8 changes: 4 additions & 4 deletions token/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func metadataSetter(key string, value interface{}, tr *Request) {
}

func pathValuesSetter(key string, value interface{}, tr *Request) {
tr.PathValues[key] = value
tr.PathWildCards[key] = value
}

type headerParameterRequestBuilder struct {
Expand Down Expand Up @@ -210,7 +210,7 @@ func (prb partnerIDRequestBuilder) Build(original *http.Request, tr *Request) er
}

if len(prb.PathValue) > 0 {
tr.PathValues[prb.PathValue] = partnerID
tr.PathWildCards[prb.PathValue] = partnerID
}
}

Expand Down Expand Up @@ -290,7 +290,7 @@ func NewRequestBuilders(o Options) (RequestBuilders, error) {
}
}

for _, value := range o.PathValues {
for _, value := range o.PathWildCards {
switch {
case len(value.Key) == 0:
return nil, ErrMissingKey
Expand Down Expand Up @@ -449,7 +449,7 @@ func EncodeRemoteClaimsRequest(c context.Context, r *http.Request, request inter
}

tr := request.(*Request)
for k, v := range tr.PathValues {
for k, v := range tr.PathWildCards {
r.URL.Path = strings.ReplaceAll(r.URL.Path, fmt.Sprintf("{%s}", k), v.(string))
}

Expand Down
51 changes: 26 additions & 25 deletions token/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func testNewRequestBuildersInvalidMetadata(t *testing.T) {
func testNewRequestBuildersInvalidPathValues(t *testing.T) {
assert := assert.New(t)
rb, err := NewRequestBuilders(Options{
PathValues: []Value{
PathWildCards: []Value{
{
Key: "bad",
Header: "xxx",
Expand All @@ -71,6 +71,7 @@ func testNewRequestBuildersInvalidPathValues(t *testing.T) {
assert.Equal(ErrVariableNotAllowed, err)
assert.Empty(rb)
}

func testNewRequestBuildersSuccess(t *testing.T) {
testData := []struct {
options Options
Expand Down Expand Up @@ -105,7 +106,7 @@ func testNewRequestBuildersSuccess(t *testing.T) {
Header: "X-Missing",
},
},
PathValues: []Value{
PathWildCards: []Value{
{
Key: "fromHeader",
Header: "X-PathVlaue",
Expand Down Expand Up @@ -135,7 +136,7 @@ func testNewRequestBuildersSuccess(t *testing.T) {
"fromHeader": "bar",
"partner-id-metadata": "test",
},
PathValues: map[string]any{
PathWildCards: map[string]any{
"fromHeader": "foobar",
"partner-id-pathValue": "test",
},
Expand Down Expand Up @@ -163,7 +164,7 @@ func testNewRequestBuildersSuccess(t *testing.T) {
Parameter: "missing",
},
},
PathValues: []Value{
PathWildCards: []Value{
{
Key: "fromParameter",
Parameter: "pathValue",
Expand Down Expand Up @@ -191,7 +192,7 @@ func testNewRequestBuildersSuccess(t *testing.T) {
"fromParameter": "bar",
"partner-id-metadata": "test",
},
PathValues: map[string]any{
PathWildCards: map[string]any{
"fromParameter": "foobar",
"partner-id-pathValue": "test",
},
Expand All @@ -211,7 +212,7 @@ func testNewRequestBuildersSuccess(t *testing.T) {
Variable: "metadata",
},
},
PathValues: []Value{
PathWildCards: []Value{
{
Key: "fromVariable",
Variable: "pathValues",
Expand Down Expand Up @@ -241,7 +242,7 @@ func testNewRequestBuildersSuccess(t *testing.T) {
"fromVariable": "bar",
"partner-id-metadata": "test",
},
PathValues: map[string]any{
PathWildCards: map[string]any{
"fromVariable": "foobar",
"partner-id-pathValue": "test",
},
Expand All @@ -261,7 +262,7 @@ func testNewRequestBuildersSuccess(t *testing.T) {
Variable: "metadata",
},
},
PathValues: []Value{
PathWildCards: []Value{
{
Key: "fromVariable",
Variable: "pathValue",
Expand All @@ -282,7 +283,7 @@ func testNewRequestBuildersSuccess(t *testing.T) {
Metadata: map[string]interface{}{
"fromVariable": "bar",
},
PathValues: map[string]any{
PathWildCards: map[string]any{
"fromVariable": "foobar",
},
},
Expand Down Expand Up @@ -407,10 +408,10 @@ func testBuildRequestSuccess(t *testing.T) {
}),
},
expected: &Request{
Logger: sallust.Default(),
Claims: map[string]interface{}{"claim": []int{1, 2, 3}},
Metadata: make(map[string]interface{}),
PathValues: make(map[string]interface{}),
Logger: sallust.Default(),
Claims: map[string]interface{}{"claim": []int{1, 2, 3}},
Metadata: make(map[string]interface{}),
PathWildCards: make(map[string]interface{}),
},
},
{
Expand All @@ -421,10 +422,10 @@ func testBuildRequestSuccess(t *testing.T) {
}),
},
expected: &Request{
Logger: sallust.Default(),
Claims: make(map[string]interface{}),
Metadata: map[string]interface{}{"metadata": -75.8},
PathValues: make(map[string]interface{}),
Logger: sallust.Default(),
Claims: make(map[string]interface{}),
Metadata: map[string]interface{}{"metadata": -75.8},
PathWildCards: make(map[string]interface{}),
},
},
{
Expand All @@ -444,10 +445,10 @@ func testBuildRequestSuccess(t *testing.T) {
}),
},
expected: &Request{
Logger: sallust.Default(),
Claims: map[string]interface{}{"claim1": 238947123, "claim2": []byte{1, 2, 3}},
Metadata: map[string]interface{}{"metadata1": "value1", "metadata2": 15.7},
PathValues: make(map[string]interface{}),
Logger: sallust.Default(),
Claims: map[string]interface{}{"claim1": 238947123, "claim2": []byte{1, 2, 3}},
Metadata: map[string]interface{}{"metadata1": "value1", "metadata2": 15.7},
PathWildCards: make(map[string]interface{}),
},
},
}
Expand Down Expand Up @@ -638,10 +639,10 @@ func testDecodeServerRequestSuccess(t *testing.T) {
require.IsType((*Request)(nil), v)
assert.Equal(
Request{
Logger: sallust.Default(),
Claims: map[string]interface{}{"claim": "value"},
Metadata: make(map[string]interface{}),
PathValues: make(map[string]interface{}),
Logger: sallust.Default(),
Claims: map[string]interface{}{"claim": "value"},
Metadata: make(map[string]interface{}),
PathWildCards: make(map[string]interface{}),
},
*v.(*Request),
)
Expand Down
Loading