From cd9d6a52ebe1a279610e674f72ff929f3f861b16 Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Tue, 1 Apr 2025 16:38:11 +0200 Subject: [PATCH 1/2] Reproduce tests for #4693 --- Duplicati/UnitTest/Issue4693.cs | 132 ++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 Duplicati/UnitTest/Issue4693.cs diff --git a/Duplicati/UnitTest/Issue4693.cs b/Duplicati/UnitTest/Issue4693.cs new file mode 100644 index 000000000..6ddc34856 --- /dev/null +++ b/Duplicati/UnitTest/Issue4693.cs @@ -0,0 +1,132 @@ +// Copyright (C) 2025, The Duplicati Team +// https://duplicati.com, hello@duplicati.com +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +using System; +using System.IO; +using System.Security.Cryptography; +using NUnit.Framework; + +namespace Duplicati.UnitTest +{ + public class Issue4693 : BasicSetupHelper + { + [Test] + [Category("Targeted")] + public void RunCommandsOriginal() + { + var testopts = TestOptions.Expand(new { no_encryption = true, keep_versions = 1, dblock_size = "5mb" }); + + File.WriteAllText(Path.Combine(DATAFOLDER, "A.txt"), "A"); + File.WriteAllText(Path.Combine(DATAFOLDER, "B.txt"), "B"); + var buffer = new byte[1024 * 1024 * 12]; + Random.Shared.NextBytes(buffer); + File.WriteAllBytes(Path.Combine(DATAFOLDER, "b1.bin"), buffer); + + var a_hash = Convert.ToBase64String(SHA256.HashData(File.ReadAllBytes(Path.Combine(DATAFOLDER, "A.txt")))); + + // Backup 1 + using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) + TestUtils.AssertResults(c.Backup([DATAFOLDER])); + + File.Delete(Path.Combine(DATAFOLDER, "A.txt")); + File.WriteAllText(Path.Combine(DATAFOLDER, "C.txt"), "C"); + + Random.Shared.NextBytes(buffer); + File.WriteAllBytes(Path.Combine(DATAFOLDER, "b2.bin"), buffer); + + // Backup 2 + using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) + TestUtils.AssertResults(c.Backup([DATAFOLDER])); + + File.WriteAllText(Path.Combine(DATAFOLDER, "A.txt"), "A"); + Random.Shared.NextBytes(buffer); + File.WriteAllBytes(Path.Combine(DATAFOLDER, "b3.bin"), buffer); + + if (a_hash != Convert.ToBase64String(SHA256.HashData(File.ReadAllBytes(Path.Combine(DATAFOLDER, "A.txt"))))) + throw new Exception("Hash of A.txt changed"); + + // Backup 3 + using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) + TestUtils.AssertResults(c.Backup([DATAFOLDER])); + + File.Delete(Path.Combine(DATAFOLDER, "b1.bin")); + File.Delete(Path.Combine(DATAFOLDER, "b2.bin")); + + // Backup 4 + using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) + { + var res = c.Backup([DATAFOLDER]); + TestUtils.AssertResults(res); + Assert.That(res.CompactResults.DeletedFileCount, Is.GreaterThan(0), "Compact was not run"); + } + + using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) + TestUtils.AssertResults(c.Test(long.MaxValue)); + + // Test we can recrate without errors + File.Delete(DBFILE); + using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) + TestUtils.AssertResults(c.Repair()); + + using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) + TestUtils.AssertResults(c.Test(long.MaxValue)); + } + + [Test] + [Category("Targeted")] + public void RunCommandsSimplified() + { + var testopts = TestOptions.Expand(new { no_encryption = true, keep_versions = 1, dblock_size = "5mb" }); + + File.WriteAllText(Path.Combine(DATAFOLDER, "A.txt"), "A"); + File.WriteAllText(Path.Combine(DATAFOLDER, "B.txt"), "B"); + + // Backup 1 + using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) + TestUtils.AssertResults(c.Backup([DATAFOLDER])); + + File.Delete(Path.Combine(DATAFOLDER, "A.txt")); + File.WriteAllText(Path.Combine(DATAFOLDER, "C.txt"), "C"); + + // Backup 2 + using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) + TestUtils.AssertResults(c.Backup([DATAFOLDER])); + + File.WriteAllText(Path.Combine(DATAFOLDER, "A.txt"), "A"); + + // Backup 3 + using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) + TestUtils.AssertResults(c.Backup([DATAFOLDER])); + + // using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) + // TestUtils.AssertResults(c.Test(long.MaxValue)); + + // Test we can recrate without errors + File.Delete(DBFILE); + using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) + TestUtils.AssertResults(c.Repair()); + + using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) + TestUtils.AssertResults(c.Test(long.MaxValue)); + } + } +} + From 496d1ebbeff6e9de3df3b8be8668f9dcf71a160e Mon Sep 17 00:00:00 2001 From: Kenneth Skovhede Date: Tue, 1 Apr 2025 16:38:38 +0200 Subject: [PATCH 2/2] Commented in check --- Duplicati/UnitTest/Issue4693.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Duplicati/UnitTest/Issue4693.cs b/Duplicati/UnitTest/Issue4693.cs index 6ddc34856..afb28fa9c 100644 --- a/Duplicati/UnitTest/Issue4693.cs +++ b/Duplicati/UnitTest/Issue4693.cs @@ -116,8 +116,8 @@ namespace Duplicati.UnitTest using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) TestUtils.AssertResults(c.Backup([DATAFOLDER])); - // using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) - // TestUtils.AssertResults(c.Test(long.MaxValue)); + using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null)) + TestUtils.AssertResults(c.Test(long.MaxValue)); // Test we can recrate without errors File.Delete(DBFILE);