package modules
import "testing"
// A file only earns an inline image MIME when its extension and its magic
// bytes agree and the format is a raster one. The cases that must return ""
// are the attacker-influenced ones: content that is not an image at all, and
// SVG, which is an active document rather than a picture.
func TestImageContentType(t *testing.T) {
png := []byte("\x89PNG\r\n\x1a\n" + "rest of the file")
tests := []struct {
name string
path string
data []byte
want string
}{
{"png", "logo.png", png, "image/png"},
{"uppercase extension", "LOGO.PNG", png, "image/png"},
{"jpeg", "a.jpg", []byte{0xff, 0xd8, 0xff, 0xe0}, "image/jpeg"},
{"jpeg long extension", "a.jpeg", []byte{0xff, 0xd8, 0xff, 0xe0}, "image/jpeg"},
{"gif87", "a.gif", []byte("GIF87a...."), "image/gif"},
{"gif89", "a.gif", []byte("GIF89a...."), "image/gif"},
{"webp", "a.webp", []byte("RIFF\x00\x00\x00\x00WEBPVP8 "), "image/webp"},
{"bmp", "a.bmp", []byte("BM...."), "image/bmp"},
{"ico", "a.ico", []byte{0x00, 0x00, 0x01, 0x00}, "image/x-icon"},
{"avif", "a.avif", []byte("\x00\x00\x00\x18ftypavif"), "image/avif"},
// HTML wearing a .png name, and a real PNG named .txt, must both
// fall back to the download path.
{"html named png", "evil.png", []byte(""), ""},
{"png extension without magic", "evil.png", []byte("not an image"), ""},
{"magic without extension", "evil.txt", png, ""},
{"truncated png", "evil.png", []byte("\x89PNG"), ""},
// SVG can carry