mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-05-02 00:02:39 +02:00
add miscellaneous tests
also fix minor bug in detecting content type for content less than 512 bytes.
This commit is contained in:
parent
6975320eb4
commit
a7a8966289
4 changed files with 33 additions and 3 deletions
|
|
@ -17,6 +17,7 @@ package imageproxy
|
|||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
|
|
@ -31,6 +32,21 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestPeekContentType(t *testing.T) {
|
||||
// 1 pixel png image, base64 encoded
|
||||
b, _ := base64.StdEncoding.DecodeString("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAEUlEQVR4nGJiYGBgAAQAAP//AA8AA/6P688AAAAASUVORK5CYII=")
|
||||
got := peekContentType(bufio.NewReader(bytes.NewReader(b)))
|
||||
if want := "image/png"; got != want {
|
||||
t.Errorf("peekContentType returned %v, want %v", got, want)
|
||||
}
|
||||
|
||||
// single zero byte
|
||||
got = peekContentType(bufio.NewReader(bytes.NewReader([]byte{0x0})))
|
||||
if want := "application/octet-stream"; got != want {
|
||||
t.Errorf("peekContentType returned %v, want %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCopyHeader(t *testing.T) {
|
||||
tests := []struct {
|
||||
dst, src http.Header
|
||||
|
|
@ -234,6 +250,8 @@ func TestValidSignature(t *testing.T) {
|
|||
{"http://test/image", Options{Signature: "NDx5zZHx7QfE8E-ijowRreq6CJJBZjwiRfOVk_mkfQQ", Rotate: 90}, true},
|
||||
// signature calculated from url plus options
|
||||
{"http://test/image", Options{Signature: "ZGTzEm32o4iZ7qcChls3EVYaWyrDd9u0etySo0-WkF8=", Rotate: 90}, true},
|
||||
// invalid base64 encoded signature
|
||||
{"http://test/image", Options{Signature: "!!"}, false},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue