|
|
|
@ -9,6 +9,7 @@ using NLog;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
|
|
|
using NzbDrone.Common.Processes;
|
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
|
using RestSharp;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Test.Common
|
|
|
|
@ -30,7 +31,10 @@ namespace NzbDrone.Test.Common
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
AppData = Path.Combine(TestContext.CurrentContext.TestDirectory, "_intg_" + DateTime.Now.Ticks);
|
|
|
|
|
AppData = Path.Combine(TestContext.CurrentContext.TestDirectory, "_intg_" + TestBase.GetUID());
|
|
|
|
|
Directory.CreateDirectory(AppData);
|
|
|
|
|
|
|
|
|
|
GenerateApiKey();
|
|
|
|
|
|
|
|
|
|
var sonarrConsoleExe = OsInfo.IsWindows ? "Sonarr.Console.exe" : "Sonarr.exe";
|
|
|
|
|
|
|
|
|
@ -52,8 +56,6 @@ namespace NzbDrone.Test.Common
|
|
|
|
|
Assert.Fail("Process has exited");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetApiKey();
|
|
|
|
|
|
|
|
|
|
var request = new RestRequest("system/status");
|
|
|
|
|
request.AddHeader("Authorization", ApiKey);
|
|
|
|
|
request.AddHeader("X-Api-Key", ApiKey);
|
|
|
|
@ -73,6 +75,8 @@ namespace NzbDrone.Test.Common
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void KillAll()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (_nzbDroneProcess != null)
|
|
|
|
|
{
|
|
|
|
@ -82,6 +86,14 @@ namespace NzbDrone.Test.Common
|
|
|
|
|
_processProvider.KillAll(ProcessProvider.SONARR_CONSOLE_PROCESS_NAME);
|
|
|
|
|
_processProvider.KillAll(ProcessProvider.SONARR_PROCESS_NAME);
|
|
|
|
|
}
|
|
|
|
|
catch (InvalidOperationException)
|
|
|
|
|
{
|
|
|
|
|
// May happen if the process closes while being closed
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TestBase.DeleteTempFolder(AppData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Start(string outputNzbdroneConsoleExe)
|
|
|
|
|
{
|
|
|
|
@ -100,33 +112,25 @@ namespace NzbDrone.Test.Common
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetApiKey()
|
|
|
|
|
private void GenerateApiKey()
|
|
|
|
|
{
|
|
|
|
|
var configFile = Path.Combine(AppData, "config.xml");
|
|
|
|
|
var attempts = 0;
|
|
|
|
|
|
|
|
|
|
while (ApiKey == null && attempts < 50)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(configFile))
|
|
|
|
|
{
|
|
|
|
|
var apiKeyElement = XDocument.Load(configFile)
|
|
|
|
|
.XPathSelectElement("Config/ApiKey");
|
|
|
|
|
if (apiKeyElement != null)
|
|
|
|
|
{
|
|
|
|
|
ApiKey = apiKeyElement.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (XmlException ex)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Error getting API Key from XML file: " + ex.Message, ex);
|
|
|
|
|
}
|
|
|
|
|
// Generate and set the api key so we don't have to poll the config file
|
|
|
|
|
var apiKey = Guid.NewGuid().ToString().Replace("-", "");
|
|
|
|
|
|
|
|
|
|
attempts++;
|
|
|
|
|
Thread.Sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
var xDoc = new XDocument(
|
|
|
|
|
new XDeclaration("1.0", "utf-8", "yes"),
|
|
|
|
|
new XElement(ConfigFileProvider.CONFIG_ELEMENT_NAME,
|
|
|
|
|
new XElement(nameof(ConfigFileProvider.ApiKey), apiKey)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
var data = xDoc.ToString();
|
|
|
|
|
|
|
|
|
|
File.WriteAllText(configFile, data);
|
|
|
|
|
|
|
|
|
|
ApiKey = apiKey;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|