ad72c3d630
Remotes answer only GET, so HEAD probes get 405, and there is no RubyGems remote. Synthesized (github_*) and rewritten (npm, helm, pypi, puppet, terraform, nuget) mutable responses need the GET path for HEAD lengths to match.
- add a HEAD route for /api/v1/remote/{name}/*; rewritten and synthesized mutable HEADs go through the GET path
- mark rewriting providers with a ResponseRewriter capability; set Content-Length on proxied GETs
- use the remote's upstream client for upstream HEAD
- add a gems remote type: compact index and specs mutable, .gem and gemspec immutable
- add gems docs, UI snippet and e2e caching case; add HEAD-vs-GET e2e checks
Reviewed-on: #148
Co-authored-by: unkin-agent <unkin-agent@unkin.net>
Co-committed-by: unkin-agent <unkin-agent@unkin.net>
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package v1
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"git.unkin.net/unkin/artifactapi/internal/provider"
|
|
"git.unkin.net/unkin/artifactapi/internal/provider/npm"
|
|
"git.unkin.net/unkin/artifactapi/internal/provider/nuget"
|
|
"git.unkin.net/unkin/artifactapi/internal/provider/rpm"
|
|
)
|
|
|
|
func TestRoutesRemoteHead(t *testing.T) {
|
|
r := (&ProxyHandler{}).Routes()
|
|
for _, m := range []string{http.MethodGet, http.MethodHead} {
|
|
if !r.Match(chi.NewRouteContext(), m, "/remote/myremote/some/path") {
|
|
t.Errorf("%s /remote/myremote/some/path not routed", m)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestRewritesMutable(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
prov provider.Provider
|
|
path string
|
|
want bool
|
|
}{
|
|
{"npm packument", &npm.Provider{}, "left-pad", true},
|
|
{"npm tarball", &npm.Provider{}, "left-pad/-/left-pad-1.3.0.tgz", false},
|
|
{"nuget index", &nuget.Provider{}, "index.json", true},
|
|
{"rpm repodata", &rpm.Provider{}, "repodata/repomd.xml", false},
|
|
}
|
|
for _, tc := range tests {
|
|
if got := rewritesMutable(tc.prov, tc.path); got != tc.want {
|
|
t.Errorf("%s: rewritesMutable = %v, want %v", tc.name, got, tc.want)
|
|
}
|
|
}
|
|
}
|