def test_password_process(self): self.assertTrue(Security.new_password_required()) password = "******" secrets_manager = ETHKeyFileSecretManger(password) store_password_verification(secrets_manager) self.assertFalse(Security.new_password_required()) self.assertTrue(validate_password(secrets_manager)) another_secrets_manager = ETHKeyFileSecretManger("another-password") self.assertFalse(validate_password(another_secrets_manager))
def login_prompt(secrets_manager_cls: Type[BaseSecretsManager], style: Style): err_msg = None secrets_manager = None if Security.new_password_required() and legacy_confs_exist(): secrets_manager = migrate_configs_prompt(secrets_manager_cls, style) if Security.new_password_required(): show_welcome(style) password = input_dialog(title="Set Password", text=""" Create a password to protect your sensitive data. This password is not shared with us nor with anyone else, so please store it securely. If you have used hummingbot before and already have secure configs stored, input your previous password in this prompt. The next step will automatically migrate your existing configs. Enter your new password:""", password=True, style=style).run() if password is None: return None re_password = input_dialog(title="Set Password", text="Please re-enter your password:"******"Passwords entered do not match, please try again." else: secrets_manager = secrets_manager_cls(password) store_password_verification(secrets_manager) migrate_non_secure_only_prompt(style) else: password = input_dialog(title="Welcome back to Hummingbot", text="Enter your password:"******"Invalid password - please try again." if err_msg is not None: message_dialog(title='Error', text=err_msg, style=style).run() return login_prompt(secrets_manager_cls, style) return secrets_manager
def test_new_password_process(self): # empty folder, new password is required self.assertFalse(Security.any_encryped_files()) self.assertTrue(Security.new_password_required()) # login will pass with any password result = Security.login("a") self.assertTrue(result) Security.update_secure_config("new_key", "new_value") self.assertTrue(os.path.exists(f"{temp_folder}encrypted_new_key.json")) self.assertTrue(Security.encrypted_file_exists("new_key"))
def login_prompt(): from hummingbot.client.config.security import Security err_msg = None if Security.new_password_required(): show_welcome() password = input_dialog( title="Set Password", text="Create a password to protect your sensitive data. " "This password is not shared with us nor with anyone else, so please store it securely." "\n\nEnter your new password:"******"Set Password", text="Please re-enter your password:"******"Passwords entered do not match, please try again." else: Security.login(password) else: password = input_dialog( title="Welcome back to Hummingbot", text="Enter your password:"******"Invalid password - please try again." if err_msg is not None: message_dialog( title='Error', text=err_msg, style=dialog_style).run() return login_prompt() return True
def login_prompt(): from hummingbot.client.config.security import Security import time err_msg = None if Security.new_password_required(): show_welcome() password = input_dialog( title="Set Password", text="Create a password to protect your sensitive data. " "This password is not shared with us nor with anyone else, so please store it securely." "\n\nEnter your new password:"******"Set Password", text="Please re-enter your password:"******"Passwords entered do not match, please try again." else: Security.login(password) # encrypt current timestamp as a dummy to prevent promping for password if bot exits without connecting an exchange dummy = f"{time.time()}" Security.update_secure_config("default", dummy) else: password = input_dialog(title="Welcome back to Hummingbot", text="Enter your password:"******"Invalid password - please try again." if err_msg is not None: message_dialog(title='Error', text=err_msg, style=dialog_style).run() return login_prompt() return True
async def _test_existing_password(self): # check the 2 encrypted files exist self.assertTrue( os.path.exists(f"{temp_folder}encrypted_test_key_1.json")) self.assertTrue( os.path.exists(f"{temp_folder}encrypted_test_key_2.json")) self.assertTrue(Security.any_encryped_files()) self.assertFalse(Security.new_password_required()) # login fails with incorrect password result = Security.login("b") self.assertFalse(result) # login passes with correct password result = Security.login("a") self.assertTrue(result) # right after logging in, the decryption shouldn't finished yet self.assertFalse(Security.is_decryption_done()) await Security.wait_til_decryption_done() self.assertEqual(len(Security.all_decrypted_values()), 2) config_value = Security.decrypted_value("test_key_1") self.assertEqual("test_value_1", config_value) Security.update_secure_config("test_key_1", "new_value") self.assertEqual("new_value", Security.decrypted_value("test_key_1"))