From 0bc58b66a4850cdb8458a86c3d9a2fc81de82aa3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 11:14:42 +0200 Subject: Adding upstream version 1:2.11. Signed-off-by: Daniel Baumann --- test/t/test_sudo.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 test/t/test_sudo.py (limited to 'test/t/test_sudo.py') diff --git a/test/t/test_sudo.py b/test/t/test_sudo.py new file mode 100644 index 0000000..a349466 --- /dev/null +++ b/test/t/test_sudo.py @@ -0,0 +1,83 @@ +import pytest + +from conftest import assert_complete + + +class TestSudo: + @pytest.mark.complete("sudo -", require_cmd=True) + def test_1(self, completion): + assert completion + + @pytest.mark.complete("sudo cd fo", cwd="shared/default") + def test_2(self, completion): + assert completion == "o.d/" + assert not completion.endswith(" ") + + @pytest.mark.complete("sudo sh share") + def test_3(self, completion): + assert completion == "d/" + assert not completion.endswith(" ") + + @pytest.mark.complete("sudo mount /dev/sda1 def", cwd="shared") + def test_4(self, completion): + assert completion == "ault/" + assert not completion.endswith(" ") + + @pytest.mark.complete("sudo -e -u root bar foo", cwd="shared/default") + def test_5(self, completion): + assert completion == "foo foo.d/".split() + + def test_6(self, bash, part_full_user): + part, full = part_full_user + completion = assert_complete(bash, "sudo chown %s" % part) + assert completion == full[len(part) :] + assert completion.endswith(" ") + + def test_7(self, bash, part_full_user, part_full_group): + _, user = part_full_user + partgroup, fullgroup = part_full_group + completion = assert_complete( + bash, "sudo chown %s:%s" % (user, partgroup) + ) + assert completion == fullgroup[len(partgroup) :] + assert completion.endswith(" ") + + def test_8(self, bash, part_full_group): + part, full = part_full_group + completion = assert_complete(bash, "sudo chown dot.user:%s" % part) + assert completion == full[len(part) :] + assert completion.endswith(" ") + + @pytest.mark.parametrize( + "prefix", + [ + r"funky\ user:", + "funky.user:", + r"funky\.user:", + r"fu\ nky.user:", + r"f\ o\ o\.\bar:", + r"foo\_b\ a\.r\ :", + ], + ) + def test_9(self, bash, part_full_group, prefix): + """Test preserving special chars in $prefix$partgroup.""" + part, full = part_full_group + completion = assert_complete(bash, "sudo chown %s%s" % (prefix, part)) + assert completion == full[len(part) :] + assert completion.endswith(" ") + + def test_10(self, bash, part_full_user, part_full_group): + """Test giving up on degenerate cases instead of spewing junk.""" + _, user = part_full_user + partgroup, _ = part_full_group + for x in range(2, 5): + completion = assert_complete( + bash, "sudo chown %s%s:%s" % (user, x * "\\", partgroup) + ) + assert not completion + + def test_11(self, bash, part_full_group): + """Test graceful fail on colon in user/group name.""" + part, _ = part_full_group + completion = assert_complete(bash, "sudo chown foo:bar:%s" % part) + assert not completion -- cgit v1.2.3