Exemple #1
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")
}
Exemple #2
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")

}
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")
}