You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

filetype_test.go 1012B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package upload
  5. import (
  6. "bytes"
  7. "compress/gzip"
  8. "testing"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestUpload(t *testing.T) {
  12. testContent := []byte(`This is a plain text file.`)
  13. var b bytes.Buffer
  14. w := gzip.NewWriter(&b)
  15. w.Write(testContent)
  16. w.Close()
  17. kases := []struct {
  18. data []byte
  19. allowedTypes []string
  20. err error
  21. }{
  22. {
  23. data: testContent,
  24. allowedTypes: []string{"text/plain"},
  25. err: nil,
  26. },
  27. {
  28. data: testContent,
  29. allowedTypes: []string{"application/x-gzip"},
  30. err: ErrFileTypeForbidden{"text/plain; charset=utf-8"},
  31. },
  32. {
  33. data: b.Bytes(),
  34. allowedTypes: []string{"application/x-gzip"},
  35. err: nil,
  36. },
  37. }
  38. for _, kase := range kases {
  39. assert.Equal(t, kase.err, VerifyAllowedContentType(kase.data, kase.allowedTypes))
  40. }
  41. }