forked from security/hakurei
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 <cat@gensokyo.uk>
This commit is contained in:
@@ -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")},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user