Skip to content

Commit

Permalink
Add Fix to solace endpointURL to query escape special character fro…
Browse files Browse the repository at this point in the history
…m `queueName` (kedacore#4940)
  • Loading branch information
dttung2905 committed Sep 3, 2023
1 parent fdb23d0 commit 151245b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ To learn more about active deprecations, we recommend checking [GitHub Discussio

### Fixes

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

### Deprecations

Expand Down
4 changes: 3 additions & 1 deletion pkg/scalers/solace_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
"strings"

Expand Down Expand Up @@ -252,7 +253,8 @@ func parseSolaceMetadata(config *ScalerConfig) (*SolaceMetadata, error) {
solaceAPIVersion,
meta.messageVpn,
solaceAPIObjectTypeQueue,
meta.queueName)
url.QueryEscape(meta.queueName),
)

// Get Credentials
var e error
Expand Down
25 changes: 24 additions & 1 deletion pkg/scalers/solace_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"net/http"
"net/url"
"strings"
"testing"

v2 "k8s.io/api/autoscaling/v2"
Expand Down Expand Up @@ -246,6 +248,23 @@ var testParseSolaceMetadata = []testSolaceMetadata{
1,
true,
},
// +Case - Properly encode queueName
{
"#016 - Properly Encode QueueName- ",
map[string]string{
"": "",
solaceMetaSempBaseURL: soltestValidBaseURL,
solaceMetaMsgVpn: soltestValidVpn,
solaceMetaUsernameFromEnv: "",
solaceMetaPasswordFromEnv: "",
solaceMetaUsername: soltestValidUsername,
solaceMetaPassword: soltestValidPassword,
solaceMetaQueueName: "with/slash",
solaceMetaMsgCountTarget: soltestValidMsgCountTarget,
},
1,
false,
},
}

var testSolaceEnvCreds = []testSolaceMetadata{
Expand Down Expand Up @@ -513,7 +532,7 @@ var testSolaceExpectedMetricNames = map[string]string{
func TestSolaceParseSolaceMetadata(t *testing.T) {
for _, testData := range testParseSolaceMetadata {
fmt.Print(testData.testID)
_, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: nil, ScalerIndex: testData.scalerIndex})
meta, err := parseSolaceMetadata(&ScalerConfig{ResolvedEnv: nil, TriggerMetadata: testData.metadata, AuthParams: nil, ScalerIndex: testData.scalerIndex})
switch {
case err != nil && !testData.isError:
t.Error("expected success but got error: ", err)
Expand All @@ -524,6 +543,10 @@ func TestSolaceParseSolaceMetadata(t *testing.T) {
default:
fmt.Println(" --> PASS")
}
if !testData.isError && strings.Contains(testData.metadata["queueName"], "/") && !strings.Contains(meta.endpointURL, url.QueryEscape(testData.metadata["queueName"])) {
t.Error("expected endpointURL to query escape special characters in the URL but got:", meta.endpointURL)
fmt.Println(" --> FAIL")
}
}
for _, testData := range testSolaceEnvCreds {
fmt.Print(testData.testID)
Expand Down

0 comments on commit 151245b

Please sign in to comment.