Exemple #1
0
 def test_character_substitution(self):
     password = "******"
     munged = substitute(password, Config())
     self.assertTrue('%' in munged)
     password = "******"
     munged = substitute(password, Config())
     self.assertTrue('3' in munged)
Exemple #2
0
 def test_case_change(self):
     password = "******"
     munged = substitute(password, Config())
     self.assertTrue('x' in munged)
     self.assertTrue('X' in munged)
     password = "******"
     munged = substitute(password, Config())
     self.assertTrue('x' in munged)
     self.assertTrue('X' in munged)
Exemple #3
0
 def test_generate_from_type(self):
     password = generate_from_type(Config(), 'pin')
     try:
         int(password)
     except ValueError:
         self.fail("PIN password contains non-numerals")
     self.assertEqual(len(password), 4)
Exemple #4
0
def generate(args):
    makedirs(args.out, exist_ok=True)

    generate_error_pages()

    certificates = get_certificates()
    config = Config('config.json')
    for domain in config.domains:
        host = domain.host.replace('*', 'wildcard')

        output = ''

        if host.startswith('http:'):
            domain.host = domain.host[5:]
            host = host[5:]
            output = server_http(domain)
        else:
            if certificates.has(domain.host):
                output = server(certificates, domain)
            else:
                print(f'Certificate not found for {domain.host}!')
                cert = issue_certificate(domain.host)
                if cert is not None:
                    print(f'Failed to issue certificate for {domain.host}!')
                    output = server(certificates, domain)
                else:
                    output = server_http(domain)

        with open(path.join(args.out, f'{host}.conf'), 'w') as f:
            f.write(output)
Exemple #5
0
 def test_ordered(self):
     pattern = "onu{20}n"
     password = generate(Config(), pattern)
     self.assertEqual(len(password), 22)
     try:
         int(password[0])
         int(password[21])
     except ValueError:
         self.fail("Numerals not at expected indices")
Exemple #6
0
 def test_descriptor_range_syntax_error(self):
     pattern = "n{10-20"
     with self.assertRaises(ValueError):
         generate(Config(), pattern)
Exemple #7
0
 def test_illegal_descriptor_range(self):
     pattern = "n{20-10}"
     with self.assertRaises(ValueError):
         generate(Config(), pattern)
Exemple #8
0
 def test_illegal_ordered_placement(self):
     pattern = "no"
     with self.assertRaises(ValueError):
         generate(Config(), pattern)
Exemple #9
0
 def test_illegal_character_class(self):
     pattern = "nay"
     with self.assertRaises(ValueError):
         generate(Config(), pattern)
Exemple #10
0
 def test_range_descriptor(self):
     pattern = "h{5-6}"
     password = generate(Config(), pattern)
     self.assertGreaterEqual(len(password), 5)
     self.assertLessEqual(len(password), 6)
Exemple #11
0
 def test_length_descriptor(self):
     pattern = "a{10}"
     password = generate(Config(), pattern)
     self.assertEqual(len(password), 10)
Exemple #12
0
 def setUp(self):
     self.config = Config()
Exemple #13
0
class ConfigTest(unittest.TestCase):
    def setUp(self):
        self.config = Config()

    def test_set_type(self):
        self.config.set_type("mytype", "xxx")
        self.assertEqual(self.config.types["mytype"], "xxx")

    def test_remove_type(self):
        self.config.set_type("mytype", "xxx")
        self.assertTrue("mytype" in self.config.types)
        self.config.remove_type("mytype")
        self.assertFalse("mytype" in self.config.types)

    def test_remove_default(self):
        default = self.config.types["default"]
        self.config.set_type("default", "xxx")
        self.assertEqual(self.config.types["default"], "xxx")
        self.config.remove_type("default")
        self.assertEqual(self.config.types["default"], default)

    def test_add_chars_to_class(self):
        original = self.config.char_class('n')
        self.config.add_chars_to_class('n', "xyz123")
        self.assertEqual(self.config.char_class('n'), original + "xyz")

    def test_add_to_invalid_class(self):
        with self.assertRaises(ValueError):
            self.config.add_chars_to_class('y', "xyz")

    def test_remove_chars_from_class(self):
        self.config.remove_chars_from_class('n', "xyz123")
        self.assertEqual(self.config.char_class('n'), "0456789")

    def test_remove_from_invalid_class(self):
        with self.assertRaises(ValueError):
            self.config.remove_chars_from_class('y', "xyz")
Exemple #14
0
 def test_basic(self):
     password = "******"
     munged = substitute(password, Config())
     self.assertGreaterEqual(len(munged), len(password))
     self.assertNotEqual(password, munged)
Exemple #15
0
 def test_unsubstitutable_character(self):
     password = "******"
     munged = substitute(password, Config())
     self.assertTrue('u' in munged)
     self.assertTrue('U' in munged)
     self.assertEqual(len(password), len(munged))
Exemple #16
0
 def test_basic(self):
     pattern = "lunNsxSaAhHbcC"
     password = generate(Config(), pattern)
     self.assertEqual(len(password), 14)
Exemple #17
0
import pathlib
from generator.config import Config

config = Config(root_dir=pathlib.Path().absolute(),
                src_dir="src",
                data_dir="data",
                style_dir="styles",
                template_dir="templates",
                route_path="routes.yml",
                output_dir="build")
Exemple #18
0
 def test_optional_descriptor(self):
     pattern = "nN?"
     password = generate(Config(), pattern)
     self.assertGreaterEqual(len(password), 1)
     self.assertLessEqual(len(password), 2)