Exemplo n.º 1
0
class SoftChrootNonInitialized(TestCase):
    def setUp(self):
        self.b = SoftChroot()

    def test_is_root_abs(self):
        with self.assertRaises(RuntimeError):
            self.b.is_root_abs('1')

    def test_is_subdir(self):
        with self.assertRaises(RuntimeError):
            self.b.is_subdir('1')

    def test_chroot2abs(self):
        with self.assertRaises(RuntimeError):
            self.b.chroot2abs('1')

    def test_abs2chroot(self):
        with self.assertRaises(RuntimeError):
            self.b.abs2chroot('1')

    def test_get_root(self):
        with self.assertRaises(RuntimeError):
            self.b.get_chroot()
Exemplo n.º 2
0
class SoftChrootNonInitialized(TestCase):
    def setUp(self):
        self.b = SoftChroot()

    def test_is_root_abs(self):
        with self.assertRaises(RuntimeError):
            self.b.is_root_abs('1')

    def test_is_subdir(self):
        with self.assertRaises(RuntimeError):
            self.b.is_subdir('1')

    def test_chroot2abs(self):
        with self.assertRaises(RuntimeError):
            self.b.chroot2abs('1')

    def test_abs2chroot(self):
        with self.assertRaises(RuntimeError):
            self.b.abs2chroot('1')

    def test_get_root(self):
        with self.assertRaises(RuntimeError):
            self.b.get_chroot()
Exemplo n.º 3
0
 def tuneMock(self, env):
     #set up mock:
     sc = SoftChroot()
     sc.initialize(CHROOT_DIR)
     env.get.return_value = sc
Exemplo n.º 4
0
class Env(object):

    _appname = 'CouchPotato'
    ''' Environment variables '''
    _app = None
    _encoding = 'UTF-8'
    _debug = False
    _dev = False
    _settings = Settings()
    _database = Database()
    _loader = Loader()
    _softchroot = SoftChroot()
    _cache = None
    _options = None
    _args = None
    _quiet = False
    _daemonized = False
    _desktop = None
    _http_opener = None
    ''' Data paths and directories '''
    _app_dir = ""
    _data_dir = ""
    _cache_dir = ""
    _db = ""
    _log_path = ""

    @staticmethod
    def doDebug():
        return Env._debug

    @staticmethod
    def get(attr, unicode=False):
        if unicode:
            return toUnicode(getattr(Env, '_' + attr))
        else:
            return getattr(Env, '_' + attr)

    @staticmethod
    def all():
        ret = ''
        for attr in [
                'encoding', 'debug', 'args', 'app_dir', 'data_dir', 'desktop',
                'options'
        ]:
            ret += '%s=%s ' % (attr, Env.get(attr))

        return ret

    @staticmethod
    def set(attr, value):
        return setattr(Env, '_' + attr, value)

    @staticmethod
    def setting(attr, section='core', value=None, default='', type=None):

        s = Env.get('settings')

        # Return setting
        if value is None:
            return s.get(attr, default=default, section=section, type=type)

        # Set setting
        s.addSection(section)
        s.set(section, attr, value)
        s.save()

        return s

    @staticmethod
    def prop(identifier, value=None, default=None):
        s = Env.get('settings')
        if value is None:
            v = s.getProperty(identifier)
            return v if v else default

        s.setProperty(identifier, value)

    @staticmethod
    def getPermission(setting_type):
        perm = Env.get('settings').get('permission_%s' % setting_type,
                                       default='0777')
        if perm[0] == '0':
            return int(perm, 8)
        else:
            return int(perm)

    @staticmethod
    def fireEvent(*args, **kwargs):
        return fireEvent(*args, **kwargs)

    @staticmethod
    def addEvent(*args, **kwargs):
        return addEvent(*args, **kwargs)

    @staticmethod
    def getPid():
        try:
            try:
                parent = os.getppid()
            except:
                parent = None
            return '%d %s' % (os.getpid(),
                              '(%d)' % parent if parent and parent > 1 else '')
        except:
            return 0

    @staticmethod
    def getIdentifier():
        return '%s %s' % (Env.get('appname'),
                          fireEvent('app.version', single=True))
Exemplo n.º 5
0
 def setUp(self):
     self.b = SoftChroot()
     self.b.initialize(CHROOT_DIR)
Exemplo n.º 6
0
class SoftChrootEnabledTest(TestCase):
    def setUp(self):
        self.b = SoftChroot()
        self.b.initialize(CHROOT_DIR)

    def test_enabled(self):
        self.assertTrue( self.b.enabled)

    def test_is_subdir(self):
        self.assertFalse( self.b.is_subdir('') )
        self.assertFalse( self.b.is_subdir(None) )

        self.assertTrue( self.b.is_subdir(CHROOT_DIR) )
        noslash = CHROOT_DIR[:-1]
        self.assertTrue( self.b.is_subdir(noslash) )

        self.assertTrue( self.b.is_subdir(CHROOT_DIR + 'come') )

    def test_is_root_abs_none(self):
        with self.assertRaises(ValueError):
            self.assertFalse( self.b.is_root_abs(None) )

    def test_is_root_abs(self):
        self.assertFalse( self.b.is_root_abs('') )

        self.assertTrue( self.b.is_root_abs(CHROOT_DIR) )
        noslash = CHROOT_DIR[:-1]
        self.assertTrue( self.b.is_root_abs(noslash) )

        self.assertFalse( self.b.is_root_abs(CHROOT_DIR + 'come') )

    def test_chroot2abs_noleading_slash(self):
        path = 'no_leading_slash'
        path_sl = CHROOT_DIR + path
        #with self.assertRaises(ValueError):
        #    self.b.chroot2abs('no_leading_slash')
        self.assertEqual( self.b.chroot2abs(path), path_sl )

    def test_chroot2abs(self):
        self.assertEqual( self.b.chroot2abs(None), CHROOT_DIR )
        self.assertEqual( self.b.chroot2abs(''), CHROOT_DIR )

        self.assertEqual( self.b.chroot2abs('/asdf'), CHROOT_DIR + 'asdf' )

    def test_abs2chroot_raise_on_empty(self):
        with self.assertRaises(ValueError): self.b.abs2chroot(None)
        with self.assertRaises(ValueError): self.b.abs2chroot('')

    def test_abs2chroot(self):
        self.assertEqual( self.b.abs2chroot(CHROOT_DIR + 'asdf'), '/asdf' )
        self.assertEqual( self.b.abs2chroot(CHROOT_DIR), '/' )
        self.assertEqual( self.b.abs2chroot(CHROOT_DIR.rstrip(os.path.sep)), '/' )

    def test_get_root(self):
        self.assertEqual( self.b.get_chroot(), CHROOT_DIR )
Exemplo n.º 7
0
 def setUp(self):
     self.b = SoftChroot()
     self.b.initialize(None)
Exemplo n.º 8
0
class SoftChrootNOTEnabledTest(TestCase):
    def setUp(self):
        self.b = SoftChroot()
        self.b.initialize(None)

    def test_get_root(self):
        with self.assertRaises(RuntimeError):
            self.b.get_chroot()

    def test_chroot2abs_noleading_slash(self):
        path = 'no_leading_slash'
        self.assertEqual( self.b.chroot2abs(path), path )

    def test_chroot2abs(self):
        self.assertIsNone( self.b.chroot2abs(None), None )
        self.assertEqual( self.b.chroot2abs(''), '' )
        self.assertEqual( self.b.chroot2abs('/asdf'), '/asdf' )

    def test_abs2chroot_raise_on_empty(self):
        with self.assertRaises(ValueError):
            self.b.abs2chroot(None)

    def test_abs2chroot(self):
        self.assertEqual( self.b.abs2chroot(''), '' )
        self.assertEqual( self.b.abs2chroot('/asdf'), '/asdf' )
        self.assertEqual( self.b.abs2chroot('/'), '/' )

    def test_get_root(self):
        with self.assertRaises(RuntimeError):
            self.b.get_chroot()
Exemplo n.º 9
0
 def setUp(self):
     self.b = SoftChroot()
Exemplo n.º 10
0
 def setUp(self):
     self.b = SoftChroot()
     self.b.initialize(CHROOT_DIR)
Exemplo n.º 11
0
class SoftChrootEnabledTest(TestCase):
    def setUp(self):
        self.b = SoftChroot()
        self.b.initialize(CHROOT_DIR)

    def test_enabled(self):
        self.assertTrue(self.b.enabled)

    def test_is_subdir(self):
        self.assertFalse(self.b.is_subdir(''))
        self.assertFalse(self.b.is_subdir(None))

        self.assertTrue(self.b.is_subdir(CHROOT_DIR))
        noslash = CHROOT_DIR[:-1]
        self.assertTrue(self.b.is_subdir(noslash))

        self.assertTrue(self.b.is_subdir(CHROOT_DIR + 'come'))

    def test_is_root_abs_none(self):
        with self.assertRaises(ValueError):
            self.assertFalse(self.b.is_root_abs(None))

    def test_is_root_abs(self):
        self.assertFalse(self.b.is_root_abs(''))

        self.assertTrue(self.b.is_root_abs(CHROOT_DIR))
        noslash = CHROOT_DIR[:-1]
        self.assertTrue(self.b.is_root_abs(noslash))

        self.assertFalse(self.b.is_root_abs(CHROOT_DIR + 'come'))

    def test_chroot2abs_noleading_slash(self):
        path = 'no_leading_slash'
        path_sl = CHROOT_DIR + path
        #with self.assertRaises(ValueError):
        #    self.b.chroot2abs('no_leading_slash')
        self.assertEqual(self.b.chroot2abs(path), path_sl)

    def test_chroot2abs(self):
        self.assertEqual(self.b.chroot2abs(None), CHROOT_DIR)
        self.assertEqual(self.b.chroot2abs(''), CHROOT_DIR)

        self.assertEqual(self.b.chroot2abs('/asdf'), CHROOT_DIR + 'asdf')

    def test_abs2chroot_raise_on_empty(self):
        with self.assertRaises(ValueError):
            self.b.abs2chroot(None)
        with self.assertRaises(ValueError):
            self.b.abs2chroot('')

    def test_abs2chroot(self):
        self.assertEqual(self.b.abs2chroot(CHROOT_DIR + 'asdf'), '/asdf')
        self.assertEqual(self.b.abs2chroot(CHROOT_DIR), '/')
        self.assertEqual(self.b.abs2chroot(CHROOT_DIR.rstrip(os.path.sep)),
                         '/')

    def test_get_root(self):
        self.assertEqual(self.b.get_chroot(), CHROOT_DIR)
Exemplo n.º 12
0
 def setUp(self):
     self.b = SoftChroot()
     self.b.initialize(None)
Exemplo n.º 13
0
class SoftChrootNOTEnabledTest(TestCase):
    def setUp(self):
        self.b = SoftChroot()
        self.b.initialize(None)

    def test_get_root(self):
        with self.assertRaises(RuntimeError):
            self.b.get_chroot()

    def test_chroot2abs_noleading_slash(self):
        path = 'no_leading_slash'
        self.assertEqual(self.b.chroot2abs(path), path)

    def test_chroot2abs(self):
        self.assertIsNone(self.b.chroot2abs(None), None)
        self.assertEqual(self.b.chroot2abs(''), '')
        self.assertEqual(self.b.chroot2abs('/asdf'), '/asdf')

    def test_abs2chroot_raise_on_empty(self):
        with self.assertRaises(ValueError):
            self.b.abs2chroot(None)

    def test_abs2chroot(self):
        self.assertEqual(self.b.abs2chroot(''), '')
        self.assertEqual(self.b.abs2chroot('/asdf'), '/asdf')
        self.assertEqual(self.b.abs2chroot('/'), '/')

    def test_get_root(self):
        with self.assertRaises(RuntimeError):
            self.b.get_chroot()
Exemplo n.º 14
0
 def setUp(self):
     self.b = SoftChroot()