test(opened-ports): ufw's commands on a shell; a missing rule deletes as done

This commit is contained in:
christianmanivong committed 2026-11-26 08:16:25 +01:00
1 parent ebd3255e5a
commit cbd1cd3d11
2 files changed
+71 -5

No files matched your search

+9 -4
View File
@@ -223,15 +223,20 @@ def ufw_allow_recorded_command(source: str, port: int, proto: str, purpose: str)
}
)
return (
f'{{ o=$(LC_ALL=C ufw allow {_ufw_rule(source, port, proto)} 2>&1) && echo "$o"'
f' && case "$o" in *Skipping*) ;;'
f"{{ o=$(LC_ALL=C ufw allow {_ufw_rule(source, port, proto)} 2>&1);"
f' s=$?; echo "$o"; [ "$s" -eq 0 ] && case "$o" in *Skipping*) ;;'
f" *'Rule added'*|*'Rules updated'*) {record_opened_rule_command(line)};; esac; }}"
)
def ufw_delete_command(rule: OpenedRuleDict) -> str:
"""The shell, as root, that deletes *rule* from ufw."""
return f"LC_ALL=C ufw delete allow {_ufw_rule(rule['source'], rule['port'], rule['proto'])}"
"""The shell, as root, that deletes *rule* from ufw; done too where ufw no longer
has it ("Could not delete non-existent rule")."""
return (
"{ o=$(LC_ALL=C ufw delete allow"
f" {_ufw_rule(rule['source'], rule['port'], rule['proto'])} 2>&1)"
' || case "$o" in *non-existent*) ;; *) echo "$o"; false ;; esac; }'
)
def revoked_output(