Add safe stale repository unlock action

This commit is contained in:
Mikei386
2026-06-15 00:25:27 +02:00
parent 054fde24d3
commit e23563afb1
11 changed files with 67 additions and 9 deletions
+22
View File
@@ -76,6 +76,28 @@ func TestForgetUsesAgeAndCalendarRetention(t *testing.T) {
}
}
func TestUnlockUsesSafeResticCommand(t *testing.T) {
dir := t.TempDir()
argsPath := filepath.Join(dir, "args")
script := filepath.Join(dir, "restic")
body := fmt.Sprintf("#!/bin/sh\nprintf '%%s\\n' \"$@\" > '%s'\n", argsPath)
if err := os.WriteFile(script, []byte(body), 0700); err != nil {
t.Fatal(err)
}
runner := &Runner{Binary: script, RuntimeDir: dir, Secrets: fakeSecrets{"password": "secret"}}
repo := model.Repository{Type: model.RepositoryLocal, Location: "/repo", PasswordRef: "password"}
if err := runner.Unlock(context.Background(), repo); err != nil {
t.Fatal(err)
}
args, _ := os.ReadFile(argsPath)
if !strings.Contains(string(args), "unlock") {
t.Fatalf("unlock command missing: %s", args)
}
if strings.Contains(string(args), "--remove-all") {
t.Fatalf("unsafe remove-all option used: %s", args)
}
}
func TestResticErrorExplainsExistingRepository(t *testing.T) {
err := resticError("Fatal: create repository failed: config file already exists", fmt.Errorf("exit status 1"))
if !strings.Contains(err.Error(), "already initialized") || !strings.Contains(err.Error(), "select Test") {