mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-22 14:00:42 +00:00
Fixed: Fingerprinting service swallows UnexpectedHtmlContentException (#808)
This commit is contained in:
parent
d381bab9d9
commit
adfaec3864
2 changed files with 36 additions and 6 deletions
|
@ -7,6 +7,11 @@
|
|||
using System.Linq;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using System;
|
||||
using NzbDrone.Common.Http;
|
||||
using Moq;
|
||||
using static NzbDrone.Core.Parser.FingerprintingService;
|
||||
using NzbDrone.Test.Common;
|
||||
using System.Net;
|
||||
|
||||
namespace NzbDrone.Core.Test.ParserTests
|
||||
{
|
||||
|
@ -181,5 +186,19 @@ public void should_not_fail_for_some_invalid_fingerprints()
|
|||
idpairs[1].Item1.AcoustIdResults.Should().Contain("30f3f33e-8d0c-4e69-8539-cbd701d18f28");
|
||||
idpairs[2].Item1.AcoustIdResults.Should().BeNull();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_throw_if_api_returns_html()
|
||||
{
|
||||
Mocker.GetMock<IHttpClient>().Setup(x => x.Post<LookupResponse>(It.IsAny<HttpRequest>()))
|
||||
.Callback<HttpRequest>(req => throw new UnexpectedHtmlContentException(new HttpResponse(req, req.Headers, "html content", HttpStatusCode.Accepted)));
|
||||
|
||||
var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Files", "Media", "nin.mp3");
|
||||
var localTrack = new LocalTrack { Path = path };
|
||||
Subject.Lookup(new List<LocalTrack> { localTrack }, 0.5);
|
||||
localTrack.AcoustIdResults.Should().BeNull();
|
||||
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -360,7 +360,18 @@ public void Lookup(List<Tuple<LocalTrack, AcoustId>> files, double threshold)
|
|||
httpRequest.Headers.ContentType = "application/x-www-form-urlencoded";
|
||||
httpRequest.SuppressHttpError = true;
|
||||
|
||||
var httpResponse = _httpClient.Post<LookupResponse>(httpRequest);
|
||||
HttpResponse<LookupResponse> httpResponse;
|
||||
|
||||
try
|
||||
{
|
||||
httpResponse = _httpClient.Post<LookupResponse>(httpRequest);
|
||||
}
|
||||
catch (UnexpectedHtmlContentException e)
|
||||
{
|
||||
_logger.Warn(e, "AcoustId API gave invalid response");
|
||||
return;
|
||||
}
|
||||
|
||||
var response = httpResponse.Resource;
|
||||
|
||||
// The API will give errors if fingerprint isn't found or is invalid.
|
||||
|
@ -407,33 +418,33 @@ public void Lookup(List<Tuple<LocalTrack, AcoustId>> files, double threshold)
|
|||
_logger.Debug($"*** FingerprintingService TestCaseGenerator ***\n{JsonConvert.SerializeObject(output, SerializerSettings)}");
|
||||
}
|
||||
|
||||
private class LookupResponse
|
||||
public class LookupResponse
|
||||
{
|
||||
public string Status { get; set; }
|
||||
public LookupError Error { get; set; }
|
||||
public List<LookupResultListItem> Fingerprints { get; set; }
|
||||
}
|
||||
|
||||
private class LookupError
|
||||
public class LookupError
|
||||
{
|
||||
public string Message { get; set; }
|
||||
public int Code { get; set; }
|
||||
}
|
||||
|
||||
private class LookupResultListItem
|
||||
public class LookupResultListItem
|
||||
{
|
||||
public int index { get; set; }
|
||||
public List<LookupResult> Results { get; set; }
|
||||
}
|
||||
|
||||
private class LookupResult
|
||||
public class LookupResult
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public double Score { get; set; }
|
||||
public List<RecordingResult> Recordings { get; set; }
|
||||
}
|
||||
|
||||
private class RecordingResult
|
||||
public class RecordingResult
|
||||
{
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue