Merge pull request #21781 from mattxtaz2/master

This commit is contained in:
Michael Eischer
2026-05-10 22:20:24 +02:00
committed by GitHub
3 changed files with 41 additions and 1 deletions
+8
View File
@@ -0,0 +1,8 @@
Bugfix: respect `--user` and `--host` in `key passwd`
The `key passwd` command silently ignored the `--user` and `--host` flags
and always recorded the new key with the current user and host name.
This has been fixed,
https://github.com/restic/restic/issues/5757
https://github.com/restic/restic/pull/21781
+32
View File
@@ -86,6 +86,36 @@ func testRunKeyPasswd(t testing.TB, newPassword string, gopts global.Options) {
rtest.OK(t, err)
}
func testRunKeyPasswdUserHost(t testing.TB, newPassword string, gopts global.Options) {
testKeyNewPassword = newPassword
defer func() {
testKeyNewPassword = ""
}()
t.Log("changing password and setting key for john@example.com")
err := withTermStatus(t, gopts, func(ctx context.Context, gopts global.Options) error {
return runKeyPasswd(ctx, gopts, KeyPasswdOptions{
KeyAddOptions: KeyAddOptions{
Username: "john",
Hostname: "example.com",
},
}, []string{}, gopts.Term)
})
rtest.OK(t, err)
gopts.Password = testKeyNewPassword
_ = withTermStatus(t, gopts, func(ctx context.Context, gopts global.Options) error {
repo, err := global.OpenRepository(ctx, gopts, &progress.NoopPrinter{})
rtest.OK(t, err)
key, err := repository.SearchKey(ctx, repo, testKeyNewPassword, 1, "")
rtest.OK(t, err)
rtest.Equals(t, "john", key.Username)
rtest.Equals(t, "example.com", key.Hostname)
return nil
})
}
func testRunKeyRemove(t testing.TB, gopts global.Options, IDs []string) {
t.Logf("remove %d keys: %q\n", len(IDs), IDs)
for _, id := range IDs {
@@ -111,6 +141,8 @@ func TestKeyAddRemove(t *testing.T) {
testRunKeyPasswd(t, "geheim2", env.gopts)
env.gopts.Password = "geheim2"
testRunKeyPasswdUserHost(t, "geheim3", env.gopts)
env.gopts.Password = "geheim3"
t.Logf("changed password to %q", env.gopts.Password)
for _, newPassword := range passwordList {
+1 -1
View File
@@ -71,7 +71,7 @@ func changePassword(ctx context.Context, repo *repository.Repository, gopts glob
return err
}
id, err := repository.AddKey(ctx, repo, pw, "", "", repo.Key())
id, err := repository.AddKey(ctx, repo, pw, opts.Username, opts.Hostname, repo.Key())
if err != nil {
return errors.Fatalf("creating new key failed: %v", err)
}