Integration tests use the api key now
This commit is contained in:
parent
e19e523824
commit
d19a755fb1
|
@ -32,7 +32,7 @@ namespace NzbDrone.Core.Configuration
|
||||||
|
|
||||||
public class ConfigFileProvider : IConfigFileProvider
|
public class ConfigFileProvider : IConfigFileProvider
|
||||||
{
|
{
|
||||||
private const string CONFIG_ELEMENT_NAME = "Config";
|
public const string CONFIG_ELEMENT_NAME = "Config";
|
||||||
|
|
||||||
private readonly IEventAggregator _eventAggregator;
|
private readonly IEventAggregator _eventAggregator;
|
||||||
private readonly ICached<string> _cache;
|
private readonly ICached<string> _cache;
|
||||||
|
@ -214,6 +214,8 @@ namespace NzbDrone.Core.Configuration
|
||||||
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
|
var xDoc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
|
||||||
xDoc.Add(new XElement(CONFIG_ELEMENT_NAME));
|
xDoc.Add(new XElement(CONFIG_ELEMENT_NAME));
|
||||||
xDoc.Save(_configFile);
|
xDoc.Save(_configFile);
|
||||||
|
|
||||||
|
SaveConfigDictionary(GetConfigDictionary());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,10 @@ namespace NzbDrone.Integration.Test.Client
|
||||||
{
|
{
|
||||||
private readonly IRestClient _restClient;
|
private readonly IRestClient _restClient;
|
||||||
private readonly string _resource;
|
private readonly string _resource;
|
||||||
|
private readonly string _apiKey;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public ClientBase(IRestClient restClient, string resource = null)
|
public ClientBase(IRestClient restClient, string apiKey, string resource = null)
|
||||||
{
|
{
|
||||||
if (resource == null)
|
if (resource == null)
|
||||||
{
|
{
|
||||||
|
@ -26,6 +26,7 @@ namespace NzbDrone.Integration.Test.Client
|
||||||
|
|
||||||
_restClient = restClient;
|
_restClient = restClient;
|
||||||
_resource = resource;
|
_resource = resource;
|
||||||
|
_apiKey = apiKey;
|
||||||
|
|
||||||
_logger = LogManager.GetLogger("REST");
|
_logger = LogManager.GetLogger("REST");
|
||||||
}
|
}
|
||||||
|
@ -88,10 +89,14 @@ namespace NzbDrone.Integration.Test.Client
|
||||||
|
|
||||||
public RestRequest BuildRequest(string command = "")
|
public RestRequest BuildRequest(string command = "")
|
||||||
{
|
{
|
||||||
return new RestRequest(_resource + "/" + command.Trim('/'))
|
var request = new RestRequest(_resource + "/" + command.Trim('/'))
|
||||||
{
|
{
|
||||||
RequestFormat = DataFormat.Json
|
RequestFormat = DataFormat.Json,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
request.AddHeader("Authorization", _apiKey);
|
||||||
|
|
||||||
|
return request;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Get<T>(IRestRequest request, HttpStatusCode statusCode = HttpStatusCode.OK) where T : class, new()
|
public T Get<T>(IRestRequest request, HttpStatusCode statusCode = HttpStatusCode.OK) where T : class, new()
|
||||||
|
|
|
@ -6,8 +6,8 @@ namespace NzbDrone.Integration.Test.Client
|
||||||
{
|
{
|
||||||
public class EpisodeClient : ClientBase<EpisodeResource>
|
public class EpisodeClient : ClientBase<EpisodeResource>
|
||||||
{
|
{
|
||||||
public EpisodeClient(IRestClient restClient)
|
public EpisodeClient(IRestClient restClient, string apiKey)
|
||||||
: base(restClient, "episodes")
|
: base(restClient, apiKey, "episodes")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,9 @@ namespace NzbDrone.Integration.Test.Client
|
||||||
{
|
{
|
||||||
public class IndexerClient : ClientBase<IndexerResource>
|
public class IndexerClient : ClientBase<IndexerResource>
|
||||||
{
|
{
|
||||||
public IndexerClient(IRestClient restClient)
|
public IndexerClient(IRestClient restClient, string apiKey)
|
||||||
: base(restClient)
|
: base(restClient, apiKey)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,12 +5,9 @@ namespace NzbDrone.Integration.Test.Client
|
||||||
{
|
{
|
||||||
public class ReleaseClient : ClientBase<ReleaseResource>
|
public class ReleaseClient : ClientBase<ReleaseResource>
|
||||||
{
|
{
|
||||||
public ReleaseClient(IRestClient restClient)
|
public ReleaseClient(IRestClient restClient, string apiKey)
|
||||||
: base(restClient)
|
: base(restClient, apiKey)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@ namespace NzbDrone.Integration.Test.Client
|
||||||
{
|
{
|
||||||
public class SeriesClient : ClientBase<SeriesResource>
|
public class SeriesClient : ClientBase<SeriesResource>
|
||||||
{
|
{
|
||||||
public SeriesClient(IRestClient restClient)
|
public SeriesClient(IRestClient restClient, string apiKey)
|
||||||
: base(restClient)
|
: base(restClient, apiKey)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,14 +27,11 @@ namespace NzbDrone.Integration.Test.Client
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class SystemInfoClient : ClientBase<SeriesResource>
|
public class SystemInfoClient : ClientBase<SeriesResource>
|
||||||
{
|
{
|
||||||
public SystemInfoClient(IRestClient restClient)
|
public SystemInfoClient(IRestClient restClient, string apiKey)
|
||||||
: base(restClient)
|
: base(restClient, apiKey)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,22 +47,21 @@ namespace NzbDrone.Integration.Test
|
||||||
_runner = new NzbDroneRunner();
|
_runner = new NzbDroneRunner();
|
||||||
_runner.KillAll();
|
_runner.KillAll();
|
||||||
|
|
||||||
InitRestClients();
|
|
||||||
|
|
||||||
_runner.Start();
|
_runner.Start();
|
||||||
|
InitRestClients();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitRestClients()
|
private void InitRestClients()
|
||||||
{
|
{
|
||||||
RestClient = new RestClient("http://localhost:8989/api");
|
RestClient = new RestClient("http://localhost:8989/api");
|
||||||
Series = new SeriesClient(RestClient);
|
Series = new SeriesClient(RestClient, _runner.ApiKey);
|
||||||
Releases = new ReleaseClient(RestClient);
|
Releases = new ReleaseClient(RestClient, _runner.ApiKey);
|
||||||
RootFolders = new ClientBase<RootFolderResource>(RestClient);
|
RootFolders = new ClientBase<RootFolderResource>(RestClient, _runner.ApiKey);
|
||||||
Commands = new ClientBase<CommandResource>(RestClient);
|
Commands = new ClientBase<CommandResource>(RestClient, _runner.ApiKey);
|
||||||
History = new ClientBase<HistoryResource>(RestClient);
|
History = new ClientBase<HistoryResource>(RestClient, _runner.ApiKey);
|
||||||
Indexers = new IndexerClient(RestClient);
|
Indexers = new IndexerClient(RestClient, _runner.ApiKey);
|
||||||
Episodes = new EpisodeClient(RestClient);
|
Episodes = new EpisodeClient(RestClient, _runner.ApiKey);
|
||||||
NamingConfig = new ClientBase<NamingConfigResource>(RestClient, "config/naming");
|
NamingConfig = new ClientBase<NamingConfigResource>(RestClient, _runner.ApiKey, "config/naming");
|
||||||
}
|
}
|
||||||
|
|
||||||
//[TestFixtureTearDown]
|
//[TestFixtureTearDown]
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Xml.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Common;
|
using NzbDrone.Common;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
using RestSharp;
|
using RestSharp;
|
||||||
|
|
||||||
namespace NzbDrone.Integration.Test
|
namespace NzbDrone.Integration.Test
|
||||||
|
@ -15,16 +18,18 @@ namespace NzbDrone.Integration.Test
|
||||||
private readonly IRestClient _restClient;
|
private readonly IRestClient _restClient;
|
||||||
private Process _nzbDroneProcess;
|
private Process _nzbDroneProcess;
|
||||||
|
|
||||||
|
public string AppData { get; private set; }
|
||||||
|
public string ApiKey { get; private set; }
|
||||||
|
|
||||||
public NzbDroneRunner(int port = 8989)
|
public NzbDroneRunner(int port = 8989)
|
||||||
{
|
{
|
||||||
_processProvider = new ProcessProvider();
|
_processProvider = new ProcessProvider();
|
||||||
_restClient = new RestClient("http://localhost:8989/api");
|
_restClient = new RestClient("http://localhost:8989/api");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
AppDate = Path.Combine(Directory.GetCurrentDirectory(), "_intg_" + DateTime.Now.Ticks);
|
AppData = Path.Combine(Directory.GetCurrentDirectory(), "_intg_" + DateTime.Now.Ticks);
|
||||||
|
|
||||||
var nzbdroneConsoleExe = "NzbDrone.Console.exe";
|
var nzbdroneConsoleExe = "NzbDrone.Console.exe";
|
||||||
|
|
||||||
|
@ -33,7 +38,6 @@ namespace NzbDrone.Integration.Test
|
||||||
nzbdroneConsoleExe = "NzbDrone.exe";
|
nzbdroneConsoleExe = "NzbDrone.exe";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (BuildInfo.IsDebug)
|
if (BuildInfo.IsDebug)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -53,8 +57,12 @@ namespace NzbDrone.Integration.Test
|
||||||
Assert.Fail("Process has exited");
|
Assert.Fail("Process has exited");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetApiKey();
|
||||||
|
|
||||||
var statusCall = _restClient.Get(new RestRequest("system/status"));
|
var request = new RestRequest("system/status");
|
||||||
|
request.AddHeader("Authorization", ApiKey);
|
||||||
|
|
||||||
|
var statusCall = _restClient.Get(request);
|
||||||
|
|
||||||
if (statusCall.ResponseStatus == ResponseStatus.Completed)
|
if (statusCall.ResponseStatus == ResponseStatus.Completed)
|
||||||
{
|
{
|
||||||
|
@ -76,7 +84,7 @@ namespace NzbDrone.Integration.Test
|
||||||
|
|
||||||
private void Start(string outputNzbdroneConsoleExe)
|
private void Start(string outputNzbdroneConsoleExe)
|
||||||
{
|
{
|
||||||
var args = "-nobrowser -data=\"" + AppDate + "\"";
|
var args = "-nobrowser -data=\"" + AppData + "\"";
|
||||||
_nzbDroneProcess = _processProvider.Start(outputNzbdroneConsoleExe, args, OnOutputDataReceived, OnOutputDataReceived);
|
_nzbDroneProcess = _processProvider.Start(outputNzbdroneConsoleExe, args, OnOutputDataReceived, OnOutputDataReceived);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -91,7 +99,16 @@ namespace NzbDrone.Integration.Test
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetApiKey()
|
||||||
|
{
|
||||||
|
var configFile = Path.Combine(AppData, "config.xml");
|
||||||
|
|
||||||
public string AppDate { get; private set; }
|
if (!String.IsNullOrWhiteSpace(ApiKey)) return;
|
||||||
|
if (!File.Exists(configFile)) return;
|
||||||
|
|
||||||
|
var xDoc = XDocument.Load(configFile);
|
||||||
|
var config = xDoc.Descendants(ConfigFileProvider.CONFIG_ELEMENT_NAME).Single();
|
||||||
|
ApiKey = config.Descendants("ApiKey").Single().Value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue