From 02c68bd3875072774e9cf3020717792f9305635c Mon Sep 17 00:00:00 2001 From: kayone Date: Mon, 2 Dec 2013 14:11:17 -0800 Subject: [PATCH] fixed newznab validation when URL is null. --- .../NewznabTests/NewznabSettingFixture.cs | 20 ++++++++++++++++++- .../Indexers/Newznab/NewznabSettings.cs | 5 +++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabSettingFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabSettingFixture.cs index 7ef91def5..4bd26817d 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabSettingFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/NewznabTests/NewznabSettingFixture.cs @@ -21,7 +21,25 @@ namespace NzbDrone.Core.Test.IndexerTests.NewznabTests setting.Validate().IsValid.Should().BeFalse(); setting.Validate().Errors.Should().Contain(c => c.PropertyName == "ApiKey"); - + + } + + [TestCase("")] + [TestCase(" ")] + [TestCase(null)] + public void invalid_url_should_not_apikey(string url) + { + var setting = new NewznabSettings + { + ApiKey = "", + Url = url + }; + + + setting.Validate().IsValid.Should().BeFalse(); + setting.Validate().Errors.Should().NotContain(c => c.PropertyName == "ApiKey"); + setting.Validate().Errors.Should().Contain(c => c.PropertyName == "Url"); + } diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs index c5a0eb230..012e09a7d 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs @@ -23,6 +23,11 @@ namespace NzbDrone.Core.Indexers.Newznab private static bool ShouldHaveApiKey(NewznabSettings settings) { + if (settings.Url == null) + { + return false; + } + return ApiKeyWhiteList.Any(c => settings.Url.ToLowerInvariant().Contains(c)); }