Reject a retention duration longer than about 292 years (closes #289)
check / check (push) Failing after 3m36s
check / check (push) Failing after 3m36s
parseDuration multiplied each number by the length of its unit with no limit, so from 293y (or 15251w, 3559mo, 106752d, or a sum such as 200y200y) the result wrapped to a negative duration. The purge cutoff then lay in the future and every snapshot of the name was selected, for --older-than and --keep-newer-than alike. Each part is now checked before it is added, and a total past the largest time.Duration is rejected as an invalid duration, so nothing is deleted. Go units were already safe: time.ParseDuration rejects an overflow. With --prune the backup still runs before the duration is read; only the prune step fails. Model: opus-5-5
This commit was merged in pull request #328.
This commit is contained in:
@@ -267,6 +267,29 @@ func TestPurgeOlderThan_WithNameFilter(t *testing.T) {
|
||||
assert.Contains(t, remaining, snapHomeT0)
|
||||
}
|
||||
|
||||
func TestPurgeOlderThan_TooLargeDeletesNothing(t *testing.T) {
|
||||
log.Initialize(log.Config{})
|
||||
t.Parallel()
|
||||
|
||||
snapshotIDs := []string{snapHomeT0, snapHomeT1}
|
||||
|
||||
v := setupPurgeTest(t, snapHostname, snapshotIDs)
|
||||
|
||||
err := v.PurgeSnapshotsWithOptions(&vaultik.SnapshotPurgeOptions{
|
||||
OlderThan: "1000y",
|
||||
Force: true,
|
||||
})
|
||||
require.Error(t, err)
|
||||
|
||||
err = v.PurgeSnapshotsWithOptions(&vaultik.SnapshotPurgeOptions{
|
||||
OlderThan: "292y",
|
||||
Force: true,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.ElementsMatch(t, snapshotIDs, listRemainingSnapshots(t, v))
|
||||
}
|
||||
|
||||
func TestPurgeKeepLatest_ThreeNames(t *testing.T) {
|
||||
log.Initialize(log.Config{})
|
||||
t.Parallel()
|
||||
|
||||
Reference in New Issue
Block a user