Skip to content

Commit

Permalink
Only warn user in case there is an issue
Browse files Browse the repository at this point in the history
  • Loading branch information
yorickdowne committed Sep 1, 2024
1 parent 39625e3 commit 831e5b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
18 changes: 0 additions & 18 deletions ethstaker_deposit/deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,6 @@ def check_python_version() -> None:
sys.exit(78)


def check_term_encoding() -> None:
'''
Checks that the terminal uses utf-8 encoding and exits if not. This is done to avoid issues with passwords
'''
encoding = sys.stdin.encoding.lower()
acceptable_encodings = ['utf-8']

# Windows has a zoo of cp codepages, none of which map to utf-8, and utf-8 is generally not available
# "It is what it is" on Windows
if encoding not in acceptable_encodings and sys.platform != 'win32':
click.pause(
f'Your terminal is using {encoding} encoding which can present problems with passwords. '
'Please use "utf-8".'
)
sys.exit(78)


def check_connectivity() -> None:
'''
Checks if there is an internet connection and warns the user if so.
Expand Down Expand Up @@ -129,7 +112,6 @@ def cli(ctx: click.Context, language: str, non_interactive: bool, ignore_connect
def run() -> None:
freeze_support() # Needed when running under Windows in a frozen bundle
check_python_version()
check_term_encoding()

try:
cli()
Expand Down
2 changes: 2 additions & 0 deletions ethstaker_deposit/intl/en/utils/validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
},
"validate_password_strength": {
"msg_password_length": "The password length should be at least 8. Please retype"
"msg_password_utf8": "Your terminal is not utf-8 encoded. The password should only use English-language characters, so the keystore file can be imported on Linux. Please retype"
"msg_password_utf8_switch": "Alternatively, quit this program and relaunch it from a utf-8 encoded terminal."
},
"validate_int_range": {
"err_not_positive_integer": "That is not a positive integer. Please retype."
Expand Down
9 changes: 9 additions & 0 deletions ethstaker_deposit/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import click
import json
import re
import sys
import concurrent.futures
from typing import Any, Dict, Sequence

Expand Down Expand Up @@ -138,6 +139,14 @@ def validate_deposit(deposit_data_dict: Dict[str, Any], credential: Credential =
def validate_password_strength(password: str) -> str:
if len(password) < 8:
raise ValidationError(load_text(['msg_password_length']))

encoding = sys.stdin.encoding.lower()
if encoding != 'utf-8' and not password.isascii():
if sys.platform == 'win32':
raise ValidationError(load_text(['msg_password_utf8']))
else:
raise ValidationError(load_text(['msg_password_utf8', 'msg_password_utf8_switch']))

return password


Expand Down

0 comments on commit 831e5b0

Please sign in to comment.