(pyfile, tmpdir, run, target)
| 138 | @pytest.mark.skipif(sys.platform == "win32", reason="sudo not available on Windows") |
| 139 | @pytest.mark.parametrize("run", runners.all_launch) |
| 140 | def test_sudo(pyfile, tmpdir, run, target): |
| 141 | # Since the test can't rely on sudo being allowed for the user, create a dummy |
| 142 | # sudo script that doesn't actually elevate, but sets an environment variable |
| 143 | # that can be checked in the debuggee. |
| 144 | sudo = tmpdir / "sudo" |
| 145 | sudo.write( |
| 146 | """#!/bin/sh |
| 147 | if [ "$1" = "-E" ]; then shift; fi |
| 148 | exec env DEBUGPY_SUDO=1 "$@" |
| 149 | """ |
| 150 | ) |
| 151 | os.chmod(sudo.strpath, 0o777) |
| 152 | |
| 153 | @pyfile |
| 154 | def code_to_debug(): |
| 155 | import os |
| 156 | |
| 157 | import debuggee |
| 158 | from debuggee import backchannel |
| 159 | |
| 160 | debuggee.setup() |
| 161 | backchannel.send(os.getenv("DEBUGPY_SUDO", "0")) |
| 162 | |
| 163 | with debug.Session() as session: |
| 164 | session.config["sudo"] = True |
| 165 | session.spawn_adapter.env["PATH"] = session.spawn_debuggee.env["PATH"] = ( |
| 166 | tmpdir.strpath + ":" + os.environ["PATH"] |
| 167 | ) |
| 168 | |
| 169 | backchannel = session.open_backchannel() |
| 170 | with run(session, target(code_to_debug)): |
| 171 | pass |
| 172 | |
| 173 | # The "runInTerminal" request sent by the adapter to spawn the launcher, |
| 174 | # if any, shouldn't be using sudo. |
| 175 | assert all( |
| 176 | "sudo" not in req.arguments["args"] |
| 177 | for req in session.all_occurrences_of(timeline.Request("runInTerminal")) |
| 178 | ) |
| 179 | |
| 180 | # The launcher, however, should use our dummy sudo to spawn the debuggee, |
| 181 | # and the debuggee should report the environment variable accordingly. |
| 182 | assert backchannel.receive() == "1" |
| 183 | |
| 184 | |
| 185 | def make_custompy(tmpdir, id=""): |
nothing calls this directly
no test coverage detected
searching dependent graphs…