mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-26 06:37:07 +00:00
npm and pnpm request scoped packages as @scope%2fname. Fiber's adaptor answers 404 to an escaped slash, so a route middleware now rewrites the scope separator before the adaptor runs. With scanning off, the cache still waited 30 s for a scan result and then refused the package. A scanner that is off is now treated as absent. A scan that fails on infrastructure (timeout, network error, upstream 5xx) no longer blocks the package until its entry expires. The package is served and the scan is retried every scan_retry_interval. Set security.fail_closed to refuse such packages. The OSV api_url default and the docs named the host, which answers 404 to a query. They now name https://api.osv.dev/v1/query, and a bare host is completed with the query path.
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package osv
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/lukaszraczylo/gohoarder/pkg/config"
|
|
)
|
|
|
|
// A host-only api_url (the previously documented value) must still reach the
|
|
// query endpoint.
|
|
func TestScan_HostOnlyAPIURLUsesQueryEndpoint(t *testing.T) {
|
|
var gotPath string
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
gotPath = r.URL.Path
|
|
_, _ = w.Write([]byte(`{}`))
|
|
}))
|
|
t.Cleanup(srv.Close)
|
|
|
|
s := New(config.OSVConfig{APIURL: srv.URL})
|
|
if _, err := s.Scan(context.Background(), "npm", "left-pad", "1.0.0", ""); err != nil {
|
|
t.Fatalf("Scan: %v", err)
|
|
}
|
|
if gotPath != "/v1/query" {
|
|
t.Errorf("request path = %q, want /v1/query", gotPath)
|
|
}
|
|
}
|
|
|
|
func TestScan_FullQueryURLIsKept(t *testing.T) {
|
|
var gotPath string
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
gotPath = r.URL.Path
|
|
_, _ = w.Write([]byte(`{}`))
|
|
}))
|
|
t.Cleanup(srv.Close)
|
|
|
|
s := New(config.OSVConfig{APIURL: srv.URL + "/v1/query"})
|
|
if _, err := s.Scan(context.Background(), "npm", "left-pad", "1.0.0", ""); err != nil {
|
|
t.Fatalf("Scan: %v", err)
|
|
}
|
|
if gotPath != "/v1/query" {
|
|
t.Errorf("request path = %q, want /v1/query", gotPath)
|
|
}
|
|
}
|