Skip to content

Commit 4cd5e4f

Browse files
committed
Name /api/git in the cache_delete notes and test a literal %2F before the delete
1 parent 0a48042 commit 4cd5e4f

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎config.example.yaml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ base_url: "http://localhost:8080"
2222
# scanning. Set to "0" to disable. Default: "5m". Does not limit proxy mirror.
2323
# artifact_timeout: "5m"
2424

25-
# Register DELETE /api/cache and show Delete buttons on the UI's version page,
26-
# for removing cached artifacts so they are fetched again. Has no
27-
# authentication: restrict /api/cache and /ui at the ingress first.
25+
# Register DELETE /api/cache and, with upstream.git set, DELETE /api/git, and
26+
# show Delete buttons on the UI's version and git pages, for removing cached
27+
# artifacts and repositories so they are fetched again. Has no authentication:
28+
# restrict /api/cache, /api/git and /ui at the ingress first.
2829
# cache_delete: false
2930

3031
# Largest upstream artifact to fetch (e.g. "2GB"). Larger ones are refused

‎internal/config/config.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,10 @@ type Config struct {
212212
// Mirror configures scheduled mirroring.
213213
Mirror MirrorConfig `json:"mirror" yaml:"mirror"`
214214

215-
// CacheDelete enables DELETE /api/cache for removing cached artifacts, and
216-
// the delete buttons on the UI's version page. It has no authentication of
217-
// its own, so restrict /api/cache and /ui at the ingress when enabling it.
215+
// CacheDelete enables DELETE /api/cache and DELETE /api/git for removing
216+
// cached artifacts and git repositories, and the delete buttons on the
217+
// UI's version and git pages. It has no authentication of its own, so
218+
// restrict /api/cache, /api/git and /ui at the ingress when enabling it.
218219
CacheDelete bool `json:"cache_delete" yaml:"cache_delete"`
219220

220221
// Hosted configures pushing packages to the proxy (/api/hosted).

‎internal/server/git_delete_test.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ func TestGitRepositoryDelete(t *testing.T) {
2424
})
2525
gitCommand(t, "", "clone", "--quiet", cfg.BaseURL+"/git/up/team/repo.git", filepath.Join(t.TempDir(), "clone"))
2626

27+
// A literal %2F names no cached repository, and leaves team/repo.
28+
if status, body := request(t, http.MethodDelete, cfg.BaseURL+prefix+"up/team%252Frepo.git", "", nil); status != http.StatusNotFound {
29+
t.Errorf("DELETE up/team%%252Frepo.git: status %d, want 404\n%s", status, body)
30+
}
2731
if _, body := request(t, http.MethodGet, cfg.BaseURL+"/ui/git", "", nil); !strings.Contains(body, `data-cache-url="/ui/api/git/up/team/repo.git"`) {
2832
t.Errorf("the git page has no delete control:\n%s", body)
2933
}
@@ -45,7 +49,7 @@ func TestGitRepositoryDelete(t *testing.T) {
4549
t.Errorf("the repository is still listed:\n%s", body)
4650
}
4751

48-
for _, path := range []string{"up/team/repo.git", "up/team/repo", "other/team/repo.git", "up/", "up/team%252Frepo.git"} {
52+
for _, path := range []string{"up/team/repo.git", "up/team/repo", "other/team/repo.git", "up/"} {
4953
if status, body := request(t, http.MethodDelete, cfg.BaseURL+prefix+path, "", nil); status != http.StatusNotFound {
5054
t.Errorf("DELETE %s: status %d, want 404\n%s", path, status, body)
5155
}

0 commit comments

Comments
 (0)