mime_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package fileupload
  2. import "testing"
  3. func TestMimeAllowed_plainWithCharset(t *testing.T) {
  4. allowed := []string{"text/plain"}
  5. if !mimeAllowed("text/plain; charset=utf-8", allowed) {
  6. t.Fatal("text/plain rule should allow text/plain with charset parameter")
  7. }
  8. }
  9. func TestMimeAllowed_exactPlain(t *testing.T) {
  10. allowed := []string{"text/plain"}
  11. if !mimeAllowed("text/plain", allowed) {
  12. t.Fatal("text/plain should match text/plain")
  13. }
  14. }
  15. func TestMimeAllowed_wildcard(t *testing.T) {
  16. allowed := []string{"text/*"}
  17. if !mimeAllowed("text/plain; charset=utf-8", allowed) {
  18. t.Fatal("text/* should allow text/plain with charset")
  19. }
  20. }
  21. func TestMimeAllowed_rejectOther(t *testing.T) {
  22. allowed := []string{"text/plain"}
  23. if mimeAllowed("application/octet-stream", allowed) {
  24. t.Fatal("application/octet-stream should not match text/plain")
  25. }
  26. }
  27. func TestMimeAllowed_ruleWithParams(t *testing.T) {
  28. allowed := []string{"text/plain; charset=utf-8"}
  29. if !mimeAllowed("text/plain; charset=utf-8", allowed) {
  30. t.Fatal("config with charset should still match")
  31. }
  32. }