2019-09-29 04:41:47 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2019-10-16 03:10:34 +00:00
|
|
|
|
using Wabbajack.Lib.Downloaders;
|
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
using Wabbajack.Lib.Validation;
|
2019-09-29 04:41:47 +00:00
|
|
|
|
using Game = Wabbajack.Common.Game;
|
2019-12-07 02:05:24 +00:00
|
|
|
|
using Wabbajack.Common;
|
2019-12-04 01:26:26 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2020-07-25 18:09:02 +00:00
|
|
|
|
using Wabbajack.Lib.NexusApi;
|
2020-03-26 21:31:25 +00:00
|
|
|
|
using Xunit;
|
2019-09-29 04:41:47 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Test
|
|
|
|
|
{
|
2020-03-26 21:31:25 +00:00
|
|
|
|
public class ContentRightsManagementTests : IDisposable
|
2019-09-29 04:41:47 +00:00
|
|
|
|
{
|
|
|
|
|
private ValidateModlist validate;
|
2019-12-13 13:02:58 +00:00
|
|
|
|
private WorkQueue queue;
|
2019-09-29 20:53:25 +00:00
|
|
|
|
private static string server_whitelist = @"
|
|
|
|
|
|
|
|
|
|
GoogleIDs:
|
|
|
|
|
- googleDEADBEEF
|
|
|
|
|
|
|
|
|
|
AllowedPrefixes:
|
|
|
|
|
- https://somegoodplace.com/
|
|
|
|
|
|
|
|
|
|
";
|
|
|
|
|
|
2019-09-29 04:41:47 +00:00
|
|
|
|
|
2020-03-26 21:31:25 +00:00
|
|
|
|
public ContentRightsManagementTests()
|
2019-09-29 04:41:47 +00:00
|
|
|
|
{
|
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
|
|
|
|
|
2019-09-29 04:41:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-26 21:31:25 +00:00
|
|
|
|
|
|
|
|
|
[Fact]
|
2019-12-04 01:26:26 +00:00
|
|
|
|
public async Task TestModValidation()
|
2019-09-29 04:41:47 +00:00
|
|
|
|
{
|
|
|
|
|
var modlist = new ModList
|
|
|
|
|
{
|
|
|
|
|
GameType = Game.Skyrim,
|
|
|
|
|
Archives = new List<Archive>
|
|
|
|
|
{
|
2020-04-10 01:29:53 +00:00
|
|
|
|
new Archive(
|
|
|
|
|
new NexusDownloader.State
|
2019-10-12 22:15:20 +00:00
|
|
|
|
{
|
2020-03-30 22:26:34 +00:00
|
|
|
|
Game = Game.Skyrim,
|
2019-10-12 22:15:20 +00:00
|
|
|
|
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)
|
2019-09-29 04:41:47 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
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"
|
2019-09-29 04:41:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-09-29 20:53:25 +00:00
|
|
|
|
// 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"))
|
2019-09-29 20:53:25 +00:00
|
|
|
|
{
|
2020-03-22 15:50:53 +00:00
|
|
|
|
Hash = Hash.FromLong(42)
|
2019-09-29 20:53:25 +00:00
|
|
|
|
};
|
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);
|
2019-09-29 20:53:25 +00:00
|
|
|
|
|
|
|
|
|
// 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"))
|
2019-09-29 20:53:25 +00:00
|
|
|
|
{
|
2020-03-22 15:50:53 +00:00
|
|
|
|
Hash = Hash.FromLong(42)
|
2019-09-29 20:53:25 +00:00
|
|
|
|
};
|
2019-12-04 01:26:26 +00:00
|
|
|
|
errors = await validate.Validate(modlist);
|
2020-03-26 21:31:25 +00:00
|
|
|
|
Assert.Empty(errors);
|
2019-09-29 20:53:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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"))
|
2019-09-29 20:53:25 +00:00
|
|
|
|
{
|
2020-03-22 15:50:53 +00:00
|
|
|
|
Hash = Hash.FromLong(42)
|
2019-09-29 20:53:25 +00:00
|
|
|
|
};
|
2019-12-04 01:26:26 +00:00
|
|
|
|
errors = await validate.Validate(modlist);
|
2020-03-26 21:31:25 +00:00
|
|
|
|
Assert.Single(errors);
|
2019-09-29 20:53:25 +00:00
|
|
|
|
|
2019-10-12 22:15:20 +00:00
|
|
|
|
// Ok due to file downloaded from good google site
|
2019-09-29 20:53:25 +00:00
|
|
|
|
modlist.GameType = Game.Skyrim;
|
2020-04-10 01:29:53 +00:00
|
|
|
|
modlist.Archives[0] = new Archive(new GoogleDriveDownloader.State("googleDEADBEEF"))
|
2019-09-29 20:53:25 +00:00
|
|
|
|
{
|
2020-03-22 15:50:53 +00:00
|
|
|
|
Hash = Hash.FromLong(42)
|
2019-09-29 20:53:25 +00:00
|
|
|
|
};
|
2019-12-04 01:26:26 +00:00
|
|
|
|
errors = await validate.Validate(modlist);
|
2020-03-26 21:31:25 +00:00
|
|
|
|
Assert.Empty(errors);
|
2019-09-29 20:53:25 +00:00
|
|
|
|
|
2019-09-29 04:41:47 +00:00
|
|
|
|
}
|
2019-10-03 03:23:11 +00:00
|
|
|
|
|
2020-03-26 21:31:25 +00:00
|
|
|
|
[Fact]
|
2019-12-13 00:40:21 +00:00
|
|
|
|
public async Task CanLoadFromGithub()
|
2019-10-03 03:23:11 +00:00
|
|
|
|
{
|
2019-12-07 02:05:24 +00:00
|
|
|
|
using (var workQueue = new WorkQueue())
|
|
|
|
|
{
|
2020-03-22 15:50:53 +00:00
|
|
|
|
await new ValidateModlist().LoadListsFromGithub();
|
2019-12-07 02:05:24 +00:00
|
|
|
|
}
|
2019-10-03 03:23:11 +00:00
|
|
|
|
}
|
2020-07-25 18:09:02 +00:00
|
|
|
|
|
|
|
|
|
[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));
|
|
|
|
|
|
2020-07-25 18:09:02 +00:00
|
|
|
|
}
|
2019-09-29 04:41:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|