1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-09-19 07:52:33 +02:00

New: Newznab providers will be rejected if they are not valid addresses.

Tests added for checking DNS.
This commit is contained in:
Mark McDowall 2012-05-11 10:26:56 -07:00
parent 7e5445fa3a
commit 7a80c81ffb
3 changed files with 47 additions and 3 deletions

View File

@ -9,6 +9,7 @@
using NzbDrone.Core.Repository;
using NzbDrone.Core.Repository.Quality;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.ProviderTests
@ -295,5 +296,19 @@ public void InitializeNewznabIndexers_should_not_blow_up_if_more_than_one_indexe
var result = db.Fetch<NewznabDefinition>();
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);
}
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Ninject;
using NLog;
using NzbDrone.Core.Providers.Indexer;
@ -56,7 +57,11 @@ public virtual void SaveAll(IEnumerable<NewznabDefinition> definitions)
var definitionsList = definitions.ToList();
//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);
}
@ -99,5 +104,22 @@ public virtual void Delete(int 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;
}
}
}
}

View File

@ -391,8 +391,15 @@ public JsonResult SaveIndexers(IndexerSettingsModel data)
_configProvider.FileSharingTalkUid = data.FileSharingTalkUid;
_configProvider.FileSharingTalkSecret = data.FileSharingTalkSecret;
if (data.NewznabDefinitions != null)
_newznabProvider.SaveAll(data.NewznabDefinitions);
try
{
if (data.NewznabDefinitions != null)
_newznabProvider.SaveAll(data.NewznabDefinitions);
}
catch(Exception)
{
return JsonNotificationResult.Oops("Invalid Nzbnab Indexer found, please check your settings");
}
return GetSuccessResult();
}