diff --git a/netutils/config/parser.py b/netutils/config/parser.py index 5e4ddbb8..40d62025 100644 --- a/netutils/config/parser.py +++ b/netutils/config/parser.py @@ -913,6 +913,7 @@ def banner_end(self) -> str: class ASAConfigParser(CiscoConfigParser): """Cisco ASA implementation of ConfigParser Class.""" + banner_start: t.List[str] = ["banner"] comment_chars: t.List[str] = ["!", ":"] def __init__(self, config: str): @@ -925,6 +926,22 @@ def __init__(self, config: str): self.same_line_children: t.Set[ConfigLine] = set() super(ASAConfigParser, self).__init__(config) + def is_banner_start(self, line: str) -> bool: + """Determine if the line starts a banner config. + + Args: + line: The current config line in iteration. + + Returns: + True if line starts banner, else False. + """ + for banner_start in self.banner_start: + if not line: + return False + if line.startswith(banner_start): + return True + return False + def _update_config_lines(self, config_line: str) -> None: """Add a ``ConfigLine`` object to ``self.config_lines``. diff --git a/tests/unit/mock/config/parser/base/cisco_asa/asa_nested_banner_received.py b/tests/unit/mock/config/parser/base/cisco_asa/asa_nested_banner_received.py new file mode 100644 index 00000000..910e519e --- /dev/null +++ b/tests/unit/mock/config/parser/base/cisco_asa/asa_nested_banner_received.py @@ -0,0 +1,13 @@ +from netutils.config.parser import ConfigLine + +data = [ + ConfigLine(config_line="group-policy Grs-POLICY attributes", parents=()), + ConfigLine( + config_line=" banner value This is an", + parents=("group-policy Grs-POLICY attributes",), + ), + ConfigLine( + config_line=" banner value example nested banner", + parents=("group-policy Grs-POLICY attributes",), + ), +] diff --git a/tests/unit/mock/config/parser/base/cisco_asa/asa_nested_banner_sent.txt b/tests/unit/mock/config/parser/base/cisco_asa/asa_nested_banner_sent.txt new file mode 100644 index 00000000..ed8c8f09 --- /dev/null +++ b/tests/unit/mock/config/parser/base/cisco_asa/asa_nested_banner_sent.txt @@ -0,0 +1,3 @@ +group-policy Grs-POLICY attributes + banner value This is an + banner value example nested banner \ No newline at end of file diff --git a/tests/unit/test_parser.py b/tests/unit/test_parser.py index c7ff747e..26a50963 100644 --- a/tests/unit/test_parser.py +++ b/tests/unit/test_parser.py @@ -4,6 +4,7 @@ import os import pytest + from netutils.config import compliance MOCK_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "mock", "config", "parser")