From b43732b343bf3b143d7297fa45d64dee692eef99 Mon Sep 17 00:00:00 2001 From: Qstick Date: Wed, 9 Sep 2020 21:39:52 -0400 Subject: [PATCH] Fixed: Validate TMDb ListId is a valid integer --- .../TMDb/TMDbListSettingsValidatorFixture.cs | 38 +++++++++++++++++++ .../ImportLists/TMDb/List/TMDbListSettings.cs | 4 +- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/NzbDrone.Core.Test/ImportListTests/TMDb/TMDbListSettingsValidatorFixture.cs diff --git a/src/NzbDrone.Core.Test/ImportListTests/TMDb/TMDbListSettingsValidatorFixture.cs b/src/NzbDrone.Core.Test/ImportListTests/TMDb/TMDbListSettingsValidatorFixture.cs new file mode 100644 index 000000000..a11e2fcf7 --- /dev/null +++ b/src/NzbDrone.Core.Test/ImportListTests/TMDb/TMDbListSettingsValidatorFixture.cs @@ -0,0 +1,38 @@ +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Core.ImportLists.TMDb.List; +using NzbDrone.Core.Test.Framework; + +namespace NzbDrone.Core.Test.ImportListTests.TMDb +{ + public class TMDbListSettingsValidatorFixture : CoreTest + { + [TestCase("")] + [TestCase("0")] + [TestCase("ls12345678")] + [TestCase(null)] + public void invalid_listId_should_not_validate(string listId) + { + var setting = new TMDbListSettings + { + ListId = listId, + }; + + setting.Validate().IsValid.Should().BeFalse(); + setting.Validate().Errors.Should().Contain(c => c.PropertyName == "ListId"); + } + + [TestCase("1")] + [TestCase("706123")] + public void valid_listId_should_validate(string listId) + { + var setting = new TMDbListSettings + { + ListId = listId, + }; + + setting.Validate().IsValid.Should().BeTrue(); + setting.Validate().Errors.Should().NotContain(c => c.PropertyName == "ListId"); + } + } +} diff --git a/src/NzbDrone.Core/ImportLists/TMDb/List/TMDbListSettings.cs b/src/NzbDrone.Core/ImportLists/TMDb/List/TMDbListSettings.cs index 78137b6c5..bb153dd03 100644 --- a/src/NzbDrone.Core/ImportLists/TMDb/List/TMDbListSettings.cs +++ b/src/NzbDrone.Core/ImportLists/TMDb/List/TMDbListSettings.cs @@ -1,4 +1,4 @@ -using FluentValidation; +using FluentValidation; using NzbDrone.Core.Annotations; namespace NzbDrone.Core.ImportLists.TMDb.List @@ -8,7 +8,7 @@ public class TMDbListSettingsValidator : TMDbSettingsBaseValidator c.ListId).NotEmpty(); + RuleFor(c => c.ListId).Matches("^[1-9][0-9]*$").NotEmpty(); } }