diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs index 1729e4b18..668f66143 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/SabnzbdTests/SabnzbdFixture.cs @@ -396,5 +396,21 @@ public void should_return_status_with_mounted_outputdir() result.OutputRootFolders.Should().NotBeNull(); result.OutputRootFolders.First().Should().Be(@"O:\mymount".AsOsAgnostic()); } + + [TestCase("0.6.9", false)] + [TestCase("0.7.0", true)] + [TestCase("0.8.0", true)] + [TestCase("1.0.0", true)] + [TestCase("1.0.0RC1", true)] + public void should_test_version(string version, bool expected) + { + Mocker.GetMock() + .Setup(v => v.GetVersion(It.IsAny())) + .Returns(version); + + var error = Subject.Test(); + + error.IsValid.Should().Be(expected); + } } } diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index f35a71a2e..79830fb6b 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; using FluentValidation.Results; using NLog; using NzbDrone.Common.Disk; @@ -28,6 +29,8 @@ public Sabnzbd(ISabnzbdProxy proxy, _proxy = proxy; } + private static readonly Regex VersionRegex = new Regex(@"(?\d+)\.(?\d+)\.(?\d+)(?.*)", RegexOptions.Compiled); + protected override string AddFromNzbFile(RemoteEpisode remoteEpisode, string filename, byte[] fileContent) { var category = Settings.TvCategory; @@ -253,25 +256,44 @@ public override DownloadClientStatus GetStatus() protected override void Test(List failures) { - failures.AddIfNotNull(TestConnection()); + failures.AddIfNotNull(TestConnectionAndVersion()); failures.AddIfNotNull(TestAuthentication()); failures.AddIfNotNull(TestGlobalConfig()); failures.AddIfNotNull(TestCategory()); } - private ValidationFailure TestConnection() + private ValidationFailure TestConnectionAndVersion() { try { - _proxy.GetVersion(Settings); + var version = _proxy.GetVersion(Settings); + var parsed = VersionRegex.Match(version); + + if (!parsed.Success) + { + return new ValidationFailure("Version", "Unknown Version: " + version); + } + + var major = Convert.ToInt32(parsed.Groups["major"].Value); + var minor = Convert.ToInt32(parsed.Groups["minor"].Value); + + if (major >= 1) + { + return null; + } + + if (minor >= 7) + { + return null; + } + + return new ValidationFailure("Version", "Version 0.7.0+ is required, but found: " + version); } catch (Exception ex) { _logger.Error(ex, ex.Message); return new ValidationFailure("Host", "Unable to connect to SABnzbd"); } - - return null; } private ValidationFailure TestAuthentication() diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs index ae34c2179..14e58d5d9 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/SabnzbdProxy.cs @@ -14,7 +14,7 @@ public interface ISabnzbdProxy SabnzbdAddResponse DownloadNzb(byte[] nzbData, string filename, string category, int priority, SabnzbdSettings settings); void RemoveFrom(string source, string id,bool deleteData, SabnzbdSettings settings); string ProcessRequest(IRestRequest restRequest, string action, SabnzbdSettings settings); - SabnzbdVersionResponse GetVersion(SabnzbdSettings settings); + string GetVersion(SabnzbdSettings settings); SabnzbdConfig GetConfig(SabnzbdSettings settings); SabnzbdQueue GetQueue(int start, int limit, SabnzbdSettings settings); SabnzbdHistory GetHistory(int start, int limit, string category, SabnzbdSettings settings); @@ -68,7 +68,7 @@ public string ProcessRequest(IRestRequest restRequest, string action, SabnzbdSet return response.Content; } - public SabnzbdVersionResponse GetVersion(SabnzbdSettings settings) + public string GetVersion(SabnzbdSettings settings) { var request = new RestRequest(); var action = "mode=version"; @@ -80,7 +80,7 @@ public SabnzbdVersionResponse GetVersion(SabnzbdSettings settings) response = new SabnzbdVersionResponse(); } - return response; + return response.Version; } public SabnzbdConfig GetConfig(SabnzbdSettings settings)