2026-01-20 21:52:44 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"log/slog"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestMavenParsePath(t *testing.T) {
|
|
|
|
|
h := &MavenHandler{proxy: &Proxy{Logger: slog.Default()}}
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
path string
|
|
|
|
|
wantGroup string
|
|
|
|
|
wantArtifact string
|
|
|
|
|
wantVersion string
|
|
|
|
|
wantFilename string
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
"com/google/guava/guava/32.1.3-jre/guava-32.1.3-jre.jar",
|
|
|
|
|
"com.google.guava", "guava", "32.1.3-jre", "guava-32.1.3-jre.jar",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"org/apache/commons/commons-lang3/3.14.0/commons-lang3-3.14.0.jar",
|
|
|
|
|
"org.apache.commons", "commons-lang3", "3.14.0", "commons-lang3-3.14.0.jar",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"junit/junit/4.13.2/junit-4.13.2.jar",
|
|
|
|
|
"junit", "junit", "4.13.2", "junit-4.13.2.jar",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"short/path",
|
|
|
|
|
"", "", "", "",
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
group, artifact, version, filename := h.parsePath(tt.path)
|
|
|
|
|
if group != tt.wantGroup || artifact != tt.wantArtifact || version != tt.wantVersion || filename != tt.wantFilename {
|
|
|
|
|
t.Errorf("parsePath(%q) = (%q, %q, %q, %q), want (%q, %q, %q, %q)",
|
|
|
|
|
tt.path, group, artifact, version, filename,
|
|
|
|
|
tt.wantGroup, tt.wantArtifact, tt.wantVersion, tt.wantFilename)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestMavenIsArtifactFile(t *testing.T) {
|
|
|
|
|
h := &MavenHandler{}
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
filename string
|
|
|
|
|
want bool
|
|
|
|
|
}{
|
|
|
|
|
{"guava-32.1.3-jre.jar", true},
|
|
|
|
|
{"guava-32.1.3-jre.pom", true},
|
2026-05-22 18:05:20 +02:00
|
|
|
{"guava-32.1.3-jre.module", true},
|
2026-01-20 21:52:44 +00:00
|
|
|
{"app-1.0.war", true},
|
|
|
|
|
{"lib-1.0.aar", true},
|
Cache archive artifacts from Maven repositories (#425)
The Maven handler cached only .jar, .war, .ear, .pom, .aar, .klib and
.module files, so distributions published as archives, such as
apache-maven-{version}-bin.tar.gz, were proxied uncached on every request.
.zip, .tar.gz, .tgz, .tar.bz2 and .tar.xz files now go through the artifact
cache like other artifacts.
Co-authored-by: Giles Westwood <201443+gilesw@users.noreply.github.com>
2026-10-10 07:17:53 +01:00
|
|
|
{"apache-maven-3.9.9-bin.tar.gz", true},
|
|
|
|
|
{"apache-maven-3.9.9-bin.zip", true},
|
|
|
|
|
{"maven-mvnd-1.0.6-linux-amd64.tgz", true},
|
2026-01-20 21:52:44 +00:00
|
|
|
{"maven-metadata.xml", false},
|
|
|
|
|
{"guava-32.1.3-jre.jar.sha1", false},
|
Cache archive artifacts from Maven repositories (#425)
The Maven handler cached only .jar, .war, .ear, .pom, .aar, .klib and
.module files, so distributions published as archives, such as
apache-maven-{version}-bin.tar.gz, were proxied uncached on every request.
.zip, .tar.gz, .tgz, .tar.bz2 and .tar.xz files now go through the artifact
cache like other artifacts.
Co-authored-by: Giles Westwood <201443+gilesw@users.noreply.github.com>
2026-10-10 07:17:53 +01:00
|
|
|
{"apache-maven-3.9.9-bin.tar.gz.sha512", false},
|
2026-01-20 21:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
got := h.isArtifactFile(tt.filename)
|
|
|
|
|
if got != tt.want {
|
|
|
|
|
t.Errorf("isArtifactFile(%q) = %v, want %v", tt.filename, got, tt.want)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-22 18:05:20 +02:00
|
|
|
|
2026-10-14 12:31:06 +01:00
|
|
|
func TestMavenIsVersionListingFile(t *testing.T) {
|
2026-05-22 18:05:20 +02:00
|
|
|
h := &MavenHandler{}
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
filename string
|
|
|
|
|
want bool
|
|
|
|
|
}{
|
2026-10-14 12:31:06 +01:00
|
|
|
{"maven-metadata.xml", true},
|
|
|
|
|
{"maven-metadata.xml.sha1", true},
|
|
|
|
|
{"maven-metadata.xml.sha256", true},
|
|
|
|
|
{"guava-32.1.3-jre.jar", false},
|
|
|
|
|
{"guava-32.1.3-jre.jar.sha1", false},
|
|
|
|
|
{"com.diffplug.spotless.gradle.plugin-8.4.0.pom", false},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
if got := h.isVersionListingFile(tt.filename); got != tt.want {
|
|
|
|
|
t.Errorf("isVersionListingFile(%q) = %v, want %v", tt.filename, got, tt.want)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestMavenIsChecksumFile(t *testing.T) {
|
|
|
|
|
h := &MavenHandler{}
|
|
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
|
filename string
|
|
|
|
|
want bool
|
|
|
|
|
}{
|
|
|
|
|
{"guava-32.1.3-jre.jar.sha1", true},
|
|
|
|
|
{"guava-32.1.3-jre.jar.md5", true},
|
|
|
|
|
{"guava-32.1.3-jre.pom.sha1", true},
|
|
|
|
|
{"guava-32.1.3-jre.jar.asc", true},
|
|
|
|
|
{"apache-maven-3.9.9-bin.tar.gz.sha512", true},
|
|
|
|
|
{"com.diffplug.spotless.gradle.plugin-8.4.0.pom.sha1", true},
|
|
|
|
|
{"guava-32.1.3-jre.jar", false},
|
|
|
|
|
{"guava-32.1.3-jre.pom", false},
|
|
|
|
|
{"maven-metadata.xml", false},
|
2026-05-22 18:05:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
2026-10-14 12:31:06 +01:00
|
|
|
if got := h.isChecksumFile(tt.filename); got != tt.want {
|
|
|
|
|
t.Errorf("isChecksumFile(%q) = %v, want %v", tt.filename, got, tt.want)
|
|
|
|
|
}
|
2026-05-22 18:05:20 +02:00
|
|
|
}
|
|
|
|
|
}
|