Skip to content

Commit

Permalink
[Filebeat][httpjson] Fix date_cursor validation (#21756)
Browse files Browse the repository at this point in the history
* Fix date_cursor validation

* Only check for parse errors
  • Loading branch information
marc-gr authored Oct 15, 2020
1 parent ace440f commit 471df0b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 7 additions & 2 deletions x-pack/filebeat/input/httpjson/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,15 @@ func (dc *dateCursorConfig) Validate() error {
if dc.DateFormat == "" {
return nil
}
now := time.Now().Format(dc.DateFormat)
if _, err := time.Parse(dc.DateFormat, now); err != nil {

const knownTimestamp = 1602601228 // 2020-10-13T15:00:28+00:00 RFC3339
knownDate := time.Unix(knownTimestamp, 0).UTC()

dateStr := knownDate.Format(dc.DateFormat)
if _, err := time.Parse(dc.DateFormat, dateStr); err != nil {
return errors.New("invalid configuration: date_format is not a valid date layout")
}

return nil
}

Expand Down
2 changes: 0 additions & 2 deletions x-pack/filebeat/input/httpjson/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ func TestConfigOauth2Validation(t *testing.T) {
"url": "localhost",
},
},
/* Flaky test: https://github.com/elastic/beats/issues/21748
{
name: "date_cursor.date_format will fail if invalid",
expectedErr: "invalid configuration: date_format is not a valid date layout accessing 'date_cursor'",
Expand All @@ -371,7 +370,6 @@ func TestConfigOauth2Validation(t *testing.T) {
"url": "localhost",
},
},
*/
{
name: "date_cursor must work with a valid date_format",
input: map[string]interface{}{
Expand Down

0 comments on commit 471df0b

Please sign in to comment.