Add test for checking automatically determining IP

pull/1040/head
tuxxy 2019-05-15 13:02:35 -06:00 committed by Kieran Prasch
parent 12ef4c48d6
commit 882ce735ab
No known key found for this signature in database
GPG Key ID: 199AB839D4125A62
1 changed files with 75 additions and 3 deletions

View File

@ -15,15 +15,21 @@ You should have received a copy of the GNU Affero General Public License
along with nucypher. If not, see <https://www.gnu.org/licenses/>. along with nucypher. If not, see <https://www.gnu.org/licenses/>.
""" """
import pytest_twisted as pt
import time import time
import pytest
import pytest_twisted as pt
from twisted.internet import threads from twisted.internet import threads
from nucypher.characters.base import Learner from nucypher.characters.base import Learner
from nucypher.cli import actions
from nucypher.cli.main import nucypher_cli from nucypher.cli.main import nucypher_cli
from nucypher.config.node import NodeConfiguration from nucypher.config.node import NodeConfiguration
from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD, \ from nucypher.utilities.sandbox.constants import (
MOCK_URSULA_STARTING_PORT, TEMPORARY_DOMAIN INSECURE_DEVELOPMENT_PASSWORD,
MOCK_URSULA_STARTING_PORT,
TEMPORARY_DOMAIN
)
from nucypher.utilities.sandbox.ursula import start_pytest_ursula_services from nucypher.utilities.sandbox.ursula import start_pytest_ursula_services
@ -108,3 +114,69 @@ def test_ursula_cannot_init_with_dev_flag(click_runner):
result = click_runner.invoke(nucypher_cli, init_args, catch_exceptions=False) result = click_runner.invoke(nucypher_cli, init_args, catch_exceptions=False)
assert result.exit_code == 2 assert result.exit_code == 2
assert 'Cannot create a persistent development character' in result.output, 'Missing or invalid error message was produced.' assert 'Cannot create a persistent development character' in result.output, 'Missing or invalid error message was produced.'
def test_ursula_rest_host_determination(click_runner):
# Patch the get_external_ip call
original_call = actions.get_external_ip
actions.get_external_ip = lambda: '192.0.2.0'
args = ('ursula', 'init',
'--federated-only',
'--network', TEMPORARY_DOMAIN
)
user_input = f'Y\n{INSECURE_DEVELOPMENT_PASSWORD}\n{INSECURE_DEVELOPMENT_PASSWORD}'
breakpoint()
result = click_runner.invoke(nucypher_cli, args, catch_exceptions=False,
input=user_input)
assert result.exit_code == 0
assert '(192.0.2.0)' in result.output
args = ('ursula', 'init',
'--federated-only',
'--network', TEMPORARY_DOMAIN,
'--force'
)
user_input = f'{INSECURE_DEVELOPMENT_PASSWORD}\n{INSECURE_DEVELOPMENT_PASSWORD}\n'
result = click_runner.invoke(nucypher_cli, args, catch_exceptions=False,
input=user_input)
assert result.exit_code == 0
assert 'IP 192.0.2.0' in result.output
# Patch get_external_ip call to error output
actions.get_external_ip = lambda: None
args = ('ursula', 'init',
'--federated-only',
'--network', TEMPORARY_DOMAIN,
'--force'
)
user_input = f'{INSECURE_DEVELOPMENT_PASSWORD}\n{INSECURE_DEVELOPMENT_PASSWORD}\n'
with pytest.raises(RuntimeError):
result = click_runner.invoke(nucypher_cli, args, catch_exceptions=True,
input=user_input)
# Patch get_external_ip call to return bad IP
actions.get_external_ip = lambda: '382.328.382.328'
args = ('ursula', 'init',
'--federated-only',
'--network', TEMPORARY_DOMAIN,
'--force'
)
user_input = f'{INSECURE_DEVELOPMENT_PASSWORD}\n{INSECURE_DEVELOPMENT_PASSWORD}\n'
with pytest.raises(OSError):
result = click_runner.invoke(nucypher_cli, args, catch_exceptions=True,
input=user_input)
# Unpatch call
actions.get_external_ip = original_call