mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-10-30 23:42:33 +01:00
Proxy BypassList tests
Lightly refactored and updated documentation to make it easier for users
This commit is contained in:
parent
c82b90aca8
commit
2b11ad4585
@ -25,13 +25,21 @@ namespace NzbDrone.Common.Http.Proxy
|
|||||||
public string BypassFilter { get; private set; }
|
public string BypassFilter { get; private set; }
|
||||||
public bool BypassLocalAddress { get; private set; }
|
public bool BypassLocalAddress { get; private set; }
|
||||||
|
|
||||||
public string[] SubnetFilterAsArray
|
public string[] BypassListAsArray
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrWhiteSpace(BypassFilter))
|
if (!string.IsNullOrWhiteSpace(BypassFilter))
|
||||||
{
|
{
|
||||||
return BypassFilter.Split(';');
|
var hostlist = BypassFilter.Split(',');
|
||||||
|
for(int i = 0; i < hostlist.Length; i++)
|
||||||
|
{
|
||||||
|
if(hostlist[i].StartsWith("*"))
|
||||||
|
{
|
||||||
|
hostlist[i] = ";" + hostlist[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hostlist;
|
||||||
}
|
}
|
||||||
return new string[] { };
|
return new string[] { };
|
||||||
}
|
}
|
||||||
|
@ -40,11 +40,11 @@ namespace NzbDrone.Common.Http.Proxy
|
|||||||
case ProxyType.Http:
|
case ProxyType.Http:
|
||||||
if (proxySettings.Username.IsNotNullOrWhiteSpace() && proxySettings.Password.IsNotNullOrWhiteSpace())
|
if (proxySettings.Username.IsNotNullOrWhiteSpace() && proxySettings.Password.IsNotNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
return new WebProxy(proxySettings.Host + ":" + proxySettings.Port, proxySettings.BypassLocalAddress, proxySettings.SubnetFilterAsArray, new NetworkCredential(proxySettings.Username, proxySettings.Password));
|
return new WebProxy(proxySettings.Host + ":" + proxySettings.Port, proxySettings.BypassLocalAddress, proxySettings.BypassListAsArray, new NetworkCredential(proxySettings.Username, proxySettings.Password));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new WebProxy(proxySettings.Host + ":" + proxySettings.Port, proxySettings.BypassLocalAddress, proxySettings.SubnetFilterAsArray);
|
return new WebProxy(proxySettings.Host + ":" + proxySettings.Port, proxySettings.BypassLocalAddress, proxySettings.BypassListAsArray);
|
||||||
}
|
}
|
||||||
case ProxyType.Socks4:
|
case ProxyType.Socks4:
|
||||||
return new SocksWebProxy(new ProxyConfig(IPAddress.Loopback, GetNextFreePort(), GetProxyIpAddress(proxySettings.Host), proxySettings.Port, ProxyConfig.SocksVersion.Four, proxySettings.Username, proxySettings.Password), false);
|
return new SocksWebProxy(new ProxyConfig(IPAddress.Loopback, GetNextFreePort(), GetProxyIpAddress(proxySettings.Host), proxySettings.Port, ProxyConfig.SocksVersion.Four, proxySettings.Username, proxySettings.Password), false);
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
using NzbDrone.Core.Http;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NzbDrone.Test.Common;
|
||||||
|
using NzbDrone.Common.Http.Proxy;
|
||||||
|
using NzbDrone.Common.Http;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test.Http
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class HttpProxySettingsProviderFixture : TestBase<HttpProxySettingsProvider>
|
||||||
|
{
|
||||||
|
private HttpProxySettings GetProxySettings()
|
||||||
|
{
|
||||||
|
return new HttpProxySettings(ProxyType.Socks5, "localhost", 8080, "*.httpbin.org,google.com", true, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_bypass_proxy()
|
||||||
|
{
|
||||||
|
var settings = GetProxySettings();
|
||||||
|
|
||||||
|
Subject.ShouldProxyBeBypassed(settings, new HttpUri("http://eu.httpbin.org/get")).Should().BeTrue();
|
||||||
|
Subject.ShouldProxyBeBypassed(settings, new HttpUri("http://google.com/get")).Should().BeTrue();
|
||||||
|
Subject.ShouldProxyBeBypassed(settings, new HttpUri("http://localhost:8654/get")).Should().BeTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void should_not_bypass_proxy()
|
||||||
|
{
|
||||||
|
var settings = GetProxySettings();
|
||||||
|
|
||||||
|
Subject.ShouldProxyBeBypassed(settings, new HttpUri("http://bing.com/get")).Should().BeFalse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -217,6 +217,7 @@
|
|||||||
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedMetadataFilesFixture.cs" />
|
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedMetadataFilesFixture.cs" />
|
||||||
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedPendingReleasesFixture.cs" />
|
<Compile Include="Housekeeping\Housekeepers\CleanupOrphanedPendingReleasesFixture.cs" />
|
||||||
<Compile Include="Housekeeping\Housekeepers\FixFutureRunScheduledTasksFixture.cs" />
|
<Compile Include="Housekeeping\Housekeepers\FixFutureRunScheduledTasksFixture.cs" />
|
||||||
|
<Compile Include="Http\HttpProxySettingsProviderFixture.cs" />
|
||||||
<Compile Include="Http\TorCacheHttpRequestInterceptorFixture.cs" />
|
<Compile Include="Http\TorCacheHttpRequestInterceptorFixture.cs" />
|
||||||
<Compile Include="IndexerSearchTests\SeriesSearchServiceFixture.cs" />
|
<Compile Include="IndexerSearchTests\SeriesSearchServiceFixture.cs" />
|
||||||
<Compile Include="IndexerSearchTests\NzbSearchServiceFixture.cs" />
|
<Compile Include="IndexerSearchTests\NzbSearchServiceFixture.cs" />
|
||||||
|
@ -41,7 +41,7 @@ namespace NzbDrone.Core.Http
|
|||||||
public bool ShouldProxyBeBypassed(HttpProxySettings proxySettings, HttpUri url)
|
public bool ShouldProxyBeBypassed(HttpProxySettings proxySettings, HttpUri url)
|
||||||
{
|
{
|
||||||
//We are utilising the WebProxy implementation here to save us having to reimplement it. This way we use Microsofts implementation
|
//We are utilising the WebProxy implementation here to save us having to reimplement it. This way we use Microsofts implementation
|
||||||
var proxy = new WebProxy(proxySettings.Host + ":" + proxySettings.Port, proxySettings.BypassLocalAddress, proxySettings.SubnetFilterAsArray);
|
var proxy = new WebProxy(proxySettings.Host + ":" + proxySettings.Port, proxySettings.BypassLocalAddress, proxySettings.BypassListAsArray);
|
||||||
|
|
||||||
return proxy.IsBypassed((Uri)url);
|
return proxy.IsBypassed((Uri)url);
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@
|
|||||||
<label class="col-sm-3 control-label">Addresses for the proxy to ignore</label>
|
<label class="col-sm-3 control-label">Addresses for the proxy to ignore</label>
|
||||||
|
|
||||||
<div class="col-sm-1 col-sm-push-4 help-inline">
|
<div class="col-sm-1 col-sm-push-4 help-inline">
|
||||||
<i class="icon-sonarr-form-info" title="Use ';' as a separator"/>
|
<i class="icon-sonarr-form-info" title="Use ',' as a separator, and '*.' as a wildcard for subdomains"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-4 col-sm-pull-1">
|
<div class="col-sm-4 col-sm-pull-1">
|
||||||
|
Loading…
Reference in New Issue
Block a user