From 4da26681b58fb3afa9c2a297f159e6b325910e2d Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 5 Jan 2026 00:43:21 +0900 Subject: internal/pkg: compute http identifier from url The previous implementation exposes arbitrary user input to the cache as an identifier, which is highly error-prone and can cause the cache to enter an inconsistent state if the user is not careful. This change replaces the implementation to compute identifier late, using url string as params. Signed-off-by: Ophestra --- internal/pkg/tar_test.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'internal/pkg/tar_test.go') diff --git a/internal/pkg/tar_test.go b/internal/pkg/tar_test.go index 309a1c76..feff9c14 100644 --- a/internal/pkg/tar_test.go +++ b/internal/pkg/tar_test.go @@ -74,12 +74,13 @@ func TestTar(t *testing.T) { h := sha512.New384() h.Write([]byte{byte(pkg.KindTar), 0, 0, 0, 0, 0, 0, 0}) h.Write([]byte{pkg.TarGzip, 0, 0, 0, 0, 0, 0, 0}) - h.Write([]byte{byte(pkg.KindHTTP), 0, 0, 0, 0, 0, 0, 0}) - h.Write(testdataChecksum[:]) + h.Write([]byte{byte(pkg.KindHTTPGet), 0, 0, 0, 0, 0, 0, 0}) + httpIdent := pkg.KindHTTPGet.Ident([]byte("file:///testdata")) + h.Write(httpIdent[:]) return pkg.ID(h.Sum(nil)) }() - a, err := pkg.NewHTTPGetTar( + a := pkg.NewHTTPGetTar( t.Context(), &client, "file:///testdata", @@ -87,16 +88,10 @@ func TestTar(t *testing.T) { pkg.TarGzip, ) - if err != nil { - t.Fatalf("NewHTTPGetTar: error = %v", err) - } else if id := pkg.Ident(a); id != wantIdent { + if id := pkg.Ident(a); id != wantIdent { t.Fatalf("Ident: %s, want %s", pkg.Encode(id), pkg.Encode(wantIdent)) } - var ( - pathname *check.Absolute - checksum pkg.Checksum - ) wantPathname := base.Append( "identifier", pkg.Encode(wantIdent), @@ -104,7 +99,7 @@ func TestTar(t *testing.T) { wantChecksum := pkg.MustDecode( "yJlSb2A3jxaMLuKqwp1GwHOguAHddS9MjygF9ICEeegKfRvgLPdPmNh8mva47f8o", ) - if pathname, checksum, err = c.Cure(a); err != nil { + if pathname, checksum, err := c.Cure(a); err != nil { t.Fatalf("Cure: error = %v", err) } else if !pathname.Is(wantPathname) { t.Fatalf("Cure: %q, want %q", pathname, wantPathname) @@ -114,6 +109,6 @@ func TestTar(t *testing.T) { Want: wantChecksum, }) } - }, pkg.MustDecode("p1HdTOQhIeWzpXdZ45xo00H9CFeXNIvazxOhBAfExlhFO64zt7TUbxoLJ2eAL5oc")}, + }, pkg.MustDecode("lmVlYEGNFkwGVpzzS8KYjGBVB6FCyPtk9ViX88zen0GgTKLgGqO6eFxb4dpcP6bR")}, }) } -- cgit v1.3.1