Add safe stale repository unlock action
This commit is contained in:
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user