Skip to content

Commit

Permalink
Fix date_cursor validation
Browse files Browse the repository at this point in the history
  • Loading branch information
marc-gr committed Oct 14, 2020
1 parent fff5f6a commit 75df6ef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 8 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,16 @@ 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

// if we can't get back the same date from Format than from Parse
// it is because the defined format is invalid
dateStr := time.Unix(knownTimestamp, 0).UTC().Format(dc.DateFormat)
if t, err := time.Parse(dc.DateFormat, dateStr); err != nil || t.Unix() != knownTimestamp {
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 75df6ef

Please sign in to comment.