handle create blob if the uuid couldn't be retrieved from headers or URL
Signed-off-by: Damien Mathieu <dmathieu@salesforce.com>master
							parent
							
								
									8b31a894bd
								
							
						
					
					
						commit
						a45e5cb13f
					
				|  | @ -756,6 +756,9 @@ func (bs *blobs) Create(ctx context.Context, options ...distribution.BlobCreateO | ||||||
| 			parts := strings.Split(resp.Header.Get("Location"), "/") | 			parts := strings.Split(resp.Header.Get("Location"), "/") | ||||||
| 			uuid = parts[len(parts)-1] | 			uuid = parts[len(parts)-1] | ||||||
| 		} | 		} | ||||||
|  | 		if uuid == "" { | ||||||
|  | 			return nil, errors.New("cannot retrieve docker upload UUID") | ||||||
|  | 		} | ||||||
| 
 | 
 | ||||||
| 		location, err := sanitizeLocation(resp.Header.Get("Location"), u) | 		location, err := sanitizeLocation(resp.Header.Get("Location"), u) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
|  |  | ||||||
|  | @ -473,7 +473,7 @@ func TestBlobUploadMonolithic(t *testing.T) { | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestBlobUploadMonolithicNoDockerUploadUUID(t *testing.T) { | func TestBlobUploadMonolithicDockerUploadUUIDFromURL(t *testing.T) { | ||||||
| 	dgst, b1 := newRandomBlob(1024) | 	dgst, b1 := newRandomBlob(1024) | ||||||
| 	var m testutil.RequestResponseMap | 	var m testutil.RequestResponseMap | ||||||
| 	repo, _ := reference.WithName("test.example.com/uploadrepo") | 	repo, _ := reference.WithName("test.example.com/uploadrepo") | ||||||
|  | @ -579,6 +579,92 @@ func TestBlobUploadMonolithicNoDockerUploadUUID(t *testing.T) { | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func TestBlobUploadMonolithicNoDockerUploadUUID(t *testing.T) { | ||||||
|  | 	dgst, b1 := newRandomBlob(1024) | ||||||
|  | 	var m testutil.RequestResponseMap | ||||||
|  | 	repo, _ := reference.WithName("test.example.com/uploadrepo") | ||||||
|  | 	m = append(m, testutil.RequestResponseMapping{ | ||||||
|  | 		Request: testutil.Request{ | ||||||
|  | 			Method: "POST", | ||||||
|  | 			Route:  "/v2/" + repo.Name() + "/blobs/uploads/", | ||||||
|  | 		}, | ||||||
|  | 		Response: testutil.Response{ | ||||||
|  | 			StatusCode: http.StatusAccepted, | ||||||
|  | 			Headers: http.Header(map[string][]string{ | ||||||
|  | 				"Content-Length": {"0"}, | ||||||
|  | 				"Location":       {"/v2/" + repo.Name() + "/blobs/uploads/"}, | ||||||
|  | 				"Range":          {"0-0"}, | ||||||
|  | 			}), | ||||||
|  | 		}, | ||||||
|  | 	}) | ||||||
|  | 	m = append(m, testutil.RequestResponseMapping{ | ||||||
|  | 		Request: testutil.Request{ | ||||||
|  | 			Method: "PATCH", | ||||||
|  | 			Route:  "/v2/" + repo.Name() + "/blobs/uploads/", | ||||||
|  | 			Body:   b1, | ||||||
|  | 		}, | ||||||
|  | 		Response: testutil.Response{ | ||||||
|  | 			StatusCode: http.StatusAccepted, | ||||||
|  | 			Headers: http.Header(map[string][]string{ | ||||||
|  | 				"Location":              {"/v2/" + repo.Name() + "/blobs/uploads/"}, | ||||||
|  | 				"Content-Length":        {"0"}, | ||||||
|  | 				"Docker-Content-Digest": {dgst.String()}, | ||||||
|  | 				"Range":                 {fmt.Sprintf("0-%d", len(b1)-1)}, | ||||||
|  | 			}), | ||||||
|  | 		}, | ||||||
|  | 	}) | ||||||
|  | 	m = append(m, testutil.RequestResponseMapping{ | ||||||
|  | 		Request: testutil.Request{ | ||||||
|  | 			Method: "PUT", | ||||||
|  | 			Route:  "/v2/" + repo.Name() + "/blobs/uploads/", | ||||||
|  | 			QueryParams: map[string][]string{ | ||||||
|  | 				"digest": {dgst.String()}, | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
|  | 		Response: testutil.Response{ | ||||||
|  | 			StatusCode: http.StatusCreated, | ||||||
|  | 			Headers: http.Header(map[string][]string{ | ||||||
|  | 				"Content-Length":        {"0"}, | ||||||
|  | 				"Docker-Content-Digest": {dgst.String()}, | ||||||
|  | 				"Content-Range":         {fmt.Sprintf("0-%d", len(b1)-1)}, | ||||||
|  | 			}), | ||||||
|  | 		}, | ||||||
|  | 	}) | ||||||
|  | 	m = append(m, testutil.RequestResponseMapping{ | ||||||
|  | 		Request: testutil.Request{ | ||||||
|  | 			Method: "HEAD", | ||||||
|  | 			Route:  "/v2/" + repo.Name() + "/blobs/" + dgst.String(), | ||||||
|  | 		}, | ||||||
|  | 		Response: testutil.Response{ | ||||||
|  | 			StatusCode: http.StatusOK, | ||||||
|  | 			Headers: http.Header(map[string][]string{ | ||||||
|  | 				"Content-Length": {fmt.Sprint(len(b1))}, | ||||||
|  | 				"Last-Modified":  {time.Now().Add(-1 * time.Second).Format(time.ANSIC)}, | ||||||
|  | 			}), | ||||||
|  | 		}, | ||||||
|  | 	}) | ||||||
|  | 
 | ||||||
|  | 	e, c := testServer(m) | ||||||
|  | 	defer c() | ||||||
|  | 
 | ||||||
|  | 	ctx := context.Background() | ||||||
|  | 	r, err := NewRepository(repo, e, nil) | ||||||
|  | 	if err != nil { | ||||||
|  | 		t.Fatal(err) | ||||||
|  | 	} | ||||||
|  | 	l := r.Blobs(ctx) | ||||||
|  | 
 | ||||||
|  | 	upload, err := l.Create(ctx) | ||||||
|  | 
 | ||||||
|  | 	if err.Error() != "cannot retrieve docker upload UUID" { | ||||||
|  | 		log.Fatalf("expected rejection to retrieve docker upload UUID error. Got %q", err) | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	if upload != nil { | ||||||
|  | 		log.Fatal("Expected upload to be nil") | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func TestBlobMount(t *testing.T) { | func TestBlobMount(t *testing.T) { | ||||||
| 	dgst, content := newRandomBlob(1024) | 	dgst, content := newRandomBlob(1024) | ||||||
| 	var m testutil.RequestResponseMap | 	var m testutil.RequestResponseMap | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue