mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add unit tests to cover rich rules normalization
This commit is contained in:
parent
bd60c9b40a
commit
22611256aa
1 changed files with 51 additions and 0 deletions
|
@ -59,3 +59,54 @@ def test_masquerade():
|
|||
"comment": "'public' is already in the desired state.",
|
||||
"name": "public",
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"rich_rule",
|
||||
[
|
||||
(
|
||||
[
|
||||
'rule family="ipv4" source address="192.168.0.0/16" port port=22 protocol=tcp accept'
|
||||
]
|
||||
),
|
||||
(
|
||||
[
|
||||
'rule family="ipv4" source address="192.168.0.0/16" port port=\'22\' protocol=tcp accept'
|
||||
]
|
||||
),
|
||||
(
|
||||
[
|
||||
"rule family='ipv4' source address='192.168.0.0/16' port port='22' protocol=tcp accept"
|
||||
]
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_present_rich_rules_normalized(rich_rule):
|
||||
firewalld_reload_rules = MagicMock(return_value={})
|
||||
firewalld_rich_rules = [
|
||||
'rule family="ipv4" source address="192.168.0.0/16" port port="22" protocol="tcp" accept',
|
||||
]
|
||||
|
||||
firewalld_get_zones = MagicMock(
|
||||
return_value=[
|
||||
"block",
|
||||
"public",
|
||||
]
|
||||
)
|
||||
firewalld_get_masquerade = MagicMock(return_value=True)
|
||||
firewalld_get_rich_rules = MagicMock(return_value=firewalld_rich_rules)
|
||||
|
||||
__salt__ = {
|
||||
"firewalld.reload_rules": firewalld_reload_rules,
|
||||
"firewalld.get_zones": firewalld_get_zones,
|
||||
"firewalld.get_masquerade": firewalld_get_masquerade,
|
||||
"firewalld.get_rich_rules": firewalld_get_rich_rules,
|
||||
}
|
||||
with patch.dict(firewalld.__dict__, {"__salt__": __salt__}):
|
||||
ret = firewalld.present("public", rich_rules=rich_rule)
|
||||
assert ret == {
|
||||
"changes": {},
|
||||
"result": True,
|
||||
"comment": "'public' is already in the desired state.",
|
||||
"name": "public",
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue