mirror of
https://github.com/certbot/certbot.git
synced 2026-08-02 03:11:55 +02:00
Properly handle EOF in input (#4612)
* properly handle eof * cleanup InputWithTimeoutTest * add test_eof * add comment about mimicking getpass
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import inspect
|
||||
import os
|
||||
import socket
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import six
|
||||
@@ -25,15 +26,17 @@ class InputWithTimeoutTest(unittest.TestCase):
|
||||
from certbot.display.util import input_with_timeout
|
||||
return input_with_timeout(*args, **kwargs)
|
||||
|
||||
def setUp(self):
|
||||
self.expected_msg = "foo bar"
|
||||
self.stdin = six.StringIO(self.expected_msg + "\n")
|
||||
def test_eof(self):
|
||||
with tempfile.TemporaryFile("r+") as f:
|
||||
with mock.patch("certbot.display.util.sys.stdin", new=f):
|
||||
self.assertRaises(EOFError, self._call)
|
||||
|
||||
def test_input(self, prompt=None):
|
||||
expected = "foo bar"
|
||||
stdin = six.StringIO(expected + "\n")
|
||||
with mock.patch("certbot.display.util.select.select") as mock_select:
|
||||
mock_select.return_value = ([self.stdin], [], [],)
|
||||
self.assertEqual(display_util.input_with_timeout(prompt),
|
||||
self.expected_msg)
|
||||
mock_select.return_value = ([stdin], [], [],)
|
||||
self.assertEqual(self._call(prompt), expected)
|
||||
|
||||
@mock.patch("certbot.display.util.sys.stdout")
|
||||
def test_input_with_prompt(self, mock_stdout):
|
||||
|
||||
Reference in New Issue
Block a user