Ejemplo n.º 1
0
 def test_channel_star_perms(self):
     acl = ACL(StringIO.StringIO(TEST_ACL.strip('\n')).read())
     comm = {
         'user': '******',
         'channel': '#channel',
     }
     self.assertTrue(acl.hasPermission(comm, 'foo'))
Ejemplo n.º 2
0
 def test_channel_everything_but_figlet(self):
     acl = ACL(StringIO.StringIO(TEST_ACL).read())
     comm = {
         'user': '******',  # not in any groups
         'channel': '#channel2',
     }
     self.assertTrue(acl.hasPermission(comm, 'cmd'))
     self.assertTrue(acl.hasPermission(comm, 'anothercmd'))
     self.assertFalse(acl.hasPermission(comm, 'figlet'))
Ejemplo n.º 3
0
 def test_channel_perms(self):
     acl = ACL(StringIO.StringIO(TEST_ACL).read())
     comm = {
         'user': '******',  # not in any groups
         'channel': '#channel1',
     }
     self.assertTrue(acl.hasPermission(comm, 'figlet'))
     self.assertTrue(acl.hasPermission(comm, 'quote'))
     self.assertFalse(acl.hasPermission(comm, 'quote.add'))
     self.assertFalse(acl.hasPermission(comm, 'channel.leave'))
Ejemplo n.º 4
0
    def __init__(self, config):
        self.channels = [c.split(' ', 1) for c in config['channels']]
        self.nickname = config['nickname']
        self.password = config.get('password', None)
        self.history = {}
        self.sent_messages = {}
        acl_fname = config.get('acl', None)

        if acl_fname:
            # Bubble up an IOError if they passed a bad file
            with open(acl_fname, 'r') as acl_fd:
                self.acl = ACL(acl_fd.read())
            log.info('Loaded ACLs from %s', acl_fname)
        else:
            self.acl = AllowAllACL()
            log.info('Using no-op ACLs.')

        self.loader = PluginLoader(config)

        if 'db' in config:
            log.info('Loading db from config: %s', config['db'])
            db_engine = sqlalchemy.create_engine(config['db'])
        else:
            log.info('Using in-memory db')
            db_engine = sqlalchemy.create_engine('sqlite:///:memory:')

        DBSession = orm.sessionmaker(db_engine)
        session = DBSession()
        self.loader.db = DB(db_engine, session)

        self.loader.loadAll()
Ejemplo n.º 5
0
class TestAddGroups(TestCase):
    def setUp(self):
        self.acl = ACL(TEST_ACL)

    def test_single(self):
        comm = {'user': '******'}
        self.assertEqual(self.acl.add_groups(comm)['groups'], ['@ops'])

    def test_double(self):
        comm = {'user': '******'}
        groups = set(self.acl.add_groups(comm)['groups'])
        expected = set(['@ops', '@7letters'])
        self.assertEqual(groups, expected)

    def test_none(self):
        comm = {'user': '******'}
        self.assertEqual(self.acl.add_groups(comm)['groups'], [])
Ejemplo n.º 6
0
class TestAddGroups(TestCase):

    def setUp(self):
        self.acl = ACL(TEST_ACL)

    def test_single(self):
        comm = {'user': '******'}
        self.assertEqual(self.acl.add_groups(comm)['groups'], ['@ops'])

    def test_double(self):
        comm = {'user': '******'}
        groups = set(self.acl.add_groups(comm)['groups'])
        expected = set(['@ops', '@7letters'])
        self.assertEqual(groups, expected)

    def test_none(self):
        comm = {'user': '******'}
        self.assertEqual(self.acl.add_groups(comm)['groups'], [])
Ejemplo n.º 7
0
class TestPermissionGlobbing(TestCase):

    def setUp(self):
        self.acl = ACL(TEST_ACL)

    def _check(self, perm, pattern, match=ACL.ALLOW):
        if match:
            self.assertTrue(self.acl.glob_permission_match(perm, pattern))
        else:
            self.assertFalse(self.acl.glob_permission_match(perm, pattern))

    def test_single(self):
        self._check('foo', 'foo')
        self._check('foo', 'bar', None)

    def test_dotted(self):
        self._check('foo.bar', 'foo.bar')
        self._check('foo.bar', 'foo.baz', None)

    def test_partial(self):
        self._check('foo', 'foo.bar', None)
        self._check('foo.bar', 'foo', None)

    def test_end_star(self):
        self._check('foo.bar', 'foo.*')
        self._check('foo.bar', 'bar.*', None)

    def test_middle_star(self):
        self._check('foo.bar.baz', 'foo.*.baz')
        self._check('foo.bar.baz', 'foo.*.qux', None)

    def test_partial_star(self):
        self._check('foo.bar.baz', 'foo.*')
        self._check('foo.bar.baz', 'bar.*', None)

    def test_negation(self):
        self._check('foo', '-foo', ACL.DENY)
        self._check('foo.bar', '-foo.bar', ACL.DENY)
        self._check('foo', '-foo.bar', None)
Ejemplo n.º 8
0
class TestPermissionGlobbing(TestCase):
    def setUp(self):
        self.acl = ACL(TEST_ACL)

    def _check(self, perm, pattern, match=ACL.ALLOW):
        if match:
            self.assertTrue(self.acl.glob_permission_match(perm, pattern))
        else:
            self.assertFalse(self.acl.glob_permission_match(perm, pattern))

    def test_single(self):
        self._check('foo', 'foo')
        self._check('foo', 'bar', None)

    def test_dotted(self):
        self._check('foo.bar', 'foo.bar')
        self._check('foo.bar', 'foo.baz', None)

    def test_partial(self):
        self._check('foo', 'foo.bar', None)
        self._check('foo.bar', 'foo', None)

    def test_end_star(self):
        self._check('foo.bar', 'foo.*')
        self._check('foo.bar', 'bar.*', None)

    def test_middle_star(self):
        self._check('foo.bar.baz', 'foo.*.baz')
        self._check('foo.bar.baz', 'foo.*.qux', None)

    def test_partial_star(self):
        self._check('foo.bar.baz', 'foo.*')
        self._check('foo.bar.baz', 'bar.*', None)

    def test_negation(self):
        self._check('foo', '-foo', ACL.DENY)
        self._check('foo.bar', '-foo.bar', ACL.DENY)
        self._check('foo', '-foo.bar', None)
Ejemplo n.º 9
0
 def _check(self, selector, expected):
     acl = ACL(TEST_ACL)
     self.assertEqual(acl.parse_selector(selector), expected)
Ejemplo n.º 10
0
 def setUp(self):
     self.acl = ACL(TEST_ACL)
Ejemplo n.º 11
0
 def test_empty_acls(self):
     # This should not error.
     acl = ACL('{}')
     acl.has_permission({}, 'foo')
Ejemplo n.º 12
0
class TestACL(TestCase):
    def setUp(self):
        self.acl = ACL(TEST_ACL)

    def test_channel_star_perms(self):
        comm = {
            'user': '******',
            'channel': '#channel2',
        }
        self.assertTrue(self.acl.has_permission(comm, 'foo'))

    def test_channel_perms(self):
        comm = {
            'user': '******',
            'channel': '#channel1',
        }
        self.assertTrue(self.acl.has_permission(comm, 'figlet'))
        self.assertTrue(self.acl.has_permission(comm, 'quote'))
        self.assertFalse(self.acl.has_permission(comm, 'quote.add'))
        self.assertFalse(self.acl.has_permission(comm, 'channel.leave'))

    def test_channel_everything_but_figlet(self):
        comm = {
            'user': '******',
            'channel': '#channel2',
        }
        self.assertTrue(self.acl.has_permission(comm, 'cmd'))
        self.assertTrue(self.acl.has_permission(comm, 'anothercmd'))
        self.assertFalse(self.acl.has_permission(comm, 'figlet'))

    def test_group_permissions(self):
        comm = {
            'user': '******',
            'channel': '#channel3',
            # group will be filled in as '@op'
        }
        self.assertTrue(self.acl.has_permission(comm, 'cmd'))

        comm['channel'] = '#channel2'
        # Not even ops can use figlet here.
        self.assertFalse(self.acl.has_permission(comm, 'figlet'))

    def test_user_permission(self):
        comm = {
            'user': '******',
            'channel': '#channel3',
        }
        self.assertTrue(self.acl.has_permission(comm, 'quote'))
        self.assertTrue(self.acl.has_permission(comm, 'quote.add'))
        self.assertTrue(self.acl.has_permission(comm, 'quote.delete'))

    def test_empty_acls(self):
        # This should not error.
        acl = ACL('{}')
        acl.has_permission({}, 'foo')
Ejemplo n.º 13
0
 def _check(self, selector, expected):
     acl = ACL(TEST_ACL)
     self.assertEqual(acl.parse_selector(selector), expected)
Ejemplo n.º 14
0
 def test_empty_acls(self):
     # This should not error.
     acl = ACL('{}')
     acl.has_permission({}, 'foo')
Ejemplo n.º 15
0
 def setUp(self):
     self.acl = ACL(TEST_ACL)
Ejemplo n.º 16
0
class TestACL(TestCase):
    def setUp(self):
        self.acl = ACL(TEST_ACL)

    def test_channel_star_perms(self):
        comm = {
            'user': '******',
            'channel': '#channel2',
        }
        self.assertTrue(self.acl.has_permission(comm, 'foo'))

    def test_channel_perms(self):
        comm = {
            'user': '******',
            'channel': '#channel1',
        }
        self.assertTrue(self.acl.has_permission(comm, 'figlet'))
        self.assertTrue(self.acl.has_permission(comm, 'quote'))
        self.assertFalse(self.acl.has_permission(comm, 'quote.add'))
        self.assertFalse(self.acl.has_permission(comm, 'channel.leave'))

    def test_channel_everything_but_figlet(self):
        comm = {
            'user': '******',
            'channel': '#channel2',
        }
        self.assertTrue(self.acl.has_permission(comm, 'cmd'))
        self.assertTrue(self.acl.has_permission(comm, 'anothercmd'))
        self.assertFalse(self.acl.has_permission(comm, 'figlet'))

    def test_group_permissions(self):
        comm = {
            'user': '******',
            'channel': '#channel3',
            # group will be filled in as '@op'
        }
        self.assertTrue(self.acl.has_permission(comm, 'cmd'))

        comm['channel'] = '#channel2'
        # Not even ops can use figlet here.
        self.assertFalse(self.acl.has_permission(comm, 'figlet'))

    def test_user_permission(self):
        comm = {
            'user': '******',
            'channel': '#channel3',
        }
        self.assertTrue(self.acl.has_permission(comm, 'quote'))
        self.assertTrue(self.acl.has_permission(comm, 'quote.add'))
        self.assertTrue(self.acl.has_permission(comm, 'quote.delete'))

    def test_empty_acls(self):
        # This should not error.
        acl = ACL('{}')
        acl.has_permission({}, 'foo')