Linux sudo raises UnexpectedExit instead of AuthFailure on incorrect password
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- python
- Domain
- authentication, cli
Research direction
Start with the Linux sudo path in invoke/context.py, especially _sudo, then trace the runner behavior named in invoke/runners.py through _finish. Compare the incorrect-password result with the macOS behavior; done means invoke.sudo raises AuthFailure rather than UnexpectedExit for the reported Linux case.
Written by the indexing model from the issue text.
Description
On Linux, invoke.sudo raises UnexpectedExit instead of AuthFailure on incorrect password.
>>> import invoke
>>> invoke.sudo("ls", password="a")
[sudo] password: Sorry, try again.
[sudo] password: Sorry, try again.
[sudo] password: sudo: 3 incorrect password attempts
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/nelson/foo/.venv/lib/python3.7/site-packages/invoke/__init__.py", line 68, in sudo
return Context().sudo(command, **kwargs)
File "/home/nelson/foo/.venv/lib/python3.7/site-packages/invoke/context.py", line 170, in sudo
return self._sudo(runner, command, **kwargs)
File "/home/nelson/foo/.venv/lib/python3.7/site-packages/invoke/context.py", line 215, in _sudo
return runner.run(cmd_str, watchers=watchers, **kwargs)
File "/home/nelson/foo/.venv/lib/python3.7/site-packages/invoke/runners.py", line 376, in run
return self._run_body(command, **kwargs)
File "/home/nelson/foo/.venv/lib/python3.7/site-packages/invoke/runners.py", line 432, in _run_body
return self.make_promise() if self._asynchronous else self._finish()
File "/home/nelson/foo/.venv/lib/python3.7/site-packages/invoke/runners.py", line 499, in _finish
raise UnexpectedExit(result)
invoke.exceptions.UnexpectedExit: Encountered a bad command exit code!
Command: "sudo -S -p '[sudo] password: ' ls"
Exit code: 1
Stdout: already printed
Stderr: already printed
Version info
invoke: 2.0.0 (also tested on 1.7.1)
OS: Ubuntu 20.04.5 LTS
Python: 3.7.13 (also tested on 3.8.13 and 3.10.5)
I tested this on macOS and it raises AuthFailure as expected.
- Dominant language
- Python
- Stars
- 4.8k
- Forks
- 412
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from pyinvoke/invoke
-
[Security] Shell injection via Context.cd() path argument — metacharacters not escaped (CWE-78) Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
stephrobert/dsoxlab#238 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
sublimehq/package_control#1780 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
nwg-piotr/nwg-displays#145 ·