EventManager: support placeholders within URL paths

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2023-01-22 08:46:58 +01:00
parent 707729ee61
commit 3ce4d04b27
5 changed files with 52 additions and 10 deletions

View File

@@ -21,6 +21,7 @@ import (
"io"
"mime/multipart"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
@@ -703,6 +704,7 @@ func TestEventRuleActions(t *testing.T) {
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "unable to decrypt HTTP password")
}
action.Options.HTTPConfig.Endpoint = fmt.Sprintf("http://%v", httpAddr)
action.Options.HTTPConfig.Password = kms.NewEmptySecret()
action.Options.HTTPConfig.Body = ""
action.Options.HTTPConfig.Parts = []dataprovider.HTTPPart{
@@ -1890,3 +1892,33 @@ func getErrorString(err error) string {
}
return err.Error()
}
func TestHTTPEndpointWithPlaceholders(t *testing.T) {
c := dataprovider.EventActionHTTPConfig{
Endpoint: "http://127.0.0.1:8080/base/url/{{Name}}/{{VirtualPath}}/upload",
QueryParameters: []dataprovider.KeyValue{
{
Key: "u",
Value: "{{Name}}",
},
{
Key: "p",
Value: "{{VirtualPath}}",
},
},
}
name := "uname"
vPath := "/a dir/@ file.txt"
replacer := strings.NewReplacer("{{Name}}", name, "{{VirtualPath}}", vPath)
u, err := getHTTPRuleActionEndpoint(c, replacer)
assert.NoError(t, err)
expected := "http://127.0.0.1:8080/base/url/" + url.PathEscape(name) + "/" + url.PathEscape(vPath) +
"/upload?" + "p=" + url.QueryEscape(vPath) + "&u=" + url.QueryEscape(name)
assert.Equal(t, expected, u)
c.Endpoint = "http://127.0.0.1/upload"
u, err = getHTTPRuleActionEndpoint(c, replacer)
assert.NoError(t, err)
expected = c.Endpoint + "?p=" + url.QueryEscape(vPath) + "&u=" + url.QueryEscape(name)
assert.Equal(t, expected, u)
}