Files
LambdaMail/services/protocols/internal/domain/entity/dmarc_report_test.go
T
Lucas Rayan 880dced9e4 feat: implement message deletion functionality and improve draft handling
- Added `MoveToTrash` method in `WebmailRepository` to move messages to the Trash folder instead of deleting them permanently.
- Introduced `handleDelete` method in `mailAPI` to handle message deletion requests from the client.
- Updated router to include a new route for message deletion.
- Enhanced the compose page to manage draft integrity, ensuring drafts are correctly associated with sent messages.
- Implemented UI changes to allow users to delete messages from the mail folder view.
- Added tests to verify the correct behavior of message deletion and draft handling.
- Updated database migration scripts to reconcile folder counters and ensure accurate unread counts.
- Added tests for TLS-RPT report parsing and webmail repository functionalities.
2026-08-20 15:32:14 -03:00

97 lines
2.3 KiB
Go

package entity
import (
"bytes"
"compress/gzip"
"testing"
)
func TestParseDmarcXmlReport_ValidXML(t *testing.T) {
xmlData := `<?xml version="1.0"?>
<feedback>
<report_metadata>
<org_name>google.com</org_name>
<report_id>123456</report_id>
<date_range>
<begin>1609459200</begin>
<end>1609545600</end>
</date_range>
</report_metadata>
<policy_published>
<domain>example.test</domain>
</policy_published>
<record>
<row>
<source_ip>198.51.100.1</source_ip>
<count>10</count>
<policy_evaluated>
<disposition>none</disposition>
<dkim>pass</dkim>
<spf>pass</spf>
</policy_evaluated>
</row>
<identifiers>
<header_from>example.test</header_from>
</identifiers>
</record>
</feedback>`
report, err := ParseDmarcXmlReport([]byte(xmlData))
if err != nil {
t.Fatalf("ParseDmarcXmlReport: %v", err)
}
if report.OrgName != "google.com" || report.Domain != "example.test" {
t.Errorf("unexpected report metadata: %+v", report)
}
if len(report.Records) != 1 || report.Records[0].Count != 10 {
t.Errorf("unexpected records: %+v", report.Records)
}
// Test Gzip handling
var gzBuf bytes.Buffer
gw := gzip.NewWriter(&gzBuf)
gw.Write([]byte(xmlData))
gw.Close()
gzReport, err := ParseDmarcXmlReport(gzBuf.Bytes())
if err != nil || gzReport.OrgName != "google.com" {
t.Fatalf("ParseDmarcXmlReport gzip: %v", err)
}
}
func TestParseTlsRptReport_ValidJSON(t *testing.T) {
jsonData := `{
"organization-name": "Google LLC",
"report-id": "2026-07-25-001",
"date-range": {
"start-datetime": "2026-07-25T00:00:00Z",
"end-datetime": "2026-07-25T23:59:59Z"
},
"policies": [
{
"policy": {
"policy-type": "sts",
"policy-domain": "example.test"
},
"summary": {
"total-successful-session-count": 100,
"total-failure-session-count": 0
}
}
]
}`
report, err := ParseTlsRptReport([]byte(jsonData))
if err != nil {
t.Fatalf("ParseTlsRptReport: %v", err)
}
if report.OrganizationName != "Google LLC" || report.Domain != "example.test" {
t.Errorf("unexpected tlsrpt metadata: %+v", report)
}
if len(report.Policies) != 1 || report.Policies[0].SuccessCount != 100 {
t.Errorf("unexpected policies: %+v", report.Policies)
}
}