diff --git a/src/NzbDrone.Core.Test/Datastore/Migration/219_nzb_su_url_to_nzb_lifeFixture.cs b/src/NzbDrone.Core.Test/Datastore/Migration/219_nzb_su_url_to_nzb_lifeFixture.cs new file mode 100644 index 000000000..ccc08bfe7 --- /dev/null +++ b/src/NzbDrone.Core.Test/Datastore/Migration/219_nzb_su_url_to_nzb_lifeFixture.cs @@ -0,0 +1,88 @@ +using System.Collections.Generic; +using System.Linq; +using FluentAssertions; +using Newtonsoft.Json.Linq; +using NUnit.Framework; +using NzbDrone.Common.Serializer; +using NzbDrone.Core.Datastore.Migration; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.Datastore.Migration +{ + [TestFixture] + public class nzb_su_url_to_nzb_lifeFixture : MigrationTest + { + [TestCase("Newznab", "https://api.nzb.su")] + [TestCase("Newznab", "http://api.nzb.su")] + public void should_replace_old_url(string impl, string baseUrl) + { + var db = WithMigrationTestDb(c => + { + c.Insert.IntoTable("Indexers").Row(new + { + Name = "Nzb.su", + Implementation = impl, + Settings = new NewznabSettings219 + { + BaseUrl = baseUrl, + ApiPath = "/api" + }.ToJson(), + ConfigContract = impl + "Settings", + EnableInteractiveSearch = false + }); + }); + + var items = db.Query("SELECT * FROM \"Indexers\""); + + items.Should().HaveCount(1); + items.First().Settings.ToObject().BaseUrl.Should().Be(baseUrl.Replace("su", "life")); + } + + [TestCase("Newznab", "https://api.indexer.com")] + public void should_not_replace_different_url(string impl, string baseUrl) + { + var db = WithMigrationTestDb(c => + { + c.Insert.IntoTable("Indexers").Row(new + { + Name = "Indexer.com", + Implementation = impl, + Settings = new NewznabSettings219 + { + BaseUrl = baseUrl, + ApiPath = "/api" + }.ToJson(), + ConfigContract = impl + "Settings", + EnableInteractiveSearch = false + }); + }); + + var items = db.Query("SELECT * FROM \"Indexers\""); + + items.Should().HaveCount(1); + items.First().Settings.ToObject().BaseUrl.Should().Be(baseUrl); + } + } + + internal class IndexerDefinition219 + { + public int Id { get; set; } + public string Name { get; set; } + public JObject Settings { get; set; } + public int Priority { get; set; } + public string Implementation { get; set; } + public string ConfigContract { get; set; } + public bool EnableRss { get; set; } + public bool EnableAutomaticSearch { get; set; } + public bool EnableInteractiveSearch { get; set; } + public HashSet Tags { get; set; } + public int DownloadClientId { get; set; } + public int SeasonSearchMaximumSingleEpisodeAge { get; set; } + } + + internal class NewznabSettings219 + { + public string BaseUrl { get; set; } + public string ApiPath { get; set; } + } +} diff --git a/src/NzbDrone.Core/Datastore/Migration/219_nzb_su_url_to_nzb_life.cs b/src/NzbDrone.Core/Datastore/Migration/219_nzb_su_url_to_nzb_life.cs new file mode 100644 index 000000000..3de29dbc7 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/219_nzb_su_url_to_nzb_life.cs @@ -0,0 +1,16 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(219)] + public class nzb_su_url_to_nzb_life : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Execute.Sql("UPDATE \"Indexers\" SET \"Settings\" = replace(\"Settings\", '//api.nzb.su', '//api.nzb.life')" + + "WHERE \"Implementation\" = 'Newznab'" + + "AND \"Settings\" LIKE '%//api.nzb.su%'"); + } + } +} diff --git a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs index 56489770a..2e39b9815 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/Newznab.cs @@ -50,7 +50,7 @@ namespace NzbDrone.Core.Indexers.Newznab { yield return GetDefinition("DOGnzb", GetSettings("https://api.dognzb.cr")); yield return GetDefinition("DrunkenSlug", GetSettings("https://drunkenslug.com")); - yield return GetDefinition("Nzb.su", GetSettings("https://api.nzb.su")); + yield return GetDefinition("Nzb.life", GetSettings("https://api.nzb.life")); yield return GetDefinition("NZBCat", GetSettings("https://nzb.cat")); yield return GetDefinition("NZBFinder.ws", GetSettings("https://nzbfinder.ws", categories: new[] { 5030, 5040, 5045 })); yield return GetDefinition("NZBgeek", GetSettings("https://api.nzbgeek.info")); diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs index 3324916c7..984af2df4 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs @@ -13,10 +13,10 @@ namespace NzbDrone.Core.Indexers.Newznab { public class NewznabSettingsValidator : AbstractValidator { - private static readonly string[] ApiKeyWhiteList = + private static readonly string[] ApiKeyAllowList = { "nzbs.org", - "nzb.su", + "nzb.life", "dognzb.cr", "nzbplanet.net", "nzbid.org", @@ -26,7 +26,7 @@ namespace NzbDrone.Core.Indexers.Newznab private static bool ShouldHaveApiKey(NewznabSettings settings) { - return settings.BaseUrl != null && ApiKeyWhiteList.Any(c => settings.BaseUrl.ToLowerInvariant().Contains(c)); + return settings.BaseUrl != null && ApiKeyAllowList.Any(c => settings.BaseUrl.ToLowerInvariant().Contains(c)); } private static readonly Regex AdditionalParametersRegex = new(@"(&.+?\=.+?)+", RegexOptions.Compiled); diff --git a/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs b/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs index f39a4528c..41073f327 100644 --- a/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs @@ -12,11 +12,11 @@ namespace NzbDrone.Core.Indexers.Torznab { public class TorznabSettingsValidator : AbstractValidator { - private static readonly string[] ApiKeyWhiteList = Array.Empty(); + private static readonly string[] ApiKeyAllowList = Array.Empty(); private static bool ShouldHaveApiKey(TorznabSettings settings) { - return settings.BaseUrl != null && ApiKeyWhiteList.Any(c => settings.BaseUrl.ToLowerInvariant().Contains(c)); + return settings.BaseUrl != null && ApiKeyAllowList.Any(c => settings.BaseUrl.ToLowerInvariant().Contains(c)); } private static readonly Regex AdditionalParametersRegex = new(@"(&.+?\=.+?)+", RegexOptions.Compiled);