mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-19 13:10:13 -07: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.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NzbDrone.Core.Parser.Model;
|
using NzbDrone.Core.Parser.Model;
|
||||||
using System;
|
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
|
namespace NzbDrone.Core.Test.ParserTests
|
||||||
{
|
{
|
||||||
|
@ -181,5 +186,19 @@ FINGERPRINT=AQAHJlMURlEURcgP6cwRD43Y4Ptw9FowncWPWkf6GB9-JYdP9OgJHw8u4Apw4SsOHMdx
|
||||||
idpairs[1].Item1.AcoustIdResults.Should().Contain("30f3f33e-8d0c-4e69-8539-cbd701d18f28");
|
idpairs[1].Item1.AcoustIdResults.Should().Contain("30f3f33e-8d0c-4e69-8539-cbd701d18f28");
|
||||||
idpairs[2].Item1.AcoustIdResults.Should().BeNull();
|
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 @@ namespace NzbDrone.Core.Parser
|
||||||
httpRequest.Headers.ContentType = "application/x-www-form-urlencoded";
|
httpRequest.Headers.ContentType = "application/x-www-form-urlencoded";
|
||||||
httpRequest.SuppressHttpError = true;
|
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;
|
var response = httpResponse.Resource;
|
||||||
|
|
||||||
// The API will give errors if fingerprint isn't found or is invalid.
|
// The API will give errors if fingerprint isn't found or is invalid.
|
||||||
|
@ -407,33 +418,33 @@ namespace NzbDrone.Core.Parser
|
||||||
_logger.Debug($"*** FingerprintingService TestCaseGenerator ***\n{JsonConvert.SerializeObject(output, SerializerSettings)}");
|
_logger.Debug($"*** FingerprintingService TestCaseGenerator ***\n{JsonConvert.SerializeObject(output, SerializerSettings)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LookupResponse
|
public class LookupResponse
|
||||||
{
|
{
|
||||||
public string Status { get; set; }
|
public string Status { get; set; }
|
||||||
public LookupError Error { get; set; }
|
public LookupError Error { get; set; }
|
||||||
public List<LookupResultListItem> Fingerprints { get; set; }
|
public List<LookupResultListItem> Fingerprints { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LookupError
|
public class LookupError
|
||||||
{
|
{
|
||||||
public string Message { get; set; }
|
public string Message { get; set; }
|
||||||
public int Code { get; set; }
|
public int Code { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LookupResultListItem
|
public class LookupResultListItem
|
||||||
{
|
{
|
||||||
public int index { get; set; }
|
public int index { get; set; }
|
||||||
public List<LookupResult> Results { get; set; }
|
public List<LookupResult> Results { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LookupResult
|
public class LookupResult
|
||||||
{
|
{
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public double Score { get; set; }
|
public double Score { get; set; }
|
||||||
public List<RecordingResult> Recordings { get; set; }
|
public List<RecordingResult> Recordings { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RecordingResult
|
public class RecordingResult
|
||||||
{
|
{
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue