package httppresentation import ( "bytes" "net/http" "net/http/httptest" "strings" "testing" appusecase "lambdamail/protocols/internal/application/usecase" ) func TestRouter_MtaSts_Autoconfig_SecurityTxt_Ingest(t *testing.T) { uc := appusecase.NewIngestReportsUseCase(nil) router := NewRouter(uc, func() error { return nil }) // 1. Health req := httptest.NewRequest(http.MethodGet, "/health", nil) w := httptest.NewRecorder() router.ServeHTTP(w, req) if w.Code != http.StatusOK { t.Errorf("health status = %d", w.Code) } // 2. MTA-STS req = httptest.NewRequest(http.MethodGet, "/.well-known/mta-sts.txt", nil) req.Host = "mta-sts.example.test" w = httptest.NewRecorder() router.ServeHTTP(w, req) if w.Code != http.StatusOK || !strings.Contains(w.Body.String(), "version: STSv1") { t.Errorf("mta-sts response = %q", w.Body.String()) } // 3. Thunderbird Autoconfig req = httptest.NewRequest(http.MethodGet, "/mail/config-v1.1.xml", nil) req.Host = "autoconfig.example.test" w = httptest.NewRecorder() router.ServeHTTP(w, req) if w.Code != http.StatusOK || !strings.Contains(w.Body.String(), "orgid12dom` req = httptest.NewRequest(http.MethodPost, "/api/v1/reports/dmarc", bytes.NewBufferString(dmarcPayload)) w = httptest.NewRecorder() router.ServeHTTP(w, req) if w.Code != http.StatusOK || !strings.Contains(w.Body.String(), `"status":"ok"`) { t.Errorf("dmarc ingest status = %d, body = %q", w.Code, w.Body.String()) } }