fix(GODT-2480): Do not override X-Original-Date with invalid Date

This commit is contained in:
Leander Beernaert
2023-03-13 12:00:23 +01:00
parent b57ca1506d
commit 30c1c14505
3 changed files with 67 additions and 10 deletions

View File

@ -836,6 +836,41 @@ func TestBuildMessageWithInvalidDate(t *testing.T) {
expectHeader(`X-Original-Date`, is(`Wed, 31 Dec 1969 23:59:59 +0000`))
}
func TestBuildMessageWithExistingOriginalDate(t *testing.T) {
m := gomock.NewController(t)
defer m.Finish()
kr := utils.MakeKeyRing(t)
// Create a new message with existing original date
msg := newTestMessageWithHeaders(t, kr,
"messageID",
"addressID",
"text/html",
"<html><body>body</body></html>",
time.Unix(-1, 0),
map[string][]string{
"X-Original-Date": {"Sun, 15 Jan 2023 04:23:03 +0100 (W. Europe Standard Time)"},
"Date": {"15-Jan-2023 04:23:13 +0100"},
})
// Build the message as usual; the date will be before 1970.
res, err := BuildRFC822(kr, msg, nil, JobOptions{})
require.NoError(t, err)
section(t, res).
expectDate(is(`15-Jan-2023 04:23:13 +0100`)).
expectHeader(`X-Original-Date`, is("Sun, 15 Jan 2023 04:23:03 +0100 (W. Europe Standard Time)"))
// Build the message with date sanitization enabled; the date will be RFC822's birthdate.
resFix, err := BuildRFC822(kr, msg, nil, JobOptions{SanitizeDate: true})
require.NoError(t, err)
section(t, resFix).
expectDate(is(`Fri, 13 Aug 1982 00:00:00 +0000`)).
expectHeader(`X-Original-Date`, is("Sun, 15 Jan 2023 04:23:03 +0100 (W. Europe Standard Time)"))
}
func TestBuildMessageInternalID(t *testing.T) {
m := gomock.NewController(t)
defer m.Finish()