wabbajack/Wabbajack.Test/ContentRightsManagementTests.cs
2020-04-03 16:37:27 -06:00

147 lines
4.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Wabbajack.Lib.Downloaders;
using Wabbajack.Lib;
using Wabbajack.Lib.Validation;
using Game = Wabbajack.Common.Game;
using Wabbajack.Common;
using System.Threading.Tasks;
namespace Wabbajack.Test
{
[TestClass]
public class ContentRightsManagementTests
{
private ValidateModlist validate;
private WorkQueue queue;
private static string permissions = @"
bill:
Permissions:
CanExtractBSAs: false
Games:
Skyrim:
Permissions:
CanModifyESPs: false
Mods:
42:
Permissions:
CanModifyAssets: false
Files:
33:
Permissions:
CanUseInOtherGames: false
";
private static string server_whitelist = @"
GoogleIDs:
- googleDEADBEEF
AllowedPrefixes:
- https://somegoodplace.com/
";
[TestInitialize]
public void TestSetup()
{
queue = new WorkQueue();
validate = new ValidateModlist();
validate.LoadServerWhitelist(server_whitelist);
}
[TestCleanup]
public void TestCleanup()
{
queue?.Dispose();
}
[TestMethod]
public async Task TestModValidation()
{
var modlist = new ModList
{
GameType = Game.Skyrim,
Archives = new List<Archive>
{
new Archive
{
State = new NexusDownloader.State
{
GameName = "Skyrim",
Author = "bill",
ModID = "42",
FileID = "33",
},
Hash = Hash.FromLong(42)
}
},
Directives = new List<Directive>
{
new FromArchive
{
ArchiveHashPath = new[] {"DEADBEEF", "foo\\bar\\baz.pex"},
To = "foo\\bar\\baz.pex"
}
}
};
// Error due to file downloaded from 3rd party
modlist.GameType = Game.Skyrim;
modlist.Archives[0] = new Archive()
{
State = new HTTPDownloader.State() { Url = "https://somebadplace.com" },
Hash = Hash.FromLong(42)
};
var errors = await validate.Validate(modlist);
Assert.AreEqual(1, errors.Count());
// Ok due to file downloaded from whitelisted 3rd party
modlist.GameType = Game.Skyrim;
modlist.Archives[0] = new Archive
{
State = new HTTPDownloader.State { Url = "https://somegoodplace.com/baz.7z" },
Hash = Hash.FromLong(42)
};
errors = await validate.Validate(modlist);
Assert.AreEqual(0, errors.Count());
// Error due to file downloaded from bad 3rd party
modlist.GameType = Game.Skyrim;
modlist.Archives[0] = new Archive
{
State = new GoogleDriveDownloader.State { Id = "bleg"},
Hash = Hash.FromLong(42)
};
errors = await validate.Validate(modlist);
Assert.AreEqual(errors.Count(), 1);
// Ok due to file downloaded from good google site
modlist.GameType = Game.Skyrim;
modlist.Archives[0] = new Archive
{
State = new GoogleDriveDownloader.State { Id = "googleDEADBEEF" },
Hash = Hash.FromLong(42)
};
errors = await validate.Validate(modlist);
Assert.AreEqual(0, errors.Count());
}
[TestMethod]
public async Task CanLoadFromGithub()
{
using (var workQueue = new WorkQueue())
{
await new ValidateModlist().LoadListsFromGithub();
}
}
}
}