2019-09-29 04:41:47 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
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-09-29 04:41:47 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Test
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class ContentRightsManagementTests
|
|
|
|
|
{
|
|
|
|
|
private ValidateModlist validate;
|
|
|
|
|
|
|
|
|
|
private static string permissions = @"
|
|
|
|
|
|
|
|
|
|
bill:
|
|
|
|
|
Permissions:
|
|
|
|
|
CanExtractBSAs: false
|
|
|
|
|
Games:
|
|
|
|
|
Skyrim:
|
|
|
|
|
Permissions:
|
|
|
|
|
CanModifyESPs: false
|
|
|
|
|
Mods:
|
|
|
|
|
42:
|
|
|
|
|
Permissions:
|
|
|
|
|
CanModifyAssets: false
|
|
|
|
|
Files:
|
|
|
|
|
33:
|
|
|
|
|
Permissions:
|
|
|
|
|
CanUseInOtherGames: false
|
|
|
|
|
";
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
[TestInitialize]
|
|
|
|
|
public void TestSetup()
|
|
|
|
|
{
|
2019-12-07 02:05:24 +00:00
|
|
|
|
using (var workQueue = new WorkQueue())
|
|
|
|
|
{
|
|
|
|
|
validate = new ValidateModlist(workQueue);
|
|
|
|
|
validate.LoadAuthorPermissionsFromString(permissions);
|
|
|
|
|
validate.LoadServerWhitelist(server_whitelist);
|
|
|
|
|
}
|
2019-09-29 04:41:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestRightsFallthrough()
|
|
|
|
|
{
|
2019-10-12 22:15:20 +00:00
|
|
|
|
var permissions = validate.FilePermissions(new NexusDownloader.State
|
2019-09-29 04:41:47 +00:00
|
|
|
|
{
|
|
|
|
|
Author = "bill",
|
|
|
|
|
GameName = "Skyrim",
|
|
|
|
|
ModID = "42",
|
|
|
|
|
FileID = "33"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
permissions.CanExtractBSAs.AssertIsFalse();
|
|
|
|
|
permissions.CanModifyESPs.AssertIsFalse();
|
|
|
|
|
permissions.CanModifyAssets.AssertIsFalse();
|
|
|
|
|
permissions.CanUseInOtherGames.AssertIsFalse();
|
|
|
|
|
|
2019-10-12 22:15:20 +00:00
|
|
|
|
permissions = validate.FilePermissions(new NexusDownloader.State
|
2019-09-29 04:41:47 +00:00
|
|
|
|
{
|
|
|
|
|
Author = "bob",
|
|
|
|
|
GameName = "Skyrim",
|
|
|
|
|
ModID = "42",
|
|
|
|
|
FileID = "33"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
permissions.CanExtractBSAs.AssertIsTrue();
|
|
|
|
|
permissions.CanModifyESPs.AssertIsTrue();
|
|
|
|
|
permissions.CanModifyAssets.AssertIsTrue();
|
|
|
|
|
permissions.CanUseInOtherGames.AssertIsTrue();
|
|
|
|
|
|
2019-10-12 22:15:20 +00:00
|
|
|
|
permissions = validate.FilePermissions(new NexusDownloader.State
|
2019-09-29 04:41:47 +00:00
|
|
|
|
{
|
|
|
|
|
Author = "bill",
|
|
|
|
|
GameName = "Fallout4",
|
|
|
|
|
ModID = "42",
|
|
|
|
|
FileID = "33"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
permissions.CanExtractBSAs.AssertIsFalse();
|
|
|
|
|
permissions.CanModifyESPs.AssertIsTrue();
|
|
|
|
|
permissions.CanModifyAssets.AssertIsTrue();
|
|
|
|
|
permissions.CanUseInOtherGames.AssertIsTrue();
|
|
|
|
|
|
2019-10-12 22:15:20 +00:00
|
|
|
|
permissions = validate.FilePermissions(new NexusDownloader.State
|
2019-09-29 04:41:47 +00:00
|
|
|
|
{
|
|
|
|
|
Author = "bill",
|
|
|
|
|
GameName = "Skyrim",
|
|
|
|
|
ModID = "43",
|
|
|
|
|
FileID = "33"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
permissions.CanExtractBSAs.AssertIsFalse();
|
|
|
|
|
permissions.CanModifyESPs.AssertIsFalse();
|
|
|
|
|
permissions.CanModifyAssets.AssertIsTrue();
|
|
|
|
|
permissions.CanUseInOtherGames.AssertIsTrue();
|
|
|
|
|
|
2019-10-12 22:15:20 +00:00
|
|
|
|
permissions = validate.FilePermissions(new NexusDownloader.State
|
2019-09-29 04:41:47 +00:00
|
|
|
|
{
|
|
|
|
|
Author = "bill",
|
|
|
|
|
GameName = "Skyrim",
|
|
|
|
|
ModID = "42",
|
|
|
|
|
FileID = "31"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
permissions.CanExtractBSAs.AssertIsFalse();
|
|
|
|
|
permissions.CanModifyESPs.AssertIsFalse();
|
|
|
|
|
permissions.CanModifyAssets.AssertIsFalse();
|
|
|
|
|
permissions.CanUseInOtherGames.AssertIsTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestModValidation()
|
|
|
|
|
{
|
|
|
|
|
var modlist = new ModList
|
|
|
|
|
{
|
|
|
|
|
GameType = Game.Skyrim,
|
|
|
|
|
Archives = new List<Archive>
|
|
|
|
|
{
|
2019-10-12 22:15:20 +00:00
|
|
|
|
new Archive
|
2019-09-29 04:41:47 +00:00
|
|
|
|
{
|
2019-10-12 22:15:20 +00:00
|
|
|
|
State = new NexusDownloader.State
|
|
|
|
|
{
|
|
|
|
|
GameName = "Skyrim",
|
|
|
|
|
Author = "bill",
|
|
|
|
|
ModID = "42",
|
|
|
|
|
FileID = "33",
|
|
|
|
|
},
|
2019-09-29 04:41:47 +00:00
|
|
|
|
Hash = "DEADBEEF"
|
|
|
|
|
}
|
2019-10-12 22:15:20 +00:00
|
|
|
|
|
2019-09-29 04:41:47 +00:00
|
|
|
|
},
|
|
|
|
|
Directives = new List<Directive>
|
|
|
|
|
{
|
|
|
|
|
new FromArchive
|
|
|
|
|
{
|
|
|
|
|
ArchiveHashPath = new[] {"DEADBEEF", "foo\\bar\\baz.pex"},
|
|
|
|
|
To = "foo\\bar\\baz.pex"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
IEnumerable<string> errors;
|
|
|
|
|
|
|
|
|
|
// No errors, simple archive extraction
|
|
|
|
|
errors = validate.Validate(modlist);
|
|
|
|
|
Assert.AreEqual(errors.Count(), 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Error due to patched file
|
|
|
|
|
modlist.Directives[0] = new PatchedFromArchive
|
|
|
|
|
{
|
2019-10-01 22:39:25 +00:00
|
|
|
|
PatchID = Guid.NewGuid().ToString(),
|
2019-09-29 04:41:47 +00:00
|
|
|
|
ArchiveHashPath = new[] {"DEADBEEF", "foo\\bar\\baz.pex"},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
errors = validate.Validate(modlist);
|
|
|
|
|
Assert.AreEqual(errors.Count(), 1);
|
|
|
|
|
|
|
|
|
|
// Error due to extracted BSA file
|
|
|
|
|
modlist.Directives[0] = new FromArchive
|
|
|
|
|
{
|
|
|
|
|
ArchiveHashPath = new[] { "DEADBEEF", "foo.bsa", "foo\\bar\\baz.dds" },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
errors = validate.Validate(modlist);
|
|
|
|
|
Assert.AreEqual(errors.Count(), 1);
|
|
|
|
|
|
2019-10-01 22:39:25 +00:00
|
|
|
|
// No error since we're just installing the .bsa, not extracting it
|
|
|
|
|
modlist.Directives[0] = new FromArchive
|
|
|
|
|
{
|
|
|
|
|
ArchiveHashPath = new[] { "DEADBEEF", "foo.bsa"},
|
|
|
|
|
};
|
2019-09-29 04:41:47 +00:00
|
|
|
|
|
2019-10-01 22:39:25 +00:00
|
|
|
|
errors = validate.Validate(modlist);
|
|
|
|
|
Assert.AreEqual(0, errors.Count());
|
|
|
|
|
|
2019-09-29 04:41:47 +00:00
|
|
|
|
// Error due to game conversion
|
|
|
|
|
modlist.GameType = Game.SkyrimSpecialEdition;
|
|
|
|
|
modlist.Directives[0] = new FromArchive
|
|
|
|
|
{
|
|
|
|
|
ArchiveHashPath = new[] { "DEADBEEF", "foo\\bar\\baz.dds" },
|
|
|
|
|
};
|
|
|
|
|
errors = validate.Validate(modlist);
|
|
|
|
|
Assert.AreEqual(errors.Count(), 1);
|
|
|
|
|
|
2019-09-29 20:53:25 +00:00
|
|
|
|
// Error due to file downloaded from 3rd party
|
|
|
|
|
modlist.GameType = Game.Skyrim;
|
2019-10-12 22:15:20 +00:00
|
|
|
|
modlist.Archives[0] = new Archive()
|
2019-09-29 20:53:25 +00:00
|
|
|
|
{
|
2019-10-12 22:15:20 +00:00
|
|
|
|
State = new HTTPDownloader.State() { Url = "https://somebadplace.com" },
|
2019-09-29 20:53:25 +00:00
|
|
|
|
Hash = "DEADBEEF"
|
|
|
|
|
};
|
|
|
|
|
errors = validate.Validate(modlist);
|
2019-10-12 22:15:20 +00:00
|
|
|
|
Assert.AreEqual(1, errors.Count());
|
2019-09-29 20:53:25 +00:00
|
|
|
|
|
|
|
|
|
// Ok due to file downloaded from whitelisted 3rd party
|
|
|
|
|
modlist.GameType = Game.Skyrim;
|
2019-10-12 22:15:20 +00:00
|
|
|
|
modlist.Archives[0] = new Archive
|
2019-09-29 20:53:25 +00:00
|
|
|
|
{
|
2019-10-12 22:15:20 +00:00
|
|
|
|
State = new HTTPDownloader.State { Url = "https://somegoodplace.com/baz.7z" },
|
2019-09-29 20:53:25 +00:00
|
|
|
|
Hash = "DEADBEEF"
|
|
|
|
|
};
|
|
|
|
|
errors = validate.Validate(modlist);
|
2019-10-12 22:15:20 +00:00
|
|
|
|
Assert.AreEqual(0, errors.Count());
|
2019-09-29 20:53:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Error due to file downloaded from bad 3rd party
|
|
|
|
|
modlist.GameType = Game.Skyrim;
|
2019-10-12 22:15:20 +00:00
|
|
|
|
modlist.Archives[0] = new Archive
|
2019-09-29 20:53:25 +00:00
|
|
|
|
{
|
2019-10-12 22:15:20 +00:00
|
|
|
|
State = new GoogleDriveDownloader.State { Id = "bleg"},
|
2019-09-29 20:53:25 +00:00
|
|
|
|
Hash = "DEADBEEF"
|
|
|
|
|
};
|
|
|
|
|
errors = validate.Validate(modlist);
|
|
|
|
|
Assert.AreEqual(errors.Count(), 1);
|
|
|
|
|
|
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;
|
2019-10-12 22:15:20 +00:00
|
|
|
|
modlist.Archives[0] = new Archive
|
2019-09-29 20:53:25 +00:00
|
|
|
|
{
|
2019-10-12 22:15:20 +00:00
|
|
|
|
State = new GoogleDriveDownloader.State { Id = "googleDEADBEEF" },
|
2019-09-29 20:53:25 +00:00
|
|
|
|
Hash = "DEADBEEF"
|
|
|
|
|
};
|
|
|
|
|
errors = validate.Validate(modlist);
|
2019-10-12 22:15:20 +00:00
|
|
|
|
Assert.AreEqual(0, errors.Count());
|
2019-09-29 20:53:25 +00:00
|
|
|
|
|
2019-09-29 04:41:47 +00:00
|
|
|
|
}
|
2019-10-03 03:23:11 +00:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void CanLoadFromGithub()
|
|
|
|
|
{
|
2019-12-07 02:05:24 +00:00
|
|
|
|
using (var workQueue = new WorkQueue())
|
|
|
|
|
{
|
|
|
|
|
new ValidateModlist(workQueue).LoadListsFromGithub();
|
|
|
|
|
}
|
2019-10-03 03:23:11 +00:00
|
|
|
|
}
|
2019-09-29 04:41:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|