package theme import ( "crypto/sha256" "encoding/hex" "net/http" "net/http/httptest" "testing" ) func TestFontHandlerServesOnlyItsTwoFiles(t *testing.T) { h := FontHandler() for path, want := range map[string]int{ FontPrefix + "fonts.css": 200, FontPrefix + "onest-latin.woff2": 200, FontPrefix + "onest.woff2": 404, FontPrefix + "../theme/estilo.css": 404, FontPrefix: 404, "/static/other/onest-latin.woff2": 404, } { rec := httptest.NewRecorder() h.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, path, nil)) if rec.Code != want { t.Errorf("GET %s = %d, want %d", path, rec.Code, want) } } rec := httptest.NewRecorder() h.ServeHTTP(rec, httptest.NewRequest(http.MethodPost, FontPrefix+"fonts.css", nil)) if rec.Code != http.StatusMethodNotAllowed { t.Errorf("POST = %d, want 405", rec.Code) } } // The embedded font is the one the provenance record names. func TestOnestIsTheRecordedFile(t *testing.T) { body, err := fontFS.ReadFile("fonts/onest-latin.woff2") if err != nil { t.Fatal(err) } sum := sha256.Sum256(body) if got := hex.EncodeToString(sum[:]); got != "cc61cbd632bb677cd55f0eec9ebdd3e1525c5f30904cbf0769e2ac50d0fba992" { t.Fatalf("onest-latin.woff2 is not the file credits/notices/onest-provenance.json records (sha256 %s)", got) } }