2021-04-17 19:52:58 +02:00
|
|
|
from authentication import Authetication
|
2021-04-22 14:35:58 +02:00
|
|
|
import config_init as init
|
2021-04-17 19:52:58 +02:00
|
|
|
import json
|
|
|
|
import logging
|
2021-04-18 23:06:20 +02:00
|
|
|
import os
|
2021-04-17 19:52:58 +02:00
|
|
|
|
|
|
|
test_logger = logging.getLogger('TEST ')
|
|
|
|
test_logger.root.setLevel(logging.INFO)
|
|
|
|
|
2021-04-18 13:36:04 +02:00
|
|
|
|
2021-04-18 14:23:13 +02:00
|
|
|
def testSaveUser(username: str, password: str):
|
2021-04-17 19:52:58 +02:00
|
|
|
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')
|
|
|
|
|
|
|
|
|
2021-04-18 14:23:13 +02:00
|
|
|
def testAuth(username: str, password: str):
|
2021-04-17 19:52:58 +02:00
|
|
|
logging.info('STARTING AUTHENTICATION TEST')
|
|
|
|
auth = Authetication()
|
|
|
|
auth.initConfig()
|
|
|
|
auth.saveUser(username, password)
|
|
|
|
homeDir = auth.login(username, password)
|
|
|
|
|
2021-04-18 16:30:01 +02:00
|
|
|
if homeDir == '1':
|
2021-04-17 19:52:58 +02:00
|
|
|
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')
|
|
|
|
|
|
|
|
|
2021-04-18 14:23:13 +02:00
|
|
|
def testUserExists(username: str, password: str):
|
2021-04-17 19:52:58 +02:00
|
|
|
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')
|
|
|
|
|
2021-04-18 13:36:04 +02:00
|
|
|
|
2021-04-18 23:06:20 +02:00
|
|
|
def testPersistency():
|
|
|
|
logging.info('PERSISTENCY TEST')
|
|
|
|
auth = Authetication()
|
|
|
|
auth.initConfig()
|
2021-04-25 16:06:56 +02:00
|
|
|
serverPublicKey = init.generatePrivateKeyForServer(auth, 'admin')
|
2021-04-18 23:06:20 +02:00
|
|
|
auth.saveUser('alma','alma')
|
2021-04-25 16:06:56 +02:00
|
|
|
homeDir = auth.login('alma','alma')
|
|
|
|
init.generatePrivateKeyForUser(auth, 'alma', 'amla', serverPublicKey, init.generateSourceAddress(homeDir))
|
2021-04-18 23:06:20 +02:00
|
|
|
auth.saveUser('citrom','citrom')
|
2021-04-25 16:06:56 +02:00
|
|
|
homeDir = auth.login('citrom','citrom')
|
|
|
|
init.generatePrivateKeyForUser(auth, 'citrom', 'mortic', serverPublicKey, init.generateSourceAddress(homeDir))
|
2021-04-18 23:06:20 +02:00
|
|
|
|
|
|
|
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')
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-17 19:52:58 +02:00
|
|
|
if __name__ == '__main__':
|
2021-04-18 13:36:04 +02:00
|
|
|
testSaveUser("Diósbejglia", "Diósbejgli")
|
|
|
|
testAuth("Diósbejglia", "Diósbejgli")
|
|
|
|
testUserExists("Diósbejglia", "Diósbejgli")
|
2021-04-18 23:06:20 +02:00
|
|
|
testPersistency()
|