Merge remote-tracking branch 'origin/main' into fix/hosts-tempfile-2446
driver / standard (pull_request) Successful in 14s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Successful in 50s
driver / test (3.12) (pull_request) Successful in 58s
driver / test (3.13) (pull_request) Successful in 58s
driver / lowest (pull_request) Successful in 31s
driver / build (pull_request) Successful in 25s
driver / security (pull_request) Successful in 57s
CI / driver (pull_request) Successful in 2m23s
driver / publish (pull_request) Skipped
driver / standard (pull_request) Successful in 14s
driver / lint (pull_request) Successful in 13s
driver / types (pull_request) Successful in 50s
driver / test (3.12) (pull_request) Successful in 58s
driver / test (3.13) (pull_request) Successful in 58s
driver / lowest (pull_request) Successful in 31s
driver / build (pull_request) Successful in 25s
driver / security (pull_request) Successful in 57s
CI / driver (pull_request) Successful in 2m23s
driver / publish (pull_request) Skipped
This commit is contained in:
commit
a421a595d4
3 files changed
+60
-9
No files matched your search
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import re
|
||||
import shlex
|
||||
|
||||
import pytest
|
||||
from napalm.base.exceptions import CommandErrorException
|
||||
@@ -107,6 +108,51 @@ def test_an_unreadable_cluster_check_refuses_too(driver, node):
|
||||
assert [c for c in node.ran if "corosync.conf" not in c] == []
|
||||
|
||||
|
||||
# ── the name reaches the shell quoted (NetOrk/netork#2456) ──────────────────
|
||||
#
|
||||
# The name went into the root commands between single quotes of their own, so a name
|
||||
# with a single quote ended them: ``x';reboot;'`` ran ``reboot``. Each command now
|
||||
# hands it on as one shell word, whatever it holds.
|
||||
|
||||
INJECTED = "x';reboot;'"
|
||||
|
||||
|
||||
def _run(node: _Node, start: str) -> str:
|
||||
return next(c for c in node.ran if c.startswith(start))
|
||||
|
||||
|
||||
def test_the_runtime_hostname_is_one_word(driver, node):
|
||||
driver.set_hostname(f"{INJECTED}.dom.lan")
|
||||
|
||||
assert shlex.split(_run(node, "hostname ")) == ["hostname", INJECTED]
|
||||
|
||||
|
||||
def test_postfix_gets_the_fqdn_as_one_word(driver, node):
|
||||
driver.set_hostname(f"{INJECTED}.dom.lan")
|
||||
|
||||
words = shlex.split(_run(node, "command -v postconf"))
|
||||
assert words[words.index("-e") + 1] == f"myhostname = {INJECTED}.dom.lan"
|
||||
|
||||
|
||||
def test_the_node_directory_is_moved_by_quoted_paths(driver, node):
|
||||
driver.set_hostname(INJECTED)
|
||||
|
||||
words = shlex.split(_run(node, "if [ -d"))
|
||||
assert words[words.index("mv") + 1 : words.index("mv") + 3] == [
|
||||
"/etc/pve/nodes/pve",
|
||||
f"/etc/pve/nodes/{INJECTED}",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name", [INJECTED, "$(reboot)", "`reboot`", "a b"])
|
||||
def test_no_command_runs_what_the_name_holds(driver, node, name):
|
||||
driver.set_hostname(name)
|
||||
|
||||
for command in node.ran:
|
||||
words = list(shlex.shlex(command, posix=True, punctuation_chars=True))
|
||||
assert "reboot" not in words, command
|
||||
|
||||
|
||||
# ── /etc/hosts is written through a private temporary file (#66, NetOrk/netork#2446) ──
|
||||
#
|
||||
# The new file was written as root to the fixed /tmp/_netork_hosts and moved over
|
||||
|
||||
Reference in new issue
Block a user