From 55026aa62683fdc1029cb64cbd2ca344d4567272 Mon Sep 17 00:00:00 2001 From: "DESKTOP-DPA61F8\\Benedek" Date: Sun, 18 Apr 2021 14:23:13 +0200 Subject: [PATCH] Typing --- server/authentication.py | 10 ++++------ server/authentication_test.py | 6 +++--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/server/authentication.py b/server/authentication.py index f1ceec3..9ddc19b 100644 --- a/server/authentication.py +++ b/server/authentication.py @@ -25,13 +25,11 @@ class Authetication: if not os.path.isfile(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt") or os.stat( self.CONFIG_DIRECTORY_LOCATION + "\\config.txt").st_size == 0: - data = {} - data['index'] = 0 - data['user'] = [] + data = {'index': 0, 'user': []} with open(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt", 'w+') as outfile: json.dump(data, outfile) - def login(self, username, password): + def login(self, username: str, password: str) -> str: with open(Authetication.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file: data = json.load(json_file) @@ -47,7 +45,7 @@ class Authetication: auth_logger.debug("User logged in: " + username) return user['homeDir'] - def checkUserExists(self, username): + def checkUserExists(self, username: str) -> bool: with open(Authetication.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file: data = json.load(json_file) @@ -64,7 +62,7 @@ class Authetication: shutil.rmtree(self.HOME_DIRECTORY_LOCATION) os.mkdir(self.HOME_DIRECTORY_LOCATION) - def saveUser(self, username, password): + def saveUser(self, username: str, password: str) -> bool: bytePass = password.encode('utf-8') b64pwd = b64encode(SHA256.new(bytePass).digest()) bcrypt_hash = bcrypt(b64pwd, 12) diff --git a/server/authentication_test.py b/server/authentication_test.py index e0ab9ae..b6254f3 100644 --- a/server/authentication_test.py +++ b/server/authentication_test.py @@ -6,7 +6,7 @@ test_logger = logging.getLogger('TEST ') test_logger.root.setLevel(logging.INFO) -def testSaveUser(username, password): +def testSaveUser(username: str, password: str): logging.info('STARTING SAVE USER TEST') auth = Authetication() auth.initConfig() @@ -26,7 +26,7 @@ def testSaveUser(username, password): test_logger.info('TEST 1 ---> Save VALID user :: FAILED') -def testAuth(username, password): +def testAuth(username: str, password: str): logging.info('STARTING AUTHENTICATION TEST') auth = Authetication() auth.initConfig() @@ -45,7 +45,7 @@ def testAuth(username, password): test_logger.info('TEST 2 --> Authentication test with INVALID ::FAILED') -def testUserExists(username, password): +def testUserExists(username: str, password: str): logging.info('STARTING USER EXISTS TEST') auth = Authetication() auth.initConfig()