Skip to content

Commit

Permalink
prevent operator from panic on invalid characters within eventhub-sto…
Browse files Browse the repository at this point in the history
…rage path

Signed-off-by: Christian Leinweber <christian.leinweber@maibornwolff.de>
  • Loading branch information
christle committed May 31, 2022
1 parent 9fab913 commit 28e4e84
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ To learn more about our roadmap, we recommend reading [this document](ROADMAP.md

### Fixes

- **General:** Refactor adapter startup to ensure proper log initilization. ([2316](https://github.com/kedacore/keda/issues/2316))
- **General:** Use metricName from GetMetricsSpec in ScaledJobs instead of `queueLength` ([#3032](https://github.com/kedacore/keda/issue/3032))
- **General:** Refactor adapter startup to ensure proper log initilization. ([2316](https://github.com/kedacore/keda/issues/2316))
- **Azure Eventhub Scaler:** KEDA operator crashes on nil memory panic if the eventhub connectionstring for Azure Eventhub Scaler contains an invalid character ([#3082](https://github.com/kedacore/keda/issues/3082))

### Deprecations

Expand Down
16 changes: 13 additions & 3 deletions pkg/scalers/azure/azure_eventhub_checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ func (checkpointer *azureFunctionCheckpointer) resolvePath(info EventHubInfo) (*
return nil, err
}

path, _ := url.Parse(fmt.Sprintf("/%s/%s/%s/%s/%s", checkpointer.containerName, eventHubNamespace, eventHubName, info.EventHubConsumerGroup, checkpointer.partitionID))
path, err := url.Parse(fmt.Sprintf("/%s/%s/%s/%s/%s", checkpointer.containerName, eventHubNamespace, eventHubName, info.EventHubConsumerGroup, checkpointer.partitionID))
if err != nil {
return nil, err
}

return path, nil
}
Expand All @@ -148,7 +151,11 @@ func (checkpointer *blobMetadataCheckpointer) resolvePath(info EventHubInfo) (*u
return nil, err
}

path, _ := url.Parse(fmt.Sprintf("/%s/%s/%s/%s/checkpoint/%s", checkpointer.containerName, eventHubNamespace, eventHubName, strings.ToLower(info.EventHubConsumerGroup), checkpointer.partitionID))
path, err := url.Parse(fmt.Sprintf("/%s/%s/%s/%s/checkpoint/%s", checkpointer.containerName, eventHubNamespace, eventHubName, strings.ToLower(info.EventHubConsumerGroup), checkpointer.partitionID))
if err != nil {
return nil, err
}

return path, nil
}

Expand All @@ -159,7 +166,10 @@ func (checkpointer *blobMetadataCheckpointer) extractCheckpoint(get *azblob.Down

// resolve path for goSdkCheckpointer
func (checkpointer *goSdkCheckpointer) resolvePath(info EventHubInfo) (*url.URL, error) {
path, _ := url.Parse(fmt.Sprintf("/%s/%s", info.BlobContainer, checkpointer.partitionID))
path, err := url.Parse(fmt.Sprintf("/%s/%s", info.BlobContainer, checkpointer.partitionID))
if err != nil {
return nil, err
}

return path, nil
}
Expand Down
16 changes: 16 additions & 0 deletions pkg/scalers/azure/azure_eventhub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,22 @@ func TestShouldParseCheckpointForBlobMetadata(t *testing.T) {
assert.Equal(t, url.Path, "/containername/eventhubnamespace.servicebus.windows.net/hub-test/$default/checkpoint/0")
}

func TestShouldParseCheckpointForBlobMetadataWithError(t *testing.T) {
eventHubInfo := EventHubInfo{
EventHubConnection: "Endpoint=sb://eventhubnamespace.servicebus.windows.net/;EntityPath=hub-test\n",
EventHubConsumerGroup: "$Default",
BlobContainer: "containername",
CheckpointStrategy: "blobMetadata",
}

cp := newCheckpointer(eventHubInfo, "0")
_, err := cp.resolvePath(eventHubInfo)

if err == nil {
t.Errorf("Should have return an err on invalid url characters")
}
}

func TestShouldParseCheckpointForBlobMetadataWithPodIdentity(t *testing.T) {
eventHubInfo := EventHubInfo{
Namespace: "eventhubnamespace",
Expand Down

0 comments on commit 28e4e84

Please sign in to comment.