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
  • Loading branch information
christle committed May 30, 2022
1 parent ea8cc19 commit 12bb992
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
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 12bb992

Please sign in to comment.