Files
server/server/authentication_test.py
DESKTOP-DPA61F8\Benedek 81211b1dd5
All checks were successful
continuous-integration/drone/push Build is passing
On running test the sript generates 3 user where password == username
->  user1: 'alma' with passphrase: 'amla'
    ->  user2: 'citrom' with passphrase: 'mortic'
    ->  user1: 'dinnye' with passphrase: 'eynnid'

The private keys are envrypted in DER format with pkcs#8 using the passphrase.
The private keys are temporarly stored under config/{homeDir}
The public keys are stored in the config file without encryption
2021-04-18 18:59:01 +02:00

80 lines
2.4 KiB
Python

from authentication import Authetication
import json
import logging
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 productionInit():
auth = Authetication()
auth.initConfig()
auth.saveUser('alma','alma')
auth.generatePrivateKeyForUser('alma', 'amla')
auth.saveUser('citrom','citrom')
auth.generatePrivateKeyForUser('citrom', 'mortic')
auth.saveUser('dinnye','dinnye')
auth.generatePrivateKeyForUser('dinnye', 'eynnid')
if __name__ == '__main__':
testSaveUser("Diósbejglia", "Diósbejgli")
testAuth("Diósbejglia", "Diósbejgli")
testUserExists("Diósbejglia", "Diósbejgli")
productionInit()