Skip to content

Commit

Permalink
[fix][httpjson] Fix incorrect key for template data (#26848)
Browse files Browse the repository at this point in the history
* [httpjson] Fix incorrect key for template data

* Add test
  • Loading branch information
marc-gr authored Jul 13, 2021
1 parent 0b1736e commit eb758b9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix Elasticsearch compatibility for modules that use the `network_direction` processor. {issue}26629[26629] {pull}26676[26676]
- Fix Elasticsearch compatibility for modules that use the `registered_domain` processor. {issue}26629[26629] {pull}26676[26676]
- Fix Suricata metadata fields breaking visualizations, moved out of flattened datatype. {pull}26710[26710]
- Fix `httpjson` template data key for `url.params`. {pull}26848[26848]

*Heartbeat*

Expand Down
10 changes: 5 additions & 5 deletions x-pack/filebeat/input/httpjson/internal/v2/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ func (resp *response) templateValues() common.MapStr {
return common.MapStr{}
}
return common.MapStr{
"header": resp.header.Clone(),
"page": resp.page,
"url.value": resp.url.String(),
"params": resp.url.Query(),
"body": resp.body,
"header": resp.header.Clone(),
"page": resp.page,
"url.value": resp.url.String(),
"url.params": resp.url.Query(),
"body": resp.body,
}
}
42 changes: 42 additions & 0 deletions x-pack/filebeat/input/httpjson/internal/v2/response_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package v2

import (
"net/http"
"testing"

"github.com/stretchr/testify/assert"

"github.com/elastic/beats/v7/libbeat/common"
)

func TestTemplateValues(t *testing.T) {
resp := &response{
page: 1,
url: newURL("http://test?p1=v1"),
header: http.Header{
"Authorization": []string{"Bearer token"},
},
body: common.MapStr{
"param": "value",
},
}

vals := resp.templateValues()

assert.Equal(t, resp.page, vals["page"])
assert.Equal(t, resp.url.String(), vals["url.value"])
assert.EqualValues(t, resp.url.Query(), vals["url.params"])
assert.EqualValues(t, resp.header, vals["header"])
assert.EqualValues(t, resp.body, vals["body"])

resp = nil

vals = resp.templateValues()

assert.NotNil(t, vals)
assert.Equal(t, 0, len(vals))
}

0 comments on commit eb758b9

Please sign in to comment.