2020-05-19 03:46:33 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-08-08 03:21:23 +00:00
|
|
|
|
using Dapper;
|
2020-06-05 21:34:23 +00:00
|
|
|
|
using Wabbajack.BuildServer;
|
2020-05-19 03:46:33 +00:00
|
|
|
|
using Wabbajack.BuildServer.Test;
|
|
|
|
|
using Wabbajack.Common;
|
2020-05-21 22:12:51 +00:00
|
|
|
|
using Wabbajack.Common.Exceptions;
|
2020-05-19 03:46:33 +00:00
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
using Wabbajack.Lib.Downloaders;
|
2020-08-06 22:40:07 +00:00
|
|
|
|
using Wabbajack.Lib.FileUploader;
|
2020-05-19 03:46:33 +00:00
|
|
|
|
using Wabbajack.Server.DataLayer;
|
|
|
|
|
using Wabbajack.Server.Services;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Server.Test
|
|
|
|
|
{
|
|
|
|
|
public class ModlistUpdater : ABuildServerSystemTest
|
|
|
|
|
{
|
|
|
|
|
public ModlistUpdater(ITestOutputHelper output, SingletonAdaptor<BuildServerFixture> fixture) : base(output,
|
|
|
|
|
fixture)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task CanIndexAndUpdateFiles()
|
|
|
|
|
{
|
2020-08-08 03:21:23 +00:00
|
|
|
|
var _sql = Fixture.GetService<SqlService>();
|
|
|
|
|
await using var conn = await _sql.Open();
|
|
|
|
|
await conn.ExecuteAsync("DELETE FROM dbo.NoPatch");
|
|
|
|
|
|
2020-06-05 21:34:23 +00:00
|
|
|
|
var settings = Fixture.GetService<AppSettings>();
|
|
|
|
|
settings.ValidateModUpgrades = false;
|
2020-05-19 03:46:33 +00:00
|
|
|
|
var validator = Fixture.GetService<ListValidator>();
|
|
|
|
|
var nonNexus = Fixture.GetService<NonNexusDownloadValidator>();
|
2020-05-20 22:36:29 +00:00
|
|
|
|
var modLists = await MakeModList("CanIndexAndUpdateFiles.txt");
|
2020-05-19 03:46:33 +00:00
|
|
|
|
Consts.ModlistMetadataURL = modLists.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var listDownloader = Fixture.GetService<ModListDownloader>();
|
|
|
|
|
var downloader = Fixture.GetService<ArchiveDownloader>();
|
|
|
|
|
var archiver = Fixture.GetService<ArchiveMaintainer>();
|
2020-05-20 03:25:41 +00:00
|
|
|
|
var patcher = Fixture.GetService<PatchBuilder>();
|
2020-06-29 21:57:09 +00:00
|
|
|
|
patcher.NoCleaning = true;
|
2020-05-19 03:46:33 +00:00
|
|
|
|
|
|
|
|
|
var sql = Fixture.GetService<SqlService>();
|
|
|
|
|
var oldFileData = Encoding.UTF8.GetBytes("Cheese for Everyone!");
|
|
|
|
|
var newFileData = Encoding.UTF8.GetBytes("Forks for Everyone!");
|
|
|
|
|
var oldDataHash = oldFileData.xxHash();
|
|
|
|
|
var newDataHash = newFileData.xxHash();
|
|
|
|
|
|
2020-05-20 03:25:41 +00:00
|
|
|
|
var oldArchive = new Archive(new NexusDownloader.State {Game = Game.Enderal, ModID = 42, FileID = 10})
|
2020-05-19 03:46:33 +00:00
|
|
|
|
{
|
2020-05-20 03:25:41 +00:00
|
|
|
|
Size = oldFileData.Length,
|
|
|
|
|
Hash = oldDataHash
|
|
|
|
|
};
|
|
|
|
|
var newArchive = new Archive(new NexusDownloader.State {Game = Game.Enderal, ModID = 42, FileID = 11})
|
2020-05-19 03:46:33 +00:00
|
|
|
|
{
|
2020-05-20 03:25:41 +00:00
|
|
|
|
Size = newFileData.Length,
|
|
|
|
|
Hash = newDataHash
|
|
|
|
|
};
|
2020-05-19 03:46:33 +00:00
|
|
|
|
|
2020-05-20 03:25:41 +00:00
|
|
|
|
await IngestData(archiver, oldFileData);
|
|
|
|
|
await IngestData(archiver, newFileData);
|
2020-05-19 03:46:33 +00:00
|
|
|
|
|
2020-05-20 03:25:41 +00:00
|
|
|
|
await sql.EnqueueDownload(oldArchive);
|
|
|
|
|
var oldDownload = await sql.GetNextPendingDownload();
|
|
|
|
|
await oldDownload.Finish(sql);
|
2020-05-19 03:46:33 +00:00
|
|
|
|
|
2020-05-20 03:25:41 +00:00
|
|
|
|
await sql.EnqueueDownload(newArchive);
|
|
|
|
|
var newDownload = await sql.GetNextPendingDownload();
|
|
|
|
|
await newDownload.Finish(sql);
|
2020-05-19 03:46:33 +00:00
|
|
|
|
|
|
|
|
|
|
2020-05-20 03:25:41 +00:00
|
|
|
|
await Assert.ThrowsAsync<HttpException>(async () => await ClientAPI.GetModUpgrade(oldArchive, newArchive, TimeSpan.Zero, TimeSpan.Zero));
|
2020-05-26 04:48:37 +00:00
|
|
|
|
Assert.True(await patcher.Execute() > 1);
|
2020-05-20 03:25:41 +00:00
|
|
|
|
|
2020-08-05 23:04:54 +00:00
|
|
|
|
Assert.Equal(new Uri("https://wabbajacktest.b-cdn.net/79223277e28e1b7b_3286c571d95f5666"),await ClientAPI.GetModUpgrade(oldArchive, newArchive, TimeSpan.Zero, TimeSpan.Zero));
|
2020-08-06 22:40:07 +00:00
|
|
|
|
|
|
|
|
|
Assert.Equal("Purged", await AuthorAPI.NoPatch(oldArchive.Hash, "Testing NoPatch"));
|
|
|
|
|
|
|
|
|
|
await Assert.ThrowsAsync<HttpException>(async () => await ClientAPI.GetModUpgrade(oldArchive, newArchive, TimeSpan.Zero, TimeSpan.Zero));
|
|
|
|
|
Assert.True(await sql.IsNoPatch(oldArchive.Hash));
|
|
|
|
|
|
2020-05-20 03:55:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-20 12:18:47 +00:00
|
|
|
|
[Fact]
|
2020-05-20 03:55:12 +00:00
|
|
|
|
public async Task TestEndToEndArchiveUpdating()
|
|
|
|
|
{
|
2020-08-08 03:21:23 +00:00
|
|
|
|
var _sql = Fixture.GetService<SqlService>();
|
|
|
|
|
await using var conn = await _sql.Open();
|
|
|
|
|
await conn.ExecuteAsync("DELETE FROM dbo.NoPatch");
|
|
|
|
|
|
2020-06-05 21:34:23 +00:00
|
|
|
|
var settings = Fixture.GetService<AppSettings>();
|
|
|
|
|
settings.ValidateModUpgrades = false;
|
|
|
|
|
|
2020-05-20 22:36:29 +00:00
|
|
|
|
var modLists = await MakeModList("TestEndToEndArchiveUpdating.txt");
|
2020-05-20 03:55:12 +00:00
|
|
|
|
Consts.ModlistMetadataURL = modLists.ToString();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var downloader = Fixture.GetService<ArchiveDownloader>();
|
|
|
|
|
var archiver = Fixture.GetService<ArchiveMaintainer>();
|
|
|
|
|
var patcher = Fixture.GetService<PatchBuilder>();
|
2020-06-29 21:57:09 +00:00
|
|
|
|
patcher.NoCleaning = true;
|
2020-05-20 03:55:12 +00:00
|
|
|
|
|
|
|
|
|
var sql = Fixture.GetService<SqlService>();
|
2020-08-08 04:20:49 +00:00
|
|
|
|
var oldFileData = Encoding.UTF8.GetBytes("Cheese for Everyone!" + Guid.NewGuid());
|
2020-05-20 03:55:12 +00:00
|
|
|
|
var newFileData = Encoding.UTF8.GetBytes("Forks for Everyone!");
|
|
|
|
|
var oldDataHash = oldFileData.xxHash();
|
|
|
|
|
var newDataHash = newFileData.xxHash();
|
|
|
|
|
|
2020-05-21 02:15:23 +00:00
|
|
|
|
await "TestEndToEndArchiveUpdating.txt".RelativeTo(Fixture.ServerPublicFolder).WriteAllBytesAsync(oldFileData);
|
2020-05-20 03:55:12 +00:00
|
|
|
|
|
2020-05-21 02:15:23 +00:00
|
|
|
|
var oldArchive = new Archive(new HTTPDownloader.State(MakeURL("TestEndToEndArchiveUpdating.txt")))
|
2020-05-20 03:55:12 +00:00
|
|
|
|
{
|
|
|
|
|
Size = oldFileData.Length,
|
|
|
|
|
Hash = oldDataHash
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await IngestData(archiver, oldFileData);
|
|
|
|
|
await sql.EnqueueDownload(oldArchive);
|
|
|
|
|
var oldDownload = await sql.GetNextPendingDownload();
|
|
|
|
|
await oldDownload.Finish(sql);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Now update the file
|
2020-05-21 02:15:23 +00:00
|
|
|
|
await"TestEndToEndArchiveUpdating.txt".RelativeTo(Fixture.ServerPublicFolder).WriteAllBytesAsync(newFileData);
|
2020-05-20 03:55:12 +00:00
|
|
|
|
|
|
|
|
|
|
2020-05-28 02:43:57 +00:00
|
|
|
|
await using var tempFile = new TempFile();
|
2020-05-20 03:55:12 +00:00
|
|
|
|
var pendingRequest = DownloadDispatcher.DownloadWithPossibleUpgrade(oldArchive, tempFile.Path);
|
|
|
|
|
|
|
|
|
|
for (var times = 0; await downloader.Execute() == 0 && times < 40; times ++)
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(TimeSpan.FromMilliseconds(200));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (var times = 0; await patcher.Execute() == 0 && times < 40; times ++)
|
|
|
|
|
{
|
|
|
|
|
await Task.Delay(TimeSpan.FromMilliseconds(200));
|
|
|
|
|
}
|
2020-05-19 03:46:33 +00:00
|
|
|
|
|
2020-08-20 22:02:50 +00:00
|
|
|
|
Assert.Equal(DownloadDispatcher.DownloadResult.Update, await pendingRequest);
|
2020-05-20 03:55:12 +00:00
|
|
|
|
Assert.Equal(oldDataHash, await tempFile.Path.FileHashAsync());
|
2020-05-20 03:25:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task IngestData(ArchiveMaintainer am, byte[] data)
|
|
|
|
|
{
|
2020-05-28 02:43:57 +00:00
|
|
|
|
await using var f = new TempFile();
|
2020-05-20 03:25:41 +00:00
|
|
|
|
await f.Path.WriteAllBytesAsync(data);
|
|
|
|
|
await am.Ingest(f.Path);
|
2020-05-19 03:46:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|