mirror of
https://github.com/git-pkgs/proxy.git
synced 2026-11-09 15:49:16 -05:00
Closes #525. With metadata caching and the rewrite cache on, a packument is streamed from upstream into storage and rewritten from there in two passes: the first collects the time map, dist-tags and version names, the second copies each kept version and rewrites its tarball URL. Neither the packument nor its rewrite is held in memory uncompressed, so metadata_max_size no longer limits packuments. Both passes check the stored bytes against the digest in the cache row, so a document replaced in between is not rewritten from mixed bytes. Documents the stream can't handle (abbreviated, no versions object) and rewrite errors fall back to the in-memory rewrite.
48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package npm
|
|
|
|
import (
|
|
"os/exec"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestPortableImports keeps the package free of the proxy's infrastructure:
|
|
// no handler, database, storage, metrics, HTTP or logging, so it builds for
|
|
// targets such as WASI where those are not available.
|
|
func TestPortableImports(t *testing.T) {
|
|
goTool, err := exec.LookPath("go")
|
|
if err != nil {
|
|
t.Skip("go tool not found")
|
|
}
|
|
out, err := exec.Command(goTool, "list", "-deps", "-f", "{{.Standard}} {{.ImportPath}}", ".").Output()
|
|
if err != nil {
|
|
t.Fatalf("go list: %v", err)
|
|
}
|
|
allowed := []string{
|
|
"github.com/Masterminds/semver/v3",
|
|
"github.com/git-pkgs/cooldown",
|
|
"github.com/git-pkgs/proxy/internal/jsonscan",
|
|
"github.com/git-pkgs/proxy/internal/jsonstream",
|
|
"github.com/git-pkgs/proxy/internal/metadata/npm",
|
|
"github.com/git-pkgs/proxy/internal/packageurl",
|
|
"github.com/git-pkgs/purl",
|
|
"github.com/git-pkgs/vers",
|
|
"github.com/package-url/packageurl-go",
|
|
}
|
|
// database/sql/driver comes in through semver, which implements its
|
|
// Valuer interface; it is only interfaces, no driver.
|
|
forbiddenStd := []string{"database/sql", "log/slog", "net", "net/http"}
|
|
for line := range strings.Lines(string(out)) {
|
|
standard, path, _ := strings.Cut(strings.TrimSpace(line), " ")
|
|
if standard == "true" {
|
|
if slices.Contains(forbiddenStd, path) {
|
|
t.Errorf("imports %s", path)
|
|
}
|
|
continue
|
|
}
|
|
if !slices.Contains(allowed, path) {
|
|
t.Errorf("imports %s, which is not on the portable list", path)
|
|
}
|
|
}
|
|
}
|