def make_cli_character(character_config, emitter, unlock_keystore: bool = True, unlock_signer: bool = True, teacher_uri: str = None, min_stake: int = 0, json_ipc: bool = False, **config_args ) -> Character: # # Pre-Init # # Handle KEYSTORE if unlock_keystore: unlock_nucypher_keystore(emitter, character_configuration=character_config, password=get_nucypher_password(emitter=emitter, confirm=False)) # Handle Signer/Wallet if unlock_signer: unlock_signer_account(config=character_config, json_ipc=json_ipc) # Handle Teachers # TODO: Is this still relevant? Is it better to DRY this up by doing it later? sage_nodes = list() # # Character Init # # Produce Character if teacher_uri: maybe_sage_node = character_config.known_node_class.from_teacher_uri( teacher_uri=teacher_uri, min_stake=min_stake, federated_only=character_config.federated_only, network_middleware=character_config.network_middleware, registry=character_config.registry ) sage_nodes.append(maybe_sage_node) CHARACTER = character_config(known_nodes=sage_nodes, network_middleware=character_config.network_middleware, **config_args) # # Post-Init # if CHARACTER.controller is not NO_CONTROL_PROTOCOL: CHARACTER.controller.emitter = emitter # Federated if character_config.federated_only: emitter.message(FEDERATED_WARNING, color='yellow') emitter.message(f"Loaded {CHARACTER.__class__.__name__} {CHARACTER.checksum_address} ({CHARACTER.domain})", color='green') return CHARACTER
def test_unlock_nucypher_keystore_invalid_password( mocker, test_emitter, alice_blockchain_test_config, capsys, tmpdir, test_registry_source_manager): # Setup mocker.patch.object(passwords, 'secret_box_decrypt', side_effect=SecretBoxAuthenticationError) mocker.patch.object(CharacterConfiguration, 'dev_mode', return_value=False, new_callable=mocker.PropertyMock) keystore = Keystore.generate(password=INSECURE_DEVELOPMENT_PASSWORD, keystore_dir=tmpdir) alice_blockchain_test_config.attach_keystore(keystore) # Test with pytest.raises(Keystore.AuthenticationFailed): unlock_nucypher_keystore( emitter=test_emitter, password=INSECURE_DEVELOPMENT_PASSWORD + 'typo', character_configuration=alice_blockchain_test_config) captured = capsys.readouterr() assert DECRYPTING_CHARACTER_KEYSTORE.format( name=alice_blockchain_test_config.NAME.capitalize()) in captured.out
def test_unlock_nucypher_keystore(mocker, test_emitter, capsys, alice_blockchain_test_config, patch_keystore, tmpdir): # Setup # Do not test "real" unlocking here, just the plumbing unlock_spy = mocker.patch.object(Keystore, 'unlock', return_value=True) mocker.patch.object(CharacterConfiguration, 'dev_mode', return_value=False, new_callable=mocker.PropertyMock) mocker.patch.object(Mnemonic, 'detect_language', return_value='english') keystore = Keystore.generate(password=INSECURE_DEVELOPMENT_PASSWORD, keystore_dir=tmpdir) alice_blockchain_test_config.attach_keystore(keystore) result = unlock_nucypher_keystore( emitter=test_emitter, password=INSECURE_DEVELOPMENT_PASSWORD, character_configuration=alice_blockchain_test_config) assert result captured = capsys.readouterr() message = DECRYPTING_CHARACTER_KEYSTORE.format( name=alice_blockchain_test_config.NAME.capitalize()) assert message in captured.out unlock_spy.assert_called_once_with(password=INSECURE_DEVELOPMENT_PASSWORD)
def test_unlock_nucypher_keystore_dev_mode(mocker, test_emitter, capsys, alice_blockchain_test_config, tmpdir): # Setup unlock_spy = mocker.spy(Keystore, 'unlock') mocker.patch.object(CharacterConfiguration, 'dev_mode', return_value=True, new_callable=mocker.PropertyMock) keystore = Keystore.generate(password=INSECURE_DEVELOPMENT_PASSWORD, keystore_dir=tmpdir) alice_blockchain_test_config.attach_keystore(keystore) result = unlock_nucypher_keystore( emitter=test_emitter, password=INSECURE_DEVELOPMENT_PASSWORD, character_configuration=alice_blockchain_test_config) assert result output = capsys.readouterr().out message = DECRYPTING_CHARACTER_KEYSTORE.format( name=alice_blockchain_test_config.NAME.capitalize()) assert message in output unlock_spy.assert_not_called()