From c954940bec09066dc63289f188fe9f07dae11bfc Mon Sep 17 00:00:00 2001 From: Darksider3 Date: Fri, 12 Jun 2020 13:44:53 +0200 Subject: [PATCH] tests: Adds verificator-tests & lib: __init__ file Also more strings to operate on for the tests, obviously. --- private/lib/__init__.py | 0 private/test/test_Validator.py | 65 ++++++++++++++++++++++++++++++++++ private/test/testcfg.py | 43 +++++++++++++++++++++- 3 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 private/lib/__init__.py create mode 100644 private/test/test_Validator.py diff --git a/private/lib/__init__.py b/private/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/private/test/test_Validator.py b/private/test/test_Validator.py new file mode 100644 index 0000000..3ead2a8 --- /dev/null +++ b/private/test/test_Validator.py @@ -0,0 +1,65 @@ +import sys +sys.path.append('..') +import unittest +import lib.Validator +import test.testcfg as testcfg + + +class TestValidator(unittest.TestCase): + def setUp(self) -> None: + self.validator = lib.Validator + + def test_check_username_characters(self): + for name in testcfg.Validator_Valid_Users_Chars_List: + self.assertTrue(self.validator.checkUsernameCharacters(name)) + for name in testcfg.Validator_Invalid_Users_Chars_List: + self.assertFalse(self.validator.checkUsernameCharacters(name), name) + + def test_check_username_length(self): + for name in testcfg.Validator_Valid_Users_Length: + self.assertTrue(self.validator.checkUsernameLength(name)) + for name in testcfg.Validator_Invalid_Users_Length: + self.assertFalse(self.validator.checkUsernameLength(name), name) + + def test_check_email(self): + for name in testcfg.Validator_Valid_Mail: + self.assertTrue(self.validator.checkEmail(name)) + for name in testcfg.Validator_Invalid_Mail: + self.assertFalse(self.validator.checkEmail(name)) + + def test_check_user_exists(self): + self.assertTrue(self.validator.checkUserExists("root")) + self.assertTrue(self.validator.checkUserExists("nobody")) # remove in case there exists an actual system without + self.assertFalse(self.validator.checkUserExists("blsjdkfl")) + self.assertFalse(self.validator.checkUserExists("b90123ijk")) + self.assertFalse(self.validator.checkUserExists("curArrSosss")) + self.assertFalse(self.validator.checkUserExists("123WildPack123")) + # are there any more users which are assertable? + + def test_check_user_in_db(self): + for name in testcfg.Validator_db_user_exists: + self.assertTrue(self.validator.checkUserInDB(name, testcfg.test_db)) + for name in testcfg.Validator_db_user_inexistent: + self.assertFalse(self.validator.checkUserInDB(name, testcfg.test_db)) + + def test_check_sshkey(self): + for key in testcfg.Validator_valid_ssh: + self.assertTrue(self.validator.checkSSHKey(key)) + for key in testcfg.Validator_invalid_ssh: + self.assertFalse(self.validator.checkSSHKey(key)) + + def test_check_datetime_format(self): + for cur in testcfg.Validator_valid_datetime: + self.assertTrue(self.validator.checkDatetimeFormat(cur)) + + def test_check_name(self): + for checkname in testcfg.Validator_valid_checkname_names: + self.assertTrue(self.validator.checkName(checkname)) + for checkname in testcfg.Validator_invalid_checkname_names: + self.assertFalse(self.validator.checkName(checkname)) + + def test_check_import_file(self): + self.assertTrue(self.validator.checkImportFile(testcfg.test_import_csv, + testcfg.test_db)) + if not self.validator.checkImportFile(testcfg.test_import_invalid_csv, testcfg.test_db): + self.fail("Invalid import file should've failed the test") diff --git a/private/test/testcfg.py b/private/test/testcfg.py index 1fc8f5b..1150e1f 100644 --- a/private/test/testcfg.py +++ b/private/test/testcfg.py @@ -1,4 +1,45 @@ test_backup_csv: str = "test/testbackup.csv" test_db: str = "./test/applications.sqlite" +test_import_csv: str = "test/testimport.csv" +test_import_invalid_csv: str = "test/testimport_fail.csv" ListUsers_fetch_size_min: int = 3 -ListUsers_output_newlines: int = 1 \ No newline at end of file +ListUsers_output_newlines: int = 1 + +Validator_Valid_Users_Chars_List: list = ["darksider", "dirty", "hAndS", "world312Lol"] +Validator_Invalid_Users_Chars_List: list = ["12", "#uรŸ", "Rawr"] + +Validator_Valid_Users_Length: list = ["w๐Ÿ’๐Ÿ’๐Ÿ’ž๐Ÿ’želt", "hallo", "japp", "eksdee", "harrharr", "rรคraRรผdigerSauรŸํ•˜", + "ุงู„ุชูŽู‘ุทู’ุจููŠู‚ูŽุงุชู", + "๐“ฝ๐“ฑ๐“ฎ", "๐“ต๐“ช๐”ƒ๐”‚", "๐“ญ๐“ธ๐“ฐ"] +Validator_Invalid_Users_Length: list = ["f", "i", "fa", "fo", "ar"] + +Validator_Valid_Mail: list = ["larp@example.org", "rawr@lulz.com", "woerld@hassa.fun"] +Validator_Invalid_Mail: list = ["lรคร„@wi", "@rawr.", ".com", "@.de", ".@.de"] + +Validator_db_user_exists: list = ["darksider3", "Darksider2", "Darksider1"] +Validator_db_user_inexistent: list = ["welt", "world", "hรค#", "root"] + +# @TODO: More valid and invalid test keys... +Validator_valid_ssh: list = ["""ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC7qmegDxzv1omqG2cWM+ +i+qaEGzCoSBwqCeXyGUU93sTqtNYYHJVGj6YZqXeXEGzJtKm2A/uo59Y+WmqhJgW7HcT2Hqvo80NfbIRhqE9TJETyBe +GiiC8qpiYgPC2zigCNvTsRXh0CH5FJ1qy4QEBjztQDWOqSrsoOSJEEWCJiKJizTiXDmlGdiKE409GBo8lvlbMRWbrMj +3iX825WTqy/T0Pio1kqANDotLnPA0sRXUPVyzc/ghzqRHzFetzP9j7C0nh +EvjiJphiuYvhbgix79FrCQG0lXBGcAWzsWUeAoT/d3kQu79+UTWxm+z4pnJ7gkKVMejqrWys560SdAqD264dc5UBRGI9j6X +xVKdraSaEitDneONrSAt2tE/RwRxh2ASxqQfdF88zyDI8/ma608tHc +FROaNsn5hF+/wzjRK9akdhp5WjA5HXhg2OlkwKvSMhGlSgotRj5pr4Ebxjegysy1mEWRFN/vh/oNq4uHQy8adpfogaVELkI/Z2nuAdQk ++uMy6D1hrKhUWubmBPxTbG00IWF25Tyuz8hnFRP9+gB/P +NRlF59/EHy27a72nirvuOyfxKnx/Mn+FD9Ah59OSLhWuo3sN9Im8yc2cliecwMz+DmTtE7TwzNw9v2zfxU9JDQwyLtppULiGpmKFOLHjz ++SVGxSbVsWS//IyNK1GrQ== gschoenb@gschoenb-X220""", + """ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAklOUpkDHrfHY17SbrmTIpNLTGK9Tjom/BWDSU +GPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3 +Pbv7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK/7XA +t3FaoJoAsncM1Q9x5+3V0Ww68/eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw/Pb0rwert/En +mZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbx +NrRFi9wrf+M7Q== schacon@mylaptop.local"""] +Validator_invalid_ssh: list = ["lol.", "ssh-rsa lol."] + +#Y-%m-%d %H:%M:%S +Validator_valid_datetime: list = ["2020-10-07 14:15:30"] + +Validator_valid_checkname_names: list = ["HalloWelt"] +Validator_invalid_checkname_names: list = ["\\n", "\n\b"] \ No newline at end of file