Files
server/server/authentication_test.py
DESKTOP-DPA61F8\Benedek 3ca93438e6
All checks were successful
continuous-integration/drone/push Build is passing
1: config init in separate file
2: auth_test doesnt generate production state
2021-04-22 14:35:58 +02:00

119 lines
3.7 KiB
Python

from authentication import Authetication
import config_init as init
import json
import logging
import os
test_logger = logging.getLogger('TEST ')
test_logger.root.setLevel(logging.INFO)
def testSaveUser(username: str, password: str):
logging.info('STARTING SAVE USER TEST')
auth = Authetication()
auth.initConfig()
result = auth.saveUser(username, password)
check = False
with open(auth.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
data = json.load(json_file)
for user in data['user']:
if username == user['username']:
check = True
if result and check:
test_logger.info('TEST 1 ---> Save VALID user :: PASSED')
else:
test_logger.info('TEST 1 ---> Save VALID user :: FAILED')
def testAuth(username: str, password: str):
logging.info('STARTING AUTHENTICATION TEST')
auth = Authetication()
auth.initConfig()
auth.saveUser(username, password)
homeDir = auth.login(username, password)
if homeDir == '1':
test_logger.info('TEST 1 --> Authentication test with VALID :: PASSED')
else:
test_logger.info('TEST 1 --> Authentication test with VALID :: FAILED')
homeDir = auth.login(username, "")
if homeDir == "":
test_logger.info('TEST 2 --> Authentication test with INVALID :: PASSED')
else:
test_logger.info('TEST 2 --> Authentication test with INVALID ::FAILED')
def testUserExists(username: str, password: str):
logging.info('STARTING USER EXISTS TEST')
auth = Authetication()
auth.initConfig()
auth.saveUser(username, password)
if auth.checkUserExists(username):
logging.info('TEST 1 --> User exists with VALID user :: PASSED')
else:
logging.info('TEST 1 --> User exists with VALID user :: FAILED')
if auth.checkUserExists(""):
logging.info('TEST 2 --> User exists with INVALID user :: FAILED')
else:
logging.info('TEST 2 --> User exists with INVALID user :: PASSED')
def testPersistency():
logging.info('PERSISTENCY TEST')
auth = Authetication()
auth.initConfig()
auth.saveUser('alma','alma')
init.generatePrivateKeyForUser(auth, 'alma', 'amla')
auth.saveUser('citrom','citrom')
init.generatePrivateKeyForUser(auth, 'citrom', 'mortic')
auth2 = Authetication()
if auth2.checkUserExists('alma'):
logging.info('TEST 1 --> Persictency test :: PASSED')
else:
logging.info('TEST 1 --> Persictency test :: FAILED')
if auth2.checkUserExists(""):
logging.info('TEST 2 --> Persictency test :: FAILED')
else:
logging.info('TEST 2 --> Persictency test :: PASSED')
if os.path.isdir(auth.HOME_DIRECTORY_LOCATION):
logging.info('TEST 3 --> Persictency test :: PASSED')
else:
logging.info('TEST 3 --> Persictency test :: FAILED')
if os.path.isdir(auth.CONFIG_DIRECTORY_LOCATION):
logging.info('TEST 4 --> Persictency test :: PASSED')
else:
logging.info('TEST 4 --> Persictency test :: FAILED')
if os.path.isfile(auth.CONFIG_FILE_LOCATION):
logging.info('TEST 5 --> Persictency test :: PASSED')
else:
logging.info('TEST 5 --> Persictency test :: FAILED')
if os.stat(auth.CONFIG_FILE_LOCATION).st_size > 0:
logging.info('TEST 6 --> Persictency test :: PASSED')
else:
logging.info('TEST 6 --> Persictency test :: FAILED')
if os.path.isdir(auth.PRIVATE_KEY_DIRECTORY_LOCATION):
logging.info('TEST 7 --> Persictency test :: PASSED')
else:
logging.info('TEST 7 --> Persictency test :: FAILED')
if __name__ == '__main__':
testSaveUser("Diósbejglia", "Diósbejgli")
testAuth("Diósbejglia", "Diósbejgli")
testUserExists("Diósbejglia", "Diósbejgli")
testPersistency()