-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
brainbot-devops
committed
Aug 23, 2019
1 parent
f23fa20
commit db6adfd
Showing
8 changed files
with
229 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from scenario_player.exceptions import ScenarioError | ||
|
||
|
||
class WrongPassword(ScenarioError): | ||
""" | ||
Generic Error that gets raised if eth_keystore raises ValueError("MAC mismatch") | ||
Usually that's caused by an invalid password | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"id":"e66b03f8-4ce7-8f9b-b5d1-36dc9d5154ba","version":3,"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"49b8891b02604fb05884280509b82fbb"},"ciphertext":"4ce3a7059820b516746d7cc5defca17c2a54ea9dbb7e3a5411a01630b5021244","kdf":"pbkdf2","kdfparams":{"c":10240,"dklen":32,"prf":"hmac-sha256","salt":"9ef5e56c835cf59f4c9dbe6bd6a88b11056d6f01c0590c17d1cbb1653f749e7a"},"mac":"861354d5dd3efb2c6470090fb901957c53035175ababc9dc1863f5c07572d33b"},"address":"ec1fdb2d29c5689416b3f1b55a4d879fddf0e6e3","name":"","meta":"{}"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
123 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
123456 |
48 changes: 48 additions & 0 deletions
48
tests/unittests/cli/scenario/join-network-scenario-J1.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
version: 2 | ||
|
||
settings: | ||
gas_price: "fast" | ||
chain: any | ||
services: | ||
pfs: | ||
url: https://pfs-goerli.services-dev.raiden.network | ||
udc: | ||
enable: true | ||
token: | ||
deposit: true | ||
|
||
token: | ||
|
||
nodes: | ||
mode: managed | ||
count: 4 | ||
|
||
default_options: | ||
gas-price: fast | ||
environment-type: development | ||
routing-mode: pfs | ||
pathfinding-max-paths: 5 | ||
pathfinding-max-fee: 10 | ||
|
||
scenario: | ||
serial: | ||
tasks: | ||
- parallel: | ||
name: "Setting up a network" | ||
tasks: | ||
- open_channel: {from: 0, to: 1, total_deposit: 10, expected_http_status: 201} | ||
- open_channel: {from: 0, to: 2, total_deposit: 10, expected_http_status: 201} | ||
- open_channel: {from: 1, to: 2, total_deposit: 10, expected_http_status: 201} | ||
- serial: | ||
name: "Checking the network" | ||
tasks: | ||
- assert: {from: 0, to: 1, total_deposit: 10, balance: 10, state: "opened"} | ||
- assert: {from: 0, to: 2, total_deposit: 10, balance: 10, state: "opened"} | ||
- assert: {from: 1, to: 2, total_deposit: 10, balance: 10, state: "opened"} | ||
- serial: | ||
name: "Node Nr. 4 joins" | ||
tasks: | ||
- join_network: {from: 3, funds: 100, initial_channel_target: 3, joinable_funds_target: 0.4, expected_http_status: 204} | ||
- assert: {from: 3, to: 0, total_deposit: 20, balance: 20, state: "opened"} | ||
- assert: {from: 3, to: 1, total_deposit: 20, balance: 20, state: "opened"} | ||
- assert: {from: 3, to: 2, total_deposit: 20, balance: 20, state: "opened"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from pathlib import Path | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from click.testing import CliRunner | ||
|
||
from scenario_player import main | ||
from scenario_player.exceptions.cli import WrongPassword | ||
|
||
KEYSTORE_PATH = str(Path(__file__).resolve().parents[0].joinpath("keystore")) | ||
SCENARIO = f"{Path(__file__).parent.joinpath('scenario', 'join-network-scenario-J1.yaml')}" | ||
CLI_ARGS = f"--chain goerli:http://geth.goerli.ethnodes.brainbot.com:8545 run " \ | ||
f"--keystore-file " + KEYSTORE_PATH + "/UTC--1 " \ | ||
f"--no-ui " \ | ||
f"{{pw_option}} " \ | ||
f"{SCENARIO}" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def runner(): | ||
return CliRunner() | ||
|
||
|
||
class Sentinel(Exception): | ||
pass | ||
|
||
|
||
class TestPasswordHandling: | ||
# use a fixture instead of patch directly, | ||
# to avoid having to pass an extra argument to all methods. | ||
@pytest.fixture(autouse=True) | ||
def patch_collect_tasks_on_setup(self): | ||
with patch("scenario_player.main.collect_tasks", side_effect=Sentinel): | ||
# Yield instead of return, | ||
# as that allows the patching to be undone after the test is complete. | ||
yield | ||
|
||
def test_password_file_not_existent(self, runner): | ||
"""A not existing password file should raise error""" | ||
result = runner.invoke( | ||
main.main, | ||
CLI_ARGS.format(pw_option=f"--password-file /does/not/exist").split(" ") | ||
) | ||
assert result.exit_code == 2 | ||
assert '"--password-file": File "/does/not/exist" does not exist.' in result.output | ||
|
||
def test_mutually_exclusive(self, runner): | ||
result = runner.invoke( | ||
main.main, | ||
CLI_ARGS.format( | ||
pw_option= | ||
f"--password-file {KEYSTORE_PATH}" + "/password " + "--password 123").split(" ") | ||
) | ||
assert result.exit_code == 2 | ||
assert 'Error: Illegal usage: password_file is mutually exclusive' in result.output | ||
|
||
@pytest.mark.parametrize( | ||
"password_file, expected_exec", | ||
argvalues=[("/wrong_password", WrongPassword), ("/password", Sentinel)], | ||
ids=["wrong password", "correct password"], | ||
) | ||
def test_password_file(self, password_file, expected_exec, runner): | ||
result = runner.invoke(main.main, CLI_ARGS.format( | ||
pw_option=f"--password-file {KEYSTORE_PATH + password_file}")) | ||
assert result.exc_info[0] == expected_exec | ||
assert result.exit_code == 1 | ||
|
||
@pytest.mark.parametrize( | ||
"password, expected_exc", | ||
argvalues=[("wrong_password", WrongPassword), ("123", Sentinel)], | ||
ids=["wrong password", "correct password"], | ||
) | ||
def test_password(self, password, expected_exc, runner): | ||
result = runner.invoke(main.main, | ||
CLI_ARGS.format(pw_option=f"--password {password}").split(" ")) | ||
assert result.exc_info[0] == expected_exc | ||
assert result.exit_code == 1 | ||
|
||
@pytest.mark.parametrize( | ||
"user_input, expected_exc", | ||
argvalues=[("wrongpassword", WrongPassword), ("123", Sentinel)], | ||
ids=["wrong password", "correct password"], | ||
) | ||
def test_manual_password_validation(self, user_input, expected_exc, runner): | ||
result = runner.invoke(main.main, | ||
CLI_ARGS.format(pw_option=f"--password {user_input}").split(" ")) | ||
assert result.exc_info[0] == expected_exc | ||
assert result.exit_code == 1 |