This PR adds a flag to the test method so we can choose to test for read-only access (needed for restore) or read-write (needed for backups). Additionally, this PR fixes a logic bug in that the BackendSourceProvider would not actually test the connection, but just check the placeholder element returned (which is always returned). With this PR the backend's ListAsync command is tested fully. Also renamed the methods on ISourceProvider to have the `...Async` prefix. This replaces #6939
107 lines
5.1 KiB
C#
107 lines
5.1 KiB
C#
// Copyright (C) 2026, 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.IO;
|
|
using NUnit.Framework;
|
|
using System.Linq;
|
|
using Duplicati.Library.Interface;
|
|
using Duplicati.Library.DynamicLoader;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using System.Threading;
|
|
|
|
namespace Duplicati.UnitTest
|
|
{
|
|
public class Issue5862 : BasicSetupHelper
|
|
{
|
|
private class PreventingBackend : IStreamingBackend
|
|
{
|
|
public const string Key = "test-backend-5862";
|
|
public string DisplayName => "Test backend";
|
|
public string ProtocolKey => Key;
|
|
public string Description => "Test backend";
|
|
public bool SupportsStreaming => backend.SupportsStreaming;
|
|
public IList<ICommandLineArgument> SupportedCommands => backend.SupportedCommands;
|
|
private readonly IStreamingBackend backend;
|
|
|
|
public static string RealKey { get; set; } = "file";
|
|
public PreventingBackend()
|
|
{
|
|
backend = (IStreamingBackend)BackendLoader.Backends.First(x => x.ProtocolKey == RealKey);
|
|
}
|
|
|
|
public PreventingBackend(string url, Dictionary<string, string> opts)
|
|
{
|
|
backend = (IStreamingBackend)BackendLoader.GetBackend(RealKey + url.Substring(ProtocolKey.Length), opts);
|
|
}
|
|
|
|
public Task CreateFolderAsync(CancellationToken cancellationToken)
|
|
=> backend.CreateFolderAsync(cancellationToken);
|
|
|
|
public Task DeleteAsync(string remotename, CancellationToken cancellationToken)
|
|
=> backend.DeleteAsync(remotename, cancellationToken);
|
|
public void Dispose()
|
|
=> backend.Dispose();
|
|
public Task GetAsync(string remotename, Stream stream, CancellationToken cancelToken)
|
|
=> backend.GetAsync(remotename, stream, cancelToken);
|
|
public Task GetAsync(string remotename, string filename, CancellationToken cancellationToken)
|
|
=> backend.GetAsync(remotename, filename, cancellationToken);
|
|
public Task<string[]> GetDNSNamesAsync(CancellationToken cancelToken)
|
|
=> backend.GetDNSNamesAsync(cancelToken);
|
|
public IAsyncEnumerable<IFileEntry> ListAsync(CancellationToken cancellationToken)
|
|
=> backend.ListAsync(cancellationToken);
|
|
|
|
public Task PutAsync(string remotename, Stream stream, CancellationToken cancelToken)
|
|
=> throw new DeterministicErrorBackend.DeterministicErrorBackendException("Prevent");
|
|
|
|
public Task PutAsync(string remotename, string filename, CancellationToken cancellationToken)
|
|
=> throw new DeterministicErrorBackend.DeterministicErrorBackendException("Prevent");
|
|
|
|
public Task TestAsync(bool alsoWrite, CancellationToken cancellationToken)
|
|
=> backend.TestAsync(alsoWrite, cancellationToken);
|
|
}
|
|
|
|
[Test]
|
|
[Category("Targeted")]
|
|
public async Task TestUploadFailureWithResumeAsync()
|
|
{
|
|
var testopts = TestOptions.Expand(new
|
|
{
|
|
no_encryption = true,
|
|
number_of_retries = 0,
|
|
});
|
|
|
|
BackendLoader.AddBackend(new PreventingBackend());
|
|
var data = new byte[1024 * 1024 * 10];
|
|
File.WriteAllBytes(Path.Combine(DATAFOLDER, "a"), data);
|
|
|
|
// Make a failing backup
|
|
using (var c = new Library.Main.Controller(PreventingBackend.Key + "://" + TARGETFOLDER, testopts, null))
|
|
Assert.ThrowsAsync<DeterministicErrorBackend.DeterministicErrorBackendException>(async () => await c.BackupAsync(new string[] { DATAFOLDER }));
|
|
|
|
// Make a working backup, should not give any errors
|
|
using (var c = new Library.Main.Controller("file://" + TARGETFOLDER, testopts, null))
|
|
TestUtils.AssertResults(await c.BackupAsync(new string[] { DATAFOLDER }));
|
|
}
|
|
}
|
|
}
|
|
|