From b3464f05fa8248796ae2020e8ecb869678959a24 Mon Sep 17 00:00:00 2001 From: Christoph Deppisch Date: Wed, 15 Nov 2023 08:10:09 +0100 Subject: [PATCH] fix(#4916): Improve component resolver - 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 --- pkg/util/camel/camel_runtime_catalog.go | 7 +++++- pkg/util/camel/camel_runtime_catalog_test.go | 25 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/pkg/util/camel/camel_runtime_catalog.go b/pkg/util/camel/camel_runtime_catalog.go index 0bea96bbbe..b33b838002 100644 --- a/pkg/util/camel/camel_runtime_catalog.go +++ b/pkg/util/camel/camel_runtime_catalog.go @@ -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 } diff --git a/pkg/util/camel/camel_runtime_catalog_test.go b/pkg/util/camel/camel_runtime_catalog_test.go index 487547a0a8..796ee93412 100644 --- a/pkg/util/camel/camel_runtime_catalog_test.go +++ b/pkg/util/camel/camel_runtime_catalog_test.go @@ -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) + + } + }) + } +}