Skip to content

Commit 151245b

Browse files
authored
Add Fix to solace endpointURL to query escape special character from queueName (#4940)
1 parent fdb23d0 commit 151245b

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio
6262

6363
### Fixes
6464

65-
- TODO ([#XXX](https://github.com/kedacore/keda/issues/XXX))
65+
- **Solace Scaler**: Fix a bug where `queueName` is not properly escaped during URL encode ([#4936](https://github.com/kedacore/keda/issues/4936))
6666

6767
### Deprecations
6868

pkg/scalers/solace_scaler.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"net/http"
8+
"net/url"
89
"strconv"
910
"strings"
1011

@@ -252,7 +253,8 @@ func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) {
252253
solaceAPIVersion,
253254
meta.messageVpn,
254255
solaceAPIObjectTypeQueue,
255-
meta.queueName)
256+
url.QueryEscape(meta.queueName),
257+
)
256258

257259
// Get Credentials
258260
var e error

pkg/scalers/solace_scaler_test.go

+24-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"fmt"
66
"net/http"
7+
"net/url"
8+
"strings"
79
"testing"
810

911
v2 "k8s.io/api/autoscaling/v2"
@@ -246,6 +248,23 @@ var testParseSolaceMetadata = []testSolaceMetadata{
246248
1,
247249
true,
248250
},
251+
// +Case - Properly encode queueName
252+
{
253+
"#016 - Properly Encode QueueName- ",
254+
map[string]string{
255+
"": "",
256+
solaceMetaSempBaseURL: soltestValidBaseURL,
257+
solaceMetaMsgVpn: soltestValidVpn,
258+
solaceMetaUsernameFromEnv: "",
259+
solaceMetaPasswordFromEnv: "",
260+
solaceMetaUsername: soltestValidUsername,
261+
solaceMetaPassword: soltestValidPassword,
262+
solaceMetaQueueName: "with/slash",
263+
solaceMetaMsgCountTarget: soltestValidMsgCountTarget,
264+
},
265+
1,
266+
false,
267+
},
249268
}
250269

251270
var testSolaceEnvCreds = []testSolaceMetadata{
@@ -513,7 +532,7 @@ var testSolaceExpectedMetricNames = map[string]string{
513532
func TestSolaceParseSolaceMetadata(t *testing.T) {
514533
for _, testData := range testParseSolaceMetadata {
515534
fmt.Print(testData.testID)
516-
_, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: nil, ScalerIndex: testData.scalerIndex})
535+
meta, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: nil, ScalerIndex: testData.scalerIndex})
517536
switch {
518537
case err != nil && !testData.isError:
519538
t.Error("expected success but got error: ", err)
@@ -524,6 +543,10 @@ func TestSolaceParseSolaceMetadata(t *testing.T) {
524543
default:
525544
fmt.Println(" --> PASS")
526545
}
546+
if !testData.isError && strings.Contains(testData.metadata["queueName"], "/") && !strings.Contains(meta.endpointURL, url.QueryEscape(testData.metadata["queueName"])) {
547+
t.Error("expected endpointURL to query escape special characters in the URL but got:", meta.endpointURL)
548+
fmt.Println(" --> FAIL")
549+
}
527550
}
528551
for _, testData := range testSolaceEnvCreds {
529552
fmt.Print(testData.testID)

0 commit comments

Comments
 (0)