Switch from relative paths to bare names in pointer files
- currentvault now contains just the vault name (e.g., "default") - current-unlocker now contains just the unlocker name (e.g., "passphrase") - current version file now contains just the version (e.g., "20231215.001") - Resolution functions prepend the appropriate directory prefix
This commit is contained in:
@@ -332,12 +332,12 @@ func test01Initialize(t *testing.T, tempDir, testMnemonic, testPassphrase string
|
||||
defaultVaultDir := filepath.Join(vaultsDir, "default")
|
||||
verifyFileExists(t, defaultVaultDir)
|
||||
|
||||
// Check currentvault file contains the relative path
|
||||
// Check currentvault file contains the vault name
|
||||
currentVaultFile := filepath.Join(tempDir, "currentvault")
|
||||
targetBytes, err := os.ReadFile(currentVaultFile)
|
||||
require.NoError(t, err, "should be able to read currentvault file")
|
||||
target := string(targetBytes)
|
||||
assert.Equal(t, "vaults.d/default", target, "currentvault should contain relative path")
|
||||
assert.Equal(t, "default", target, "currentvault should contain vault name")
|
||||
|
||||
// Verify vault structure
|
||||
pubKeyFile := filepath.Join(defaultVaultDir, "pub.age")
|
||||
@@ -463,7 +463,7 @@ func test03CreateVault(t *testing.T, tempDir string, runSecret func(...string) (
|
||||
targetBytes, err := os.ReadFile(currentVaultFile)
|
||||
require.NoError(t, err, "should be able to read currentvault file")
|
||||
target := string(targetBytes)
|
||||
assert.Equal(t, "vaults.d/work", target, "currentvault should contain relative path to work")
|
||||
assert.Equal(t, "work", target, "currentvault should contain vault name")
|
||||
|
||||
// Verify work vault has basic structure
|
||||
unlockersDir := filepath.Join(workVaultDir, "unlockers.d")
|
||||
@@ -593,12 +593,11 @@ func test05AddSecret(t *testing.T, tempDir, testMnemonic string, runSecret func(
|
||||
currentLink := filepath.Join(secretDir, "current")
|
||||
verifyFileExists(t, currentLink)
|
||||
|
||||
// Verify current file contains the version path
|
||||
// Verify current file contains the version name
|
||||
targetBytes, err := os.ReadFile(currentLink)
|
||||
require.NoError(t, err, "should read current file")
|
||||
target := string(targetBytes)
|
||||
expectedTarget := filepath.Join("versions", versionName)
|
||||
assert.Equal(t, expectedTarget, target, "current file should point to version")
|
||||
assert.Equal(t, versionName, target, "current file should contain version name")
|
||||
|
||||
// Verify we can retrieve the secret
|
||||
getOutput, err := runSecretWithEnv(map[string]string{
|
||||
@@ -685,8 +684,7 @@ func test07AddSecretVersion(t *testing.T, tempDir, testMnemonic string, runSecre
|
||||
targetBytes, err := os.ReadFile(currentLink)
|
||||
require.NoError(t, err, "should read current file")
|
||||
target := string(targetBytes)
|
||||
expectedTarget := filepath.Join("versions", newVersion)
|
||||
assert.Equal(t, expectedTarget, target, "current file should point to new version")
|
||||
assert.Equal(t, newVersion, target, "current file should contain version name")
|
||||
|
||||
// Verify we get the new value when retrieving the secret
|
||||
getOutput, err := runSecretWithEnv(map[string]string{
|
||||
@@ -801,7 +799,7 @@ func test10PromoteVersion(t *testing.T, tempDir, testMnemonic string, runSecret
|
||||
targetBytes, err := os.ReadFile(currentLink)
|
||||
require.NoError(t, err, "should read current file")
|
||||
target := string(targetBytes)
|
||||
assert.Equal(t, filepath.Join("versions", version002), target, "current should initially point to .002")
|
||||
assert.Equal(t, version002, target, "current should initially point to .002")
|
||||
|
||||
// Promote the old version
|
||||
output, err := runSecretWithEnv(map[string]string{
|
||||
@@ -816,8 +814,7 @@ func test10PromoteVersion(t *testing.T, tempDir, testMnemonic string, runSecret
|
||||
newTargetBytes, err := os.ReadFile(currentLink)
|
||||
require.NoError(t, err, "should read current file after promotion")
|
||||
newTarget := string(newTargetBytes)
|
||||
expectedTarget := filepath.Join("versions", version001)
|
||||
assert.Equal(t, expectedTarget, newTarget, "current file should now point to .001")
|
||||
assert.Equal(t, version001, newTarget, "current file should now point to .001")
|
||||
|
||||
// Verify we now get the old value when retrieving the secret
|
||||
getOutput, err := runSecretWithEnv(map[string]string{
|
||||
@@ -1240,7 +1237,7 @@ func test14SwitchVault(t *testing.T, tempDir string, runSecret func(...string) (
|
||||
targetBytes, err := os.ReadFile(currentVaultFile)
|
||||
require.NoError(t, err, "should read currentvault file")
|
||||
target := string(targetBytes)
|
||||
assert.Equal(t, "vaults.d/default", target, "currentvault should point to default")
|
||||
assert.Equal(t, "default", target, "currentvault should contain vault name")
|
||||
|
||||
// Switch to work vault
|
||||
_, err = runSecret("vault", "select", "work")
|
||||
@@ -1250,7 +1247,7 @@ func test14SwitchVault(t *testing.T, tempDir string, runSecret func(...string) (
|
||||
targetBytes, err = os.ReadFile(currentVaultFile)
|
||||
require.NoError(t, err, "should read currentvault file")
|
||||
target = string(targetBytes)
|
||||
assert.Equal(t, "vaults.d/work", target, "currentvault should point to work")
|
||||
assert.Equal(t, "work", target, "currentvault should contain vault name")
|
||||
|
||||
// Switch back to default
|
||||
_, err = runSecret("vault", "select", "default")
|
||||
@@ -1989,11 +1986,11 @@ func test29SymlinkHandling(t *testing.T, tempDir, secretPath, testMnemonic strin
|
||||
currentVaultFile := filepath.Join(tempDir, "currentvault")
|
||||
verifyFileExists(t, currentVaultFile)
|
||||
|
||||
// Read the file
|
||||
// Read the file - should contain just the vault name
|
||||
targetBytes, err := os.ReadFile(currentVaultFile)
|
||||
require.NoError(t, err, "should read currentvault file")
|
||||
target := string(targetBytes)
|
||||
assert.Contains(t, target, "vaults.d", "should point to vaults.d directory")
|
||||
assert.NotContains(t, target, "/", "should be bare vault name without path")
|
||||
|
||||
// Test version current file
|
||||
defaultVaultDir := filepath.Join(tempDir, "vaults.d", "default")
|
||||
@@ -2004,7 +2001,7 @@ func test29SymlinkHandling(t *testing.T, tempDir, secretPath, testMnemonic strin
|
||||
targetBytes, err = os.ReadFile(currentLink)
|
||||
require.NoError(t, err, "should read current version file")
|
||||
target = string(targetBytes)
|
||||
assert.Contains(t, target, "versions", "should point to versions directory")
|
||||
assert.NotContains(t, target, "/", "should be bare version name without path")
|
||||
|
||||
// Test that current file updates properly
|
||||
// Add new version
|
||||
@@ -2024,7 +2021,7 @@ func test29SymlinkHandling(t *testing.T, tempDir, secretPath, testMnemonic strin
|
||||
require.NoError(t, err, "should read updated current file")
|
||||
newTarget := string(newTargetBytes)
|
||||
assert.NotEqual(t, target, newTarget, "current file should point to new version")
|
||||
assert.Contains(t, newTarget, "versions", "new current file should still point to versions directory")
|
||||
assert.NotContains(t, newTarget, "/", "new current file should be bare version name")
|
||||
}
|
||||
|
||||
func test30BackupRestore(t *testing.T, tempDir, secretPath, testMnemonic string, runSecretWithEnv func(map[string]string, ...string) (string, error)) {
|
||||
|
||||
Reference in New Issue
Block a user