Skip to content

Commit 59e88e9

Browse files
michalis1michalis1
andauthored
Fix PAN-OS banner parsing by removing IOS-style banner end normalization (#751)
* Remove end of banner normalization * fix tests --------- Co-authored-by: michalis1 <milatis@gmail.com>
1 parent 608d9dc commit 59e88e9

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

changes/750.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix PAN-OS banner parsing by removing IOS-style banner end normalization.

netutils/config/parser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,11 +1522,10 @@ def _build_banner(self, config_line: str) -> t.Optional[str]:
15221522
if not self.is_banner_end(line):
15231523
banner_config.append(line)
15241524
else:
1525-
line = normalise_delimiter_caret_c(self.banner_end, line)
15261525
banner_config.append(line.strip())
15271526
line = "\n".join(banner_config)
1528-
if line.endswith("^C"):
1529-
banner, end, _ = line.rpartition("^C")
1527+
if line.endswith('"'):
1528+
banner, end, _ = line.rpartition('"')
15301529
line = banner + end
15311530
self._update_config_lines(line.strip())
15321531
self._current_parents = self._current_parents[:-1]

tests/unit/mock/config/parser/base/paloalto_panos/panos_basic_received.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
parents=(),
3131
),
3232
ConfigLine(
33-
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",
33+
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"',
3434
parents=('set deviceconfig system login-banner "',),
3535
),
3636
ConfigLine(

tests/unit/mock/config/parser/base/paloalto_panos/panos_basic_set_received.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
parents=(),
3131
),
3232
ConfigLine(
33-
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",
33+
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************************************************************************"',
3434
parents=('set deviceconfig system login-banner "',),
3535
),
3636
ConfigLine(

tests/unit/mock/config/parser/base/paloalto_panos/panos_full_received.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@
272272
ConfigLine(config_line="set deviceconfig system hostname firewall1", parents=()),
273273
ConfigLine(config_line='set deviceconfig system login-banner "', parents=()),
274274
ConfigLine(
275-
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",
275+
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"',
276276
parents=('set deviceconfig system login-banner "',),
277277
),
278278
ConfigLine(

0 commit comments

Comments
 (0)