示例#1
0
def serve_standalone():
    from djdns.source import DJSource
    import os
    os.chdir('diskdemo')
    server = IdentServer(DJSource('root.json'))
    try:
        server.serve()
    except KeyboardInterrupt:
        server.stop()
示例#2
0
    def __init__(self, **config):
        if 'path' in config:
            self.path = config['path']
        else:
            self.path = 'diskdemo/root.json'

        self.source = DJSource(self.path)
        self.chain = Chain([self.source])
        config['chains'] = [self.chain]
        DnsServer.__init__(self, **config)
示例#3
0
class TestUserTraversal(unittest.TestCase):
    def setUp(self):
        os.chdir('diskdemo')
        self.source = DJSource('root.json')

    def tearDown(self):
        os.chdir('..')

    def compareTraversal(self, domain, expected):
        traversal = traverse(self.source.root, self.source.load_user, domain)
        self.assertEqual([x["selector"] for x in traversal], expected)

    def test_basic_traversal(self):
        self.compareTraversal("example.org", ['example.org$'])

    def test_subbranch_traversal(self):
        self.compareTraversal("in.subbranch.demo",
                              ['(subbranch|b3).demo$', '^in.subbranch.demo$'])

    def compareIdents(self, name, idents):
        self.assertEqual(
            sorted(self.source.get_user(name), key=lambda x: x.key),
            sorted(idents, key=lambda x: x.key))

    def test_get_root_user(self):
        name = "*****@*****.**"
        encryptor = ["rotate", 5]
        location = ["local", None, "tom"]

        ident = Identity(name, encryptor, location)
        self.compareIdents(name, [ident])

        name = "*****@*****.**"
        encryptor = ["rotate", -5]
        location = ["local", None, "jerry"]

        ident = Identity(name, encryptor, location)
        self.compareIdents(name, [ident])

    def test_get_subbranch_user(self):
        # Branch with many users
        # And they have a plan
        name = "*****@*****.**"
        classes = ['centurion', 'humanoid', 'raider', 'hybrid']
        idents = []
        for i in range(len(classes)):
            encryptor = ['rotate', i + 1]
            location = ['local', None, classes[i]]
            idents.append(Identity(name, encryptor, location))

        self.compareIdents(name, idents)
示例#4
0
 def setUp(self):
     os.chdir('diskdemo')
     self.source = DJSource('root.json')
 def setUp(self):
     os.chdir('diskdemo')
     self.source = DJSource('root.json')
class TestUserTraversal(unittest.TestCase):
    def setUp(self):
        os.chdir('diskdemo')
        self.source = DJSource('root.json')

    def tearDown(self):
        os.chdir('..')

    def compareTraversal(self, domain, expected):
        traversal = traverse(
            self.source.root,
            self.source.load_user,
            domain
        )
        self.assertEqual(
            [x["selector"] for x in traversal],
            expected
        )

    def test_basic_traversal(self):
        self.compareTraversal(
            "example.org",
            ['example.org$']
        )

    def test_subbranch_traversal(self):
        self.compareTraversal(
            "in.subbranch.demo",
            ['(subbranch|b3).demo$','^in.subbranch.demo$']
        )
        
    def compareIdents(self, name, idents):
        self.assertEqual(
            sorted(self.source.get_user(name), key=lambda x: x.key),
            sorted(idents, key=lambda x: x.key)
        )
        
    def test_get_root_user(self):
        name      = "*****@*****.**"
        encryptor = ["rotate", 5]
        location  = ["local", None, "tom"]

        ident = Identity(name, encryptor, location)
        self.compareIdents(name, [ident])

        name      = "*****@*****.**"
        encryptor = ["rotate", -5]
        location  = ["local", None, "jerry"]

        ident = Identity(name, encryptor, location)
        self.compareIdents(name, [ident])

    def test_get_subbranch_user(self):
        # Branch with many users
        # And they have a plan
        name    = "*****@*****.**"
        classes = ['centurion','humanoid','raider','hybrid']
        idents  = []
        for i in range(len(classes)):
            encryptor = ['rotate', i+1]
            location  = ['local', None, classes[i]]
            idents.append(Identity(name, encryptor, location))

        self.compareIdents(name, idents)