diff --git a/changes/750.fixed b/changes/750.fixed new file mode 100644 index 00000000..6a636101 --- /dev/null +++ b/changes/750.fixed @@ -0,0 +1 @@ +Fix PAN-OS banner parsing by removing IOS-style banner end normalization. \ No newline at end of file diff --git a/netutils/config/parser.py b/netutils/config/parser.py index 32a511be..e08dd690 100644 --- a/netutils/config/parser.py +++ b/netutils/config/parser.py @@ -1522,11 +1522,10 @@ def _build_banner(self, config_line: str) -> t.Optional[str]: if not self.is_banner_end(line): banner_config.append(line) else: - line = normalise_delimiter_caret_c(self.banner_end, line) banner_config.append(line.strip()) line = "\n".join(banner_config) - if line.endswith("^C"): - banner, end, _ = line.rpartition("^C") + if line.endswith('"'): + banner, end, _ = line.rpartition('"') line = banner + end self._update_config_lines(line.strip()) self._current_parents = self._current_parents[:-1] diff --git a/tests/unit/mock/config/parser/base/paloalto_panos/panos_basic_received.py b/tests/unit/mock/config/parser/base/paloalto_panos/panos_basic_received.py index 04c2c7e6..c8a87857 100644 --- a/tests/unit/mock/config/parser/base/paloalto_panos/panos_basic_received.py +++ b/tests/unit/mock/config/parser/base/paloalto_panos/panos_basic_received.py @@ -30,7 +30,7 @@ parents=(), ), ConfigLine( - config_line="************************************************************************\n* firewall1.example.com * [PROD VM500 firewalls]\n************************************************************************\n* WARNING *\n* Unauthorized access to this device or devices attached to *\n* or accessible from this network is strictly prohibited. *\n* Possession of passwords or devices enabling access to this *\n* device or devices does not constitute authorization. Unauthorized *\n* access will be prosecuted to the fullest extent of the law. *\n* *\n************************************************************************\n\n^C", + config_line='************************************************************************\n* firewall1.example.com * [PROD VM500 firewalls]\n************************************************************************\n* WARNING *\n* Unauthorized access to this device or devices attached to *\n* or accessible from this network is strictly prohibited. *\n* Possession of passwords or devices enabling access to this *\n* device or devices does not constitute authorization. Unauthorized *\n* access will be prosecuted to the fullest extent of the law. *\n* *\n************************************************************************\n\n"', parents=('set deviceconfig system login-banner "',), ), ConfigLine( diff --git a/tests/unit/mock/config/parser/base/paloalto_panos/panos_basic_set_received.py b/tests/unit/mock/config/parser/base/paloalto_panos/panos_basic_set_received.py index 51516605..3f51be37 100644 --- a/tests/unit/mock/config/parser/base/paloalto_panos/panos_basic_set_received.py +++ b/tests/unit/mock/config/parser/base/paloalto_panos/panos_basic_set_received.py @@ -30,7 +30,7 @@ parents=(), ), ConfigLine( - config_line="************************************************************************\n* firewall1.example.com * [PROD VM500 firewalls]\n************************************************************************\n* WARNING *\n* Unauthorized access to this device or devices attached to *\n* or accessible from this network is strictly prohibited. *\n* Possession of passwords or devices enabling access to this *\n* device or devices does not constitute authorization. Unauthorized *\n* access will be prosecuted to the fullest extent of the law. *\n* *\n************************************************************************^C", + config_line='************************************************************************\n* firewall1.example.com * [PROD VM500 firewalls]\n************************************************************************\n* WARNING *\n* Unauthorized access to this device or devices attached to *\n* or accessible from this network is strictly prohibited. *\n* Possession of passwords or devices enabling access to this *\n* device or devices does not constitute authorization. Unauthorized *\n* access will be prosecuted to the fullest extent of the law. *\n* *\n************************************************************************"', parents=('set deviceconfig system login-banner "',), ), ConfigLine( diff --git a/tests/unit/mock/config/parser/base/paloalto_panos/panos_full_received.py b/tests/unit/mock/config/parser/base/paloalto_panos/panos_full_received.py index 4cf8a408..71a1adb5 100644 --- a/tests/unit/mock/config/parser/base/paloalto_panos/panos_full_received.py +++ b/tests/unit/mock/config/parser/base/paloalto_panos/panos_full_received.py @@ -272,7 +272,7 @@ ConfigLine(config_line="set deviceconfig system hostname firewall1", parents=()), ConfigLine(config_line='set deviceconfig system login-banner "', parents=()), ConfigLine( - config_line="************************************************************************\n* firewall1.example.com * [PROD VM500 firewalls]\n************************************************************************\n* WARNING *\n* Unauthorized access to this device or devices attached to *\n* or accessible from this network is strictly prohibited. *\n* Possession of passwords or devices enabling access to this *\n* device or devices does not constitute authorization. Unauthorized *\n* access will be prosecuted to the fullest extent of the law. *\n* *\n************************************************************************\n\n^C", + config_line='************************************************************************\n* firewall1.example.com * [PROD VM500 firewalls]\n************************************************************************\n* WARNING *\n* Unauthorized access to this device or devices attached to *\n* or accessible from this network is strictly prohibited. *\n* Possession of passwords or devices enabling access to this *\n* device or devices does not constitute authorization. Unauthorized *\n* access will be prosecuted to the fullest extent of the law. *\n* *\n************************************************************************\n\n"', parents=('set deviceconfig system login-banner "',), ), ConfigLine(