2019-10-12 18:03:45 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
using Wabbajack.Common;
|
2019-10-16 03:10:34 +00:00
|
|
|
|
using Wabbajack.Lib;
|
|
|
|
|
using Wabbajack.Lib.Downloaders;
|
2019-11-05 05:08:47 +00:00
|
|
|
|
using Wabbajack.Lib.NexusApi;
|
2019-10-16 03:10:34 +00:00
|
|
|
|
using Wabbajack.Lib.Validation;
|
2019-10-12 18:03:45 +00:00
|
|
|
|
using File = Alphaleonis.Win32.Filesystem.File;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Test
|
|
|
|
|
{
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class DownloaderTests
|
|
|
|
|
{
|
2019-11-05 05:08:47 +00:00
|
|
|
|
[TestInitialize]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-13 14:18:21 +00:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestAllPrepares()
|
|
|
|
|
{
|
|
|
|
|
DownloadDispatcher.Downloaders.Do(d => d.Prepare());
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-12 18:03:45 +00:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MegaDownload()
|
|
|
|
|
{
|
|
|
|
|
var ini = @"[General]
|
|
|
|
|
directURL=https://mega.nz/#!CsMSFaaJ!-uziC4mbJPRy2e4pPk8Gjb3oDT_38Be9fzZ6Ld4NL-k";
|
|
|
|
|
|
2019-10-12 21:37:16 +00:00
|
|
|
|
var state = (AbstractDownloadState)DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
2019-10-12 18:03:45 +00:00
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
2019-10-16 11:44:45 +00:00
|
|
|
|
var url_state = DownloadDispatcher.ResolveArchive(
|
|
|
|
|
"https://mega.nz/#!CsMSFaaJ!-uziC4mbJPRy2e4pPk8Gjb3oDT_38Be9fzZ6Ld4NL-k");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("https://mega.nz/#!CsMSFaaJ!-uziC4mbJPRy2e4pPk8Gjb3oDT_38Be9fzZ6Ld4NL-k",
|
|
|
|
|
((MegaDownloader.State)url_state).Url);
|
|
|
|
|
|
|
|
|
|
|
2019-10-12 18:03:45 +00:00
|
|
|
|
var converted = state.ViaJSON();
|
|
|
|
|
Assert.IsTrue(converted.Verify());
|
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist {AllowedPrefixes = new List<string>{"https://mega.nz/#!CsMSFaaJ!-uziC4mbJPRy2e4pPk8Gjb3oDT_38Be9fzZ6Ld4NL-k" } }));
|
|
|
|
|
Assert.IsFalse(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>{ "blerg" }}));
|
|
|
|
|
|
2019-10-12 21:37:16 +00:00
|
|
|
|
converted.Download(new Archive {Name = "MEGA Test.txt"}, filename);
|
2019-10-12 18:03:45 +00:00
|
|
|
|
|
2019-10-31 03:40:33 +00:00
|
|
|
|
Assert.AreEqual("eSIyd+KOG3s=", Utils.FileHash(filename));
|
2019-10-12 18:03:45 +00:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
|
|
|
|
}
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void DropboxTests()
|
|
|
|
|
{
|
|
|
|
|
var ini = @"[General]
|
|
|
|
|
directURL=https://www.dropbox.com/s/5hov3m2pboppoc2/WABBAJACK_TEST_FILE.txt?dl=0";
|
|
|
|
|
|
|
|
|
|
var state = (AbstractDownloadState)DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
2019-10-16 11:44:45 +00:00
|
|
|
|
var url_state = DownloadDispatcher.ResolveArchive(
|
|
|
|
|
"https://www.dropbox.com/s/5hov3m2pboppoc2/WABBAJACK_TEST_FILE.txt?dl=0");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("https://www.dropbox.com/s/5hov3m2pboppoc2/WABBAJACK_TEST_FILE.txt?dl=1",
|
|
|
|
|
((HTTPDownloader.State)url_state).Url);
|
|
|
|
|
|
2019-10-12 21:37:16 +00:00
|
|
|
|
var converted = state.ViaJSON();
|
|
|
|
|
Assert.IsTrue(converted.Verify());
|
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string> { "https://www.dropbox.com/s/5hov3m2pboppoc2/WABBAJACK_TEST_FILE.txt?" } }));
|
|
|
|
|
Assert.IsFalse(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string> { "blerg" } }));
|
|
|
|
|
|
|
|
|
|
converted.Download(new Archive { Name = "MEGA Test.txt" }, filename);
|
|
|
|
|
|
2019-10-31 03:40:33 +00:00
|
|
|
|
Assert.AreEqual("eSIyd+KOG3s=", Utils.FileHash(filename));
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void GoogleDriveTests()
|
|
|
|
|
{
|
|
|
|
|
var ini = @"[General]
|
|
|
|
|
directURL=https://drive.google.com/file/d/1grLRTrpHxlg7VPxATTFNfq2OkU_Plvh_/view?usp=sharing";
|
|
|
|
|
|
|
|
|
|
var state = (AbstractDownloadState)DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
2019-10-16 11:44:45 +00:00
|
|
|
|
var url_state = DownloadDispatcher.ResolveArchive(
|
|
|
|
|
"https://drive.google.com/file/d/1grLRTrpHxlg7VPxATTFNfq2OkU_Plvh_/view?usp=sharing");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("1grLRTrpHxlg7VPxATTFNfq2OkU_Plvh_",
|
|
|
|
|
((GoogleDriveDownloader.State)url_state).Id);
|
|
|
|
|
|
2019-10-12 21:37:16 +00:00
|
|
|
|
var converted = state.ViaJSON();
|
|
|
|
|
Assert.IsTrue(converted.Verify());
|
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { GoogleIDs = new List<string> { "1grLRTrpHxlg7VPxATTFNfq2OkU_Plvh_" } }));
|
|
|
|
|
Assert.IsFalse(converted.IsWhitelisted(new ServerWhitelist { GoogleIDs = new List<string>()}));
|
|
|
|
|
|
|
|
|
|
converted.Download(new Archive { Name = "MEGA Test.txt" }, filename);
|
|
|
|
|
|
2019-10-31 03:40:33 +00:00
|
|
|
|
Assert.AreEqual("eSIyd+KOG3s=", Utils.FileHash(filename));
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void HttpDownload()
|
|
|
|
|
{
|
|
|
|
|
var ini = @"[General]
|
2019-10-24 01:19:11 +00:00
|
|
|
|
directURL=http://build.wabbajack.org/WABBAJACK_TEST_FILE.txt";
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
var state = (AbstractDownloadState)DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
2019-10-24 01:19:11 +00:00
|
|
|
|
var url_state = DownloadDispatcher.ResolveArchive("http://build.wabbajack.org/WABBAJACK_TEST_FILE.txt");
|
2019-10-16 11:44:45 +00:00
|
|
|
|
|
2019-10-24 01:19:11 +00:00
|
|
|
|
Assert.AreEqual("http://build.wabbajack.org/WABBAJACK_TEST_FILE.txt",
|
2019-10-16 11:44:45 +00:00
|
|
|
|
((HTTPDownloader.State)url_state).Url);
|
|
|
|
|
|
2019-10-12 21:37:16 +00:00
|
|
|
|
var converted = state.ViaJSON();
|
|
|
|
|
Assert.IsTrue(converted.Verify());
|
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
2019-10-24 01:19:11 +00:00
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string> { "http://build.wabbajack.org/" } }));
|
|
|
|
|
Assert.IsFalse(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
|
|
|
|
|
|
|
|
|
|
converted.Download(new Archive { Name = "MEGA Test.txt" }, filename);
|
|
|
|
|
|
2019-10-31 03:40:33 +00:00
|
|
|
|
Assert.AreEqual("eSIyd+KOG3s=", Utils.FileHash(filename));
|
2019-10-24 01:19:11 +00:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-06 23:52:48 +00:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void ManualDownload()
|
|
|
|
|
{
|
|
|
|
|
var ini = @"[General]
|
|
|
|
|
manualURL=http://build.wabbajack.org/WABBAJACK_TEST_FILE.zip";
|
|
|
|
|
|
|
|
|
|
var state = (AbstractDownloadState)DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
|
|
|
|
var converted = state.ViaJSON();
|
|
|
|
|
Assert.IsTrue(converted.Verify());
|
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string> { "http://build.wabbajack.org/" } }));
|
|
|
|
|
|
|
|
|
|
converted.Download(new Archive { Name = "WABBAJACK_TEST_FILE.zip", Size = 20, Hash = "eSIyd+KOG3s="}, filename);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("eSIyd+KOG3s=", Utils.FileHash(filename));
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 01:19:11 +00:00
|
|
|
|
[TestMethod]
|
|
|
|
|
public void MediaFireDownload()
|
|
|
|
|
{
|
|
|
|
|
var ini = @"[General]
|
2019-11-05 05:08:47 +00:00
|
|
|
|
directURL=http://www.mediafire.com/file/agiqzm1xwebczpx/WABBAJACK_TEST_FILE.txt";
|
2019-10-24 01:19:11 +00:00
|
|
|
|
|
2019-11-05 05:08:47 +00:00
|
|
|
|
var state = (AbstractDownloadState) DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
2019-10-24 01:19:11 +00:00
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
|
|
|
|
var url_state = DownloadDispatcher.ResolveArchive(
|
|
|
|
|
"http://www.mediafire.com/file/agiqzm1xwebczpx/WABBAJACK_TEST_FILE.txt");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("http://www.mediafire.com/file/agiqzm1xwebczpx/WABBAJACK_TEST_FILE.txt",
|
2019-11-05 05:08:47 +00:00
|
|
|
|
((MediaFireDownloader.State) url_state).Url);
|
2019-10-24 01:19:11 +00:00
|
|
|
|
|
|
|
|
|
var converted = state.ViaJSON();
|
|
|
|
|
Assert.IsTrue(converted.Verify());
|
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
2019-11-05 05:08:47 +00:00
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist
|
|
|
|
|
{AllowedPrefixes = new List<string> {"http://www.mediafire.com/file/agiqzm1xwebczpx/"}}));
|
|
|
|
|
Assert.IsFalse(converted.IsWhitelisted(new ServerWhitelist {AllowedPrefixes = new List<string>()}));
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-11-05 05:08:47 +00:00
|
|
|
|
converted.Download(new Archive {Name = "Media Fire Test.txt"}, filename);
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-10-24 01:19:11 +00:00
|
|
|
|
Assert.AreEqual(File.ReadAllText(filename), "Cheese for Everyone!");
|
2019-11-05 05:08:47 +00:00
|
|
|
|
|
2019-10-12 21:37:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void NexusDownload()
|
|
|
|
|
{
|
2019-11-05 05:08:47 +00:00
|
|
|
|
var old_val = NexusApiClient.UseLocalCache;
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
NexusApiClient.UseLocalCache = false;
|
|
|
|
|
var ini = @"[General]
|
2019-10-12 21:37:16 +00:00
|
|
|
|
gameName=SkyrimSE
|
|
|
|
|
modID = 12604
|
|
|
|
|
fileID=35407";
|
|
|
|
|
|
2019-11-05 05:08:47 +00:00
|
|
|
|
var state = (AbstractDownloadState)DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-11-05 05:08:47 +00:00
|
|
|
|
Assert.IsNotNull(state);
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-10-16 11:44:45 +00:00
|
|
|
|
|
2019-11-05 05:08:47 +00:00
|
|
|
|
var converted = state.ViaJSON();
|
|
|
|
|
Assert.IsTrue(converted.Verify());
|
|
|
|
|
// Exercise the cache code
|
|
|
|
|
Assert.IsTrue(converted.Verify());
|
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string> () }));
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-11-05 05:08:47 +00:00
|
|
|
|
converted.Download(new Archive { Name = "SkyUI.7z" }, filename);
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-11-05 05:08:47 +00:00
|
|
|
|
Assert.AreEqual(filename.FileHash(), "dF2yafV2Oks=");
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
2019-11-05 05:08:47 +00:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
NexusApiClient.UseLocalCache = old_val;
|
|
|
|
|
}
|
2019-10-12 21:37:16 +00:00
|
|
|
|
}
|
2019-10-12 22:31:07 +00:00
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void ModDbTests()
|
|
|
|
|
{
|
|
|
|
|
var ini = @"[General]
|
|
|
|
|
directURL=https://www.moddb.com/downloads/start/124908?referer=https%3A%2F%2Fwww.moddb.com%2Fmods%2Fautopause";
|
|
|
|
|
|
|
|
|
|
var state = (AbstractDownloadState)DownloadDispatcher.ResolveArchive(ini.LoadIniString());
|
|
|
|
|
|
|
|
|
|
Assert.IsNotNull(state);
|
|
|
|
|
|
2019-10-16 11:44:45 +00:00
|
|
|
|
var url_state = DownloadDispatcher.ResolveArchive(
|
|
|
|
|
"https://www.moddb.com/downloads/start/124908?referer=https%3A%2F%2Fwww.moddb.com%2Fmods%2Fautopause");
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual("https://www.moddb.com/downloads/start/124908?referer=https%3A%2F%2Fwww.moddb.com%2Fmods%2Fautopause",
|
|
|
|
|
((ModDBDownloader.State)url_state).Url);
|
|
|
|
|
|
2019-10-12 22:31:07 +00:00
|
|
|
|
var converted = state.ViaJSON();
|
|
|
|
|
Assert.IsTrue(converted.Verify());
|
|
|
|
|
var filename = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(converted.IsWhitelisted(new ServerWhitelist { AllowedPrefixes = new List<string>() }));
|
|
|
|
|
|
|
|
|
|
converted.Download(new Archive { Name = "moddbtest.7z" }, filename);
|
|
|
|
|
|
2019-10-31 03:40:33 +00:00
|
|
|
|
Assert.AreEqual("2lZt+1h6wxM=", filename.FileHash());
|
2019-10-12 22:31:07 +00:00
|
|
|
|
}
|
2019-10-12 18:03:45 +00:00
|
|
|
|
}
|
2019-10-12 21:37:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-12 18:03:45 +00:00
|
|
|
|
}
|