mesh/delivery-group group feat/774-l3-reland rejected: composed together: the checker's verdict at the members' heads (b48c90fea31f): integration: mesh-self-ch…
mesh/delivery closed: a newer head of the same pull request
mesh/check failed: integration: mesh-self-check/cmd/mesh-self-check.TestTheSelfCheckWholeRunsOnTheBus: the run answered {Run:doctor-1793351737-1 At:20…
One commit with exactly the tree of the reviewed head35b4509c0a, on main12c2574c9d, so two compiled programs added and removed on the branch leave no trace in history (issue 1577).
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package registry
|
|
|
|
import (
|
|
"context"
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"errors"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// A take-in reads a templates archive by its reference, and only bytes of the digest the reference names.
|
|
func TestGetBlobReadsOnlyTheBytesOfItsDigest(t *testing.T) {
|
|
good := []byte("the archive")
|
|
sum := sha256.Sum256(good)
|
|
digest := "sha256:" + hex.EncodeToString(sum[:])
|
|
liar := "sha256:" + strings.Repeat("0", 64)
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
switch {
|
|
case strings.HasSuffix(r.URL.Path, "/x/files/blobs/"+digest), strings.HasSuffix(r.URL.Path, "/x/files/blobs/"+liar):
|
|
_, _ = w.Write(good)
|
|
default:
|
|
w.WriteHeader(http.StatusNotFound)
|
|
}
|
|
}))
|
|
defer server.Close()
|
|
s := Store{Address: strings.TrimPrefix(server.URL, "http://")}
|
|
ctx := context.Background()
|
|
body, err := s.GetBlob(ctx, "artifact-store://x/files/blobs/"+digest)
|
|
if err != nil || string(body) != string(good) {
|
|
t.Fatalf("the archive: %q %v", body, err)
|
|
}
|
|
if _, err := s.GetBlob(ctx, "artifact-store://x/files/blobs/"+liar); err == nil || !strings.Contains(err.Error(), "refused") {
|
|
t.Fatalf("bytes of another digest are read: %v", err)
|
|
}
|
|
if _, err := s.GetBlob(ctx, "artifact-store://x/other/blobs/"+digest); !errors.Is(err, Gone) {
|
|
t.Fatalf("a blob the store does not hold: %v", err)
|
|
}
|
|
if _, err := s.GetBlob(ctx, "registry.example/x@"+digest); !errors.Is(err, ErrNotOurs) {
|
|
t.Fatalf("a reference outside the store: %v", err)
|
|
}
|
|
}
|