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
commit 7a80c81ffb
3 changed files with 47 additions and 3 deletions

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 @@ namespace NzbDrone.Core.Providers
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 @@ namespace NzbDrone.Core.Providers
{
_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;
}
}
}
}