Skip to content

Commit

Permalink
fix(#4916): Improve component resolver
Browse files Browse the repository at this point in the history
- Support URL query parameters when resolving components by given scheme
- Do not resolve URLs that use parameter placeholder as a scheme
- Properly extract scheme from URL that has query parameters
  • Loading branch information
christophd committed Nov 16, 2023
1 parent d6063e6 commit b3464f0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/util/camel/camel_runtime_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ func (c *RuntimeCatalog) IsResolvable(uri string) bool {
return false
}

if scheme := uriSplit[0]; strings.HasPrefix(scheme, "{{") && strings.HasSuffix(scheme, "}}") {
scheme := uriSplit[0]
if strings.Contains(scheme, "?") {
scheme = strings.SplitN(scheme, "?", 2)[0]
}

if strings.HasPrefix(scheme, "{{") && strings.HasSuffix(scheme, "}}") {
// scheme is a property placeholder (e.g. {{url}}) which is not resolvable
return false
}
Expand Down
25 changes: 25 additions & 0 deletions pkg/util/camel/camel_runtime_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,28 @@ func TestHasLoaderByArtifact(t *testing.T) {
assert.True(t, catalog.HasLoaderByArtifact("yaml-dsl"))
assert.False(t, catalog.HasLoaderByArtifact("python-dsl"))
}

func TestIsResolvable(t *testing.T) {
catalog, err := DefaultCatalog()
require.NoError(t, err)

testCases := []struct {
desc string
uri string
expected bool
}{
{desc: "Basic", uri: "{{url}}", expected: false},
{desc: "With query param placeholder", uri: "{{url}}?authMethod={{authMethod}}", expected: false},
{desc: "With query param", uri: "{{url}}?authMethod=Basic", expected: false},
{desc: "With masked AND url-encoded query params", uri: "{{url}}?authMethod=%7B%7BauthMethod%7D%7D", expected: false},
}

for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
if got := catalog.IsResolvable(testCase.uri); got != testCase.expected {
t.Errorf("IsResolvable(%v) = %v, want %v", testCase.uri, got, testCase.expected)

}
})
}
}

0 comments on commit b3464f0

Please sign in to comment.