Skip to content

Commit

Permalink
also allow setting bypass on local property
Browse files Browse the repository at this point in the history
  • Loading branch information
mikocot committed Sep 13, 2022
1 parent bc472fd commit e2053d5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ReCaptcha/Client/ProxyHttpClientHandler.cs
Expand Up @@ -25,7 +25,7 @@ public ProxyHttpClientHandler(IOptions<RecaptchaSettings> settings)
if (currentSettings != null && currentSettings.UseProxy == true && !String.IsNullOrEmpty(currentSettings.ProxyAddress))
{
this.UseProxy = true;
this.Proxy = new WebProxy(currentSettings.ProxyAddress, false);
this.Proxy = new WebProxy(currentSettings.ProxyAddress, currentSettings.BypassOnLocal);
}
else
{
Expand Down
9 changes: 8 additions & 1 deletion src/ReCaptcha/Configuration/RecaptchaSettings.cs
@@ -1,4 +1,6 @@
namespace Griesoft.AspNetCore.ReCaptcha.Configuration
using System.Runtime.Serialization;

namespace Griesoft.AspNetCore.ReCaptcha.Configuration
{
/// <summary>
/// Mandatory settings for this reCAPTCHA service. The values for this object will be read from your appsettings.json file.
Expand Down Expand Up @@ -31,5 +33,10 @@ public class RecaptchaSettings
/// Proxy server address to be used to http client
/// </summary>
public string? ProxyAddress { get; set; }

/// <summary>
/// Indicates whether to bypass proxy for local addresses
/// </summary>
public bool BypassOnLocal { get; set; }
}
}
27 changes: 26 additions & 1 deletion tests/ReCaptcha.Tests/Client/ProxyHttpClientHandlerTests.cs
@@ -1,4 +1,5 @@
using Griesoft.AspNetCore.ReCaptcha;
using System;
using Griesoft.AspNetCore.ReCaptcha;
using Griesoft.AspNetCore.ReCaptcha.Client;
using Griesoft.AspNetCore.ReCaptcha.Configuration;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -28,6 +29,30 @@ public void Initialize_WithProxy()
// Assert
Assert.IsTrue(handler.UseProxy);
Assert.IsNotNull(handler.Proxy);
Assert.IsFalse(handler.Proxy.IsBypassed(new Uri("http://127.0.0.1:8080")));

}

[Test]
public void Initialize_WithProxyBypassed()
{
// Arrange
var settingsMock = new Mock<IOptions<RecaptchaSettings>>();
settingsMock.SetupGet(instance => instance.Value)
.Returns(new RecaptchaSettings()
{
UseProxy = true,
ProxyAddress = "http://10.1.2.3:80",
BypassOnLocal = true
});

// Act
var handler = new ProxyHttpClientHandler(settingsMock.Object);

// Assert
Assert.IsTrue(handler.UseProxy);
Assert.IsNotNull(handler.Proxy);
Assert.IsTrue(handler.Proxy.IsBypassed(new Uri("http://127.0.0.1:8080")));
}

[Test]
Expand Down

0 comments on commit e2053d5

Please sign in to comment.