[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Test resuming_ephemeral_hidden_service example
commit 30e95d4feb4a72cdb62dfef963236b7368e7c7e9
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Fri Oct 2 12:31:38 2020 -0700
Test resuming_ephemeral_hidden_service example
---
.../example/resuming_ephemeral_hidden_service.py | 2 +-
test/unit/examples.py | 22 ++++++++++++++++++++--
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/docs/_static/example/resuming_ephemeral_hidden_service.py b/docs/_static/example/resuming_ephemeral_hidden_service.py
index d2073f03..3277bce2 100644
--- a/docs/_static/example/resuming_ephemeral_hidden_service.py
+++ b/docs/_static/example/resuming_ephemeral_hidden_service.py
@@ -19,5 +19,5 @@ with Controller.from_port() as controller:
service = controller.create_ephemeral_hidden_service({80: 5000}, key_type = key_type, key_content = key_content, await_publication = True)
print("Resumed %s.onion" % service.service_id)
- raw_input('press any key to shut the service down...')
+ input('press any key to shut the service down...')
controller.remove_ephemeral_hidden_service(service.service_id)
diff --git a/test/unit/examples.py b/test/unit/examples.py
index e1c223bf..0b66c124 100644
--- a/test/unit/examples.py
+++ b/test/unit/examples.py
@@ -868,8 +868,26 @@ class TestExamples(unittest.TestCase):
relay_connections.main([])
self.assertEqual(EXPECTED_RELAY_CONNECTIONS, stdout_mock.getvalue())
- def test_resuming_ephemeral_hidden_service(self):
- pass
+ @patch('builtins.input', Mock())
+ @patch('os.path.expanduser', Mock(return_value = '/tmp/stem_hs_test'))
+ @patch('stem.control.Controller.from_port', spec = Controller)
+ @patch('sys.stdout', new_callable = io.StringIO)
+ def test_resuming_ephemeral_hidden_service(self, stdout_mock, from_port_mock):
+ hs_response = '250-ServiceID=gfzprpioee3hoppz\n250-PrivateKey=RSA1024:MIICXgIB\n250 OK'
+
+ controller = from_port_mock().__enter__()
+ controller.create_ephemeral_hidden_service.return_value = ControlMessage.from_str(hs_response, 'ADD_ONION', normalize = True)
+
+ try:
+ import resuming_ephemeral_hidden_service
+
+ with open('/tmp/stem_hs_test') as key_file:
+ self.assertEqual('RSA1024:MIICXgIB', key_file.read())
+
+ self.assertEqual('Started a new hidden service with the address of gfzprpioee3hoppz.onion\n', stdout_mock.getvalue())
+ finally:
+ if os.path.exists('/tmp/stem_hs_test'):
+ os.remove('/tmp/stem_hs_test')
@patch('stem.control.Controller.from_port', spec = Controller)
@patch('shutil.rmtree')
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits