Fixed: Use Proxy for MediaCovers and Metadata

Signed-off-by: Robin Dadswell <robin@dadswell.email>
This commit is contained in:
Qstick
2020-09-07 00:28:15 -04:00
parent 1d6749ef52
commit 7ea1bf71dd
7 changed files with 95 additions and 72 deletions

View File

@@ -99,9 +99,9 @@ namespace NzbDrone.Common.Test.Http
Mocker.SetConstant<IHttpDispatcher>(Mocker.Resolve<TDispatcher>());
// Used for manual testing of socks proxies.
//Mocker.GetMock<IHttpProxySettingsProvider>()
// .Setup(v => v.GetProxySettings(It.IsAny<HttpRequest>()))
// .Returns(new HttpProxySettings(ProxyType.Socks5, "127.0.0.1", 5476, "", false));
// Mocker.GetMock<IHttpProxySettingsProvider>()
// .Setup(v => v.GetProxySettings(It.IsAny<HttpUri>()))
// .Returns(new HttpProxySettings(ProxyType.Socks5, "127.0.0.1", 5476, "", false));
// Roundrobin over the two servers, to reduce the chance of hitting the ratelimiter.
_httpBinHost2 = _httpBinHosts[_httpBinRandom++ % _httpBinHosts.Length];
@@ -283,16 +283,31 @@ namespace NzbDrone.Common.Test.Http
{
var file = GetTempFilePath();
var url = "https://sonarr.tv/img/slider/seriesdetails.png";
var url = "https://lidarr.audio/img/slider/artistdetails.png";
Subject.DownloadFile(url, file);
File.Exists(file).Should().BeTrue();
File.Exists(file + ".part").Should().BeFalse();
var fileInfo = new FileInfo(file);
fileInfo.Exists.Should().BeTrue();
fileInfo.Length.Should().Be(146122);
}
[Test]
public void should_download_file_with_redirect()
{
var file = GetTempFilePath();
var request = new HttpRequestBuilder($"https://{_httpBinHost}/redirect-to")
.AddQueryParam("url", $"https://lidarr.audio/img/slider/artistdetails.png")
.Build();
Subject.DownloadFile(request.Url.FullUri, file);
ExceptionVerification.ExpectedErrors(0);
var fileInfo = new FileInfo(file);
fileInfo.Length.Should().Be(307054);
fileInfo.Exists.Should().BeTrue();
fileInfo.Length.Should().Be(146122);
}
[Test]
@@ -303,9 +318,8 @@ namespace NzbDrone.Common.Test.Http
Assert.Throws<WebException>(() => Subject.DownloadFile("https://download.readarr.com/wrongpath", file));
File.Exists(file).Should().BeFalse();
File.Exists(file + ".part").Should().BeFalse();
ExceptionVerification.ExpectedWarns(0);
ExceptionVerification.ExpectedWarns(1);
}
[Test]
@@ -333,7 +347,7 @@ namespace NzbDrone.Common.Test.Http
var oldRequest = new HttpRequest($"https://{_httpBinHost2}/get");
oldRequest.Cookies["my"] = "cookie";
var oldClient = new HttpClient(new IHttpRequestInterceptor[0], Mocker.Resolve<ICacheManager>(), Mocker.Resolve<IRateLimitService>(), Mocker.Resolve<IHttpDispatcher>(), Mocker.GetMock<IUserAgentBuilder>().Object, Mocker.Resolve<Logger>());
var oldClient = new HttpClient(new IHttpRequestInterceptor[0], Mocker.Resolve<ICacheManager>(), Mocker.Resolve<IRateLimitService>(), Mocker.Resolve<IHttpDispatcher>(), Mocker.Resolve<Logger>());
oldClient.Should().NotBeSameAs(Subject);