Esempio n. 1
0
func TestValidSignature(t *testing.T) {

	srv := secureHandlerFor("Hello!", "validsecret")
	rec := srv("GET", "/r/eyJnIjoiMTMweDEzMCNudyIsInNyYyI6ImNoZWV0YWguanBnIn0/62cf3cd857518cd")

	th.ExpectStr(t, rec.Body.String(), "Hello!")
	th.ExpectInt(t, rec.Code, 200)

	srv = secureHandlerFor("Hello!", "invalidsecret")
	rec = srv("GET", "/r/eyJnIjoiMTMweDEzMCNudyIsInNyYyI6ImNoZWV0YWguanBnIn0/62cf3cd857518cd")

	th.ExpectInt(t, rec.Code, 400)
	th.ExpectContains(t, rec.Body.String(), "Invalid cryptographic signature")

}
Esempio n. 2
0
func TestValidEncodedData(t *testing.T) {
	srv := secureHandlerFor("Hello!", "validsecret")
	rec := srv("GET", "/r/eyJnIjoiMTMweDEzMCNudyIsInNyYyI6ImNoZWV0YWguanBnIn0foo/908a1fb15b82120")

	th.ExpectInt(t, rec.Code, 400)
	th.ExpectContains(t, rec.Body.String(), "Malformed data")
}
Esempio n. 3
0
func TestServeLargeSize(t *testing.T) {
	srv := setupNamedSizesServer()
	rec := srv("GET", "/29/large/111900-_MG_2031.JPG")

	th.ExpectInt(t, 200, rec.Code)

	img := bimg.NewImage(rec.Body.Bytes())
	meta, err := img.Metadata()
	if err != nil {
		log.Fatal(err.Error())
	}

	th.ExpectStr(t, img.Type(), "jpeg")

	th.ExpectInt(t, 1000, meta.Size.Height)
	th.ExpectInt(t, 800, meta.Size.Width)
}
Esempio n. 4
0
func TestMissingFileError(t *testing.T) {
	srv := setupNamedSizesServer()
	rec := srv("GET", "/29/small/nonexisting.jpg")

	img := bimg.NewImage(rec.Body.Bytes())
	meta, err := img.Metadata()
	if err != nil {
		log.Fatal(err.Error())
	}

	th.ExpectInt(t, 200, rec.Code)
	th.ExpectStr(t, "jpeg", img.Type())
	th.ExpectInt(t, 240, meta.Size.Width)

	l := strconv.Itoa(len(rec.Body.Bytes()))
	th.ExpectStr(t, rec.HeaderMap.Get("Content-Length"), l)

	th.ExpectStr(t, rec.HeaderMap.Get("Cache-Control"), "public, max-age=10")
	th.ExpectStr(t, rec.HeaderMap.Get("Content-Type"), "image/jpeg")

	th.ExpectContains(t, rec.HeaderMap.Get("X-Btc-Error"), "open ../fixtures/29/original/nonexisting.jpg: no such file or directory")
}
Esempio n. 5
0
func TestCachedImage(t *testing.T) {
	srv := setupCachedEndpoint()

	rec := srv("GET", "/29/small/111900-_MG_2031.JPG")

	th.ExpectInt(t, 200, rec.Code)

	img := bimg.NewImage(rec.Body.Bytes())
	meta, err := img.Metadata()
	if err != nil {
		log.Fatal(err.Error())
	}

	th.ExpectStr(t, img.Type(), "jpeg")

	th.ExpectInt(t, 300, meta.Size.Height)
	th.ExpectInt(t, 240, meta.Size.Width)

	filePath := "../fixtures/test/29/small/111900-_MG_2031.JPG"

	cachedData, err := ioutil.ReadFile(filePath)
	if err != nil {
		log.Fatal(err.Error())
	}

	img = bimg.NewImage(cachedData)
	meta, err = img.Metadata()
	if err != nil {
		log.Fatal(err.Error())
	}

	th.ExpectStr(t, img.Type(), "jpeg")

	th.ExpectInt(t, 300, meta.Size.Height)
	th.ExpectInt(t, 240, meta.Size.Width)

	os.Remove(filePath)
}
Esempio n. 6
0
func TestServeSmallSize(t *testing.T) {
	srv := setupNamedSizesServer()
	rec := srv("GET", "/29/small/111900-_MG_2031.JPG")

	th.ExpectInt(t, 200, rec.Code)

	img := bimg.NewImage(rec.Body.Bytes())
	meta, err := img.Metadata()
	if err != nil {
		log.Fatal(err.Error())
	}

	th.ExpectStr(t, img.Type(), "jpeg")

	th.ExpectInt(t, 300, meta.Size.Height)
	th.ExpectInt(t, 240, meta.Size.Width)

	l := strconv.Itoa(len(rec.Body.Bytes()))
	th.ExpectStr(t, rec.HeaderMap.Get("Content-Length"), l)

	th.ExpectStr(t, rec.HeaderMap.Get("Cache-Control"), "public, max-age=94608000")

	th.ExpectStr(t, rec.HeaderMap.Get("Content-Type"), "image/jpeg")
}
Esempio n. 7
0
func TestMissingSizeError(t *testing.T) {
	srv := setupNamedSizesServer()
	rec := srv("GET", "/29/foobar/111900-_MG_2031.JPG")

	th.ExpectInt(t, 404, rec.Code)
}