Complete typed map ergonomics and preview API
This commit is contained in:
@@ -119,6 +119,61 @@ public sealed class NftablesClientIntegrationTests
|
||||
Assert.True(result.IsValid);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ValidateAndRenderRuleset_WithTypedMapAndRule_ReturnsValidResult()
|
||||
{
|
||||
if (!CanCreateClient())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var client = new NftablesClient();
|
||||
var ruleset = new NftRuleset();
|
||||
var table = new NftTable
|
||||
{
|
||||
Family = NftFamily.Inet,
|
||||
Name = "typed_preview",
|
||||
};
|
||||
var set = new NftSet
|
||||
{
|
||||
Name = "blocked_ipv4",
|
||||
Type = NftSetType.Ipv4Address,
|
||||
};
|
||||
set.Elements.Add(NftValue.Address(System.Net.IPAddress.Parse("10.0.0.1")));
|
||||
table.Sets.Add(set);
|
||||
|
||||
var map = new NftMap
|
||||
{
|
||||
Name = "service_policy",
|
||||
KeyType = NftMapType.InetService,
|
||||
ValueType = NftMapType.Verdict,
|
||||
};
|
||||
map.Add(NftValue.Port(80), NftValue.Verdict(NftVerdict.Accept));
|
||||
table.Maps.Add(map);
|
||||
|
||||
var chain = new NftChain
|
||||
{
|
||||
Name = "input",
|
||||
Type = NftChainType.Filter,
|
||||
Hook = NftHook.Input,
|
||||
Priority = 0,
|
||||
};
|
||||
chain.Rules.Add(new NftRule
|
||||
{
|
||||
SourceAddressSetName = "blocked_ipv4",
|
||||
TransportProtocol = NftTransportProtocol.Tcp,
|
||||
DestinationPort = NftValue.Port(22),
|
||||
Verdict = NftVerdict.Accept,
|
||||
});
|
||||
table.Chains.Add(chain);
|
||||
ruleset.Tables.Add(table);
|
||||
|
||||
NftRenderedValidationResult result = client.ValidateAndRenderRuleset(ruleset);
|
||||
|
||||
Assert.True(result.ValidationResult.IsValid);
|
||||
Assert.Contains("add map inet typed_preview service_policy", result.RenderedRulesetText, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static bool CanCreateClient()
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user