forked from TrueCloudLab/distribution
Merge pull request #494 from RichardScothern/bad-digest
Ensure the instrumentedResponseWriter correctly sets the http status in the context.
This commit is contained in:
commit
f210b090bf
3 changed files with 16 additions and 4 deletions
|
@ -322,9 +322,7 @@ func (irw *instrumentedResponseWriter) Value(key interface{}) interface{} {
|
||||||
case "written":
|
case "written":
|
||||||
return irw.written
|
return irw.written
|
||||||
case "status":
|
case "status":
|
||||||
if irw.status != 0 {
|
return irw.status
|
||||||
return irw.status
|
|
||||||
}
|
|
||||||
case "contenttype":
|
case "contenttype":
|
||||||
contentType := irw.Header().Get("Content-Type")
|
contentType := irw.Header().Get("Content-Type")
|
||||||
if contentType != "" {
|
if contentType != "" {
|
||||||
|
|
|
@ -145,6 +145,10 @@ func TestWithResponseWriter(t *testing.T) {
|
||||||
t.Fatalf("unexpected response writer returned: %#v != %#v", grw, rw)
|
t.Fatalf("unexpected response writer returned: %#v != %#v", grw, rw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.Value("http.response.status") != 0 {
|
||||||
|
t.Fatalf("response status should always be a number and should be zero here: %v != 0", ctx.Value("http.response.status"))
|
||||||
|
}
|
||||||
|
|
||||||
if n, err := rw.Write(make([]byte, 1024)); err != nil {
|
if n, err := rw.Write(make([]byte, 1024)); err != nil {
|
||||||
t.Fatalf("unexpected error writing: %v", err)
|
t.Fatalf("unexpected error writing: %v", err)
|
||||||
} else if n != 1024 {
|
} else if n != 1024 {
|
||||||
|
|
|
@ -93,7 +93,7 @@ func TestURLPrefix(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestLayerAPI conducts a full of the of the layer api.
|
// TestLayerAPI conducts a full test of the of the layer api.
|
||||||
func TestLayerAPI(t *testing.T) {
|
func TestLayerAPI(t *testing.T) {
|
||||||
// TODO(stevvooe): This test code is complete junk but it should cover the
|
// TODO(stevvooe): This test code is complete junk but it should cover the
|
||||||
// complete flow. This must be broken down and checked against the
|
// complete flow. This must be broken down and checked against the
|
||||||
|
@ -246,6 +246,16 @@ func TestLayerAPI(t *testing.T) {
|
||||||
t.Fatalf("response body did not pass verification")
|
t.Fatalf("response body did not pass verification")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------
|
||||||
|
// Fetch the layer with an invalid digest
|
||||||
|
badURL := strings.Replace(layerURL, "tarsum", "trsum", 1)
|
||||||
|
resp, err = http.Get(badURL)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected error fetching layer: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
checkResponse(t, "fetching layer bad digest", resp, http.StatusBadRequest)
|
||||||
|
|
||||||
// Missing tests:
|
// Missing tests:
|
||||||
// - Upload the same tarsum file under and different repository and
|
// - Upload the same tarsum file under and different repository and
|
||||||
// ensure the content remains uncorrupted.
|
// ensure the content remains uncorrupted.
|
||||||
|
|
Loading…
Reference in a new issue