wabbajack/Wabbajack.Test/ContentRightsManagementTests.cs

132 lines
4.2 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using Wabbajack.Lib.Downloaders;
using Wabbajack.Lib;
using Wabbajack.Lib.Validation;
using Game = Wabbajack.Common.Game;
using Wabbajack.Common;
using System.Threading.Tasks;
using Wabbajack.Lib.NexusApi;
2020-03-26 21:31:25 +00:00
using Xunit;
namespace Wabbajack.Test
{
2020-03-26 21:31:25 +00:00
public class ContentRightsManagementTests : IDisposable
{
private ValidateModlist validate;
2019-12-13 13:02:58 +00:00
private WorkQueue queue;
private static string server_whitelist = @"
GoogleIDs:
- googleDEADBEEF
AllowedPrefixes:
- https://somegoodplace.com/
";
2020-03-26 21:31:25 +00:00
public ContentRightsManagementTests()
{
2019-12-13 13:02:58 +00:00
queue = new WorkQueue();
2020-03-22 15:50:53 +00:00
validate = new ValidateModlist();
2019-12-13 13:02:58 +00:00
validate.LoadServerWhitelist(server_whitelist);
}
2020-03-26 21:31:25 +00:00
public void Dispose()
2019-12-13 13:02:58 +00:00
{
queue?.Dispose();
2020-03-26 21:31:25 +00:00
}
2020-03-26 21:31:25 +00:00
[Fact]
public async Task TestModValidation()
{
var modlist = new ModList
{
GameType = Game.Skyrim,
Archives = new List<Archive>
{
2020-04-10 01:29:53 +00:00
new Archive(
new NexusDownloader.State
{
Game = Game.Skyrim,
Author = "bill",
2020-04-03 03:57:59 +00:00
ModID = 42,
FileID = 33,
2020-04-10 01:29:53 +00:00
})
{
2020-03-22 15:50:53 +00:00
Hash = Hash.FromLong(42)
}
},
Directives = new List<Directive>
{
new FromArchive
{
2020-03-26 21:31:25 +00:00
ArchiveHashPath = HashRelativePath.FromStrings(Hash.FromULong(42).ToBase64(), "foo\\bar\\baz.pex"),
To = (RelativePath)"foo\\bar\\baz.pex"
}
}
};
// Error due to file downloaded from 3rd party
modlist.GameType = Game.Skyrim;
2020-04-10 01:29:53 +00:00
modlist.Archives[0] = new Archive(new HTTPDownloader.State("https://somebadplace.com"))
{
2020-03-22 15:50:53 +00:00
Hash = Hash.FromLong(42)
};
2020-03-22 15:50:53 +00:00
var errors = await validate.Validate(modlist);
2020-03-26 21:31:25 +00:00
Assert.Single(errors);
// Ok due to file downloaded from whitelisted 3rd party
modlist.GameType = Game.Skyrim;
2020-04-10 01:29:53 +00:00
modlist.Archives[0] = new Archive(new HTTPDownloader.State("https://somegoodplace.com/baz.7z"))
{
2020-03-22 15:50:53 +00:00
Hash = Hash.FromLong(42)
};
errors = await validate.Validate(modlist);
2020-03-26 21:31:25 +00:00
Assert.Empty(errors);
// Error due to file downloaded from bad 3rd party
modlist.GameType = Game.Skyrim;
2020-04-10 01:29:53 +00:00
modlist.Archives[0] = new Archive(new GoogleDriveDownloader.State("bleg"))
{
2020-03-22 15:50:53 +00:00
Hash = Hash.FromLong(42)
};
errors = await validate.Validate(modlist);
2020-03-26 21:31:25 +00:00
Assert.Single(errors);
// Ok due to file downloaded from good google site
modlist.GameType = Game.Skyrim;
2020-04-10 01:29:53 +00:00
modlist.Archives[0] = new Archive(new GoogleDriveDownloader.State("googleDEADBEEF"))
{
2020-03-22 15:50:53 +00:00
Hash = Hash.FromLong(42)
};
errors = await validate.Validate(modlist);
2020-03-26 21:31:25 +00:00
Assert.Empty(errors);
}
2020-03-26 21:31:25 +00:00
[Fact]
public async Task CanLoadFromGithub()
{
using (var workQueue = new WorkQueue())
{
2020-03-22 15:50:53 +00:00
await new ValidateModlist().LoadListsFromGithub();
}
}
[Fact]
public async Task CanGetReuploadRights()
{
Assert.Equal(HTMLInterface.PermissionValue.No, await HTMLInterface.GetUploadPermissions(Game.SkyrimSpecialEdition, 266));
Assert.Equal(HTMLInterface.PermissionValue.Yes, await HTMLInterface.GetUploadPermissions(Game.SkyrimSpecialEdition, 1137));
Assert.Equal(HTMLInterface.PermissionValue.Hidden, await HTMLInterface.GetUploadPermissions(Game.SkyrimSpecialEdition, 34604));
2020-08-22 21:14:38 +00:00
Assert.Equal(HTMLInterface.PermissionValue.NotFound, await HTMLInterface.GetUploadPermissions(Game.SkyrimSpecialEdition, 24287));
}
}
}