Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0e857ff9d |
@@ -263,15 +263,7 @@ func TestCrossVaultMoveChecksAgainOnceLocked(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("destination vault created again from another mnemonic", func(t *testing.T) {
|
||||
// Set by the move, which has finished once
|
||||
// requireChecksAgainOnceLocked returns
|
||||
var moveErr error
|
||||
|
||||
requireChecksAgainOnceLocked(t, func(cli *Instance) error {
|
||||
moveErr = move(cli)
|
||||
|
||||
return moveErr
|
||||
}, func(fs afero.Fs) error {
|
||||
requireChecksAgainOnceLocked(t, move, func(fs afero.Fs) error {
|
||||
err := fs.RemoveAll(testStateDir + "/vaults.d/other")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -281,12 +273,6 @@ func TestCrossVaultMoveChecksAgainOnceLocked(t *testing.T) {
|
||||
|
||||
return err
|
||||
}, errVaultCreatedAgain)
|
||||
|
||||
// secret unlocker add fails with the same error, so its message
|
||||
// must fit a move too
|
||||
require.EqualError(t, moveErr, "vault 'other' was removed and "+
|
||||
"created again with another key while it was being unlocked; "+
|
||||
"nothing was changed")
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+13
-6
@@ -1097,9 +1097,10 @@ func (cli *Instance) moveSecretCrossVault(
|
||||
destVault *vault.Vault, destSecretName string,
|
||||
force bool,
|
||||
) error {
|
||||
// Before unlocking, check that the source secret exists, that the
|
||||
// destination is not the source under another name, and, without
|
||||
// --force, that the destination secret does not exist
|
||||
// Before unlocking, check that the source secret and the destination
|
||||
// vault exist, that the destination is not the source under another
|
||||
// name, and, without --force, that the destination secret does not
|
||||
// exist
|
||||
_, err := cli.checkCrossVaultMove(
|
||||
srcVault, srcSecretName, destVault, destSecretName, force)
|
||||
if err != nil {
|
||||
@@ -1179,9 +1180,10 @@ func (cli *Instance) copySecretAndRemoveSource(
|
||||
}
|
||||
|
||||
// checkCrossVaultMove checks that the secret srcSecretName exists in
|
||||
// srcVault, that destSecretName in destVault is not the source under
|
||||
// another name, and, unless force is set, that destSecretName does not
|
||||
// exist in destVault. It returns the source's directory.
|
||||
// srcVault, that destVault exists, that destSecretName in destVault is not
|
||||
// the source under another name, and, unless force is set, that
|
||||
// destSecretName does not exist in destVault. It returns the source's
|
||||
// directory.
|
||||
func (cli *Instance) checkCrossVaultMove(
|
||||
srcVault *vault.Vault, srcSecretName string,
|
||||
destVault *vault.Vault, destSecretName string,
|
||||
@@ -1202,6 +1204,11 @@ func (cli *Instance) checkCrossVaultMove(
|
||||
srcSecretName, vault.ErrSecretNotFound, srcVault.Name)
|
||||
}
|
||||
|
||||
_, err = cli.existingVault(destVault.Name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// The source is removed after the copy, so a destination that is the
|
||||
// source under another name would be lost with it.
|
||||
destVaultDir, err := destVault.GetDirectory()
|
||||
|
||||
@@ -43,7 +43,7 @@ var (
|
||||
// errVaultCreatedAgain carries only the message tail; the caller
|
||||
// composes "vault '<name>' was removed and created again ...".
|
||||
errVaultCreatedAgain = errors.New("was removed and created again " +
|
||||
"with another key while it was being unlocked; nothing was changed")
|
||||
"with another key while it was being unlocked; nothing was added")
|
||||
)
|
||||
|
||||
// UnlockerInfo represents unlocker information for display
|
||||
|
||||
Reference in New Issue
Block a user