New: Newznab providers will be rejected if they are not valid addresses.
Tests added for checking DNS.
This commit is contained in:
parent
7e5445fa3a
commit
7a80c81ffb
|
@ -9,6 +9,7 @@ using NzbDrone.Core.Providers;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
using NzbDrone.Core.Repository.Quality;
|
using NzbDrone.Core.Repository.Quality;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
using NzbDrone.Test.Common.AutoMoq;
|
using NzbDrone.Test.Common.AutoMoq;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Test.ProviderTests
|
namespace NzbDrone.Core.Test.ProviderTests
|
||||||
|
@ -295,5 +296,19 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||||
var result = db.Fetch<NewznabDefinition>();
|
var result = db.Fetch<NewznabDefinition>();
|
||||||
result.Should().HaveCount(2);
|
result.Should().HaveCount(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CheckHostname_should_do_nothing_if_hostname_is_valid()
|
||||||
|
{
|
||||||
|
Mocker.Resolve<NewznabProvider>().CheckHostname("http://www.google.com");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
[ExpectedException("System.Net.Sockets.SocketException")]
|
||||||
|
public void CheckHostname_should_log_error_and_throw_exception_if_dnsHostname_is_invalid()
|
||||||
|
{
|
||||||
|
Mocker.Resolve<NewznabProvider>().CheckHostname("http://BadName");
|
||||||
|
ExceptionVerification.ExpectedErrors(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Core.Providers.Indexer;
|
using NzbDrone.Core.Providers.Indexer;
|
||||||
|
@ -56,7 +57,11 @@ namespace NzbDrone.Core.Providers
|
||||||
var definitionsList = definitions.ToList();
|
var definitionsList = definitions.ToList();
|
||||||
|
|
||||||
//Cleanup the URL for each definition
|
//Cleanup the URL for each definition
|
||||||
definitionsList.ForEach(p => p.Url = (new Uri(p.Url).ParentUriString()));
|
foreach(var newznabDefinition in definitionsList)
|
||||||
|
{
|
||||||
|
CheckHostname(newznabDefinition.Url);
|
||||||
|
newznabDefinition.Url = new Uri(newznabDefinition.Url).ParentUriString();
|
||||||
|
}
|
||||||
|
|
||||||
_database.UpdateMany(definitionsList);
|
_database.UpdateMany(definitionsList);
|
||||||
}
|
}
|
||||||
|
@ -99,5 +104,22 @@ namespace NzbDrone.Core.Providers
|
||||||
{
|
{
|
||||||
_database.Delete<NewznabDefinition>(id);
|
_database.Delete<NewznabDefinition>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void CheckHostname(string url)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var uri = new Uri(url);
|
||||||
|
var hostname = uri.DnsSafeHost;
|
||||||
|
|
||||||
|
Dns.GetHostEntry(hostname);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Error("Invalid address {0}, please correct the site URL.", url);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -391,8 +391,15 @@ namespace NzbDrone.Web.Controllers
|
||||||
_configProvider.FileSharingTalkUid = data.FileSharingTalkUid;
|
_configProvider.FileSharingTalkUid = data.FileSharingTalkUid;
|
||||||
_configProvider.FileSharingTalkSecret = data.FileSharingTalkSecret;
|
_configProvider.FileSharingTalkSecret = data.FileSharingTalkSecret;
|
||||||
|
|
||||||
if (data.NewznabDefinitions != null)
|
try
|
||||||
_newznabProvider.SaveAll(data.NewznabDefinitions);
|
{
|
||||||
|
if (data.NewznabDefinitions != null)
|
||||||
|
_newznabProvider.SaveAll(data.NewznabDefinitions);
|
||||||
|
}
|
||||||
|
catch(Exception)
|
||||||
|
{
|
||||||
|
return JsonNotificationResult.Oops("Invalid Nzbnab Indexer found, please check your settings");
|
||||||
|
}
|
||||||
|
|
||||||
return GetSuccessResult();
|
return GetSuccessResult();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue