From 9cd60bc9864a10ff0a63ad663eeac99ae85ac06c Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 28 Dec 2017 22:47:19 -0500 Subject: [PATCH] Fixed: Skyhook Tests, Validate GUID before sending to metadata api --- .../SkyHook/SkyHookProxyFixture.cs | 34 ++++++++++++++++-- .../SkyHook/SkyHookProxySearchFixture.cs | 36 ++++++++++++++++++- .../MetadataSource/SkyHook/SkyHookProxy.cs | 10 ++++-- 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxyFixture.cs b/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxyFixture.cs index a766cba47..42521b355 100644 --- a/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxyFixture.cs +++ b/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxyFixture.cs @@ -9,6 +9,8 @@ using NzbDrone.Core.MetadataSource.SkyHook; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Music; using NzbDrone.Test.Common.Categories; +using Moq; +using NzbDrone.Core.Profiles.Metadata; namespace NzbDrone.Core.Test.MetadataSource.SkyHook { @@ -20,13 +22,38 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook public void Setup() { UseRealHttp(); + + var _metadataProfile = new MetadataProfile + { + PrimaryAlbumTypes = new List + { + new ProfilePrimaryAlbumTypeItem + { + PrimaryAlbumType = PrimaryAlbumType.Album, + Allowed = true + + } + }, + SecondaryAlbumTypes = new List + { + new ProfileSecondaryAlbumTypeItem() + { + SecondaryAlbumType = SecondaryAlbumType.Studio, + Allowed = true + } + }, + }; + + Mocker.GetMock() + .Setup(s => s.Get(It.IsAny())) + .Returns(_metadataProfile); } [TestCase("f59c5520-5f46-4d2c-b2c4-822eabf53419", "Linkin Park")] [TestCase("66c662b6-6e2f-4930-8610-912e24c63ed1", "AC/DC")] public void should_be_able_to_get_artist_detail(string mbId, string name) { - var details = Subject.GetArtistInfo(mbId, 0); + var details = Subject.GetArtistInfo(mbId, 1); ValidateArtist(details.Item1); ValidateAlbums(details.Item2); @@ -37,13 +64,14 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook [Test] public void getting_details_of_invalid_artist() { - Assert.Throws(() => Subject.GetArtistInfo("aaaaaa-aaa-aaaa-aaaa", 0)); + Assert.Throws(() => Subject.GetArtistInfo("aaaaaa-aaa-aaaa-aaaa", 1)); } [Test] + [Ignore("We don't return a dothack from Metadata")] public void should_not_have_period_at_start_of_name_slug() { - var details = Subject.GetArtistInfo("b6db95cd-88d9-492f-bbf6-a34e0e89b2e5", 0); + var details = Subject.GetArtistInfo("b6db95cd-88d9-492f-bbf6-a34e0e89b2e5", 1); details.Item1.NameSlug.Should().Be("dothack"); } diff --git a/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxySearchFixture.cs b/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxySearchFixture.cs index b9d84f0fa..22254e48a 100644 --- a/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxySearchFixture.cs +++ b/src/NzbDrone.Core.Test/MetadataSource/SkyHook/SkyHookProxySearchFixture.cs @@ -1,9 +1,13 @@ -using FluentAssertions; +using FluentAssertions; using NUnit.Framework; using NzbDrone.Core.MetadataSource.SkyHook; using NzbDrone.Core.Test.Framework; using NzbDrone.Test.Common; using NzbDrone.Test.Common.Categories; +using Moq; +using NzbDrone.Core.Profiles.Metadata; +using NzbDrone.Core.Music; +using System.Collections.Generic; namespace NzbDrone.Core.Test.MetadataSource.SkyHook { @@ -15,6 +19,36 @@ namespace NzbDrone.Core.Test.MetadataSource.SkyHook public void Setup() { UseRealHttp(); + + var _metadataProfile = new MetadataProfile + { + Id = 1, + PrimaryAlbumTypes = new List + { + new ProfilePrimaryAlbumTypeItem + { + PrimaryAlbumType = PrimaryAlbumType.Album, + Allowed = true + + } + }, + SecondaryAlbumTypes = new List + { + new ProfileSecondaryAlbumTypeItem() + { + SecondaryAlbumType = SecondaryAlbumType.Studio, + Allowed = true + } + }, + }; + + Mocker.GetMock() + .Setup(s => s.All()) + .Returns(new List{_metadataProfile}); + + Mocker.GetMock() + .Setup(s => s.Get(It.IsAny())) + .Returns(_metadataProfile); } [TestCase("Coldplay", "Coldplay")] diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index e92e5bb8b..b8c24ba22 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -70,6 +70,10 @@ namespace NzbDrone.Core.MetadataSource.SkyHook { throw new ArtistNotFoundException(foreignArtistId); } + else if (httpResponse.StatusCode == HttpStatusCode.BadRequest) + { + throw new BadRequestException(foreignArtistId); + } else { throw new HttpException(httpRequest, httpResponse); @@ -93,7 +97,9 @@ namespace NzbDrone.Core.MetadataSource.SkyHook { var slug = lowerTitle.Split(':')[1].Trim(); - if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace)) + bool isValid = Guid.TryParse(slug, out var searchGuid); + + if (slug.IsNullOrWhiteSpace() || slug.Any(char.IsWhiteSpace) || isValid == false) { return new List(); } @@ -101,7 +107,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook try { var metadataProfile = _metadataProfileService.All().First().Id; //Change this to Use last Used profile? - return new List { GetArtistInfo(slug, metadataProfile).Item1 }; + return new List { GetArtistInfo(searchGuid.ToString(), metadataProfile).Item1 }; } catch (ArtistNotFoundException) {