Typing
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DESKTOP-DPA61F8\Benedek 2021-04-18 14:23:13 +02:00
parent cb929266cd
commit 55026aa626
2 changed files with 7 additions and 9 deletions

View File

@ -25,13 +25,11 @@ class Authetication:
if not os.path.isfile(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt") or os.stat( if not os.path.isfile(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt") or os.stat(
self.CONFIG_DIRECTORY_LOCATION + "\\config.txt").st_size == 0: self.CONFIG_DIRECTORY_LOCATION + "\\config.txt").st_size == 0:
data = {} data = {'index': 0, 'user': []}
data['index'] = 0
data['user'] = []
with open(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt", 'w+') as outfile: with open(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt", 'w+') as outfile:
json.dump(data, 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: with open(Authetication.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
data = json.load(json_file) data = json.load(json_file)
@ -47,7 +45,7 @@ class Authetication:
auth_logger.debug("User logged in: " + username) auth_logger.debug("User logged in: " + username)
return user['homeDir'] return user['homeDir']
def checkUserExists(self, username): def checkUserExists(self, username: str) -> bool:
with open(Authetication.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file: with open(Authetication.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
data = json.load(json_file) data = json.load(json_file)
@ -64,7 +62,7 @@ class Authetication:
shutil.rmtree(self.HOME_DIRECTORY_LOCATION) shutil.rmtree(self.HOME_DIRECTORY_LOCATION)
os.mkdir(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') bytePass = password.encode('utf-8')
b64pwd = b64encode(SHA256.new(bytePass).digest()) b64pwd = b64encode(SHA256.new(bytePass).digest())
bcrypt_hash = bcrypt(b64pwd, 12) bcrypt_hash = bcrypt(b64pwd, 12)

View File

@ -6,7 +6,7 @@ test_logger = logging.getLogger('TEST ')
test_logger.root.setLevel(logging.INFO) test_logger.root.setLevel(logging.INFO)
def testSaveUser(username, password): def testSaveUser(username: str, password: str):
logging.info('STARTING SAVE USER TEST') logging.info('STARTING SAVE USER TEST')
auth = Authetication() auth = Authetication()
auth.initConfig() auth.initConfig()
@ -26,7 +26,7 @@ def testSaveUser(username, password):
test_logger.info('TEST 1 ---> Save VALID user :: FAILED') test_logger.info('TEST 1 ---> Save VALID user :: FAILED')
def testAuth(username, password): def testAuth(username: str, password: str):
logging.info('STARTING AUTHENTICATION TEST') logging.info('STARTING AUTHENTICATION TEST')
auth = Authetication() auth = Authetication()
auth.initConfig() auth.initConfig()
@ -45,7 +45,7 @@ def testAuth(username, password):
test_logger.info('TEST 2 --> Authentication test with INVALID ::FAILED') 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') logging.info('STARTING USER EXISTS TEST')
auth = Authetication() auth = Authetication()
auth.initConfig() auth.initConfig()