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