|
|
|
@ -201,29 +201,29 @@ namespace Jellyfin.Networking.Tests
|
|
|
|
|
using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
|
|
|
|
|
|
|
|
|
|
// Test included.
|
|
|
|
|
Collection<IPObject> nc = nm.CreateIPCollection(settings.Split(","), false);
|
|
|
|
|
Collection<IPObject> nc = nm.CreateIPCollection(settings.Split(','), false);
|
|
|
|
|
Assert.Equal(nc.AsString(), result1);
|
|
|
|
|
|
|
|
|
|
// Test excluded.
|
|
|
|
|
nc = nm.CreateIPCollection(settings.Split(","), true);
|
|
|
|
|
nc = nm.CreateIPCollection(settings.Split(','), true);
|
|
|
|
|
Assert.Equal(nc.AsString(), result3);
|
|
|
|
|
|
|
|
|
|
conf.EnableIPV6 = false;
|
|
|
|
|
nm.UpdateSettings(conf);
|
|
|
|
|
|
|
|
|
|
// Test IP4 included.
|
|
|
|
|
nc = nm.CreateIPCollection(settings.Split(","), false);
|
|
|
|
|
nc = nm.CreateIPCollection(settings.Split(','), false);
|
|
|
|
|
Assert.Equal(nc.AsString(), result2);
|
|
|
|
|
|
|
|
|
|
// Test IP4 excluded.
|
|
|
|
|
nc = nm.CreateIPCollection(settings.Split(","), true);
|
|
|
|
|
nc = nm.CreateIPCollection(settings.Split(','), true);
|
|
|
|
|
Assert.Equal(nc.AsString(), result4);
|
|
|
|
|
|
|
|
|
|
conf.EnableIPV6 = true;
|
|
|
|
|
nm.UpdateSettings(conf);
|
|
|
|
|
|
|
|
|
|
// Test network addresses of collection.
|
|
|
|
|
nc = nm.CreateIPCollection(settings.Split(","), false);
|
|
|
|
|
nc = nm.CreateIPCollection(settings.Split(','), false);
|
|
|
|
|
nc = nc.AsNetworks();
|
|
|
|
|
Assert.Equal(nc.AsString(), result5);
|
|
|
|
|
}
|
|
|
|
@ -262,8 +262,8 @@ namespace Jellyfin.Networking.Tests
|
|
|
|
|
|
|
|
|
|
using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
|
|
|
|
|
|
|
|
|
|
Collection<IPObject> nc1 = nm.CreateIPCollection(settings.Split(","), false);
|
|
|
|
|
Collection<IPObject> nc2 = nm.CreateIPCollection(compare.Split(","), false);
|
|
|
|
|
Collection<IPObject> nc1 = nm.CreateIPCollection(settings.Split(','), false);
|
|
|
|
|
Collection<IPObject> nc2 = nm.CreateIPCollection(compare.Split(','), false);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(nc1.Union(nc2).AsString(), result);
|
|
|
|
|
}
|
|
|
|
@ -372,10 +372,10 @@ namespace Jellyfin.Networking.Tests
|
|
|
|
|
using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
|
|
|
|
|
|
|
|
|
|
// Test included, IP6.
|
|
|
|
|
Collection<IPObject> ncSource = nm.CreateIPCollection(source.Split(","));
|
|
|
|
|
Collection<IPObject> ncDest = nm.CreateIPCollection(dest.Split(","));
|
|
|
|
|
Collection<IPObject> ncSource = nm.CreateIPCollection(source.Split(','));
|
|
|
|
|
Collection<IPObject> ncDest = nm.CreateIPCollection(dest.Split(','));
|
|
|
|
|
Collection<IPObject> ncResult = ncSource.Union(ncDest);
|
|
|
|
|
Collection<IPObject> resultCollection = nm.CreateIPCollection(result.Split(","));
|
|
|
|
|
Collection<IPObject> resultCollection = nm.CreateIPCollection(result.Split(','));
|
|
|
|
|
Assert.True(ncResult.Compare(resultCollection));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -514,5 +514,45 @@ namespace Jellyfin.Networking.Tests
|
|
|
|
|
|
|
|
|
|
Assert.Equal(intf, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("185.10.10.10,200.200.200.200", "79.2.3.4", true)]
|
|
|
|
|
[InlineData("185.10.10.10", "185.10.10.10", false)]
|
|
|
|
|
[InlineData("", "100.100.100.100", false)]
|
|
|
|
|
|
|
|
|
|
public void HasRemoteAccess_GivenWhitelist_AllowsOnlyIpsInWhitelist(string addresses, string remoteIp, bool denied)
|
|
|
|
|
{
|
|
|
|
|
// Comma separated list of IP addresses or IP/netmask entries for networks that will be allowed to connect remotely.
|
|
|
|
|
// If left blank, all remote addresses will be allowed.
|
|
|
|
|
var conf = new NetworkConfiguration()
|
|
|
|
|
{
|
|
|
|
|
EnableIPV4 = true,
|
|
|
|
|
RemoteIPFilter = addresses.Split(','),
|
|
|
|
|
IsRemoteIPFilterBlacklist = false
|
|
|
|
|
};
|
|
|
|
|
using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
|
|
|
|
|
|
|
|
|
|
Assert.NotEqual(nm.HasRemoteAccess(IPAddress.Parse(remoteIp)), denied);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("185.10.10.10", "79.2.3.4", false)]
|
|
|
|
|
[InlineData("185.10.10.10", "185.10.10.10", true)]
|
|
|
|
|
[InlineData("", "100.100.100.100", false)]
|
|
|
|
|
public void HasRemoteAccess_GivenBlacklist_BlacklistTheIps(string addresses, string remoteIp, bool denied)
|
|
|
|
|
{
|
|
|
|
|
// Comma separated list of IP addresses or IP/netmask entries for networks that will be allowed to connect remotely.
|
|
|
|
|
// If left blank, all remote addresses will be allowed.
|
|
|
|
|
var conf = new NetworkConfiguration()
|
|
|
|
|
{
|
|
|
|
|
EnableIPV4 = true,
|
|
|
|
|
RemoteIPFilter = addresses.Split(','),
|
|
|
|
|
IsRemoteIPFilterBlacklist = true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
using var nm = new NetworkManager(GetMockConfig(conf), new NullLogger<NetworkManager>());
|
|
|
|
|
|
|
|
|
|
Assert.NotEqual(nm.HasRemoteAccess(IPAddress.Parse(remoteIp)), denied);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|