2015-02-11 01:25:40 +00:00
|
|
|
package handlers
|
2014-11-21 03:57:01 +00:00
|
|
|
|
|
|
|
import (
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
"bytes"
|
2017-08-11 22:31:16 +00:00
|
|
|
"context"
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
"encoding/json"
|
2017-01-13 23:07:28 +00:00
|
|
|
"errors"
|
2014-11-21 03:57:01 +00:00
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"net/http/httputil"
|
|
|
|
"net/url"
|
|
|
|
"os"
|
2015-02-27 00:43:47 +00:00
|
|
|
"path"
|
2015-01-30 05:26:35 +00:00
|
|
|
"reflect"
|
2015-07-17 18:42:47 +00:00
|
|
|
"regexp"
|
|
|
|
"strconv"
|
2015-02-24 22:59:01 +00:00
|
|
|
"strings"
|
2014-11-21 03:57:01 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-08-24 11:18:39 +00:00
|
|
|
"github.com/distribution/distribution/v3"
|
|
|
|
"github.com/distribution/distribution/v3/configuration"
|
|
|
|
"github.com/distribution/distribution/v3/manifest"
|
|
|
|
"github.com/distribution/distribution/v3/manifest/manifestlist"
|
|
|
|
"github.com/distribution/distribution/v3/manifest/schema2"
|
|
|
|
"github.com/distribution/distribution/v3/registry/api/errcode"
|
|
|
|
v2 "github.com/distribution/distribution/v3/registry/api/v2"
|
|
|
|
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
|
|
|
"github.com/distribution/distribution/v3/registry/storage/driver/factory"
|
2018-11-15 10:36:19 +00:00
|
|
|
_ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
|
2020-08-24 11:18:39 +00:00
|
|
|
"github.com/distribution/distribution/v3/testutil"
|
2023-08-30 15:50:56 +00:00
|
|
|
"github.com/distribution/reference"
|
2014-12-10 05:25:54 +00:00
|
|
|
"github.com/gorilla/handlers"
|
2016-12-17 00:28:34 +00:00
|
|
|
"github.com/opencontainers/go-digest"
|
2014-11-21 03:57:01 +00:00
|
|
|
)
|
|
|
|
|
2015-08-10 21:20:52 +00:00
|
|
|
var headerConfig = http.Header{
|
|
|
|
"X-Content-Type-Options": []string{"nosniff"},
|
|
|
|
}
|
|
|
|
|
2016-12-17 00:28:34 +00:00
|
|
|
const (
|
|
|
|
// digestSha256EmptyTar is the canonical sha256 digest of empty data
|
|
|
|
digestSha256EmptyTar = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
|
|
|
|
)
|
|
|
|
|
2014-12-11 06:33:36 +00:00
|
|
|
// TestCheckAPI hits the base endpoint (/v2/) ensures we return the specified
|
|
|
|
// 200 OK response.
|
|
|
|
func TestCheckAPI(t *testing.T) {
|
2015-05-27 17:52:22 +00:00
|
|
|
env := newTestEnv(t, false)
|
2016-08-26 23:20:54 +00:00
|
|
|
defer env.Shutdown()
|
2015-02-07 00:19:19 +00:00
|
|
|
baseURL, err := env.builder.BuildBaseURL()
|
2014-12-11 06:33:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building base url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := http.Get(baseURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error issuing request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "issuing api base check", resp, http.StatusOK)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
2019-01-14 08:53:03 +00:00
|
|
|
"Content-Type": []string{"application/json"},
|
2014-12-11 06:33:36 +00:00
|
|
|
"Content-Length": []string{"2"},
|
|
|
|
})
|
|
|
|
|
2022-11-02 21:55:22 +00:00
|
|
|
p, err := io.ReadAll(resp.Body)
|
2014-12-11 06:33:36 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error reading response body: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if string(p) != "{}" {
|
|
|
|
t.Fatalf("unexpected response body: %v", string(p))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-17 18:42:47 +00:00
|
|
|
// TestCatalogAPI tests the /v2/_catalog endpoint
|
2015-07-13 20:08:13 +00:00
|
|
|
func TestCatalogAPI(t *testing.T) {
|
2015-05-27 17:52:22 +00:00
|
|
|
env := newTestEnv(t, false)
|
2016-08-26 23:20:54 +00:00
|
|
|
defer env.Shutdown()
|
2015-07-13 20:08:13 +00:00
|
|
|
|
2023-03-31 11:16:29 +00:00
|
|
|
maxEntries := env.config.Catalog.MaxEntries
|
|
|
|
allCatalog := []string{
|
|
|
|
"foo/aaaa", "foo/bbbb", "foo/cccc", "foo/dddd", "foo/eeee", "foo/ffff",
|
2022-11-02 21:05:45 +00:00
|
|
|
}
|
2015-07-13 20:08:13 +00:00
|
|
|
|
2023-03-31 11:16:29 +00:00
|
|
|
chunkLen := maxEntries - 1
|
|
|
|
|
|
|
|
catalogURL, err := env.builder.BuildCatalogURL()
|
2015-07-13 20:08:13 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building catalog url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------
|
2023-03-31 11:16:29 +00:00
|
|
|
// Case No. 1: Empty catalog
|
2015-07-13 20:08:13 +00:00
|
|
|
resp, err := http.Get(catalogURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error issuing request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "issuing catalog api check", resp, http.StatusOK)
|
|
|
|
|
|
|
|
var ctlg struct {
|
|
|
|
Repositories []string `json:"repositories"`
|
|
|
|
}
|
|
|
|
|
|
|
|
dec := json.NewDecoder(resp.Body)
|
|
|
|
if err := dec.Decode(&ctlg); err != nil {
|
|
|
|
t.Fatalf("error decoding fetched manifest: %v", err)
|
|
|
|
}
|
|
|
|
|
2023-03-31 11:16:29 +00:00
|
|
|
// No images pushed = no image returned
|
2015-07-17 18:42:47 +00:00
|
|
|
if len(ctlg.Repositories) != 0 {
|
2023-03-31 11:16:29 +00:00
|
|
|
t.Fatalf("repositories returned unexpected entries (expected: %d, returned: %d)", 0, len(ctlg.Repositories))
|
2015-07-13 20:08:13 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 11:16:29 +00:00
|
|
|
// No pagination should be returned
|
2015-07-13 20:08:13 +00:00
|
|
|
if resp.Header.Get("Link") != "" {
|
|
|
|
t.Fatalf("repositories has more data when none expected")
|
|
|
|
}
|
|
|
|
|
2023-03-31 11:16:29 +00:00
|
|
|
for _, image := range allCatalog {
|
2015-07-17 18:42:47 +00:00
|
|
|
createRepository(env, t, image, "sometag")
|
|
|
|
}
|
|
|
|
|
2023-03-31 11:16:29 +00:00
|
|
|
// -----------------------------------
|
|
|
|
// Case No. 2: Catalog populated & n is not provided nil (n internally will be min(100, maxEntries))
|
|
|
|
|
2015-07-17 18:42:47 +00:00
|
|
|
resp, err = http.Get(catalogURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error issuing request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "issuing catalog api check", resp, http.StatusOK)
|
|
|
|
|
|
|
|
dec = json.NewDecoder(resp.Body)
|
|
|
|
if err = dec.Decode(&ctlg); err != nil {
|
|
|
|
t.Fatalf("error decoding fetched manifest: %v", err)
|
|
|
|
}
|
|
|
|
|
2023-03-31 11:16:29 +00:00
|
|
|
// it must match max entries
|
|
|
|
if len(ctlg.Repositories) != maxEntries {
|
|
|
|
t.Fatalf("repositories returned unexpected entries (expected: %d, returned: %d)", maxEntries, len(ctlg.Repositories))
|
2015-07-17 18:42:47 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 11:16:29 +00:00
|
|
|
// it must return the first maxEntries entries from the catalog
|
|
|
|
for _, image := range allCatalog[:maxEntries] {
|
2015-07-17 18:42:47 +00:00
|
|
|
if !contains(ctlg.Repositories, image) {
|
|
|
|
t.Fatalf("didn't find our repository '%s' in the catalog", image)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-31 11:16:29 +00:00
|
|
|
// fail if there's no pagination
|
2015-07-17 18:42:47 +00:00
|
|
|
link := resp.Header.Get("Link")
|
|
|
|
if link == "" {
|
|
|
|
t.Fatalf("repositories has less data than expected")
|
|
|
|
}
|
2023-03-31 11:16:29 +00:00
|
|
|
// -----------------------------------
|
|
|
|
// Case No. 2.1: Second page (n internally will be min(100, maxEntries))
|
|
|
|
|
|
|
|
// build pagination link
|
|
|
|
values := checkLink(t, link, maxEntries, ctlg.Repositories[len(ctlg.Repositories)-1])
|
|
|
|
|
|
|
|
catalogURL, err = env.builder.BuildCatalogURL(values)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building catalog url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = http.Get(catalogURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error issuing request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "issuing catalog api check", resp, http.StatusOK)
|
|
|
|
|
|
|
|
dec = json.NewDecoder(resp.Body)
|
|
|
|
if err = dec.Decode(&ctlg); err != nil {
|
|
|
|
t.Fatalf("error decoding fetched manifest: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedRemainder := len(allCatalog) - maxEntries
|
|
|
|
|
|
|
|
if len(ctlg.Repositories) != expectedRemainder {
|
|
|
|
t.Fatalf("repositories returned unexpected entries (expected: %d, returned: %d)", expectedRemainder, len(ctlg.Repositories))
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
// Case No. 3: request n = maxentries
|
|
|
|
values = url.Values{
|
|
|
|
"last": []string{""},
|
|
|
|
"n": []string{strconv.Itoa(maxEntries)},
|
|
|
|
}
|
|
|
|
|
|
|
|
catalogURL, err = env.builder.BuildCatalogURL(values)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building catalog url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = http.Get(catalogURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error issuing request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "issuing catalog api check", resp, http.StatusOK)
|
|
|
|
|
|
|
|
dec = json.NewDecoder(resp.Body)
|
|
|
|
if err = dec.Decode(&ctlg); err != nil {
|
|
|
|
t.Fatalf("error decoding fetched manifest: %v", err)
|
|
|
|
}
|
2015-07-17 18:42:47 +00:00
|
|
|
|
2023-03-31 11:16:29 +00:00
|
|
|
if len(ctlg.Repositories) != maxEntries {
|
|
|
|
t.Fatalf("repositories returned unexpected entries (expected: %d, returned: %d)", maxEntries, len(ctlg.Repositories))
|
|
|
|
}
|
|
|
|
|
|
|
|
// fail if there's no pagination
|
|
|
|
link = resp.Header.Get("Link")
|
|
|
|
if link == "" {
|
|
|
|
t.Fatalf("repositories has less data than expected")
|
|
|
|
}
|
2015-07-17 18:42:47 +00:00
|
|
|
|
|
|
|
// -----------------------------------
|
2023-03-31 11:16:29 +00:00
|
|
|
// Case No. 3.1: Second (last) page
|
|
|
|
|
|
|
|
// build pagination link
|
|
|
|
values = checkLink(t, link, maxEntries, ctlg.Repositories[len(ctlg.Repositories)-1])
|
2015-07-17 18:42:47 +00:00
|
|
|
|
2023-03-31 11:16:29 +00:00
|
|
|
catalogURL, err = env.builder.BuildCatalogURL(values)
|
2015-07-17 18:42:47 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building catalog url: %v", err)
|
|
|
|
}
|
2015-07-13 20:08:13 +00:00
|
|
|
|
|
|
|
resp, err = http.Get(catalogURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error issuing request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "issuing catalog api check", resp, http.StatusOK)
|
|
|
|
|
|
|
|
dec = json.NewDecoder(resp.Body)
|
|
|
|
if err = dec.Decode(&ctlg); err != nil {
|
|
|
|
t.Fatalf("error decoding fetched manifest: %v", err)
|
|
|
|
}
|
|
|
|
|
2023-03-31 11:16:29 +00:00
|
|
|
expectedRemainder = len(allCatalog) - maxEntries
|
|
|
|
|
|
|
|
if len(ctlg.Repositories) != expectedRemainder {
|
|
|
|
t.Fatalf("repositories returned unexpected entries (expected: %d, returned: %d)", expectedRemainder, len(ctlg.Repositories))
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
// Case No. 4: request n < maxentries
|
|
|
|
|
|
|
|
values = url.Values{
|
|
|
|
"n": []string{strconv.Itoa(chunkLen)},
|
|
|
|
}
|
|
|
|
|
|
|
|
catalogURL, err = env.builder.BuildCatalogURL(values)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building catalog url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = http.Get(catalogURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error issuing request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "issuing catalog api check", resp, http.StatusOK)
|
|
|
|
|
|
|
|
dec = json.NewDecoder(resp.Body)
|
|
|
|
if err = dec.Decode(&ctlg); err != nil {
|
|
|
|
t.Fatalf("error decoding fetched manifest: %v", err)
|
2015-07-13 20:08:13 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 11:16:29 +00:00
|
|
|
// returns the requested amount
|
|
|
|
if len(ctlg.Repositories) != chunkLen {
|
|
|
|
t.Fatalf("repositories returned unexpected entries (expected: %d, returned: %d)", expectedRemainder, len(ctlg.Repositories))
|
2015-07-13 20:08:13 +00:00
|
|
|
}
|
|
|
|
|
2023-03-31 11:16:29 +00:00
|
|
|
// fail if there's no pagination
|
2015-07-17 18:42:47 +00:00
|
|
|
link = resp.Header.Get("Link")
|
2023-03-31 11:16:29 +00:00
|
|
|
if link == "" {
|
|
|
|
t.Fatalf("repositories has less data than expected")
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
// Case No. 4.1: request n < maxentries (second page)
|
|
|
|
|
|
|
|
// build pagination link
|
|
|
|
values = checkLink(t, link, chunkLen, ctlg.Repositories[len(ctlg.Repositories)-1])
|
|
|
|
|
|
|
|
catalogURL, err = env.builder.BuildCatalogURL(values)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building catalog url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = http.Get(catalogURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error issuing request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "issuing catalog api check", resp, http.StatusOK)
|
|
|
|
|
|
|
|
dec = json.NewDecoder(resp.Body)
|
|
|
|
if err = dec.Decode(&ctlg); err != nil {
|
|
|
|
t.Fatalf("error decoding fetched manifest: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedRemainder = len(allCatalog) - chunkLen
|
|
|
|
|
|
|
|
if len(ctlg.Repositories) != expectedRemainder {
|
|
|
|
t.Fatalf("repositories returned unexpected entries (expected: %d, returned: %d)", expectedRemainder, len(ctlg.Repositories))
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
// Case No. 5: request n > maxentries
|
|
|
|
|
|
|
|
values = url.Values{
|
|
|
|
"n": []string{strconv.Itoa(maxEntries + 10)},
|
|
|
|
}
|
|
|
|
|
|
|
|
catalogURL, err = env.builder.BuildCatalogURL(values)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building catalog url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = http.Get(catalogURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error issuing request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "issuing catalog api check", resp, http.StatusBadRequest)
|
2023-11-18 06:50:40 +00:00
|
|
|
// nolint:errcheck
|
2023-09-04 15:52:12 +00:00
|
|
|
checkBodyHasErrorCodes(t, "invalid number of results requested", resp, errcode.ErrorCodePaginationNumberInvalid)
|
2023-03-31 11:16:29 +00:00
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
// Case No. 6: request n > maxentries but <= total catalog
|
|
|
|
|
|
|
|
values = url.Values{
|
|
|
|
"n": []string{strconv.Itoa(len(allCatalog))},
|
|
|
|
}
|
|
|
|
|
|
|
|
catalogURL, err = env.builder.BuildCatalogURL(values)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building catalog url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = http.Get(catalogURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error issuing request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "issuing catalog api check", resp, http.StatusBadRequest)
|
2023-11-18 06:50:40 +00:00
|
|
|
// nolint:errcheck
|
2023-09-04 15:52:12 +00:00
|
|
|
checkBodyHasErrorCodes(t, "invalid number of results requested", resp, errcode.ErrorCodePaginationNumberInvalid)
|
2023-03-31 11:16:29 +00:00
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
// Case No. 7: n = 0
|
|
|
|
values = url.Values{
|
|
|
|
"n": []string{"0"},
|
|
|
|
}
|
|
|
|
|
|
|
|
catalogURL, err = env.builder.BuildCatalogURL(values)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building catalog url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = http.Get(catalogURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error issuing request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "issuing catalog api check", resp, http.StatusOK)
|
|
|
|
|
|
|
|
dec = json.NewDecoder(resp.Body)
|
|
|
|
if err = dec.Decode(&ctlg); err != nil {
|
|
|
|
t.Fatalf("error decoding fetched manifest: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// it must match max entries
|
|
|
|
if len(ctlg.Repositories) != 0 {
|
|
|
|
t.Fatalf("repositories returned unexpected entries (expected: %d, returned: %d)", 0, len(ctlg.Repositories))
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
// Case No. 8: n = -1
|
|
|
|
values = url.Values{
|
|
|
|
"n": []string{"-1"},
|
|
|
|
}
|
|
|
|
|
|
|
|
catalogURL, err = env.builder.BuildCatalogURL(values)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building catalog url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = http.Get(catalogURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error issuing request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "issuing catalog api check", resp, http.StatusBadRequest)
|
2023-11-18 06:50:40 +00:00
|
|
|
// nolint:errcheck
|
2023-09-04 15:52:12 +00:00
|
|
|
checkBodyHasErrorCodes(t, "invalid number of results requested", resp, errcode.ErrorCodePaginationNumberInvalid)
|
2023-03-31 11:16:29 +00:00
|
|
|
|
|
|
|
// -----------------------------------
|
|
|
|
// Case No. 9: n = 5, max = 5, total catalog = 4
|
|
|
|
values = url.Values{
|
|
|
|
"n": []string{strconv.Itoa(maxEntries)},
|
|
|
|
}
|
|
|
|
|
|
|
|
envWithLessImages := newTestEnv(t, false)
|
|
|
|
for _, image := range allCatalog[0:(maxEntries - 1)] {
|
2023-08-17 08:37:26 +00:00
|
|
|
createRepository(envWithLessImages, t, image, "sometag")
|
2023-03-31 11:16:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
catalogURL, err = envWithLessImages.builder.BuildCatalogURL(values)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building catalog url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = http.Get(catalogURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error issuing request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "issuing catalog api check", resp, http.StatusOK)
|
|
|
|
|
|
|
|
dec = json.NewDecoder(resp.Body)
|
|
|
|
if err = dec.Decode(&ctlg); err != nil {
|
|
|
|
t.Fatalf("error decoding fetched manifest: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// it must match max entries
|
|
|
|
if len(ctlg.Repositories) != maxEntries-1 {
|
|
|
|
t.Fatalf("repositories returned unexpected entries (expected: %d, returned: %d)", maxEntries-1, len(ctlg.Repositories))
|
2015-07-17 18:42:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-22 14:15:49 +00:00
|
|
|
// TestTagsAPI tests the /v2/<name>/tags/list endpoint
|
|
|
|
func TestTagsAPI(t *testing.T) {
|
|
|
|
env := newTestEnv(t, false)
|
|
|
|
defer env.Shutdown()
|
|
|
|
|
|
|
|
imageName, err := reference.WithName("test")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to parse reference: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
tags := []string{
|
|
|
|
"2j2ar",
|
|
|
|
"asj9e",
|
|
|
|
"jyi7b",
|
|
|
|
"kb0j5",
|
|
|
|
"sb71y",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tag := range tags {
|
|
|
|
createRepository(env, t, imageName.Name(), tag)
|
|
|
|
}
|
|
|
|
|
|
|
|
tt := []struct {
|
|
|
|
name string
|
|
|
|
queryParams url.Values
|
|
|
|
expectedStatusCode int
|
|
|
|
expectedBody tagsAPIResponse
|
|
|
|
expectedBodyErr *errcode.ErrorCode
|
|
|
|
expectedLinkHeader string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "no query parameters",
|
|
|
|
expectedStatusCode: http.StatusOK,
|
|
|
|
expectedBody: tagsAPIResponse{Name: imageName.Name(), Tags: tags},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty last query parameter",
|
|
|
|
queryParams: url.Values{"last": []string{""}},
|
|
|
|
expectedStatusCode: http.StatusOK,
|
|
|
|
expectedBody: tagsAPIResponse{Name: imageName.Name(), Tags: tags},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty n query parameter",
|
|
|
|
queryParams: url.Values{"n": []string{""}},
|
|
|
|
expectedStatusCode: http.StatusOK,
|
|
|
|
expectedBody: tagsAPIResponse{Name: imageName.Name(), Tags: tags},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty last and n query parameters",
|
|
|
|
queryParams: url.Values{"last": []string{""}, "n": []string{""}},
|
|
|
|
expectedStatusCode: http.StatusOK,
|
|
|
|
expectedBody: tagsAPIResponse{Name: imageName.Name(), Tags: tags},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "negative n query parameter",
|
|
|
|
queryParams: url.Values{"n": []string{"-1"}},
|
|
|
|
expectedStatusCode: http.StatusBadRequest,
|
2023-09-04 15:52:12 +00:00
|
|
|
expectedBodyErr: &errcode.ErrorCodePaginationNumberInvalid,
|
2021-05-22 14:15:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "non integer n query parameter",
|
|
|
|
queryParams: url.Values{"n": []string{"foo"}},
|
|
|
|
expectedStatusCode: http.StatusBadRequest,
|
2023-09-04 15:52:12 +00:00
|
|
|
expectedBodyErr: &errcode.ErrorCodePaginationNumberInvalid,
|
2021-05-22 14:15:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "1st page",
|
|
|
|
queryParams: url.Values{"n": []string{"2"}},
|
|
|
|
expectedStatusCode: http.StatusOK,
|
|
|
|
expectedBody: tagsAPIResponse{Name: imageName.Name(), Tags: []string{
|
|
|
|
"2j2ar",
|
|
|
|
"asj9e",
|
|
|
|
}},
|
|
|
|
expectedLinkHeader: `</v2/test/tags/list?last=asj9e&n=2>; rel="next"`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "nth page",
|
|
|
|
queryParams: url.Values{"last": []string{"asj9e"}, "n": []string{"1"}},
|
|
|
|
expectedStatusCode: http.StatusOK,
|
|
|
|
expectedBody: tagsAPIResponse{Name: imageName.Name(), Tags: []string{
|
|
|
|
"jyi7b",
|
|
|
|
}},
|
|
|
|
expectedLinkHeader: `</v2/test/tags/list?last=jyi7b&n=1>; rel="next"`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "last page",
|
|
|
|
queryParams: url.Values{"last": []string{"jyi7b"}, "n": []string{"3"}},
|
|
|
|
expectedStatusCode: http.StatusOK,
|
|
|
|
expectedBody: tagsAPIResponse{Name: imageName.Name(), Tags: []string{
|
|
|
|
"kb0j5",
|
|
|
|
"sb71y",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "page size bigger than full list",
|
|
|
|
queryParams: url.Values{"n": []string{"100"}},
|
|
|
|
expectedStatusCode: http.StatusOK,
|
|
|
|
expectedBody: tagsAPIResponse{Name: imageName.Name(), Tags: tags},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "after marker",
|
|
|
|
queryParams: url.Values{"last": []string{"jyi7b"}},
|
|
|
|
expectedStatusCode: http.StatusOK,
|
|
|
|
expectedBody: tagsAPIResponse{Name: imageName.Name(), Tags: []string{
|
|
|
|
"kb0j5",
|
|
|
|
"sb71y",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "after non existent marker",
|
|
|
|
queryParams: url.Values{"last": []string{"does-not-exist"}, "n": []string{"3"}},
|
|
|
|
expectedStatusCode: http.StatusOK,
|
|
|
|
expectedBody: tagsAPIResponse{Name: imageName.Name(), Tags: []string{
|
|
|
|
"kb0j5",
|
|
|
|
"sb71y",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tt {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
tagsURL, err := env.builder.BuildTagsURL(imageName, test.queryParams)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building tags URL: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := http.Get(tagsURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error issuing request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
if resp.StatusCode != test.expectedStatusCode {
|
|
|
|
t.Fatalf("expected response status code to be %d, got %d", test.expectedStatusCode, resp.StatusCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
if test.expectedBodyErr != nil {
|
2023-11-18 06:50:40 +00:00
|
|
|
// nolint:errcheck
|
2021-05-22 14:15:49 +00:00
|
|
|
checkBodyHasErrorCodes(t, "invalid number of results requested", resp, *test.expectedBodyErr)
|
|
|
|
} else {
|
|
|
|
var body tagsAPIResponse
|
|
|
|
dec := json.NewDecoder(resp.Body)
|
|
|
|
if err := dec.Decode(&body); err != nil {
|
|
|
|
t.Fatalf("unexpected error decoding response body: %v", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(body, test.expectedBody) {
|
|
|
|
t.Fatalf("expected response body to be:\n%+v\ngot:\n%+v", test.expectedBody, body)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.Header.Get("Link") != test.expectedLinkHeader {
|
|
|
|
t.Fatalf("expected response Link header to be %q, got %q", test.expectedLinkHeader, resp.Header.Get("Link"))
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-17 18:42:47 +00:00
|
|
|
func checkLink(t *testing.T, urlStr string, numEntries int, last string) url.Values {
|
|
|
|
re := regexp.MustCompile("<(/v2/_catalog.*)>; rel=\"next\"")
|
|
|
|
matches := re.FindStringSubmatch(urlStr)
|
|
|
|
|
|
|
|
if len(matches) != 2 {
|
|
|
|
t.Fatalf("Catalog link address response was incorrect")
|
|
|
|
}
|
|
|
|
linkURL, _ := url.Parse(matches[1])
|
|
|
|
urlValues := linkURL.Query()
|
|
|
|
|
|
|
|
if urlValues.Get("n") != strconv.Itoa(numEntries) {
|
2023-03-31 11:16:29 +00:00
|
|
|
t.Fatalf("Catalog link entry size is incorrect (expected: %v, returned: %v)", urlValues.Get("n"), strconv.Itoa(numEntries))
|
2015-07-17 18:42:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if urlValues.Get("last") != last {
|
|
|
|
t.Fatal("Catalog link last entry is incorrect")
|
2015-07-13 20:08:13 +00:00
|
|
|
}
|
|
|
|
|
2015-07-17 18:42:47 +00:00
|
|
|
return urlValues
|
2015-07-13 20:08:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func contains(elems []string, e string) bool {
|
|
|
|
for _, elem := range elems {
|
|
|
|
if elem == e {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-02-24 22:59:01 +00:00
|
|
|
func TestURLPrefix(t *testing.T) {
|
|
|
|
config := configuration.Configuration{
|
|
|
|
Storage: configuration.Storage{
|
2018-11-15 10:36:19 +00:00
|
|
|
"inmemory": configuration.Parameters{},
|
2016-08-26 23:10:11 +00:00
|
|
|
"maintenance": configuration.Parameters{"uploadpurging": map[interface{}]interface{}{
|
|
|
|
"enabled": false,
|
|
|
|
}},
|
2015-02-24 22:59:01 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
config.HTTP.Prefix = "/test/"
|
2015-08-10 21:20:52 +00:00
|
|
|
config.HTTP.Headers = headerConfig
|
2015-02-24 22:59:01 +00:00
|
|
|
|
|
|
|
env := newTestEnvWithConfig(t, &config)
|
2016-08-26 23:20:54 +00:00
|
|
|
defer env.Shutdown()
|
2015-02-24 22:59:01 +00:00
|
|
|
|
|
|
|
baseURL, err := env.builder.BuildBaseURL()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building base url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
parsed, _ := url.Parse(baseURL)
|
|
|
|
if !strings.HasPrefix(parsed.Path, config.HTTP.Prefix) {
|
|
|
|
t.Fatalf("Prefix %v not included in test url %v", config.HTTP.Prefix, baseURL)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := http.Get(baseURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error issuing request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "issuing api base check", resp, http.StatusOK)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
2019-01-14 08:53:03 +00:00
|
|
|
"Content-Type": []string{"application/json"},
|
2015-02-24 22:59:01 +00:00
|
|
|
"Content-Length": []string{"2"},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:52:22 +00:00
|
|
|
type blobArgs struct {
|
2015-12-15 22:35:23 +00:00
|
|
|
imageName reference.Named
|
2015-05-27 17:52:22 +00:00
|
|
|
layerFile io.ReadSeeker
|
|
|
|
layerDigest digest.Digest
|
|
|
|
}
|
2014-11-21 03:57:01 +00:00
|
|
|
|
2015-05-27 17:52:22 +00:00
|
|
|
func makeBlobArgs(t *testing.T) blobArgs {
|
2015-12-16 01:18:13 +00:00
|
|
|
layerFile, layerDigest, err := testutil.CreateRandomTarFile()
|
2014-11-21 03:57:01 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating random layer file: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:52:22 +00:00
|
|
|
args := blobArgs{
|
|
|
|
layerFile: layerFile,
|
|
|
|
layerDigest: layerDigest,
|
|
|
|
}
|
2017-01-14 01:06:03 +00:00
|
|
|
args.imageName, _ = reference.WithName("foo/bar")
|
2015-05-27 17:52:22 +00:00
|
|
|
return args
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestBlobAPI conducts a full test of the of the blob api.
|
|
|
|
func TestBlobAPI(t *testing.T) {
|
|
|
|
deleteEnabled := false
|
2016-08-26 23:20:54 +00:00
|
|
|
env1 := newTestEnv(t, deleteEnabled)
|
|
|
|
defer env1.Shutdown()
|
2015-05-27 17:52:22 +00:00
|
|
|
args := makeBlobArgs(t)
|
2016-08-26 23:20:54 +00:00
|
|
|
testBlobAPI(t, env1, args)
|
2015-05-27 17:52:22 +00:00
|
|
|
|
|
|
|
deleteEnabled = true
|
2016-08-26 23:20:54 +00:00
|
|
|
env2 := newTestEnv(t, deleteEnabled)
|
|
|
|
defer env2.Shutdown()
|
2015-05-27 17:52:22 +00:00
|
|
|
args = makeBlobArgs(t)
|
2016-08-26 23:20:54 +00:00
|
|
|
testBlobAPI(t, env2, args)
|
2015-05-27 17:52:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestBlobDelete(t *testing.T) {
|
|
|
|
deleteEnabled := true
|
|
|
|
env := newTestEnv(t, deleteEnabled)
|
2016-08-26 23:20:54 +00:00
|
|
|
defer env.Shutdown()
|
2015-05-27 17:52:22 +00:00
|
|
|
|
|
|
|
args := makeBlobArgs(t)
|
|
|
|
env = testBlobAPI(t, env, args)
|
|
|
|
testBlobDelete(t, env, args)
|
|
|
|
}
|
|
|
|
|
2016-02-23 01:49:23 +00:00
|
|
|
func TestRelativeURL(t *testing.T) {
|
|
|
|
config := configuration.Configuration{
|
|
|
|
Storage: configuration.Storage{
|
2018-11-15 10:36:19 +00:00
|
|
|
"inmemory": configuration.Parameters{},
|
2016-08-26 23:10:11 +00:00
|
|
|
"maintenance": configuration.Parameters{"uploadpurging": map[interface{}]interface{}{
|
|
|
|
"enabled": false,
|
|
|
|
}},
|
2016-02-23 01:49:23 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
config.HTTP.Headers = headerConfig
|
|
|
|
config.HTTP.RelativeURLs = false
|
|
|
|
env := newTestEnvWithConfig(t, &config)
|
2016-08-26 23:20:54 +00:00
|
|
|
defer env.Shutdown()
|
2016-02-23 01:49:23 +00:00
|
|
|
ref, _ := reference.WithName("foo/bar")
|
|
|
|
uploadURLBaseAbs, _ := startPushLayer(t, env, ref)
|
|
|
|
|
|
|
|
u, err := url.Parse(uploadURLBaseAbs)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !u.IsAbs() {
|
|
|
|
t.Fatal("Relative URL returned from blob upload chunk with non-relative configuration")
|
|
|
|
}
|
|
|
|
|
|
|
|
args := makeBlobArgs(t)
|
|
|
|
resp, err := doPushLayer(t, env.builder, ref, args.layerDigest, uploadURLBaseAbs, args.layerFile)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error doing layer push relative url: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2016-02-23 01:49:23 +00:00
|
|
|
checkResponse(t, "relativeurl blob upload", resp, http.StatusCreated)
|
|
|
|
u, err = url.Parse(resp.Header.Get("Location"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !u.IsAbs() {
|
|
|
|
t.Fatal("Relative URL returned from blob upload with non-relative configuration")
|
|
|
|
}
|
|
|
|
|
|
|
|
config.HTTP.RelativeURLs = true
|
|
|
|
args = makeBlobArgs(t)
|
|
|
|
uploadURLBaseRelative, _ := startPushLayer(t, env, ref)
|
|
|
|
u, err = url.Parse(uploadURLBaseRelative)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if u.IsAbs() {
|
|
|
|
t.Fatal("Absolute URL returned from blob upload chunk with relative configuration")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start a new upload in absolute mode to get a valid base URL
|
|
|
|
config.HTTP.RelativeURLs = false
|
|
|
|
uploadURLBaseAbs, _ = startPushLayer(t, env, ref)
|
|
|
|
u, err = url.Parse(uploadURLBaseAbs)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !u.IsAbs() {
|
|
|
|
t.Fatal("Relative URL returned from blob upload chunk with non-relative configuration")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Complete upload with relative URLs enabled to ensure the final location is relative
|
|
|
|
config.HTTP.RelativeURLs = true
|
|
|
|
resp, err = doPushLayer(t, env.builder, ref, args.layerDigest, uploadURLBaseAbs, args.layerFile)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error doing layer push relative url: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2016-02-23 01:49:23 +00:00
|
|
|
|
|
|
|
checkResponse(t, "relativeurl blob upload", resp, http.StatusCreated)
|
|
|
|
u, err = url.Parse(resp.Header.Get("Location"))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if u.IsAbs() {
|
|
|
|
t.Fatal("Relative URL returned from blob upload with non-relative configuration")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:52:22 +00:00
|
|
|
func TestBlobDeleteDisabled(t *testing.T) {
|
|
|
|
deleteEnabled := false
|
|
|
|
env := newTestEnv(t, deleteEnabled)
|
2016-08-26 23:20:54 +00:00
|
|
|
defer env.Shutdown()
|
2015-05-27 17:52:22 +00:00
|
|
|
args := makeBlobArgs(t)
|
|
|
|
|
|
|
|
imageName := args.imageName
|
|
|
|
layerDigest := args.layerDigest
|
2015-12-16 00:43:13 +00:00
|
|
|
ref, _ := reference.WithDigest(imageName, layerDigest)
|
|
|
|
layerURL, err := env.builder.BuildBlobURL(ref)
|
2015-05-27 17:52:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error building url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := httpDelete(layerURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error deleting when disabled: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-05-27 17:52:22 +00:00
|
|
|
|
|
|
|
checkResponse(t, "status of disabled delete", resp, http.StatusMethodNotAllowed)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testBlobAPI(t *testing.T, env *testEnv, args blobArgs) *testEnv {
|
|
|
|
// TODO(stevvooe): This test code is complete junk but it should cover the
|
|
|
|
// complete flow. This must be broken down and checked against the
|
|
|
|
// specification *before* we submit the final to docker core.
|
|
|
|
imageName := args.imageName
|
|
|
|
layerFile := args.layerFile
|
|
|
|
layerDigest := args.layerDigest
|
|
|
|
|
2014-11-21 03:57:01 +00:00
|
|
|
// -----------------------------------
|
|
|
|
// Test fetch for non-existent content
|
2015-12-16 00:43:13 +00:00
|
|
|
ref, _ := reference.WithDigest(imageName, layerDigest)
|
|
|
|
layerURL, err := env.builder.BuildBlobURL(ref)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error building url: %v", err)
|
|
|
|
}
|
2014-11-21 03:57:01 +00:00
|
|
|
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
resp, err := http.Get(layerURL)
|
2014-11-21 03:57:01 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error fetching non-existent layer: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2014-11-21 03:57:01 +00:00
|
|
|
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
checkResponse(t, "fetching non-existent content", resp, http.StatusNotFound)
|
2014-11-21 03:57:01 +00:00
|
|
|
|
|
|
|
// ------------------------------------------
|
|
|
|
// Test head request for non-existent content
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
resp, err = http.Head(layerURL)
|
2014-11-21 03:57:01 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error checking head on non-existent layer: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2014-11-21 03:57:01 +00:00
|
|
|
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
checkResponse(t, "checking head on non-existent layer", resp, http.StatusNotFound)
|
2014-11-21 03:57:01 +00:00
|
|
|
|
|
|
|
// ------------------------------------------
|
2015-02-27 00:43:47 +00:00
|
|
|
// Start an upload, check the status then cancel
|
2016-02-23 01:49:23 +00:00
|
|
|
uploadURLBase, uploadUUID := startPushLayer(t, env, imageName)
|
2015-02-27 00:43:47 +00:00
|
|
|
|
|
|
|
// A status check should work
|
|
|
|
resp, err = http.Get(uploadURLBase)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error getting upload status: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2015-02-27 00:43:47 +00:00
|
|
|
checkResponse(t, "status of deleted upload", resp, http.StatusNoContent)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Location": []string{"*"},
|
|
|
|
"Range": []string{"0-0"},
|
|
|
|
"Docker-Upload-UUID": []string{uploadUUID},
|
|
|
|
})
|
2015-01-30 05:26:35 +00:00
|
|
|
|
2022-11-02 22:31:23 +00:00
|
|
|
req, err := http.NewRequest(http.MethodDelete, uploadURLBase, nil)
|
2014-11-21 03:57:01 +00:00
|
|
|
if err != nil {
|
2015-01-30 05:26:35 +00:00
|
|
|
t.Fatalf("unexpected error creating delete request: %v", err)
|
2014-11-21 03:57:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-30 05:26:35 +00:00
|
|
|
resp, err = http.DefaultClient.Do(req)
|
2014-11-21 03:57:01 +00:00
|
|
|
if err != nil {
|
2015-01-30 05:26:35 +00:00
|
|
|
t.Fatalf("unexpected error sending delete request: %v", err)
|
2014-11-21 03:57:01 +00:00
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-01-30 05:26:35 +00:00
|
|
|
checkResponse(t, "deleting upload", resp, http.StatusNoContent)
|
|
|
|
|
|
|
|
// A status check should result in 404
|
|
|
|
resp, err = http.Get(uploadURLBase)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error getting upload status: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-01-30 05:26:35 +00:00
|
|
|
checkResponse(t, "status of deleted upload", resp, http.StatusNotFound)
|
|
|
|
|
|
|
|
// -----------------------------------------
|
2015-02-02 21:01:49 +00:00
|
|
|
// Do layer push with an empty body and different digest
|
2016-11-17 18:28:05 +00:00
|
|
|
uploadURLBase, _ = startPushLayer(t, env, imageName)
|
2015-02-07 00:19:19 +00:00
|
|
|
resp, err = doPushLayer(t, env.builder, imageName, layerDigest, uploadURLBase, bytes.NewReader([]byte{}))
|
2015-01-30 05:26:35 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error doing bad layer push: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2014-11-21 03:57:01 +00:00
|
|
|
|
2015-01-30 05:26:35 +00:00
|
|
|
checkResponse(t, "bad layer push", resp, http.StatusBadRequest)
|
2023-11-18 06:50:40 +00:00
|
|
|
// nolint:errcheck
|
2023-09-04 15:52:12 +00:00
|
|
|
checkBodyHasErrorCodes(t, "bad layer push", resp, errcode.ErrorCodeDigestInvalid)
|
2015-01-30 05:26:35 +00:00
|
|
|
|
|
|
|
// -----------------------------------------
|
2015-02-02 21:01:49 +00:00
|
|
|
// Do layer push with an empty body and correct digest
|
2015-12-16 01:18:13 +00:00
|
|
|
zeroDigest, err := digest.FromReader(bytes.NewReader([]byte{}))
|
2015-02-02 21:01:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error digesting empty buffer: %v", err)
|
|
|
|
}
|
2015-01-30 05:26:35 +00:00
|
|
|
|
2016-11-17 18:28:05 +00:00
|
|
|
uploadURLBase, _ = startPushLayer(t, env, imageName)
|
2015-02-07 00:19:19 +00:00
|
|
|
pushLayer(t, env.builder, imageName, zeroDigest, uploadURLBase, bytes.NewReader([]byte{}))
|
2015-02-02 21:01:49 +00:00
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
// Do layer push with an empty body and correct digest
|
|
|
|
|
|
|
|
// This is a valid but empty tarfile!
|
|
|
|
emptyTar := bytes.Repeat([]byte("\x00"), 1024)
|
2015-12-16 01:18:13 +00:00
|
|
|
emptyDigest, err := digest.FromReader(bytes.NewReader(emptyTar))
|
2015-01-30 05:26:35 +00:00
|
|
|
if err != nil {
|
2015-02-02 21:01:49 +00:00
|
|
|
t.Fatalf("unexpected error digesting empty tar: %v", err)
|
2015-01-30 05:26:35 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 18:28:05 +00:00
|
|
|
uploadURLBase, _ = startPushLayer(t, env, imageName)
|
2015-02-07 00:19:19 +00:00
|
|
|
pushLayer(t, env.builder, imageName, emptyDigest, uploadURLBase, bytes.NewReader(emptyTar))
|
2015-01-30 05:26:35 +00:00
|
|
|
|
|
|
|
// ------------------------------------------
|
|
|
|
// Now, actually do successful upload.
|
2023-11-18 06:50:40 +00:00
|
|
|
layerLength, err := layerFile.Seek(0, io.SeekEnd)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error seeking layer: %v", err)
|
|
|
|
}
|
|
|
|
if _, err := layerFile.Seek(0, io.SeekStart); err != nil {
|
|
|
|
t.Fatalf("unexpected error seeking layer: %v", err)
|
|
|
|
}
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
|
2016-11-17 18:28:05 +00:00
|
|
|
uploadURLBase, _ = startPushLayer(t, env, imageName)
|
2015-02-07 00:19:19 +00:00
|
|
|
pushLayer(t, env.builder, imageName, layerDigest, uploadURLBase, layerFile)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
|
2015-05-04 15:56:37 +00:00
|
|
|
// ------------------------------------------
|
|
|
|
// Now, push just a chunk
|
2023-11-18 06:50:40 +00:00
|
|
|
if _, err := layerFile.Seek(0, io.SeekStart); err != nil {
|
|
|
|
t.Fatalf("unexpected error seeking layer: %v", err)
|
|
|
|
}
|
2015-05-04 15:56:37 +00:00
|
|
|
|
2016-12-17 00:28:34 +00:00
|
|
|
canonicalDigester := digest.Canonical.Digester()
|
2015-05-21 06:44:08 +00:00
|
|
|
if _, err := io.Copy(canonicalDigester.Hash(), layerFile); err != nil {
|
Refactor Blob Service API
This PR refactors the blob service API to be oriented around blob descriptors.
Identified by digests, blobs become an abstract entity that can be read and
written using a descriptor as a handle. This allows blobs to take many forms,
such as a ReadSeekCloser or a simple byte buffer, allowing blob oriented
operations to better integrate with blob agnostic APIs (such as the `io`
package). The error definitions are now better organized to reflect conditions
that can only be seen when interacting with the blob API.
The main benefit of this is to separate the much smaller metadata from large
file storage. Many benefits also follow from this. Reading and writing has
been separated into discrete services. Backend implementation is also
simplified, by reducing the amount of metadata that needs to be picked up to
simply serve a read. This also improves cacheability.
"Opening" a blob simply consists of an access check (Stat) and a path
calculation. Caching is greatly simplified and we've made the mapping of
provisional to canonical hashes a first-class concept. BlobDescriptorService
and BlobProvider can be combined in different ways to achieve varying effects.
Recommend Review Approach
-------------------------
This is a very large patch. While apologies are in order, we are getting a
considerable amount of refactoring. Most changes follow from the changes to
the root package (distribution), so start there. From there, the main changes
are in storage. Looking at (*repository).Blobs will help to understand the how
the linkedBlobStore is wired. One can explore the internals within and also
branch out into understanding the changes to the caching layer. Following the
descriptions below will also help to guide you.
To reduce the chances for regressions, it was critical that major changes to
unit tests were avoided. Where possible, they are left untouched and where
not, the spirit is hopefully captured. Pay particular attention to where
behavior may have changed.
Storage
-------
The primary changes to the `storage` package, other than the interface
updates, were to merge the layerstore and blobstore. Blob access is now
layered even further. The first layer, blobStore, exposes a global
`BlobStatter` and `BlobProvider`. Operations here provide a fast path for most
read operations that don't take access control into account. The
`linkedBlobStore` layers on top of the `blobStore`, providing repository-
scoped blob link management in the backend. The `linkedBlobStore` implements
the full `BlobStore` suite, providing access-controlled, repository-local blob
writers. The abstraction between the two is slightly broken in that
`linkedBlobStore` is the only channel under which one can write into the global
blob store. The `linkedBlobStore` also provides flexibility in that it can act
over different link sets depending on configuration. This allows us to use the
same code for signature links, manifest links and blob links. Eventually, we
will fully consolidate this storage.
The improved cache flow comes from the `linkedBlobStatter` component
of `linkedBlobStore`. Using a `cachedBlobStatter`, these combine together to
provide a simple cache hierarchy that should streamline access checks on read
and write operations, or at least provide a single path to optimize. The
metrics have been changed in a slightly incompatible way since the former
operations, Fetch and Exists, are no longer relevant.
The fileWriter and fileReader have been slightly modified to support the rest
of the changes. The most interesting is the removal of the `Stat` call from
`newFileReader`. This was the source of unnecessary round trips that were only
present to look up the size of the resulting reader. Now, one must simply pass
in the size, requiring the caller to decide whether or not the `Stat` call is
appropriate. In several cases, it turned out the caller already had the size
already. The `WriterAt` implementation has been removed from `fileWriter`,
since it is no longer required for `BlobWriter`, reducing the number of paths
which writes may take.
Cache
-----
Unfortunately, the `cache` package required a near full rewrite. It was pretty
mechanical in that the cache is oriented around the `BlobDescriptorService`
slightly modified to include the ability to set the values for individual
digests. While the implementation is oriented towards caching, it can act as a
primary store. Provisions are in place to have repository local metadata, in
addition to global metadata. Fallback is implemented as a part of the storage
package to maintain this flexibility.
One unfortunate side-effect is that caching is now repository-scoped, rather
than global. This should have little effect on performance but may increase
memory usage.
Handlers
--------
The `handlers` package has been updated to leverage the new API. For the most
part, the changes are superficial or mechanical based on the API changes. This
did expose a bug in the handling of provisional vs canonical digests that was
fixed in the unit tests.
Configuration
-------------
One user-facing change has been made to the configuration and is updated in
the associated documentation. The `layerinfo` cache parameter has been
deprecated by the `blobdescriptor` cache parameter. Both are equivalent and
configuration files should be backward compatible.
Notifications
-------------
Changes the `notification` package are simply to support the interface
changes.
Context
-------
A small change has been made to the tracing log-level. Traces have been moved
from "info" to "debug" level to reduce output when not needed.
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2015-05-12 07:10:29 +00:00
|
|
|
t.Fatalf("error copying to digest: %v", err)
|
|
|
|
}
|
|
|
|
canonicalDigest := canonicalDigester.Digest()
|
|
|
|
|
2023-11-18 06:50:40 +00:00
|
|
|
if _, err := layerFile.Seek(0, io.SeekStart); err != nil {
|
|
|
|
t.Fatalf("unexpected error seeking layer: %v", err)
|
|
|
|
}
|
2016-11-17 18:28:05 +00:00
|
|
|
uploadURLBase, _ = startPushLayer(t, env, imageName)
|
2015-05-04 15:56:37 +00:00
|
|
|
uploadURLBase, dgst := pushChunk(t, env.builder, imageName, uploadURLBase, layerFile, layerLength)
|
2022-10-23 14:33:01 +00:00
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
// Check the chunk upload status
|
|
|
|
_, end, err := getUploadStatus(uploadURLBase)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error doing chunk upload check: %v", err)
|
|
|
|
}
|
|
|
|
if end+1 != layerLength {
|
|
|
|
t.Fatalf("getting wrong chunk upload status: %d", end)
|
|
|
|
}
|
|
|
|
|
2015-05-04 15:56:37 +00:00
|
|
|
finishUpload(t, env.builder, imageName, uploadURLBase, dgst)
|
2015-05-27 17:52:22 +00:00
|
|
|
|
2020-08-19 09:07:38 +00:00
|
|
|
// -----------------------------------------
|
|
|
|
// Do layer push with invalid content range
|
2023-11-18 06:50:40 +00:00
|
|
|
if _, err := layerFile.Seek(0, io.SeekStart); err != nil {
|
|
|
|
t.Fatalf("unexpected error seeking layer: %v", err)
|
|
|
|
}
|
|
|
|
|
2020-08-19 09:07:38 +00:00
|
|
|
uploadURLBase, _ = startPushLayer(t, env, imageName)
|
|
|
|
sizeInvalid := chunkOptions{
|
|
|
|
contentRange: "0-20",
|
|
|
|
}
|
|
|
|
resp, err = doPushChunk(t, uploadURLBase, layerFile, sizeInvalid)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error doing push layer request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
checkResponse(t, "putting size invalid chunk", resp, http.StatusBadRequest)
|
|
|
|
|
2023-11-18 06:50:40 +00:00
|
|
|
if _, err := layerFile.Seek(0, io.SeekStart); err != nil {
|
|
|
|
t.Fatalf("unexpected error seeking layer: %v", err)
|
|
|
|
}
|
2020-08-19 09:07:38 +00:00
|
|
|
uploadURLBase, _ = startPushLayer(t, env, imageName)
|
|
|
|
outOfOrder := chunkOptions{
|
|
|
|
contentRange: "3-22",
|
|
|
|
}
|
|
|
|
resp, err = doPushChunk(t, uploadURLBase, layerFile, outOfOrder)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error doing push layer request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
checkResponse(t, "putting range out of order chunk", resp, http.StatusRequestedRangeNotSatisfiable)
|
|
|
|
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
// ------------------------
|
|
|
|
// Use a head request to see if the layer exists.
|
|
|
|
resp, err = http.Head(layerURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error checking head on existing layer: %v", err)
|
2014-11-21 03:57:01 +00:00
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
checkResponse(t, "checking head on existing layer", resp, http.StatusOK)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
2015-02-26 23:47:04 +00:00
|
|
|
"Content-Length": []string{fmt.Sprint(layerLength)},
|
Refactor Blob Service API
This PR refactors the blob service API to be oriented around blob descriptors.
Identified by digests, blobs become an abstract entity that can be read and
written using a descriptor as a handle. This allows blobs to take many forms,
such as a ReadSeekCloser or a simple byte buffer, allowing blob oriented
operations to better integrate with blob agnostic APIs (such as the `io`
package). The error definitions are now better organized to reflect conditions
that can only be seen when interacting with the blob API.
The main benefit of this is to separate the much smaller metadata from large
file storage. Many benefits also follow from this. Reading and writing has
been separated into discrete services. Backend implementation is also
simplified, by reducing the amount of metadata that needs to be picked up to
simply serve a read. This also improves cacheability.
"Opening" a blob simply consists of an access check (Stat) and a path
calculation. Caching is greatly simplified and we've made the mapping of
provisional to canonical hashes a first-class concept. BlobDescriptorService
and BlobProvider can be combined in different ways to achieve varying effects.
Recommend Review Approach
-------------------------
This is a very large patch. While apologies are in order, we are getting a
considerable amount of refactoring. Most changes follow from the changes to
the root package (distribution), so start there. From there, the main changes
are in storage. Looking at (*repository).Blobs will help to understand the how
the linkedBlobStore is wired. One can explore the internals within and also
branch out into understanding the changes to the caching layer. Following the
descriptions below will also help to guide you.
To reduce the chances for regressions, it was critical that major changes to
unit tests were avoided. Where possible, they are left untouched and where
not, the spirit is hopefully captured. Pay particular attention to where
behavior may have changed.
Storage
-------
The primary changes to the `storage` package, other than the interface
updates, were to merge the layerstore and blobstore. Blob access is now
layered even further. The first layer, blobStore, exposes a global
`BlobStatter` and `BlobProvider`. Operations here provide a fast path for most
read operations that don't take access control into account. The
`linkedBlobStore` layers on top of the `blobStore`, providing repository-
scoped blob link management in the backend. The `linkedBlobStore` implements
the full `BlobStore` suite, providing access-controlled, repository-local blob
writers. The abstraction between the two is slightly broken in that
`linkedBlobStore` is the only channel under which one can write into the global
blob store. The `linkedBlobStore` also provides flexibility in that it can act
over different link sets depending on configuration. This allows us to use the
same code for signature links, manifest links and blob links. Eventually, we
will fully consolidate this storage.
The improved cache flow comes from the `linkedBlobStatter` component
of `linkedBlobStore`. Using a `cachedBlobStatter`, these combine together to
provide a simple cache hierarchy that should streamline access checks on read
and write operations, or at least provide a single path to optimize. The
metrics have been changed in a slightly incompatible way since the former
operations, Fetch and Exists, are no longer relevant.
The fileWriter and fileReader have been slightly modified to support the rest
of the changes. The most interesting is the removal of the `Stat` call from
`newFileReader`. This was the source of unnecessary round trips that were only
present to look up the size of the resulting reader. Now, one must simply pass
in the size, requiring the caller to decide whether or not the `Stat` call is
appropriate. In several cases, it turned out the caller already had the size
already. The `WriterAt` implementation has been removed from `fileWriter`,
since it is no longer required for `BlobWriter`, reducing the number of paths
which writes may take.
Cache
-----
Unfortunately, the `cache` package required a near full rewrite. It was pretty
mechanical in that the cache is oriented around the `BlobDescriptorService`
slightly modified to include the ability to set the values for individual
digests. While the implementation is oriented towards caching, it can act as a
primary store. Provisions are in place to have repository local metadata, in
addition to global metadata. Fallback is implemented as a part of the storage
package to maintain this flexibility.
One unfortunate side-effect is that caching is now repository-scoped, rather
than global. This should have little effect on performance but may increase
memory usage.
Handlers
--------
The `handlers` package has been updated to leverage the new API. For the most
part, the changes are superficial or mechanical based on the API changes. This
did expose a bug in the handling of provisional vs canonical digests that was
fixed in the unit tests.
Configuration
-------------
One user-facing change has been made to the configuration and is updated in
the associated documentation. The `layerinfo` cache parameter has been
deprecated by the `blobdescriptor` cache parameter. Both are equivalent and
configuration files should be backward compatible.
Notifications
-------------
Changes the `notification` package are simply to support the interface
changes.
Context
-------
A small change has been made to the tracing log-level. Traces have been moved
from "info" to "debug" level to reduce output when not needed.
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2015-05-12 07:10:29 +00:00
|
|
|
"Docker-Content-Digest": []string{canonicalDigest.String()},
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// ----------------
|
|
|
|
// Fetch the layer!
|
|
|
|
resp, err = http.Get(layerURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error fetching layer: %v", err)
|
2014-11-21 03:57:01 +00:00
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
checkResponse(t, "fetching layer", resp, http.StatusOK)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
2015-02-26 23:47:04 +00:00
|
|
|
"Content-Length": []string{fmt.Sprint(layerLength)},
|
Refactor Blob Service API
This PR refactors the blob service API to be oriented around blob descriptors.
Identified by digests, blobs become an abstract entity that can be read and
written using a descriptor as a handle. This allows blobs to take many forms,
such as a ReadSeekCloser or a simple byte buffer, allowing blob oriented
operations to better integrate with blob agnostic APIs (such as the `io`
package). The error definitions are now better organized to reflect conditions
that can only be seen when interacting with the blob API.
The main benefit of this is to separate the much smaller metadata from large
file storage. Many benefits also follow from this. Reading and writing has
been separated into discrete services. Backend implementation is also
simplified, by reducing the amount of metadata that needs to be picked up to
simply serve a read. This also improves cacheability.
"Opening" a blob simply consists of an access check (Stat) and a path
calculation. Caching is greatly simplified and we've made the mapping of
provisional to canonical hashes a first-class concept. BlobDescriptorService
and BlobProvider can be combined in different ways to achieve varying effects.
Recommend Review Approach
-------------------------
This is a very large patch. While apologies are in order, we are getting a
considerable amount of refactoring. Most changes follow from the changes to
the root package (distribution), so start there. From there, the main changes
are in storage. Looking at (*repository).Blobs will help to understand the how
the linkedBlobStore is wired. One can explore the internals within and also
branch out into understanding the changes to the caching layer. Following the
descriptions below will also help to guide you.
To reduce the chances for regressions, it was critical that major changes to
unit tests were avoided. Where possible, they are left untouched and where
not, the spirit is hopefully captured. Pay particular attention to where
behavior may have changed.
Storage
-------
The primary changes to the `storage` package, other than the interface
updates, were to merge the layerstore and blobstore. Blob access is now
layered even further. The first layer, blobStore, exposes a global
`BlobStatter` and `BlobProvider`. Operations here provide a fast path for most
read operations that don't take access control into account. The
`linkedBlobStore` layers on top of the `blobStore`, providing repository-
scoped blob link management in the backend. The `linkedBlobStore` implements
the full `BlobStore` suite, providing access-controlled, repository-local blob
writers. The abstraction between the two is slightly broken in that
`linkedBlobStore` is the only channel under which one can write into the global
blob store. The `linkedBlobStore` also provides flexibility in that it can act
over different link sets depending on configuration. This allows us to use the
same code for signature links, manifest links and blob links. Eventually, we
will fully consolidate this storage.
The improved cache flow comes from the `linkedBlobStatter` component
of `linkedBlobStore`. Using a `cachedBlobStatter`, these combine together to
provide a simple cache hierarchy that should streamline access checks on read
and write operations, or at least provide a single path to optimize. The
metrics have been changed in a slightly incompatible way since the former
operations, Fetch and Exists, are no longer relevant.
The fileWriter and fileReader have been slightly modified to support the rest
of the changes. The most interesting is the removal of the `Stat` call from
`newFileReader`. This was the source of unnecessary round trips that were only
present to look up the size of the resulting reader. Now, one must simply pass
in the size, requiring the caller to decide whether or not the `Stat` call is
appropriate. In several cases, it turned out the caller already had the size
already. The `WriterAt` implementation has been removed from `fileWriter`,
since it is no longer required for `BlobWriter`, reducing the number of paths
which writes may take.
Cache
-----
Unfortunately, the `cache` package required a near full rewrite. It was pretty
mechanical in that the cache is oriented around the `BlobDescriptorService`
slightly modified to include the ability to set the values for individual
digests. While the implementation is oriented towards caching, it can act as a
primary store. Provisions are in place to have repository local metadata, in
addition to global metadata. Fallback is implemented as a part of the storage
package to maintain this flexibility.
One unfortunate side-effect is that caching is now repository-scoped, rather
than global. This should have little effect on performance but may increase
memory usage.
Handlers
--------
The `handlers` package has been updated to leverage the new API. For the most
part, the changes are superficial or mechanical based on the API changes. This
did expose a bug in the handling of provisional vs canonical digests that was
fixed in the unit tests.
Configuration
-------------
One user-facing change has been made to the configuration and is updated in
the associated documentation. The `layerinfo` cache parameter has been
deprecated by the `blobdescriptor` cache parameter. Both are equivalent and
configuration files should be backward compatible.
Notifications
-------------
Changes the `notification` package are simply to support the interface
changes.
Context
-------
A small change has been made to the tracing log-level. Traces have been moved
from "info" to "debug" level to reduce output when not needed.
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2015-05-12 07:10:29 +00:00
|
|
|
"Docker-Content-Digest": []string{canonicalDigest.String()},
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
})
|
2014-11-21 03:57:01 +00:00
|
|
|
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
// Verify the body
|
2016-12-16 02:33:26 +00:00
|
|
|
verifier := layerDigest.Verifier()
|
2023-11-18 06:50:40 +00:00
|
|
|
if _, err := io.Copy(verifier, resp.Body); err != nil {
|
|
|
|
t.Fatalf("unexpected error reading response body: %v", err)
|
|
|
|
}
|
2014-11-21 03:57:01 +00:00
|
|
|
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
if !verifier.Verified() {
|
|
|
|
t.Fatalf("response body did not pass verification")
|
|
|
|
}
|
2014-12-10 05:25:54 +00:00
|
|
|
|
2015-05-05 21:21:33 +00:00
|
|
|
// ----------------
|
|
|
|
// Fetch the layer with an invalid digest
|
2015-12-16 01:18:13 +00:00
|
|
|
badURL := strings.Replace(layerURL, "sha256", "sha257", 1)
|
2015-05-05 21:21:33 +00:00
|
|
|
resp, err = http.Get(badURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error fetching layer: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-05-05 21:21:33 +00:00
|
|
|
checkResponse(t, "fetching layer bad digest", resp, http.StatusBadRequest)
|
|
|
|
|
2015-05-13 00:49:18 +00:00
|
|
|
// Cache headers
|
|
|
|
resp, err = http.Get(layerURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error fetching layer: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-05-13 00:49:18 +00:00
|
|
|
checkResponse(t, "fetching layer", resp, http.StatusOK)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Content-Length": []string{fmt.Sprint(layerLength)},
|
Refactor Blob Service API
This PR refactors the blob service API to be oriented around blob descriptors.
Identified by digests, blobs become an abstract entity that can be read and
written using a descriptor as a handle. This allows blobs to take many forms,
such as a ReadSeekCloser or a simple byte buffer, allowing blob oriented
operations to better integrate with blob agnostic APIs (such as the `io`
package). The error definitions are now better organized to reflect conditions
that can only be seen when interacting with the blob API.
The main benefit of this is to separate the much smaller metadata from large
file storage. Many benefits also follow from this. Reading and writing has
been separated into discrete services. Backend implementation is also
simplified, by reducing the amount of metadata that needs to be picked up to
simply serve a read. This also improves cacheability.
"Opening" a blob simply consists of an access check (Stat) and a path
calculation. Caching is greatly simplified and we've made the mapping of
provisional to canonical hashes a first-class concept. BlobDescriptorService
and BlobProvider can be combined in different ways to achieve varying effects.
Recommend Review Approach
-------------------------
This is a very large patch. While apologies are in order, we are getting a
considerable amount of refactoring. Most changes follow from the changes to
the root package (distribution), so start there. From there, the main changes
are in storage. Looking at (*repository).Blobs will help to understand the how
the linkedBlobStore is wired. One can explore the internals within and also
branch out into understanding the changes to the caching layer. Following the
descriptions below will also help to guide you.
To reduce the chances for regressions, it was critical that major changes to
unit tests were avoided. Where possible, they are left untouched and where
not, the spirit is hopefully captured. Pay particular attention to where
behavior may have changed.
Storage
-------
The primary changes to the `storage` package, other than the interface
updates, were to merge the layerstore and blobstore. Blob access is now
layered even further. The first layer, blobStore, exposes a global
`BlobStatter` and `BlobProvider`. Operations here provide a fast path for most
read operations that don't take access control into account. The
`linkedBlobStore` layers on top of the `blobStore`, providing repository-
scoped blob link management in the backend. The `linkedBlobStore` implements
the full `BlobStore` suite, providing access-controlled, repository-local blob
writers. The abstraction between the two is slightly broken in that
`linkedBlobStore` is the only channel under which one can write into the global
blob store. The `linkedBlobStore` also provides flexibility in that it can act
over different link sets depending on configuration. This allows us to use the
same code for signature links, manifest links and blob links. Eventually, we
will fully consolidate this storage.
The improved cache flow comes from the `linkedBlobStatter` component
of `linkedBlobStore`. Using a `cachedBlobStatter`, these combine together to
provide a simple cache hierarchy that should streamline access checks on read
and write operations, or at least provide a single path to optimize. The
metrics have been changed in a slightly incompatible way since the former
operations, Fetch and Exists, are no longer relevant.
The fileWriter and fileReader have been slightly modified to support the rest
of the changes. The most interesting is the removal of the `Stat` call from
`newFileReader`. This was the source of unnecessary round trips that were only
present to look up the size of the resulting reader. Now, one must simply pass
in the size, requiring the caller to decide whether or not the `Stat` call is
appropriate. In several cases, it turned out the caller already had the size
already. The `WriterAt` implementation has been removed from `fileWriter`,
since it is no longer required for `BlobWriter`, reducing the number of paths
which writes may take.
Cache
-----
Unfortunately, the `cache` package required a near full rewrite. It was pretty
mechanical in that the cache is oriented around the `BlobDescriptorService`
slightly modified to include the ability to set the values for individual
digests. While the implementation is oriented towards caching, it can act as a
primary store. Provisions are in place to have repository local metadata, in
addition to global metadata. Fallback is implemented as a part of the storage
package to maintain this flexibility.
One unfortunate side-effect is that caching is now repository-scoped, rather
than global. This should have little effect on performance but may increase
memory usage.
Handlers
--------
The `handlers` package has been updated to leverage the new API. For the most
part, the changes are superficial or mechanical based on the API changes. This
did expose a bug in the handling of provisional vs canonical digests that was
fixed in the unit tests.
Configuration
-------------
One user-facing change has been made to the configuration and is updated in
the associated documentation. The `layerinfo` cache parameter has been
deprecated by the `blobdescriptor` cache parameter. Both are equivalent and
configuration files should be backward compatible.
Notifications
-------------
Changes the `notification` package are simply to support the interface
changes.
Context
-------
A small change has been made to the tracing log-level. Traces have been moved
from "info" to "debug" level to reduce output when not needed.
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2015-05-12 07:10:29 +00:00
|
|
|
"Docker-Content-Digest": []string{canonicalDigest.String()},
|
2015-07-24 06:03:13 +00:00
|
|
|
"ETag": []string{fmt.Sprintf(`"%s"`, canonicalDigest)},
|
Refactor Blob Service API
This PR refactors the blob service API to be oriented around blob descriptors.
Identified by digests, blobs become an abstract entity that can be read and
written using a descriptor as a handle. This allows blobs to take many forms,
such as a ReadSeekCloser or a simple byte buffer, allowing blob oriented
operations to better integrate with blob agnostic APIs (such as the `io`
package). The error definitions are now better organized to reflect conditions
that can only be seen when interacting with the blob API.
The main benefit of this is to separate the much smaller metadata from large
file storage. Many benefits also follow from this. Reading and writing has
been separated into discrete services. Backend implementation is also
simplified, by reducing the amount of metadata that needs to be picked up to
simply serve a read. This also improves cacheability.
"Opening" a blob simply consists of an access check (Stat) and a path
calculation. Caching is greatly simplified and we've made the mapping of
provisional to canonical hashes a first-class concept. BlobDescriptorService
and BlobProvider can be combined in different ways to achieve varying effects.
Recommend Review Approach
-------------------------
This is a very large patch. While apologies are in order, we are getting a
considerable amount of refactoring. Most changes follow from the changes to
the root package (distribution), so start there. From there, the main changes
are in storage. Looking at (*repository).Blobs will help to understand the how
the linkedBlobStore is wired. One can explore the internals within and also
branch out into understanding the changes to the caching layer. Following the
descriptions below will also help to guide you.
To reduce the chances for regressions, it was critical that major changes to
unit tests were avoided. Where possible, they are left untouched and where
not, the spirit is hopefully captured. Pay particular attention to where
behavior may have changed.
Storage
-------
The primary changes to the `storage` package, other than the interface
updates, were to merge the layerstore and blobstore. Blob access is now
layered even further. The first layer, blobStore, exposes a global
`BlobStatter` and `BlobProvider`. Operations here provide a fast path for most
read operations that don't take access control into account. The
`linkedBlobStore` layers on top of the `blobStore`, providing repository-
scoped blob link management in the backend. The `linkedBlobStore` implements
the full `BlobStore` suite, providing access-controlled, repository-local blob
writers. The abstraction between the two is slightly broken in that
`linkedBlobStore` is the only channel under which one can write into the global
blob store. The `linkedBlobStore` also provides flexibility in that it can act
over different link sets depending on configuration. This allows us to use the
same code for signature links, manifest links and blob links. Eventually, we
will fully consolidate this storage.
The improved cache flow comes from the `linkedBlobStatter` component
of `linkedBlobStore`. Using a `cachedBlobStatter`, these combine together to
provide a simple cache hierarchy that should streamline access checks on read
and write operations, or at least provide a single path to optimize. The
metrics have been changed in a slightly incompatible way since the former
operations, Fetch and Exists, are no longer relevant.
The fileWriter and fileReader have been slightly modified to support the rest
of the changes. The most interesting is the removal of the `Stat` call from
`newFileReader`. This was the source of unnecessary round trips that were only
present to look up the size of the resulting reader. Now, one must simply pass
in the size, requiring the caller to decide whether or not the `Stat` call is
appropriate. In several cases, it turned out the caller already had the size
already. The `WriterAt` implementation has been removed from `fileWriter`,
since it is no longer required for `BlobWriter`, reducing the number of paths
which writes may take.
Cache
-----
Unfortunately, the `cache` package required a near full rewrite. It was pretty
mechanical in that the cache is oriented around the `BlobDescriptorService`
slightly modified to include the ability to set the values for individual
digests. While the implementation is oriented towards caching, it can act as a
primary store. Provisions are in place to have repository local metadata, in
addition to global metadata. Fallback is implemented as a part of the storage
package to maintain this flexibility.
One unfortunate side-effect is that caching is now repository-scoped, rather
than global. This should have little effect on performance but may increase
memory usage.
Handlers
--------
The `handlers` package has been updated to leverage the new API. For the most
part, the changes are superficial or mechanical based on the API changes. This
did expose a bug in the handling of provisional vs canonical digests that was
fixed in the unit tests.
Configuration
-------------
One user-facing change has been made to the configuration and is updated in
the associated documentation. The `layerinfo` cache parameter has been
deprecated by the `blobdescriptor` cache parameter. Both are equivalent and
configuration files should be backward compatible.
Notifications
-------------
Changes the `notification` package are simply to support the interface
changes.
Context
-------
A small change has been made to the tracing log-level. Traces have been moved
from "info" to "debug" level to reduce output when not needed.
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2015-05-12 07:10:29 +00:00
|
|
|
"Cache-Control": []string{"max-age=31536000"},
|
2015-05-13 00:49:18 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
// Matching etag, gives 304
|
|
|
|
etag := resp.Header.Get("Etag")
|
2022-11-02 22:31:23 +00:00
|
|
|
req, err = http.NewRequest(http.MethodGet, layerURL, nil)
|
2015-05-13 00:49:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
|
|
|
req.Header.Set("If-None-Match", etag)
|
2015-07-24 06:03:13 +00:00
|
|
|
|
2015-05-13 00:49:18 +00:00
|
|
|
resp, err = http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-05-13 00:49:18 +00:00
|
|
|
checkResponse(t, "fetching layer with etag", resp, http.StatusNotModified)
|
|
|
|
|
|
|
|
// Non-matching etag, gives 200
|
2022-11-02 22:31:23 +00:00
|
|
|
req, err = http.NewRequest(http.MethodGet, layerURL, nil)
|
2015-05-13 00:49:18 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
|
|
|
req.Header.Set("If-None-Match", "")
|
2023-08-19 08:16:02 +00:00
|
|
|
resp, err = http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
2015-05-13 00:49:18 +00:00
|
|
|
checkResponse(t, "fetching layer with invalid etag", resp, http.StatusOK)
|
|
|
|
|
2014-12-10 05:25:54 +00:00
|
|
|
// Missing tests:
|
2015-12-16 01:18:13 +00:00
|
|
|
// - Upload the same tar file under and different repository and
|
2014-12-10 05:25:54 +00:00
|
|
|
// ensure the content remains uncorrupted.
|
2015-05-27 17:52:22 +00:00
|
|
|
return env
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
}
|
2014-11-21 03:57:01 +00:00
|
|
|
|
2015-05-27 17:52:22 +00:00
|
|
|
func testBlobDelete(t *testing.T, env *testEnv, args blobArgs) {
|
|
|
|
// Upload a layer
|
|
|
|
imageName := args.imageName
|
|
|
|
layerFile := args.layerFile
|
|
|
|
layerDigest := args.layerDigest
|
|
|
|
|
2015-12-16 00:43:13 +00:00
|
|
|
ref, _ := reference.WithDigest(imageName, layerDigest)
|
|
|
|
layerURL, err := env.builder.BuildBlobURL(ref)
|
2015-05-27 17:52:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(err.Error())
|
|
|
|
}
|
|
|
|
// ---------------
|
|
|
|
// Delete a layer
|
|
|
|
resp, err := httpDelete(layerURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error deleting layer: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-05-27 17:52:22 +00:00
|
|
|
|
|
|
|
checkResponse(t, "deleting layer", resp, http.StatusAccepted)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Content-Length": []string{"0"},
|
|
|
|
})
|
|
|
|
|
|
|
|
// ---------------
|
|
|
|
// Try and get it back
|
|
|
|
// Use a head request to see if the layer exists.
|
|
|
|
resp, err = http.Head(layerURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error checking head on existing layer: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-05-27 17:52:22 +00:00
|
|
|
|
|
|
|
checkResponse(t, "checking existence of deleted layer", resp, http.StatusNotFound)
|
|
|
|
|
|
|
|
// Delete already deleted layer
|
|
|
|
resp, err = httpDelete(layerURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error deleting layer: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-05-27 17:52:22 +00:00
|
|
|
|
|
|
|
checkResponse(t, "deleting layer", resp, http.StatusNotFound)
|
|
|
|
|
|
|
|
// ----------------
|
|
|
|
// Attempt to delete a layer with an invalid digest
|
2015-12-16 01:18:13 +00:00
|
|
|
badURL := strings.Replace(layerURL, "sha256", "sha257", 1)
|
2015-05-27 17:52:22 +00:00
|
|
|
resp, err = httpDelete(badURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error fetching layer: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-05-27 17:52:22 +00:00
|
|
|
|
|
|
|
checkResponse(t, "deleting layer bad digest", resp, http.StatusBadRequest)
|
|
|
|
|
|
|
|
// ----------------
|
|
|
|
// Reupload previously deleted blob
|
2023-11-18 06:50:40 +00:00
|
|
|
if _, err := layerFile.Seek(0, io.SeekStart); err != nil {
|
|
|
|
t.Fatalf("unexpected error seeking layer: %v", err)
|
|
|
|
}
|
2015-05-27 17:52:22 +00:00
|
|
|
|
2016-02-23 01:49:23 +00:00
|
|
|
uploadURLBase, _ := startPushLayer(t, env, imageName)
|
2015-05-27 17:52:22 +00:00
|
|
|
pushLayer(t, env.builder, imageName, layerDigest, uploadURLBase, layerFile)
|
|
|
|
|
2023-11-18 06:50:40 +00:00
|
|
|
if _, err := layerFile.Seek(0, io.SeekStart); err != nil {
|
|
|
|
t.Fatalf("unexpected error seeking layer: %v", err)
|
|
|
|
}
|
2016-12-17 00:28:34 +00:00
|
|
|
canonicalDigester := digest.Canonical.Digester()
|
2015-05-27 17:52:22 +00:00
|
|
|
if _, err := io.Copy(canonicalDigester.Hash(), layerFile); err != nil {
|
|
|
|
t.Fatalf("error copying to digest: %v", err)
|
|
|
|
}
|
|
|
|
canonicalDigest := canonicalDigester.Digest()
|
|
|
|
|
|
|
|
// ------------------------
|
|
|
|
// Use a head request to see if it exists
|
|
|
|
resp, err = http.Head(layerURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error checking head on existing layer: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-05-27 17:52:22 +00:00
|
|
|
|
2018-08-06 21:34:15 +00:00
|
|
|
layerLength, _ := layerFile.Seek(0, io.SeekEnd)
|
2015-05-27 17:52:22 +00:00
|
|
|
checkResponse(t, "checking head on reuploaded layer", resp, http.StatusOK)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Content-Length": []string{fmt.Sprint(layerLength)},
|
|
|
|
"Docker-Content-Digest": []string{canonicalDigest.String()},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteDisabled(t *testing.T) {
|
|
|
|
env := newTestEnv(t, false)
|
2016-08-26 23:20:54 +00:00
|
|
|
defer env.Shutdown()
|
2014-11-21 03:57:01 +00:00
|
|
|
|
2017-01-14 01:06:03 +00:00
|
|
|
imageName, _ := reference.WithName("foo/bar")
|
2015-05-27 17:52:22 +00:00
|
|
|
// "build" our layer file
|
2015-12-16 01:18:13 +00:00
|
|
|
layerFile, layerDigest, err := testutil.CreateRandomTarFile()
|
2015-05-27 17:52:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating random layer file: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-12-16 00:43:13 +00:00
|
|
|
ref, _ := reference.WithDigest(imageName, layerDigest)
|
|
|
|
layerURL, err := env.builder.BuildBlobURL(ref)
|
2015-05-27 17:52:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error building blob URL")
|
|
|
|
}
|
2016-02-23 01:49:23 +00:00
|
|
|
uploadURLBase, _ := startPushLayer(t, env, imageName)
|
2015-05-27 17:52:22 +00:00
|
|
|
pushLayer(t, env.builder, imageName, layerDigest, uploadURLBase, layerFile)
|
|
|
|
|
|
|
|
resp, err := httpDelete(layerURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error deleting layer: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-05-27 17:52:22 +00:00
|
|
|
|
|
|
|
checkResponse(t, "deleting layer with delete disabled", resp, http.StatusMethodNotAllowed)
|
|
|
|
}
|
|
|
|
|
2015-08-06 17:34:35 +00:00
|
|
|
func TestDeleteReadOnly(t *testing.T) {
|
|
|
|
env := newTestEnv(t, true)
|
2016-08-26 23:20:54 +00:00
|
|
|
defer env.Shutdown()
|
2015-08-06 17:34:35 +00:00
|
|
|
|
2017-01-14 01:06:03 +00:00
|
|
|
imageName, _ := reference.WithName("foo/bar")
|
2015-08-06 17:34:35 +00:00
|
|
|
// "build" our layer file
|
2015-12-16 01:18:13 +00:00
|
|
|
layerFile, layerDigest, err := testutil.CreateRandomTarFile()
|
2015-08-06 17:34:35 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating random layer file: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-12-16 00:43:13 +00:00
|
|
|
ref, _ := reference.WithDigest(imageName, layerDigest)
|
|
|
|
layerURL, err := env.builder.BuildBlobURL(ref)
|
2015-08-06 17:34:35 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error building blob URL")
|
|
|
|
}
|
2016-02-23 01:49:23 +00:00
|
|
|
uploadURLBase, _ := startPushLayer(t, env, imageName)
|
2015-08-06 17:34:35 +00:00
|
|
|
pushLayer(t, env.builder, imageName, layerDigest, uploadURLBase, layerFile)
|
|
|
|
|
|
|
|
env.app.readOnly = true
|
|
|
|
|
|
|
|
resp, err := httpDelete(layerURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error deleting layer: %v", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-08-06 17:34:35 +00:00
|
|
|
|
2015-08-07 01:02:43 +00:00
|
|
|
checkResponse(t, "deleting layer in read-only mode", resp, http.StatusMethodNotAllowed)
|
2015-08-06 17:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStartPushReadOnly(t *testing.T) {
|
|
|
|
env := newTestEnv(t, true)
|
2016-08-26 23:20:54 +00:00
|
|
|
defer env.Shutdown()
|
2015-08-06 17:34:35 +00:00
|
|
|
env.app.readOnly = true
|
|
|
|
|
2017-01-14 01:06:03 +00:00
|
|
|
imageName, _ := reference.WithName("foo/bar")
|
2015-08-06 17:34:35 +00:00
|
|
|
|
|
|
|
layerUploadURL, err := env.builder.BuildBlobUploadURL(imageName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building layer upload url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := http.Post(layerUploadURL, "", nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error starting layer push: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2015-08-07 01:02:43 +00:00
|
|
|
checkResponse(t, "starting push in read-only mode", resp, http.StatusMethodNotAllowed)
|
2015-08-06 17:34:35 +00:00
|
|
|
}
|
|
|
|
|
2015-05-27 17:52:22 +00:00
|
|
|
func httpDelete(url string) (*http.Response, error) {
|
2022-11-02 22:31:23 +00:00
|
|
|
req, err := http.NewRequest(http.MethodDelete, url, nil)
|
2015-05-27 17:52:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
|
2015-05-27 17:52:22 +00:00
|
|
|
return resp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
type manifestArgs struct {
|
2015-12-15 22:35:23 +00:00
|
|
|
imageName reference.Named
|
2015-12-16 22:30:49 +00:00
|
|
|
mediaType string
|
|
|
|
manifest distribution.Manifest
|
|
|
|
dgst digest.Digest
|
2015-05-27 17:52:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestManifestAPI(t *testing.T) {
|
2017-01-14 01:06:03 +00:00
|
|
|
schema2Repo, _ := reference.WithName("foo/schema2")
|
2015-12-15 22:35:23 +00:00
|
|
|
|
2015-05-27 17:52:22 +00:00
|
|
|
deleteEnabled := false
|
2016-08-26 23:20:54 +00:00
|
|
|
env1 := newTestEnv(t, deleteEnabled)
|
|
|
|
defer env1.Shutdown()
|
2023-08-17 07:35:54 +00:00
|
|
|
schema2Args := testManifestAPISchema2(t, env1, schema2Repo, "schema2tag")
|
2016-08-26 23:20:54 +00:00
|
|
|
testManifestAPIManifestList(t, env1, schema2Args)
|
2015-05-27 17:52:22 +00:00
|
|
|
|
|
|
|
deleteEnabled = true
|
2016-08-26 23:20:54 +00:00
|
|
|
env2 := newTestEnv(t, deleteEnabled)
|
|
|
|
defer env2.Shutdown()
|
2023-08-17 07:35:54 +00:00
|
|
|
schema2Args = testManifestAPISchema2(t, env2, schema2Repo, "schema2tag")
|
2016-08-26 23:20:54 +00:00
|
|
|
testManifestAPIManifestList(t, env2, schema2Args)
|
2015-05-27 17:52:22 +00:00
|
|
|
}
|
|
|
|
|
2021-05-27 22:13:59 +00:00
|
|
|
func TestManifestAPI_DeleteTag(t *testing.T) {
|
|
|
|
env := newTestEnv(t, false)
|
|
|
|
defer env.Shutdown()
|
|
|
|
|
|
|
|
imageName, err := reference.WithName("foo/bar")
|
|
|
|
checkErr(t, err, "building image name")
|
|
|
|
|
|
|
|
tag := "latest"
|
|
|
|
dgst := createRepository(env, t, imageName.Name(), tag)
|
|
|
|
|
|
|
|
ref, err := reference.WithTag(imageName, tag)
|
|
|
|
checkErr(t, err, "building tag reference")
|
|
|
|
|
|
|
|
u, err := env.builder.BuildManifestURL(ref)
|
|
|
|
checkErr(t, err, "building tag URL")
|
|
|
|
|
|
|
|
resp, err := httpDelete(u)
|
|
|
|
m := "deleting tag"
|
|
|
|
checkErr(t, err, m)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, m, resp, http.StatusAccepted)
|
|
|
|
if resp.Body != http.NoBody {
|
|
|
|
t.Fatal("unexpected response body")
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := "checking tag no longer exists"
|
|
|
|
resp, err = http.Get(u)
|
|
|
|
checkErr(t, err, msg)
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2021-05-27 22:13:59 +00:00
|
|
|
checkResponse(t, msg, resp, http.StatusNotFound)
|
|
|
|
|
|
|
|
digestRef, err := reference.WithDigest(imageName, dgst)
|
|
|
|
checkErr(t, err, "building manifest digest reference")
|
|
|
|
|
|
|
|
u, err = env.builder.BuildManifestURL(digestRef)
|
|
|
|
checkErr(t, err, "building manifest URL")
|
|
|
|
|
|
|
|
msg = "checking manifest still exists"
|
|
|
|
resp, err = http.Head(u)
|
|
|
|
checkErr(t, err, msg)
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2021-05-27 22:13:59 +00:00
|
|
|
checkResponse(t, msg, resp, http.StatusOK)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestManifestAPI_DeleteTag_Unknown(t *testing.T) {
|
|
|
|
env := newTestEnv(t, false)
|
|
|
|
defer env.Shutdown()
|
|
|
|
|
|
|
|
imageName, err := reference.WithName("foo/bar")
|
|
|
|
checkErr(t, err, "building named object")
|
|
|
|
|
|
|
|
ref, err := reference.WithTag(imageName, "latest")
|
|
|
|
checkErr(t, err, "building tag reference")
|
|
|
|
|
|
|
|
u, err := env.builder.BuildManifestURL(ref)
|
|
|
|
checkErr(t, err, "building tag URL")
|
|
|
|
|
|
|
|
resp, err := httpDelete(u)
|
|
|
|
msg := "deleting unknown tag"
|
|
|
|
checkErr(t, err, msg)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, msg, resp, http.StatusNotFound)
|
2023-11-18 06:50:40 +00:00
|
|
|
// nolint:errcheck
|
2023-09-04 15:52:12 +00:00
|
|
|
checkBodyHasErrorCodes(t, msg, resp, errcode.ErrorCodeManifestUnknown)
|
2021-05-27 22:13:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestManifestAPI_DeleteTag_ReadOnly(t *testing.T) {
|
|
|
|
env := newTestEnv(t, false)
|
|
|
|
defer env.Shutdown()
|
|
|
|
env.app.readOnly = true
|
|
|
|
|
|
|
|
imageName, err := reference.WithName("foo/bar")
|
|
|
|
checkErr(t, err, "building named object")
|
|
|
|
|
|
|
|
ref, err := reference.WithTag(imageName, "latest")
|
|
|
|
checkErr(t, err, "building tag reference")
|
|
|
|
|
|
|
|
u, err := env.builder.BuildManifestURL(ref)
|
|
|
|
checkErr(t, err, "building URL")
|
|
|
|
|
|
|
|
resp, err := httpDelete(u)
|
|
|
|
msg := "deleting tag"
|
|
|
|
checkErr(t, err, msg)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, msg, resp, http.StatusMethodNotAllowed)
|
|
|
|
}
|
|
|
|
|
2017-01-13 23:07:28 +00:00
|
|
|
// storageManifestErrDriverFactory implements the factory.StorageDriverFactory interface.
|
|
|
|
type storageManifestErrDriverFactory struct{}
|
|
|
|
|
|
|
|
const (
|
|
|
|
repositoryWithManifestNotFound = "manifesttagnotfound"
|
|
|
|
repositoryWithManifestInvalidPath = "manifestinvalidpath"
|
|
|
|
repositoryWithManifestBadLink = "manifestbadlink"
|
|
|
|
repositoryWithGenericStorageError = "genericstorageerr"
|
|
|
|
)
|
|
|
|
|
2023-10-27 21:33:55 +00:00
|
|
|
func (factory *storageManifestErrDriverFactory) Create(ctx context.Context, parameters map[string]interface{}) (storagedriver.StorageDriver, error) {
|
2017-01-13 23:07:28 +00:00
|
|
|
// Initialize the mock driver
|
2022-11-02 21:05:45 +00:00
|
|
|
errGenericStorage := errors.New("generic storage error")
|
2017-01-13 23:07:28 +00:00
|
|
|
return &mockErrorDriver{
|
|
|
|
returnErrs: []mockErrorMapping{
|
|
|
|
{
|
|
|
|
pathMatch: fmt.Sprintf("%s/_manifests/tags", repositoryWithManifestNotFound),
|
|
|
|
content: nil,
|
|
|
|
err: storagedriver.PathNotFoundError{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pathMatch: fmt.Sprintf("%s/_manifests/tags", repositoryWithManifestInvalidPath),
|
|
|
|
content: nil,
|
|
|
|
err: storagedriver.InvalidPathError{},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pathMatch: fmt.Sprintf("%s/_manifests/tags", repositoryWithManifestBadLink),
|
|
|
|
content: []byte("this is a bad sha"),
|
|
|
|
err: nil,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
pathMatch: fmt.Sprintf("%s/_manifests/tags", repositoryWithGenericStorageError),
|
|
|
|
content: nil,
|
|
|
|
err: errGenericStorage,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type mockErrorMapping struct {
|
|
|
|
pathMatch string
|
|
|
|
content []byte
|
|
|
|
err error
|
|
|
|
}
|
|
|
|
|
|
|
|
// mockErrorDriver implements StorageDriver to force storage error on manifest request
|
|
|
|
type mockErrorDriver struct {
|
|
|
|
storagedriver.StorageDriver
|
|
|
|
returnErrs []mockErrorMapping
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dr *mockErrorDriver) GetContent(ctx context.Context, path string) ([]byte, error) {
|
|
|
|
for _, returns := range dr.returnErrs {
|
|
|
|
if strings.Contains(path, returns.pathMatch) {
|
|
|
|
return returns.content, returns.err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil, errors.New("Unknown storage error")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetManifestWithStorageError(t *testing.T) {
|
|
|
|
factory.Register("storagemanifesterror", &storageManifestErrDriverFactory{})
|
|
|
|
config := configuration.Configuration{
|
|
|
|
Storage: configuration.Storage{
|
|
|
|
"storagemanifesterror": configuration.Parameters{},
|
|
|
|
"maintenance": configuration.Parameters{"uploadpurging": map[interface{}]interface{}{
|
|
|
|
"enabled": false,
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
config.HTTP.Headers = headerConfig
|
|
|
|
env1 := newTestEnvWithConfig(t, &config)
|
|
|
|
defer env1.Shutdown()
|
|
|
|
|
2017-01-19 23:21:40 +00:00
|
|
|
repo, _ := reference.WithName(repositoryWithManifestNotFound)
|
2023-09-04 15:52:12 +00:00
|
|
|
testManifestWithStorageError(t, env1, repo, http.StatusNotFound, errcode.ErrorCodeManifestUnknown)
|
2017-01-13 23:07:28 +00:00
|
|
|
|
2017-01-19 23:21:40 +00:00
|
|
|
repo, _ = reference.WithName(repositoryWithGenericStorageError)
|
2017-01-13 23:07:28 +00:00
|
|
|
testManifestWithStorageError(t, env1, repo, http.StatusInternalServerError, errcode.ErrorCodeUnknown)
|
|
|
|
|
2017-01-19 23:21:40 +00:00
|
|
|
repo, _ = reference.WithName(repositoryWithManifestInvalidPath)
|
2017-01-13 23:07:28 +00:00
|
|
|
testManifestWithStorageError(t, env1, repo, http.StatusInternalServerError, errcode.ErrorCodeUnknown)
|
|
|
|
|
2017-01-19 23:21:40 +00:00
|
|
|
repo, _ = reference.WithName(repositoryWithManifestBadLink)
|
2017-01-13 23:07:28 +00:00
|
|
|
testManifestWithStorageError(t, env1, repo, http.StatusInternalServerError, errcode.ErrorCodeUnknown)
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:52:22 +00:00
|
|
|
func TestManifestDelete(t *testing.T) {
|
2017-01-14 01:06:03 +00:00
|
|
|
schema2Repo, _ := reference.WithName("foo/schema2")
|
2015-12-15 22:35:23 +00:00
|
|
|
|
2015-05-27 17:52:22 +00:00
|
|
|
deleteEnabled := true
|
|
|
|
env := newTestEnv(t, deleteEnabled)
|
2016-08-26 23:20:54 +00:00
|
|
|
defer env.Shutdown()
|
2023-08-17 07:35:54 +00:00
|
|
|
schema2Args := testManifestAPISchema2(t, env, schema2Repo, "schema2tag")
|
2015-12-16 22:30:49 +00:00
|
|
|
testManifestDelete(t, env, schema2Args)
|
2015-05-27 17:52:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestManifestDeleteDisabled(t *testing.T) {
|
2023-08-17 07:35:54 +00:00
|
|
|
schema2Repo, _ := reference.WithName("foo/schema2")
|
2015-05-27 17:52:22 +00:00
|
|
|
deleteEnabled := false
|
|
|
|
env := newTestEnv(t, deleteEnabled)
|
2016-08-26 23:20:54 +00:00
|
|
|
defer env.Shutdown()
|
2023-08-17 07:35:54 +00:00
|
|
|
testManifestDeleteDisabled(t, env, schema2Repo)
|
2015-05-27 17:52:22 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 22:35:23 +00:00
|
|
|
func testManifestDeleteDisabled(t *testing.T, env *testEnv, imageName reference.Named) {
|
2016-12-17 00:28:34 +00:00
|
|
|
ref, _ := reference.WithDigest(imageName, digestSha256EmptyTar)
|
2015-12-16 00:43:13 +00:00
|
|
|
manifestURL, err := env.builder.BuildManifestURL(ref)
|
2015-05-27 17:52:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error getting manifest url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := httpDelete(manifestURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error deleting manifest %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "status of disabled delete of manifest", resp, http.StatusMethodNotAllowed)
|
|
|
|
}
|
|
|
|
|
2017-01-13 23:07:28 +00:00
|
|
|
func testManifestWithStorageError(t *testing.T, env *testEnv, imageName reference.Named, expectedStatusCode int, expectedErrorCode errcode.ErrorCode) {
|
|
|
|
tag := "latest"
|
|
|
|
tagRef, _ := reference.WithTag(imageName, tag)
|
|
|
|
manifestURL, err := env.builder.BuildManifestURL(tagRef)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error getting manifest url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------
|
|
|
|
// Attempt to fetch the manifest
|
|
|
|
resp, err := http.Get(manifestURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error getting manifest: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
checkResponse(t, "getting non-existent manifest", resp, expectedStatusCode)
|
2023-11-18 06:50:40 +00:00
|
|
|
// nolint:errcheck
|
2017-01-13 23:07:28 +00:00
|
|
|
checkBodyHasErrorCodes(t, "getting non-existent manifest", resp, expectedErrorCode)
|
|
|
|
}
|
|
|
|
|
2023-08-17 07:35:54 +00:00
|
|
|
func testManifestAPISchema2(t *testing.T, env *testEnv, imageName reference.Named, tag string) manifestArgs {
|
2015-12-16 22:30:49 +00:00
|
|
|
args := manifestArgs{
|
|
|
|
imageName: imageName,
|
|
|
|
mediaType: schema2.MediaTypeManifest,
|
|
|
|
}
|
|
|
|
|
2015-12-16 00:43:13 +00:00
|
|
|
tagRef, _ := reference.WithTag(imageName, tag)
|
|
|
|
manifestURL, err := env.builder.BuildManifestURL(tagRef)
|
2015-12-16 22:30:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error getting manifest url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------
|
|
|
|
// Attempt to fetch the manifest
|
|
|
|
resp, err := http.Get(manifestURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error getting manifest: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "getting non-existent manifest", resp, http.StatusNotFound)
|
2023-11-18 06:50:40 +00:00
|
|
|
// nolint:errcheck
|
2023-09-04 15:52:12 +00:00
|
|
|
checkBodyHasErrorCodes(t, "getting non-existent manifest", resp, errcode.ErrorCodeManifestUnknown)
|
2015-12-16 22:30:49 +00:00
|
|
|
|
|
|
|
tagsURL, err := env.builder.BuildTagsURL(imageName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building tags url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = http.Get(tagsURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error getting unknown tags: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
// Check that we get an unknown repository error when asking for tags
|
|
|
|
checkResponse(t, "getting unknown manifest tags", resp, http.StatusNotFound)
|
2023-11-18 06:50:40 +00:00
|
|
|
// nolint:errcheck
|
2023-09-04 15:52:12 +00:00
|
|
|
checkBodyHasErrorCodes(t, "getting unknown manifest tags", resp, errcode.ErrorCodeNameUnknown)
|
2015-12-16 22:30:49 +00:00
|
|
|
|
|
|
|
// --------------------------------
|
|
|
|
// Attempt to push manifest with missing config and missing layers
|
|
|
|
manifest := &schema2.Manifest{
|
|
|
|
Versioned: manifest.Versioned{
|
|
|
|
SchemaVersion: 2,
|
2016-01-06 22:15:14 +00:00
|
|
|
MediaType: schema2.MediaTypeManifest,
|
2015-12-16 22:30:49 +00:00
|
|
|
},
|
|
|
|
Config: distribution.Descriptor{
|
|
|
|
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",
|
|
|
|
Size: 3253,
|
2016-12-15 00:17:20 +00:00
|
|
|
MediaType: schema2.MediaTypeImageConfig,
|
2015-12-16 22:30:49 +00:00
|
|
|
},
|
|
|
|
Layers: []distribution.Descriptor{
|
|
|
|
{
|
|
|
|
Digest: "sha256:463434349086340864309863409683460843608348608934092322395278926a",
|
|
|
|
Size: 6323,
|
|
|
|
MediaType: schema2.MediaTypeLayer,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Digest: "sha256:630923423623623423352523525237238023652897356239852383652aaaaaaa",
|
|
|
|
Size: 6863,
|
|
|
|
MediaType: schema2.MediaTypeLayer,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
resp = putManifest(t, "putting missing config manifest", manifestURL, schema2.MediaTypeManifest, manifest)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
checkResponse(t, "putting missing config manifest", resp, http.StatusBadRequest)
|
2023-09-04 15:52:12 +00:00
|
|
|
_, p, counts := checkBodyHasErrorCodes(t, "putting missing config manifest", resp, errcode.ErrorCodeManifestBlobUnknown)
|
2015-12-16 22:30:49 +00:00
|
|
|
|
|
|
|
expectedCounts := map[errcode.ErrorCode]int{
|
2023-09-04 15:52:12 +00:00
|
|
|
errcode.ErrorCodeManifestBlobUnknown: 3,
|
2015-12-16 22:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(counts, expectedCounts) {
|
|
|
|
t.Fatalf("unexpected number of error codes encountered: %v\n!=\n%v\n---\n%s", counts, expectedCounts, string(p))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push a config, and reference it in the manifest
|
|
|
|
sampleConfig := []byte(`{
|
|
|
|
"architecture": "amd64",
|
|
|
|
"history": [
|
|
|
|
{
|
|
|
|
"created": "2015-10-31T22:22:54.690851953Z",
|
|
|
|
"created_by": "/bin/sh -c #(nop) ADD file:a3bc1e842b69636f9df5256c49c5374fb4eef1e281fe3f282c65fb853ee171c5 in /"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"created": "2015-10-31T22:22:55.613815829Z",
|
|
|
|
"created_by": "/bin/sh -c #(nop) CMD [\"sh\"]"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"rootfs": {
|
|
|
|
"diff_ids": [
|
|
|
|
"sha256:c6f988f4874bb0add23a778f753c65efe992244e148a1d2ec2a8b664fb66bbd1",
|
|
|
|
"sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef"
|
|
|
|
],
|
|
|
|
"type": "layers"
|
|
|
|
}
|
|
|
|
}`)
|
|
|
|
sampleConfigDigest := digest.FromBytes(sampleConfig)
|
|
|
|
|
2016-02-23 01:49:23 +00:00
|
|
|
uploadURLBase, _ := startPushLayer(t, env, imageName)
|
2015-12-16 22:30:49 +00:00
|
|
|
pushLayer(t, env.builder, imageName, sampleConfigDigest, uploadURLBase, bytes.NewReader(sampleConfig))
|
|
|
|
manifest.Config.Digest = sampleConfigDigest
|
|
|
|
manifest.Config.Size = int64(len(sampleConfig))
|
|
|
|
|
2016-02-11 00:26:29 +00:00
|
|
|
// The manifest should still be invalid, because its layer doesn't exist
|
2015-12-16 22:30:49 +00:00
|
|
|
resp = putManifest(t, "putting missing layer manifest", manifestURL, schema2.MediaTypeManifest, manifest)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
checkResponse(t, "putting missing layer manifest", resp, http.StatusBadRequest)
|
2023-09-04 15:52:12 +00:00
|
|
|
_, p, counts = checkBodyHasErrorCodes(t, "getting unknown manifest tags", resp, errcode.ErrorCodeManifestBlobUnknown)
|
2015-12-16 22:30:49 +00:00
|
|
|
|
|
|
|
expectedCounts = map[errcode.ErrorCode]int{
|
2023-09-04 15:52:12 +00:00
|
|
|
errcode.ErrorCodeManifestBlobUnknown: 2,
|
2015-12-16 22:30:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(counts, expectedCounts) {
|
|
|
|
t.Fatalf("unexpected number of error codes encountered: %v\n!=\n%v\n---\n%s", counts, expectedCounts, string(p))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push 2 random layers
|
|
|
|
expectedLayers := make(map[digest.Digest]io.ReadSeeker)
|
|
|
|
|
|
|
|
for i := range manifest.Layers {
|
2019-02-05 00:01:04 +00:00
|
|
|
rs, dgst, err := testutil.CreateRandomTarFile()
|
2015-12-16 22:30:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating random layer %d: %v", i, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedLayers[dgst] = rs
|
|
|
|
manifest.Layers[i].Digest = dgst
|
|
|
|
|
2016-02-23 01:49:23 +00:00
|
|
|
uploadURLBase, _ := startPushLayer(t, env, imageName)
|
2015-12-16 22:30:49 +00:00
|
|
|
pushLayer(t, env.builder, imageName, dgst, uploadURLBase, rs)
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------
|
|
|
|
// Push the manifest with all layers pushed.
|
|
|
|
deserializedManifest, err := schema2.FromStruct(*manifest)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not create DeserializedManifest: %v", err)
|
|
|
|
}
|
|
|
|
_, canonical, err := deserializedManifest.Payload()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not get manifest payload: %v", err)
|
|
|
|
}
|
|
|
|
dgst := digest.FromBytes(canonical)
|
|
|
|
args.dgst = dgst
|
|
|
|
args.manifest = deserializedManifest
|
|
|
|
|
2015-12-16 00:43:13 +00:00
|
|
|
digestRef, _ := reference.WithDigest(imageName, dgst)
|
|
|
|
manifestDigestURL, err := env.builder.BuildManifestURL(digestRef)
|
2015-12-16 22:30:49 +00:00
|
|
|
checkErr(t, err, "building manifest url")
|
|
|
|
|
|
|
|
resp = putManifest(t, "putting manifest no error", manifestURL, schema2.MediaTypeManifest, manifest)
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-12-16 22:30:49 +00:00
|
|
|
checkResponse(t, "putting manifest no error", resp, http.StatusCreated)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Location": []string{manifestDigestURL},
|
|
|
|
"Docker-Content-Digest": []string{dgst.String()},
|
|
|
|
})
|
|
|
|
|
|
|
|
// --------------------
|
|
|
|
// Push by digest -- should get same result
|
|
|
|
resp = putManifest(t, "putting manifest by digest", manifestDigestURL, schema2.MediaTypeManifest, manifest)
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-12-16 22:30:49 +00:00
|
|
|
checkResponse(t, "putting manifest by digest", resp, http.StatusCreated)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Location": []string{manifestDigestURL},
|
|
|
|
"Docker-Content-Digest": []string{dgst.String()},
|
|
|
|
})
|
|
|
|
|
|
|
|
// ------------------
|
|
|
|
// Fetch by tag name
|
2022-11-02 22:31:23 +00:00
|
|
|
req, err := http.NewRequest(http.MethodGet, manifestURL, nil)
|
2015-12-16 22:30:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
|
|
|
req.Header.Set("Accept", schema2.MediaTypeManifest)
|
|
|
|
resp, err = http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error fetching manifest: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "fetching uploaded manifest", resp, http.StatusOK)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Docker-Content-Digest": []string{dgst.String()},
|
|
|
|
"ETag": []string{fmt.Sprintf(`"%s"`, dgst)},
|
|
|
|
})
|
|
|
|
|
|
|
|
var fetchedManifest schema2.DeserializedManifest
|
|
|
|
dec := json.NewDecoder(resp.Body)
|
|
|
|
|
|
|
|
if err := dec.Decode(&fetchedManifest); err != nil {
|
|
|
|
t.Fatalf("error decoding fetched manifest: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, fetchedCanonical, err := fetchedManifest.Payload()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error getting manifest payload: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Equal(fetchedCanonical, canonical) {
|
|
|
|
t.Fatalf("manifests do not match")
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------
|
|
|
|
// Fetch by digest
|
2022-11-02 22:31:23 +00:00
|
|
|
req, err = http.NewRequest(http.MethodGet, manifestDigestURL, nil)
|
2015-12-16 22:30:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
|
|
|
req.Header.Set("Accept", schema2.MediaTypeManifest)
|
|
|
|
resp, err = http.DefaultClient.Do(req)
|
|
|
|
checkErr(t, err, "fetching manifest by digest")
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "fetching uploaded manifest", resp, http.StatusOK)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Docker-Content-Digest": []string{dgst.String()},
|
|
|
|
"ETag": []string{fmt.Sprintf(`"%s"`, dgst)},
|
|
|
|
})
|
|
|
|
|
|
|
|
var fetchedManifestByDigest schema2.DeserializedManifest
|
|
|
|
dec = json.NewDecoder(resp.Body)
|
|
|
|
if err := dec.Decode(&fetchedManifestByDigest); err != nil {
|
|
|
|
t.Fatalf("error decoding fetched manifest: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, fetchedCanonical, err = fetchedManifest.Payload()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error getting manifest payload: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Equal(fetchedCanonical, canonical) {
|
|
|
|
t.Fatalf("manifests do not match")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get by name with etag, gives 304
|
|
|
|
etag := resp.Header.Get("Etag")
|
2022-11-02 22:31:23 +00:00
|
|
|
req, err = http.NewRequest(http.MethodGet, manifestURL, nil)
|
2015-12-16 22:30:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
|
|
|
req.Header.Set("If-None-Match", etag)
|
|
|
|
resp, err = http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-12-16 22:30:49 +00:00
|
|
|
|
|
|
|
checkResponse(t, "fetching manifest by name with etag", resp, http.StatusNotModified)
|
|
|
|
|
|
|
|
// Get by digest with etag, gives 304
|
2022-11-02 22:31:23 +00:00
|
|
|
req, err = http.NewRequest(http.MethodGet, manifestDigestURL, nil)
|
2015-12-16 22:30:49 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
|
|
|
req.Header.Set("If-None-Match", etag)
|
|
|
|
resp, err = http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-12-16 22:30:49 +00:00
|
|
|
|
|
|
|
checkResponse(t, "fetching manifest by dgst with etag", resp, http.StatusNotModified)
|
|
|
|
|
|
|
|
// Ensure that the tag is listed.
|
|
|
|
resp, err = http.Get(tagsURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error getting unknown tags: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "getting unknown manifest tags", resp, http.StatusOK)
|
|
|
|
dec = json.NewDecoder(resp.Body)
|
|
|
|
|
|
|
|
var tagsResponse tagsAPIResponse
|
|
|
|
|
|
|
|
if err := dec.Decode(&tagsResponse); err != nil {
|
|
|
|
t.Fatalf("unexpected error decoding error response: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-12-15 22:35:23 +00:00
|
|
|
if tagsResponse.Name != imageName.Name() {
|
2015-12-16 22:30:49 +00:00
|
|
|
t.Fatalf("tags name should match image name: %v != %v", tagsResponse.Name, imageName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(tagsResponse.Tags) != 1 {
|
|
|
|
t.Fatalf("expected some tags in response: %v", tagsResponse.Tags)
|
|
|
|
}
|
|
|
|
|
|
|
|
if tagsResponse.Tags[0] != tag {
|
|
|
|
t.Fatalf("tag not as expected: %q != %q", tagsResponse.Tags[0], tag)
|
|
|
|
}
|
|
|
|
|
|
|
|
return args
|
2015-05-27 17:52:22 +00:00
|
|
|
}
|
|
|
|
|
2015-12-17 01:26:13 +00:00
|
|
|
func testManifestAPIManifestList(t *testing.T, env *testEnv, args manifestArgs) {
|
|
|
|
imageName := args.imageName
|
|
|
|
tag := "manifestlisttag"
|
|
|
|
|
2015-12-16 00:43:13 +00:00
|
|
|
tagRef, _ := reference.WithTag(imageName, tag)
|
|
|
|
manifestURL, err := env.builder.BuildManifestURL(tagRef)
|
2015-12-17 01:26:13 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error getting manifest url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------
|
|
|
|
// Attempt to push manifest list that refers to an unknown manifest
|
|
|
|
manifestList := &manifestlist.ManifestList{
|
|
|
|
Versioned: manifest.Versioned{
|
|
|
|
SchemaVersion: 2,
|
2016-01-06 22:15:14 +00:00
|
|
|
MediaType: manifestlist.MediaTypeManifestList,
|
2015-12-17 01:26:13 +00:00
|
|
|
},
|
|
|
|
Manifests: []manifestlist.ManifestDescriptor{
|
|
|
|
{
|
|
|
|
Descriptor: distribution.Descriptor{
|
|
|
|
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",
|
|
|
|
Size: 3253,
|
|
|
|
MediaType: schema2.MediaTypeManifest,
|
|
|
|
},
|
|
|
|
Platform: manifestlist.PlatformSpec{
|
|
|
|
Architecture: "amd64",
|
|
|
|
OS: "linux",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := putManifest(t, "putting missing manifest manifestlist", manifestURL, manifestlist.MediaTypeManifestList, manifestList)
|
|
|
|
defer resp.Body.Close()
|
|
|
|
checkResponse(t, "putting missing manifest manifestlist", resp, http.StatusBadRequest)
|
2023-09-04 15:52:12 +00:00
|
|
|
_, p, counts := checkBodyHasErrorCodes(t, "putting missing manifest manifestlist", resp, errcode.ErrorCodeManifestBlobUnknown)
|
2015-12-17 01:26:13 +00:00
|
|
|
|
|
|
|
expectedCounts := map[errcode.ErrorCode]int{
|
2023-09-04 15:52:12 +00:00
|
|
|
errcode.ErrorCodeManifestBlobUnknown: 1,
|
2015-12-17 01:26:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(counts, expectedCounts) {
|
|
|
|
t.Fatalf("unexpected number of error codes encountered: %v\n!=\n%v\n---\n%s", counts, expectedCounts, string(p))
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------
|
|
|
|
// Push a manifest list that references an actual manifest
|
|
|
|
manifestList.Manifests[0].Digest = args.dgst
|
|
|
|
deserializedManifestList, err := manifestlist.FromDescriptors(manifestList.Manifests)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not create DeserializedManifestList: %v", err)
|
|
|
|
}
|
|
|
|
_, canonical, err := deserializedManifestList.Payload()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not get manifest list payload: %v", err)
|
|
|
|
}
|
|
|
|
dgst := digest.FromBytes(canonical)
|
|
|
|
|
2015-12-16 00:43:13 +00:00
|
|
|
digestRef, _ := reference.WithDigest(imageName, dgst)
|
|
|
|
manifestDigestURL, err := env.builder.BuildManifestURL(digestRef)
|
2015-12-17 01:26:13 +00:00
|
|
|
checkErr(t, err, "building manifest url")
|
|
|
|
|
|
|
|
resp = putManifest(t, "putting manifest list no error", manifestURL, manifestlist.MediaTypeManifestList, deserializedManifestList)
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-12-17 01:26:13 +00:00
|
|
|
checkResponse(t, "putting manifest list no error", resp, http.StatusCreated)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Location": []string{manifestDigestURL},
|
|
|
|
"Docker-Content-Digest": []string{dgst.String()},
|
|
|
|
})
|
|
|
|
|
|
|
|
// --------------------
|
|
|
|
// Push by digest -- should get same result
|
|
|
|
resp = putManifest(t, "putting manifest list by digest", manifestDigestURL, manifestlist.MediaTypeManifestList, deserializedManifestList)
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-12-17 01:26:13 +00:00
|
|
|
checkResponse(t, "putting manifest list by digest", resp, http.StatusCreated)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Location": []string{manifestDigestURL},
|
|
|
|
"Docker-Content-Digest": []string{dgst.String()},
|
|
|
|
})
|
|
|
|
|
|
|
|
// ------------------
|
|
|
|
// Fetch by tag name
|
2022-11-02 22:31:23 +00:00
|
|
|
req, err := http.NewRequest(http.MethodGet, manifestURL, nil)
|
2015-12-17 01:26:13 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
2016-06-10 23:34:08 +00:00
|
|
|
// multiple headers in mixed list format to ensure we parse correctly server-side
|
2023-08-17 07:35:54 +00:00
|
|
|
req.Header.Set("Accept", fmt.Sprintf(` %s ; q=0.8 `, manifestlist.MediaTypeManifestList))
|
2015-12-17 01:26:13 +00:00
|
|
|
req.Header.Add("Accept", schema2.MediaTypeManifest)
|
|
|
|
resp, err = http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error fetching manifest list: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "fetching uploaded manifest list", resp, http.StatusOK)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Docker-Content-Digest": []string{dgst.String()},
|
|
|
|
"ETag": []string{fmt.Sprintf(`"%s"`, dgst)},
|
|
|
|
})
|
|
|
|
|
|
|
|
var fetchedManifestList manifestlist.DeserializedManifestList
|
|
|
|
dec := json.NewDecoder(resp.Body)
|
|
|
|
|
|
|
|
if err := dec.Decode(&fetchedManifestList); err != nil {
|
|
|
|
t.Fatalf("error decoding fetched manifest list: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, fetchedCanonical, err := fetchedManifestList.Payload()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error getting manifest list payload: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Equal(fetchedCanonical, canonical) {
|
|
|
|
t.Fatalf("manifest lists do not match")
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------
|
|
|
|
// Fetch by digest
|
2022-11-02 22:31:23 +00:00
|
|
|
req, err = http.NewRequest(http.MethodGet, manifestDigestURL, nil)
|
2015-12-17 01:26:13 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
|
|
|
req.Header.Set("Accept", manifestlist.MediaTypeManifestList)
|
|
|
|
resp, err = http.DefaultClient.Do(req)
|
|
|
|
checkErr(t, err, "fetching manifest list by digest")
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "fetching uploaded manifest list", resp, http.StatusOK)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Docker-Content-Digest": []string{dgst.String()},
|
|
|
|
"ETag": []string{fmt.Sprintf(`"%s"`, dgst)},
|
|
|
|
})
|
|
|
|
|
|
|
|
var fetchedManifestListByDigest manifestlist.DeserializedManifestList
|
|
|
|
dec = json.NewDecoder(resp.Body)
|
|
|
|
if err := dec.Decode(&fetchedManifestListByDigest); err != nil {
|
|
|
|
t.Fatalf("error decoding fetched manifest: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, fetchedCanonical, err = fetchedManifestListByDigest.Payload()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error getting manifest list payload: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Equal(fetchedCanonical, canonical) {
|
|
|
|
t.Fatalf("manifests do not match")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get by name with etag, gives 304
|
|
|
|
etag := resp.Header.Get("Etag")
|
2022-11-02 22:31:23 +00:00
|
|
|
req, err = http.NewRequest(http.MethodGet, manifestURL, nil)
|
2015-12-17 01:26:13 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
|
|
|
req.Header.Set("If-None-Match", etag)
|
|
|
|
resp, err = http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-12-17 01:26:13 +00:00
|
|
|
|
|
|
|
checkResponse(t, "fetching manifest by name with etag", resp, http.StatusNotModified)
|
|
|
|
|
|
|
|
// Get by digest with etag, gives 304
|
2022-11-02 22:31:23 +00:00
|
|
|
req, err = http.NewRequest(http.MethodGet, manifestDigestURL, nil)
|
2015-12-17 01:26:13 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
|
|
|
req.Header.Set("If-None-Match", etag)
|
|
|
|
resp, err = http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Error constructing request: %s", err)
|
|
|
|
}
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-12-17 01:26:13 +00:00
|
|
|
|
|
|
|
checkResponse(t, "fetching manifest by dgst with etag", resp, http.StatusNotModified)
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:52:22 +00:00
|
|
|
func testManifestDelete(t *testing.T, env *testEnv, args manifestArgs) {
|
|
|
|
imageName := args.imageName
|
|
|
|
dgst := args.dgst
|
2015-12-16 22:30:49 +00:00
|
|
|
manifest := args.manifest
|
2016-01-05 19:22:40 +00:00
|
|
|
|
2015-12-16 00:43:13 +00:00
|
|
|
ref, _ := reference.WithDigest(imageName, dgst)
|
2016-11-17 18:28:05 +00:00
|
|
|
manifestDigestURL, _ := env.builder.BuildManifestURL(ref)
|
2015-05-27 17:52:22 +00:00
|
|
|
// ---------------
|
|
|
|
// Delete by digest
|
|
|
|
resp, err := httpDelete(manifestDigestURL)
|
|
|
|
checkErr(t, err, "deleting manifest by digest")
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-05-27 17:52:22 +00:00
|
|
|
|
|
|
|
checkResponse(t, "deleting manifest", resp, http.StatusAccepted)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Content-Length": []string{"0"},
|
|
|
|
})
|
|
|
|
|
|
|
|
// ---------------
|
|
|
|
// Attempt to fetch deleted manifest
|
|
|
|
resp, err = http.Get(manifestDigestURL)
|
|
|
|
checkErr(t, err, "fetching deleted manifest by digest")
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "fetching deleted manifest", resp, http.StatusNotFound)
|
|
|
|
|
|
|
|
// ---------------
|
|
|
|
// Delete already deleted manifest by digest
|
|
|
|
resp, err = httpDelete(manifestDigestURL)
|
|
|
|
checkErr(t, err, "re-deleting manifest by digest")
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-05-27 17:52:22 +00:00
|
|
|
|
|
|
|
checkResponse(t, "re-deleting manifest", resp, http.StatusNotFound)
|
|
|
|
|
|
|
|
// --------------------
|
|
|
|
// Re-upload manifest by digest
|
2015-12-16 22:30:49 +00:00
|
|
|
resp = putManifest(t, "putting manifest", manifestDigestURL, args.mediaType, manifest)
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-12-16 22:30:49 +00:00
|
|
|
checkResponse(t, "putting manifest", resp, http.StatusCreated)
|
2015-05-27 17:52:22 +00:00
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Location": []string{manifestDigestURL},
|
|
|
|
"Docker-Content-Digest": []string{dgst.String()},
|
|
|
|
})
|
|
|
|
|
|
|
|
// ---------------
|
|
|
|
// Attempt to fetch re-uploaded deleted digest
|
|
|
|
resp, err = http.Get(manifestDigestURL)
|
|
|
|
checkErr(t, err, "fetching re-uploaded manifest by digest")
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "fetching re-uploaded manifest", resp, http.StatusOK)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Docker-Content-Digest": []string{dgst.String()},
|
|
|
|
})
|
|
|
|
|
|
|
|
// ---------------
|
|
|
|
// Attempt to delete an unknown manifest
|
2015-12-16 00:43:13 +00:00
|
|
|
unknownDigest := digest.Digest("sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
|
|
|
|
unknownRef, _ := reference.WithDigest(imageName, unknownDigest)
|
|
|
|
unknownManifestDigestURL, err := env.builder.BuildManifestURL(unknownRef)
|
2015-05-27 17:52:22 +00:00
|
|
|
checkErr(t, err, "building unknown manifest url")
|
|
|
|
|
|
|
|
resp, err = httpDelete(unknownManifestDigestURL)
|
|
|
|
checkErr(t, err, "delting unknown manifest by digest")
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-05-27 17:52:22 +00:00
|
|
|
checkResponse(t, "fetching deleted manifest", resp, http.StatusNotFound)
|
|
|
|
|
2016-01-05 19:22:40 +00:00
|
|
|
// --------------------
|
2015-12-16 00:43:13 +00:00
|
|
|
// Upload manifest by tag
|
2016-01-11 20:52:21 +00:00
|
|
|
tag := "atag"
|
2015-12-16 00:43:13 +00:00
|
|
|
tagRef, _ := reference.WithTag(imageName, tag)
|
2016-11-17 18:28:05 +00:00
|
|
|
manifestTagURL, _ := env.builder.BuildManifestURL(tagRef)
|
2015-12-16 00:43:13 +00:00
|
|
|
resp = putManifest(t, "putting manifest by tag", manifestTagURL, args.mediaType, manifest)
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2015-12-16 00:43:13 +00:00
|
|
|
checkResponse(t, "putting manifest by tag", resp, http.StatusCreated)
|
2016-01-05 19:22:40 +00:00
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Location": []string{manifestDigestURL},
|
|
|
|
"Docker-Content-Digest": []string{dgst.String()},
|
|
|
|
})
|
|
|
|
|
|
|
|
tagsURL, err := env.builder.BuildTagsURL(imageName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building tags url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that the tag is listed.
|
|
|
|
resp, err = http.Get(tagsURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error getting unknown tags: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
dec := json.NewDecoder(resp.Body)
|
|
|
|
var tagsResponse tagsAPIResponse
|
|
|
|
if err := dec.Decode(&tagsResponse); err != nil {
|
|
|
|
t.Fatalf("unexpected error decoding error response: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-12-15 22:35:23 +00:00
|
|
|
if tagsResponse.Name != imageName.Name() {
|
2016-01-05 19:22:40 +00:00
|
|
|
t.Fatalf("tags name should match image name: %v != %v", tagsResponse.Name, imageName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(tagsResponse.Tags) != 1 {
|
|
|
|
t.Fatalf("expected some tags in response: %v", tagsResponse.Tags)
|
|
|
|
}
|
|
|
|
|
|
|
|
if tagsResponse.Tags[0] != tag {
|
|
|
|
t.Fatalf("tag not as expected: %q != %q", tagsResponse.Tags[0], tag)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------
|
|
|
|
// Delete by digest
|
|
|
|
resp, err = httpDelete(manifestDigestURL)
|
|
|
|
checkErr(t, err, "deleting manifest by digest")
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2016-01-05 19:22:40 +00:00
|
|
|
|
|
|
|
checkResponse(t, "deleting manifest with tag", resp, http.StatusAccepted)
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Content-Length": []string{"0"},
|
|
|
|
})
|
|
|
|
|
|
|
|
// Ensure that the tag is not listed.
|
|
|
|
resp, err = http.Get(tagsURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error getting unknown tags: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
dec = json.NewDecoder(resp.Body)
|
|
|
|
if err := dec.Decode(&tagsResponse); err != nil {
|
|
|
|
t.Fatalf("unexpected error decoding error response: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-12-15 22:35:23 +00:00
|
|
|
if tagsResponse.Name != imageName.Name() {
|
2016-01-05 19:22:40 +00:00
|
|
|
t.Fatalf("tags name should match image name: %v != %v", tagsResponse.Name, imageName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(tagsResponse.Tags) != 0 {
|
|
|
|
t.Fatalf("expected 0 tags in response: %v", tagsResponse.Tags)
|
|
|
|
}
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
}
|
|
|
|
|
2015-02-07 00:19:19 +00:00
|
|
|
type testEnv struct {
|
|
|
|
ctx context.Context
|
|
|
|
config configuration.Configuration
|
|
|
|
app *App
|
|
|
|
server *httptest.Server
|
|
|
|
builder *v2.URLBuilder
|
|
|
|
}
|
|
|
|
|
2015-08-11 18:00:30 +00:00
|
|
|
func newTestEnvMirror(t *testing.T, deleteEnabled bool) *testEnv {
|
2019-12-15 12:51:25 +00:00
|
|
|
upstreamEnv := newTestEnv(t, deleteEnabled)
|
2015-08-11 18:00:30 +00:00
|
|
|
config := configuration.Configuration{
|
|
|
|
Storage: configuration.Storage{
|
2018-11-15 10:36:19 +00:00
|
|
|
"inmemory": configuration.Parameters{},
|
|
|
|
"delete": configuration.Parameters{"enabled": deleteEnabled},
|
2016-08-26 23:10:11 +00:00
|
|
|
"maintenance": configuration.Parameters{"uploadpurging": map[interface{}]interface{}{
|
|
|
|
"enabled": false,
|
|
|
|
}},
|
2015-08-11 18:00:30 +00:00
|
|
|
},
|
|
|
|
Proxy: configuration.Proxy{
|
2019-12-15 12:51:25 +00:00
|
|
|
RemoteURL: upstreamEnv.server.URL,
|
2015-08-11 18:00:30 +00:00
|
|
|
},
|
2023-03-31 11:16:29 +00:00
|
|
|
Catalog: configuration.Catalog{
|
|
|
|
MaxEntries: 5,
|
|
|
|
},
|
2015-08-11 18:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return newTestEnvWithConfig(t, &config)
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:52:22 +00:00
|
|
|
func newTestEnv(t *testing.T, deleteEnabled bool) *testEnv {
|
2015-02-07 00:19:19 +00:00
|
|
|
config := configuration.Configuration{
|
|
|
|
Storage: configuration.Storage{
|
2018-11-15 10:36:19 +00:00
|
|
|
"inmemory": configuration.Parameters{},
|
|
|
|
"delete": configuration.Parameters{"enabled": deleteEnabled},
|
2016-08-26 23:10:11 +00:00
|
|
|
"maintenance": configuration.Parameters{"uploadpurging": map[interface{}]interface{}{
|
|
|
|
"enabled": false,
|
|
|
|
}},
|
2015-02-07 00:19:19 +00:00
|
|
|
},
|
2023-03-31 11:16:29 +00:00
|
|
|
Catalog: configuration.Catalog{
|
|
|
|
MaxEntries: 5,
|
|
|
|
},
|
2015-02-07 00:19:19 +00:00
|
|
|
}
|
|
|
|
|
2015-08-10 21:20:52 +00:00
|
|
|
config.HTTP.Headers = headerConfig
|
|
|
|
|
2015-02-24 22:59:01 +00:00
|
|
|
return newTestEnvWithConfig(t, &config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newTestEnvWithConfig(t *testing.T, config *configuration.Configuration) *testEnv {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2015-08-20 20:56:36 +00:00
|
|
|
app := NewApp(ctx, config)
|
2015-02-07 00:19:19 +00:00
|
|
|
server := httptest.NewServer(handlers.CombinedLoggingHandler(os.Stderr, app))
|
2016-02-23 01:49:23 +00:00
|
|
|
builder, err := v2.NewURLBuilderFromString(server.URL+config.HTTP.Prefix, false)
|
2015-02-07 00:19:19 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating url builder: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &testEnv{
|
|
|
|
ctx: ctx,
|
2015-02-24 22:59:01 +00:00
|
|
|
config: *config,
|
2015-02-07 00:19:19 +00:00
|
|
|
app: app,
|
|
|
|
server: server,
|
|
|
|
builder: builder,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-26 23:20:54 +00:00
|
|
|
func (t *testEnv) Shutdown() {
|
|
|
|
t.server.CloseClientConnections()
|
|
|
|
t.server.Close()
|
|
|
|
}
|
|
|
|
|
2015-12-16 22:30:49 +00:00
|
|
|
func putManifest(t *testing.T, msg, url, contentType string, v interface{}) *http.Response {
|
2014-12-02 01:10:33 +00:00
|
|
|
var body []byte
|
2015-08-21 04:50:15 +00:00
|
|
|
|
2015-12-17 01:26:13 +00:00
|
|
|
switch m := v.(type) {
|
|
|
|
case *manifestlist.DeserializedManifestList:
|
|
|
|
_, pl, err := m.Payload()
|
2015-08-21 04:50:15 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error getting payload: %v", err)
|
|
|
|
}
|
|
|
|
body = pl
|
2015-12-17 01:26:13 +00:00
|
|
|
default:
|
2014-12-02 01:10:33 +00:00
|
|
|
var err error
|
|
|
|
body, err = json.MarshalIndent(v, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error marshaling %v: %v", v, err)
|
|
|
|
}
|
2014-11-21 03:57:01 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 22:31:23 +00:00
|
|
|
req, err := http.NewRequest(http.MethodPut, url, bytes.NewReader(body))
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating request for %s: %v", msg, err)
|
|
|
|
}
|
2014-11-21 03:57:01 +00:00
|
|
|
|
2015-12-16 22:30:49 +00:00
|
|
|
if contentType != "" {
|
|
|
|
req.Header.Set("Content-Type", contentType)
|
|
|
|
}
|
|
|
|
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error doing put request while %s: %v", msg, err)
|
2014-11-21 03:57:01 +00:00
|
|
|
}
|
|
|
|
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
return resp
|
|
|
|
}
|
|
|
|
|
2016-02-23 01:49:23 +00:00
|
|
|
func startPushLayer(t *testing.T, env *testEnv, name reference.Named) (location string, uuid string) {
|
|
|
|
layerUploadURL, err := env.builder.BuildBlobUploadURL(name)
|
2014-11-21 03:57:01 +00:00
|
|
|
if err != nil {
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
t.Fatalf("unexpected error building layer upload url: %v", err)
|
2014-11-21 03:57:01 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 01:49:23 +00:00
|
|
|
u, err := url.Parse(layerUploadURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error parsing layer upload URL: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
base, err := url.Parse(env.server.URL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error parsing server URL: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
layerUploadURL = base.ResolveReference(u).String()
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
resp, err := http.Post(layerUploadURL, "", nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error starting layer push: %v", err)
|
|
|
|
}
|
2016-02-23 01:49:23 +00:00
|
|
|
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
defer resp.Body.Close()
|
2014-11-21 03:57:01 +00:00
|
|
|
|
2015-12-15 22:35:23 +00:00
|
|
|
checkResponse(t, fmt.Sprintf("pushing starting layer push %v", name.String()), resp, http.StatusAccepted)
|
2015-02-27 00:43:47 +00:00
|
|
|
|
2016-02-23 01:49:23 +00:00
|
|
|
u, err = url.Parse(resp.Header.Get("Location"))
|
2015-02-27 00:43:47 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error parsing location header: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
uuid = path.Base(u.Path)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
checkHeaders(t, resp, http.Header{
|
2015-02-27 00:43:47 +00:00
|
|
|
"Location": []string{"*"},
|
|
|
|
"Content-Length": []string{"0"},
|
|
|
|
"Docker-Upload-UUID": []string{uuid},
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
})
|
|
|
|
|
2015-02-27 00:43:47 +00:00
|
|
|
return resp.Header.Get("Location"), uuid
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
}
|
|
|
|
|
2015-01-30 05:26:35 +00:00
|
|
|
// doPushLayer pushes the layer content returning the url on success returning
|
|
|
|
// the response. If you're only expecting a successful response, use pushLayer.
|
2015-12-15 22:35:23 +00:00
|
|
|
func doPushLayer(t *testing.T, ub *v2.URLBuilder, name reference.Named, dgst digest.Digest, uploadURLBase string, body io.Reader) (*http.Response, error) {
|
2014-12-12 05:59:59 +00:00
|
|
|
u, err := url.Parse(uploadURLBase)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error parsing pushLayer url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
u.RawQuery = url.Values{
|
2015-01-05 07:59:29 +00:00
|
|
|
"_state": u.Query()["_state"],
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
"digest": []string{dgst.String()},
|
2014-12-12 05:59:59 +00:00
|
|
|
}.Encode()
|
|
|
|
|
|
|
|
uploadURL := u.String()
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
|
|
|
|
// Just do a monolithic upload
|
2022-11-02 22:31:23 +00:00
|
|
|
req, err := http.NewRequest(http.MethodPut, uploadURL, body)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error creating new request: %v", err)
|
2014-11-21 03:57:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-30 05:26:35 +00:00
|
|
|
return http.DefaultClient.Do(req)
|
|
|
|
}
|
|
|
|
|
|
|
|
// pushLayer pushes the layer content returning the url on success.
|
2015-12-15 22:35:23 +00:00
|
|
|
func pushLayer(t *testing.T, ub *v2.URLBuilder, name reference.Named, dgst digest.Digest, uploadURLBase string, body io.Reader) string {
|
2016-12-17 00:28:34 +00:00
|
|
|
digester := digest.Canonical.Digester()
|
2015-03-05 04:26:56 +00:00
|
|
|
|
2015-05-21 06:44:08 +00:00
|
|
|
resp, err := doPushLayer(t, ub, name, dgst, uploadURLBase, io.TeeReader(body, digester.Hash()))
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
if err != nil {
|
2015-01-30 05:26:35 +00:00
|
|
|
t.Fatalf("unexpected error doing push layer request: %v", err)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
2014-11-21 03:57:01 +00:00
|
|
|
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
checkResponse(t, "putting monolithic chunk", resp, http.StatusCreated)
|
|
|
|
|
2015-03-05 04:26:56 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error generating sha256 digest of body")
|
|
|
|
}
|
|
|
|
|
|
|
|
sha256Dgst := digester.Digest()
|
|
|
|
|
2015-12-16 00:43:13 +00:00
|
|
|
ref, _ := reference.WithDigest(name, sha256Dgst)
|
|
|
|
expectedLayerURL, err := ub.BuildBlobURL(ref)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error building expected layer url: %v", err)
|
|
|
|
}
|
2014-11-21 03:57:01 +00:00
|
|
|
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
checkHeaders(t, resp, http.Header{
|
2015-02-26 23:47:04 +00:00
|
|
|
"Location": []string{expectedLayerURL},
|
|
|
|
"Content-Length": []string{"0"},
|
2015-03-05 04:26:56 +00:00
|
|
|
"Docker-Content-Digest": []string{sha256Dgst.String()},
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return resp.Header.Get("Location")
|
|
|
|
}
|
|
|
|
|
2022-10-23 14:33:01 +00:00
|
|
|
func getUploadStatus(location string) (string, int64, error) {
|
|
|
|
req, err := http.NewRequest(http.MethodGet, location, nil)
|
|
|
|
if err != nil {
|
|
|
|
return location, -1, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
return location, -1, err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
_, end, err := parseContentRange(resp.Header.Get("Range"))
|
|
|
|
if err != nil {
|
|
|
|
return location, -1, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.Header.Get("Location"), end, nil
|
|
|
|
}
|
|
|
|
|
2015-12-15 22:35:23 +00:00
|
|
|
func finishUpload(t *testing.T, ub *v2.URLBuilder, name reference.Named, uploadURLBase string, dgst digest.Digest) string {
|
2015-05-04 15:56:37 +00:00
|
|
|
resp, err := doPushLayer(t, ub, name, dgst, uploadURLBase, nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error doing push layer request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "putting monolithic chunk", resp, http.StatusCreated)
|
|
|
|
|
2015-12-16 00:43:13 +00:00
|
|
|
ref, _ := reference.WithDigest(name, dgst)
|
|
|
|
expectedLayerURL, err := ub.BuildBlobURL(ref)
|
2015-05-04 15:56:37 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error building expected layer url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Location": []string{expectedLayerURL},
|
|
|
|
"Content-Length": []string{"0"},
|
|
|
|
"Docker-Content-Digest": []string{dgst.String()},
|
|
|
|
})
|
|
|
|
|
|
|
|
return resp.Header.Get("Location")
|
|
|
|
}
|
|
|
|
|
2020-08-19 09:07:38 +00:00
|
|
|
type chunkOptions struct {
|
|
|
|
// Content-Range header to set when pushing chunks
|
|
|
|
contentRange string
|
|
|
|
}
|
|
|
|
|
|
|
|
func doPushChunk(t *testing.T, uploadURLBase string, body io.Reader, options chunkOptions) (*http.Response, error) {
|
2015-05-04 15:56:37 +00:00
|
|
|
u, err := url.Parse(uploadURLBase)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error parsing pushLayer url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
u.RawQuery = url.Values{
|
|
|
|
"_state": u.Query()["_state"],
|
|
|
|
}.Encode()
|
|
|
|
|
|
|
|
uploadURL := u.String()
|
|
|
|
|
2022-11-02 22:31:23 +00:00
|
|
|
req, err := http.NewRequest(http.MethodPatch, uploadURL, body)
|
2015-05-04 15:56:37 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error creating new request: %v", err)
|
|
|
|
}
|
|
|
|
req.Header.Set("Content-Type", "application/octet-stream")
|
2020-08-19 09:07:38 +00:00
|
|
|
if options.contentRange != "" {
|
|
|
|
req.Header.Set("Content-Range", options.contentRange)
|
|
|
|
}
|
2015-05-04 15:56:37 +00:00
|
|
|
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
|
|
|
2020-08-19 09:07:38 +00:00
|
|
|
return resp, err
|
2015-05-04 15:56:37 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 22:35:23 +00:00
|
|
|
func pushChunk(t *testing.T, ub *v2.URLBuilder, name reference.Named, uploadURLBase string, body io.Reader, length int64) (string, digest.Digest) {
|
2020-08-19 09:07:38 +00:00
|
|
|
digester := digest.Canonical.Digester()
|
|
|
|
|
|
|
|
resp, err := doPushChunk(t, uploadURLBase, io.TeeReader(body, digester.Hash()), chunkOptions{})
|
2015-05-04 15:56:37 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error doing push layer request: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, "putting chunk", resp, http.StatusAccepted)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error generating sha256 digest of body")
|
|
|
|
}
|
|
|
|
|
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Range": []string{fmt.Sprintf("0-%d", length-1)},
|
|
|
|
"Content-Length": []string{"0"},
|
|
|
|
})
|
|
|
|
|
2020-08-19 09:07:38 +00:00
|
|
|
return resp.Header.Get("Location"), digester.Digest()
|
2015-05-04 15:56:37 +00:00
|
|
|
}
|
|
|
|
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
func checkResponse(t *testing.T, msg string, resp *http.Response, expectedStatus int) {
|
|
|
|
if resp.StatusCode != expectedStatus {
|
|
|
|
t.Logf("unexpected status %s: %v != %v", msg, resp.StatusCode, expectedStatus)
|
|
|
|
maybeDumpResponse(t, resp)
|
|
|
|
t.FailNow()
|
|
|
|
}
|
2015-08-10 21:20:52 +00:00
|
|
|
|
2015-08-18 20:33:26 +00:00
|
|
|
// We expect the headers included in the configuration, unless the
|
|
|
|
// status code is 405 (Method Not Allowed), which means the handler
|
|
|
|
// doesn't even get called.
|
|
|
|
if resp.StatusCode != 405 && !reflect.DeepEqual(resp.Header["X-Content-Type-Options"], []string{"nosniff"}) {
|
2015-08-10 21:20:52 +00:00
|
|
|
t.Logf("missing or incorrect header X-Content-Type-Options %s", msg)
|
|
|
|
maybeDumpResponse(t, resp)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
t.FailNow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-30 05:26:35 +00:00
|
|
|
// checkBodyHasErrorCodes ensures the body is an error body and has the
|
|
|
|
// expected error codes, returning the error structure, the json slice and a
|
|
|
|
// count of the errors by code.
|
2015-05-15 01:21:39 +00:00
|
|
|
func checkBodyHasErrorCodes(t *testing.T, msg string, resp *http.Response, errorCodes ...errcode.ErrorCode) (errcode.Errors, []byte, map[errcode.ErrorCode]int) {
|
2022-11-02 21:55:22 +00:00
|
|
|
p, err := io.ReadAll(resp.Body)
|
2015-01-30 05:26:35 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error reading body %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
|
2015-05-15 01:21:39 +00:00
|
|
|
var errs errcode.Errors
|
2015-01-30 05:26:35 +00:00
|
|
|
if err := json.Unmarshal(p, &errs); err != nil {
|
|
|
|
t.Fatalf("unexpected error decoding error response: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-05-27 00:18:32 +00:00
|
|
|
if len(errs) == 0 {
|
2015-01-30 05:26:35 +00:00
|
|
|
t.Fatalf("expected errors in response")
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(stevvooe): Shoot. The error setup is not working out. The content-
|
|
|
|
// type headers are being set after writing the status code.
|
2019-01-14 08:53:03 +00:00
|
|
|
// if resp.Header.Get("Content-Type") != "application/json" {
|
2015-01-30 05:26:35 +00:00
|
|
|
// t.Fatalf("unexpected content type: %v != 'application/json'",
|
|
|
|
// resp.Header.Get("Content-Type"))
|
|
|
|
// }
|
|
|
|
|
2015-05-15 01:21:39 +00:00
|
|
|
expected := map[errcode.ErrorCode]struct{}{}
|
|
|
|
counts := map[errcode.ErrorCode]int{}
|
2015-01-30 05:26:35 +00:00
|
|
|
|
|
|
|
// Initialize map with zeros for expected
|
|
|
|
for _, code := range errorCodes {
|
|
|
|
expected[code] = struct{}{}
|
|
|
|
counts[code] = 0
|
|
|
|
}
|
|
|
|
|
2015-06-03 13:52:39 +00:00
|
|
|
for _, e := range errs {
|
|
|
|
err, ok := e.(errcode.ErrorCoder)
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("not an ErrorCoder: %#v", e)
|
2015-01-30 05:26:35 +00:00
|
|
|
}
|
2015-06-03 13:52:39 +00:00
|
|
|
if _, ok := expected[err.ErrorCode()]; !ok {
|
|
|
|
t.Fatalf("unexpected error code %v encountered during %s: %s ", err.ErrorCode(), msg, string(p))
|
|
|
|
}
|
|
|
|
counts[err.ErrorCode()]++
|
2015-01-30 05:26:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ensure that counts of expected errors were all non-zero
|
|
|
|
for code := range expected {
|
|
|
|
if counts[code] == 0 {
|
2019-10-09 12:02:21 +00:00
|
|
|
t.Fatalf("expected error code %v not encountered during %s: %s", code, msg, string(p))
|
2015-01-30 05:26:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return errs, p, counts
|
|
|
|
}
|
|
|
|
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
func maybeDumpResponse(t *testing.T, resp *http.Response) {
|
|
|
|
if d, err := httputil.DumpResponse(resp, true); err != nil {
|
|
|
|
t.Logf("error dumping response: %v", err)
|
|
|
|
} else {
|
2014-11-21 03:57:01 +00:00
|
|
|
t.Logf("response:\n%s", string(d))
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// matchHeaders checks that the response has at least the headers. If not, the
|
|
|
|
// test will fail. If a passed in header value is "*", any non-zero value will
|
|
|
|
// suffice as a match.
|
|
|
|
func checkHeaders(t *testing.T, resp *http.Response, headers http.Header) {
|
|
|
|
for k, vs := range headers {
|
|
|
|
if resp.Header.Get(k) == "" {
|
|
|
|
t.Fatalf("response missing header %q", k)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, v := range vs {
|
|
|
|
if v == "*" {
|
|
|
|
// Just ensure there is some value.
|
2015-07-24 06:03:13 +00:00
|
|
|
if len(resp.Header[http.CanonicalHeaderKey(k)]) > 0 {
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-24 06:03:13 +00:00
|
|
|
for _, hv := range resp.Header[http.CanonicalHeaderKey(k)] {
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
if hv != v {
|
2015-05-27 17:52:22 +00:00
|
|
|
t.Fatalf("%+v %v header value not matched in response: %q != %q", resp.Header, k, hv, v)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-21 03:57:01 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-26 23:47:04 +00:00
|
|
|
|
|
|
|
func checkErr(t *testing.T, err error, msg string) {
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error %s: %v", msg, err)
|
|
|
|
}
|
|
|
|
}
|
2015-07-13 20:08:13 +00:00
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
func createRepository(env *testEnv, t *testing.T, imageName string, tag string) digest.Digest {
|
2017-01-14 01:06:03 +00:00
|
|
|
imageNameRef, err := reference.WithName(imageName)
|
2015-12-15 22:35:23 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to parse reference: %v", err)
|
|
|
|
}
|
|
|
|
|
2023-08-17 07:35:54 +00:00
|
|
|
tagRef, _ := reference.WithTag(imageNameRef, tag)
|
|
|
|
manifestURL, err := env.builder.BuildManifestURL(tagRef)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error getting manifest url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
manifest := &schema2.Manifest{
|
2015-07-13 20:08:13 +00:00
|
|
|
Versioned: manifest.Versioned{
|
2023-08-17 07:35:54 +00:00
|
|
|
SchemaVersion: 2,
|
|
|
|
MediaType: schema2.MediaTypeManifest,
|
2015-07-13 20:08:13 +00:00
|
|
|
},
|
2023-08-17 07:35:54 +00:00
|
|
|
Config: distribution.Descriptor{
|
|
|
|
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",
|
|
|
|
Size: 3253,
|
|
|
|
MediaType: schema2.MediaTypeImageConfig,
|
2015-11-03 19:03:17 +00:00
|
|
|
},
|
2023-08-17 07:35:54 +00:00
|
|
|
Layers: []distribution.Descriptor{
|
2015-07-13 20:08:13 +00:00
|
|
|
{
|
2023-08-17 07:35:54 +00:00
|
|
|
Digest: "sha256:463434349086340864309863409683460843608348608934092322395278926a",
|
|
|
|
Size: 6323,
|
|
|
|
MediaType: schema2.MediaTypeLayer,
|
2015-07-13 20:08:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-08-17 07:35:54 +00:00
|
|
|
// Push a config, and reference it in the manifest
|
|
|
|
sampleConfig := []byte(`{
|
|
|
|
"architecture": "amd64",
|
|
|
|
"history": [
|
|
|
|
{
|
|
|
|
"created": "2015-10-31T22:22:54.690851953Z",
|
|
|
|
"created_by": "/bin/sh -c #(nop) ADD file:a3bc1e842b69636f9df5256c49c5374fb4eef1e281fe3f282c65fb853ee171c5 in /"
|
|
|
|
},
|
|
|
|
],
|
|
|
|
"rootfs": {
|
|
|
|
"diff_ids": [
|
|
|
|
"sha256:c6f988f4874bb0add23a778f753c65efe992244e148a1d2ec2a8b664fb66bbd1",
|
|
|
|
],
|
|
|
|
"type": "layers"
|
|
|
|
}
|
|
|
|
}`)
|
|
|
|
sampleConfigDigest := digest.FromBytes(sampleConfig)
|
2015-07-13 20:08:13 +00:00
|
|
|
|
2023-08-17 07:35:54 +00:00
|
|
|
uploadURLBase, _ := startPushLayer(t, env, imageNameRef)
|
|
|
|
pushLayer(t, env.builder, imageNameRef, sampleConfigDigest, uploadURLBase, bytes.NewReader(sampleConfig))
|
|
|
|
manifest.Config.Digest = sampleConfigDigest
|
|
|
|
manifest.Config.Size = int64(len(sampleConfig))
|
|
|
|
|
|
|
|
// Push random layers
|
|
|
|
|
|
|
|
for i := range manifest.Layers {
|
2019-02-05 00:01:04 +00:00
|
|
|
rs, dgst, err := testutil.CreateRandomTarFile()
|
2015-07-13 20:08:13 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error creating random layer %d: %v", i, err)
|
|
|
|
}
|
2023-08-17 07:35:54 +00:00
|
|
|
manifest.Layers[i].Digest = dgst
|
2015-07-13 20:08:13 +00:00
|
|
|
|
2016-02-23 01:49:23 +00:00
|
|
|
uploadURLBase, _ := startPushLayer(t, env, imageNameRef)
|
2015-12-15 22:35:23 +00:00
|
|
|
pushLayer(t, env.builder, imageNameRef, dgst, uploadURLBase, rs)
|
2015-07-13 20:08:13 +00:00
|
|
|
}
|
|
|
|
|
2023-08-17 07:35:54 +00:00
|
|
|
// -------------------
|
|
|
|
// Push the manifest with all layers pushed.
|
|
|
|
deserializedManifest, err := schema2.FromStruct(*manifest)
|
2015-07-13 20:08:13 +00:00
|
|
|
if err != nil {
|
2023-08-17 07:35:54 +00:00
|
|
|
t.Fatalf("could not create DeserializedManifest: %v", err)
|
2015-07-13 20:08:13 +00:00
|
|
|
}
|
2023-08-17 07:35:54 +00:00
|
|
|
_, canonical, err := deserializedManifest.Payload()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not get manifest payload: %v", err)
|
|
|
|
}
|
|
|
|
dgst := digest.FromBytes(canonical)
|
2015-12-16 00:43:13 +00:00
|
|
|
digestRef, _ := reference.WithDigest(imageNameRef, dgst)
|
2023-08-17 07:35:54 +00:00
|
|
|
manifestDigestURL, err := env.builder.BuildManifestURL(digestRef)
|
|
|
|
checkErr(t, err, "building manifest url")
|
2015-08-21 04:50:15 +00:00
|
|
|
|
2023-08-17 07:35:54 +00:00
|
|
|
resp := putManifest(t, "putting manifest no error", manifestURL, schema2.MediaTypeManifest, manifest)
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2023-08-17 07:35:54 +00:00
|
|
|
checkResponse(t, "putting manifest no error", resp, http.StatusCreated)
|
2015-07-13 20:08:13 +00:00
|
|
|
checkHeaders(t, resp, http.Header{
|
2023-08-17 07:35:54 +00:00
|
|
|
"Location": []string{manifestDigestURL},
|
2015-07-13 20:08:13 +00:00
|
|
|
"Docker-Content-Digest": []string{dgst.String()},
|
|
|
|
})
|
2023-08-17 07:35:54 +00:00
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
return dgst
|
2015-07-13 20:08:13 +00:00
|
|
|
}
|
2015-08-11 18:00:30 +00:00
|
|
|
|
|
|
|
// Test mutation operations on a registry configured as a cache. Ensure that they return
|
|
|
|
// appropriate errors.
|
|
|
|
func TestRegistryAsCacheMutationAPIs(t *testing.T) {
|
|
|
|
deleteEnabled := true
|
|
|
|
env := newTestEnvMirror(t, deleteEnabled)
|
2016-08-26 23:20:54 +00:00
|
|
|
defer env.Shutdown()
|
2015-08-11 18:00:30 +00:00
|
|
|
|
2017-01-14 01:06:03 +00:00
|
|
|
imageName, _ := reference.WithName("foo/bar")
|
2015-08-11 18:00:30 +00:00
|
|
|
tag := "latest"
|
2015-12-16 00:43:13 +00:00
|
|
|
tagRef, _ := reference.WithTag(imageName, tag)
|
|
|
|
manifestURL, err := env.builder.BuildManifestURL(tagRef)
|
2015-08-11 18:00:30 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building base url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Manifest upload
|
2023-08-17 07:35:54 +00:00
|
|
|
manifest := &schema2.Manifest{
|
2015-08-11 18:00:30 +00:00
|
|
|
Versioned: manifest.Versioned{
|
2023-08-17 07:35:54 +00:00
|
|
|
SchemaVersion: 2,
|
|
|
|
MediaType: schema2.MediaTypeManifest,
|
|
|
|
},
|
|
|
|
Config: distribution.Descriptor{
|
|
|
|
Digest: "sha256:1a9ec845ee94c202b2d5da74a24f0ed2058318bfa9879fa541efaecba272e86b",
|
|
|
|
Size: 3253,
|
|
|
|
MediaType: schema2.MediaTypeImageConfig,
|
|
|
|
},
|
|
|
|
Layers: []distribution.Descriptor{
|
|
|
|
{
|
|
|
|
Digest: "sha256:463434349086340864309863409683460843608348608934092322395278926a",
|
|
|
|
Size: 6323,
|
|
|
|
MediaType: schema2.MediaTypeLayer,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Digest: "sha256:630923423623623423352523525237238023652897356239852383652aaaaaaa",
|
|
|
|
Size: 6863,
|
|
|
|
MediaType: schema2.MediaTypeLayer,
|
|
|
|
},
|
2015-08-11 18:00:30 +00:00
|
|
|
},
|
2015-09-15 04:12:33 +00:00
|
|
|
}
|
|
|
|
|
2023-08-17 07:35:54 +00:00
|
|
|
resp := putManifest(t, "putting missing config manifest", manifestURL, schema2.MediaTypeManifest, manifest)
|
2023-08-19 08:16:02 +00:00
|
|
|
defer resp.Body.Close()
|
2023-08-17 07:35:54 +00:00
|
|
|
checkResponse(t, "putting missing config manifest", resp, errcode.ErrorCodeUnsupported.Descriptor().HTTPStatusCode)
|
2015-08-11 18:00:30 +00:00
|
|
|
|
|
|
|
// Manifest Delete
|
2023-08-19 08:16:02 +00:00
|
|
|
resp, err = httpDelete(manifestURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
2023-08-17 07:35:54 +00:00
|
|
|
checkResponse(t, "deleting config manifest from cache", resp, errcode.ErrorCodeUnsupported.Descriptor().HTTPStatusCode)
|
2015-08-11 18:00:30 +00:00
|
|
|
|
|
|
|
// Blob upload initialization
|
|
|
|
layerUploadURL, err := env.builder.BuildBlobUploadURL(imageName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error building layer upload url: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err = http.Post(layerUploadURL, "", nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error starting layer push: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
checkResponse(t, fmt.Sprintf("starting layer push to cache %v", imageName), resp, errcode.ErrorCodeUnsupported.Descriptor().HTTPStatusCode)
|
|
|
|
|
|
|
|
// Blob Delete
|
2016-12-17 00:28:34 +00:00
|
|
|
ref, _ := reference.WithDigest(imageName, digestSha256EmptyTar)
|
2016-11-17 18:28:05 +00:00
|
|
|
blobURL, _ := env.builder.BuildBlobURL(ref)
|
2023-08-19 08:16:02 +00:00
|
|
|
resp, err = httpDelete(blobURL)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unexpected error: %v", err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
2015-08-11 18:00:30 +00:00
|
|
|
checkResponse(t, "deleting blob from cache", resp, errcode.ErrorCodeUnsupported.Descriptor().HTTPStatusCode)
|
|
|
|
}
|
2015-08-19 18:37:53 +00:00
|
|
|
|
2015-08-21 04:50:15 +00:00
|
|
|
func TestProxyManifestGetByTag(t *testing.T) {
|
|
|
|
truthConfig := configuration.Configuration{
|
|
|
|
Storage: configuration.Storage{
|
2018-11-15 10:36:19 +00:00
|
|
|
"inmemory": configuration.Parameters{},
|
2016-08-26 23:10:11 +00:00
|
|
|
"maintenance": configuration.Parameters{"uploadpurging": map[interface{}]interface{}{
|
|
|
|
"enabled": false,
|
|
|
|
}},
|
2015-08-21 04:50:15 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
truthConfig.HTTP.Headers = headerConfig
|
|
|
|
|
2017-01-14 01:06:03 +00:00
|
|
|
imageName, _ := reference.WithName("foo/bar")
|
2015-08-21 04:50:15 +00:00
|
|
|
tag := "latest"
|
|
|
|
|
|
|
|
truthEnv := newTestEnvWithConfig(t, &truthConfig)
|
2016-08-26 23:20:54 +00:00
|
|
|
defer truthEnv.Shutdown()
|
2015-08-21 04:50:15 +00:00
|
|
|
// create a repository in the truth registry
|
2015-12-15 22:35:23 +00:00
|
|
|
dgst := createRepository(truthEnv, t, imageName.Name(), tag)
|
2015-08-21 04:50:15 +00:00
|
|
|
|
|
|
|
proxyConfig := configuration.Configuration{
|
|
|
|
Storage: configuration.Storage{
|
2018-11-15 10:36:19 +00:00
|
|
|
"inmemory": configuration.Parameters{},
|
2015-08-21 04:50:15 +00:00
|
|
|
},
|
|
|
|
Proxy: configuration.Proxy{
|
|
|
|
RemoteURL: truthEnv.server.URL,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
proxyConfig.HTTP.Headers = headerConfig
|
|
|
|
|
|
|
|
proxyEnv := newTestEnvWithConfig(t, &proxyConfig)
|
2016-08-26 23:20:54 +00:00
|
|
|
defer proxyEnv.Shutdown()
|
2015-08-21 04:50:15 +00:00
|
|
|
|
2015-12-16 00:43:13 +00:00
|
|
|
digestRef, _ := reference.WithDigest(imageName, dgst)
|
|
|
|
manifestDigestURL, err := proxyEnv.builder.BuildManifestURL(digestRef)
|
2015-08-21 04:50:15 +00:00
|
|
|
checkErr(t, err, "building manifest url")
|
|
|
|
|
|
|
|
resp, err := http.Get(manifestDigestURL)
|
|
|
|
checkErr(t, err, "fetching manifest from proxy by digest")
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2015-12-16 00:43:13 +00:00
|
|
|
tagRef, _ := reference.WithTag(imageName, tag)
|
|
|
|
manifestTagURL, err := proxyEnv.builder.BuildManifestURL(tagRef)
|
2015-08-21 04:50:15 +00:00
|
|
|
checkErr(t, err, "building manifest url")
|
|
|
|
|
|
|
|
resp, err = http.Get(manifestTagURL)
|
2016-11-17 18:28:05 +00:00
|
|
|
checkErr(t, err, "fetching manifest from proxy by tag (error check 1)")
|
2015-08-21 04:50:15 +00:00
|
|
|
defer resp.Body.Close()
|
2016-11-17 18:28:05 +00:00
|
|
|
checkResponse(t, "fetching manifest from proxy by tag (response check 1)", resp, http.StatusOK)
|
2015-08-21 04:50:15 +00:00
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Docker-Content-Digest": []string{dgst.String()},
|
|
|
|
})
|
|
|
|
|
|
|
|
// Create another manifest in the remote with the same image/tag pair
|
2015-12-15 22:35:23 +00:00
|
|
|
newDigest := createRepository(truthEnv, t, imageName.Name(), tag)
|
2015-08-21 04:50:15 +00:00
|
|
|
if dgst == newDigest {
|
|
|
|
t.Fatalf("non-random test data")
|
|
|
|
}
|
|
|
|
|
|
|
|
// fetch it with the same proxy URL as before. Ensure the updated content is at the same tag
|
|
|
|
resp, err = http.Get(manifestTagURL)
|
2016-11-17 18:28:05 +00:00
|
|
|
checkErr(t, err, "fetching manifest from proxy by tag (error check 2)")
|
2015-08-21 04:50:15 +00:00
|
|
|
defer resp.Body.Close()
|
2016-11-17 18:28:05 +00:00
|
|
|
checkResponse(t, "fetching manifest from proxy by tag (response check 2)", resp, http.StatusOK)
|
2015-08-21 04:50:15 +00:00
|
|
|
checkHeaders(t, resp, http.Header{
|
|
|
|
"Docker-Content-Digest": []string{newDigest.String()},
|
|
|
|
})
|
|
|
|
}
|