1
0

Changed behaviour of remote ip address detection, renamed ip allow/block lists

This commit is contained in:
2023-06-01 20:01:19 +02:00
parent d755754198
commit 371283e653
8 changed files with 135 additions and 77 deletions

View File

@@ -14,7 +14,7 @@ namespace UnitTests.AspNetCore.Attributes
{
[TestClass]
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class IPWhitelistAttributeTests
public class IPAllowListAttributeTests
{
private Dictionary<string, string> requestHeaders;
private Dictionary<object, object> itemsCallback;
@@ -37,7 +37,7 @@ namespace UnitTests.AspNetCore.Attributes
{
// arrange
var remote = IPAddress.Parse("192.168.178.1");
var attribute = new IPWhitelistAttribute();
var attribute = new IPAllowListAttribute();
var context = GetContext(remote);
// act
@@ -57,7 +57,7 @@ namespace UnitTests.AspNetCore.Attributes
{
// arrange
var remote = IPAddress.Parse("192.168.178.1");
var attribute = new IPWhitelistAttribute
var attribute = new IPAllowListAttribute
{
AllowedIpAddresses = "192.168.178:1"
};
@@ -79,7 +79,7 @@ namespace UnitTests.AspNetCore.Attributes
public void ShouldAllowLocalAccess()
{
// arrange
var attribute = new IPWhitelistAttribute();
var attribute = new IPAllowListAttribute();
var context = GetContext();
// act
@@ -95,7 +95,7 @@ namespace UnitTests.AspNetCore.Attributes
public void ShouldDenyLocalAccess()
{
// arrange
var attribute = new IPWhitelistAttribute
var attribute = new IPAllowListAttribute
{
AllowLocalAccess = false
};
@@ -120,7 +120,7 @@ namespace UnitTests.AspNetCore.Attributes
{
// arrange
var remote = IPAddress.Parse(address);
var attribute = new IPWhitelistAttribute
var attribute = new IPAllowListAttribute
{
AllowLocalAccess = false,
AllowedIpAddresses = ",127.0.0.0/8,192.168.178.10"
@@ -154,7 +154,7 @@ namespace UnitTests.AspNetCore.Attributes
configExists = true;
allowedIpsConfig.Add("127.0.0.0/8");
allowedIpsConfig.Add("192.168.178.10");
var attribute = new IPWhitelistAttribute
var attribute = new IPAllowListAttribute
{
AllowLocalAccess = true,
ConfigurationKey = configKey
@@ -178,7 +178,7 @@ namespace UnitTests.AspNetCore.Attributes
configExists = true;
allowedIpsConfig.Add("");
allowedIpsConfig.Add("192.168.178.10");
var attribute = new IPWhitelistAttribute
var attribute = new IPAllowListAttribute
{
AllowLocalAccess = false,
ConfigurationKey = configKey
@@ -206,7 +206,7 @@ namespace UnitTests.AspNetCore.Attributes
configKey = "White:List";
configExists = true;
allowedIpsConfig.Add("192.168.178.10");
var attribute = new IPWhitelistAttribute
var attribute = new IPAllowListAttribute
{
AllowLocalAccess = false,
ConfigurationKey = configKey
@@ -239,7 +239,7 @@ namespace UnitTests.AspNetCore.Attributes
// arrange
configKey = "White:List";
configExists = false;
var attribute = new IPWhitelistAttribute
var attribute = new IPAllowListAttribute
{
AllowLocalAccess = false,
ConfigurationKey = configKey

View File

@@ -14,7 +14,7 @@ namespace UnitTests.AspNetCore.Attributes
{
[TestClass]
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class IPBlacklistAttributeTests
public class IPBlockListAttributeTests
{
private Dictionary<string, string> requestHeaders;
private Dictionary<object, object> itemsCallback;
@@ -37,7 +37,7 @@ namespace UnitTests.AspNetCore.Attributes
{
// arrange
var remote = IPAddress.Parse("192.168.178.1");
var attribute = new IPBlacklistAttribute();
var attribute = new IPBlockListAttribute();
var context = GetContext(remote);
// act
@@ -54,9 +54,9 @@ namespace UnitTests.AspNetCore.Attributes
{
// arrange
var remote = IPAddress.Parse("192.168.178.1");
var attribute = new IPBlacklistAttribute
var attribute = new IPBlockListAttribute
{
RestrictedIpAddresses = "192.168.178:1"
BlockedIpAddresses = "192.168.178:1"
};
var context = GetContext(remote);
@@ -73,10 +73,10 @@ namespace UnitTests.AspNetCore.Attributes
public void ShouldAllowLocalAccess()
{
// arrange
var attribute = new IPBlacklistAttribute
var attribute = new IPBlockListAttribute
{
RestrictLocalAccess = false,
RestrictedIpAddresses = "127.0.0.0/8"
BlockLocalAccess = false,
BlockedIpAddresses = "127.0.0.0/8"
};
var context = GetContext();
@@ -93,10 +93,10 @@ namespace UnitTests.AspNetCore.Attributes
public void ShouldBlockLocalAccess()
{
// arrange
var attribute = new IPBlacklistAttribute
var attribute = new IPBlockListAttribute
{
RestrictLocalAccess = true,
RestrictedIpAddresses = ",127.0.0.0/8"
BlockLocalAccess = true,
BlockedIpAddresses = ",127.0.0.0/8"
};
var context = GetContext();
@@ -119,10 +119,10 @@ namespace UnitTests.AspNetCore.Attributes
{
// arrange
var remote = IPAddress.Parse(address);
var attribute = new IPBlacklistAttribute
var attribute = new IPBlockListAttribute
{
RestrictLocalAccess = true,
RestrictedIpAddresses = "127.0.0.0/8,192.168.178.10"
BlockLocalAccess = true,
BlockedIpAddresses = "127.0.0.0/8,192.168.178.10"
};
var context = GetContext(remote);
@@ -153,9 +153,9 @@ namespace UnitTests.AspNetCore.Attributes
configExists = true;
restrictedIpsConfig.Add("127.0.0.0/8");
restrictedIpsConfig.Add("192.168.178.10");
var attribute = new IPBlacklistAttribute
var attribute = new IPBlockListAttribute
{
RestrictLocalAccess = false,
BlockLocalAccess = false,
ConfigurationKey = configKey
};
var context = GetContext();
@@ -178,9 +178,9 @@ namespace UnitTests.AspNetCore.Attributes
restrictedIpsConfig.Add("");
restrictedIpsConfig.Add("127.0.0.0/8");
restrictedIpsConfig.Add("192.168.178.10");
var attribute = new IPBlacklistAttribute
var attribute = new IPBlockListAttribute
{
RestrictLocalAccess = true,
BlockLocalAccess = true,
ConfigurationKey = configKey
};
var context = GetContext();
@@ -207,9 +207,9 @@ namespace UnitTests.AspNetCore.Attributes
configExists = true;
restrictedIpsConfig.Add("127.0.0.0/8");
restrictedIpsConfig.Add("192.168.178.10");
var attribute = new IPBlacklistAttribute
var attribute = new IPBlockListAttribute
{
RestrictLocalAccess = true,
BlockLocalAccess = true,
ConfigurationKey = configKey
};
var remote = IPAddress.Parse(address);
@@ -240,9 +240,9 @@ namespace UnitTests.AspNetCore.Attributes
// arrange
configKey = "Black:List";
configExists = false;
var attribute = new IPBlacklistAttribute
var attribute = new IPBlockListAttribute
{
RestrictLocalAccess = true,
BlockLocalAccess = true,
ConfigurationKey = configKey
};
var context = GetContext();