def test_getprotectedname(self): pro = Protection('', 'horde', '3.0.5', 'portage') self.assertEqual( pro.get_protectedname( '/'.join((HERE, 'testfiles', 'protect', 'empty')), 'test'), '/'.join( (HERE, 'testfiles', 'protect', 'empty', '/._cfg0000_test')))
def test_getprotectedname(self): pro = Protection('', 'horde', '3.0.5', 'portage') self.assertEqual(pro.get_protectedname('/'.join((HERE, 'testfiles', 'protect', 'empty')), 'test'), '/'.join((HERE, 'testfiles', 'protect', 'empty', '/._cfg0000_test')))
def test_how_to_update(self): OUT.color_off() pro = Protection('', 'horde', '3.0.5', 'portage') strange_htdocs = '/'.join(('/my', 'strange', 'htdocs', 'where', 'i', 'installed', 'x')) pro.how_to_update([strange_htdocs]) output = sys.stdout.getvalue().split('\n') self.assertEqual(output[3], '* CONFIG_PROTECT="' + strange_htdocs + '" etc-update') # Adding a virtual config protected directory: i = strange_htdocs.replace('/where/i/instaled/x', '') pro.config_protect += ' ' + i pro.how_to_update([strange_htdocs]) output = sys.stdout.getvalue().split('\n') self.assertEqual(output[8], '* etc-update')
def test_dirisconfprotected(self): pro = Protection('', 'horde', '3.0.5', 'portage') strange_htdocs = '/'.join(('/my', 'strange', 'htdocs')) pro.config_protect += ' ' + strange_htdocs self.assertTrue(pro.dirisconfigprotected(strange_htdocs)) self.assertTrue( pro.dirisconfigprotected('/'.join( (strange_htdocs, 'where', 'i', 'installed', 'x')))) self.assertTrue( pro.dirisconfigprotected('/'.join( (strange_htdocs, 'where', 'i', 'installed', 'x/')))) pro.config_protect += ' bad_user' + strange_htdocs self.assertFalse( pro.dirisconfigprotected('/'.join( ('/my', 'bad_user', 'htdocs', 'where', 'i', 'installed', 'x')))) self.assertFalse(pro.dirisconfigprotected('/'))
def test_how_to_update(self): OUT.color_off() pro = Protection('', 'horde', '3.0.5', 'portage') strange_htdocs = '/'.join( ('/my', 'strange', 'htdocs', 'where', 'i', 'installed', 'x')) pro.how_to_update([strange_htdocs]) output = sys.stdout.getvalue().split('\n') self.assertEqual( output[3], '* CONFIG_PROTECT="' + strange_htdocs + '" etc-update') # Adding a virtual config protected directory: i = strange_htdocs.replace('/where/i/instaled/x', '') pro.config_protect += ' ' + i pro.how_to_update([strange_htdocs]) output = sys.stdout.getvalue().split('\n') self.assertEqual(output[8], '* etc-update')
def test_dirisconfprotected(self): pro = Protection('', 'horde', '3.0.5', 'portage') strange_htdocs = '/'.join(('/my', 'strange', 'htdocs')) pro.config_protect += ' ' + strange_htdocs self.assertTrue(pro.dirisconfigprotected(strange_htdocs)) self.assertTrue(pro.dirisconfigprotected('/'.join((strange_htdocs, 'where', 'i', 'installed', 'x')))) self.assertTrue(pro.dirisconfigprotected('/'.join((strange_htdocs, 'where', 'i', 'installed', 'x/')))) pro.config_protect += ' bad_user' + strange_htdocs self.assertFalse(pro.dirisconfigprotected('/'.join(('/my', 'bad_user', 'htdocs', 'where', 'i', 'installed', 'x')))) self.assertFalse(pro.dirisconfigprotected('/'))
def test_mk(self): OUT.color_off() contents = Contents('/'.join((HERE, 'testfiles', 'installtest')), pretend=True) webrm = WebappRemove(contents, True, True) protect = Protection('', 'horde', '3.0.5', 'portage') source = WebappSource(root='/'.join( (HERE, 'testfiles', 'share-webapps')), category='', package='installtest', version='1.0') source.read() source.ignore = ['.svn'] webadd = WebappAdd( 'htdocs', '/'.join((HERE, 'testfiles', 'installtest')), { 'dir': { 'default-owned': ('root', 'root', '0644') }, 'file': { 'virtual': ('root', 'root', '0644'), 'server-owned': ('apache', 'apache', '0660'), 'config-owned': ('nobody', 'nobody', '0600') } }, { 'content': contents, 'removal': webrm, 'protect': protect, 'source': source }, { 'relative': 1, 'upgrade': False, 'pretend': True, 'verbose': False, 'linktype': 'soft' }) webadd.mkfile('test1') webadd.mkfile('test4') webadd.mkfile('test2') webadd.mkfile('test3') webadd.mkdir('dir1') webadd.mkdir('dir2') output = sys.stdout.getvalue().split('\n') self.assertEqual(output[0], '* pretending to add: sym 1 virtual ' + '"test1"') self.assertEqual( output[1], '* pretending to add: file 1 ' + 'server-owned "test4"') self.assertEqual(output[3], '* pretending to add: sym 1 virtual ' + '"test2"') self.assertEqual(output[4], '^o^ hiding test3') self.assertEqual( output[6], '* pretending to add: dir 1 ' + 'default-owned "dir1"') self.assertEqual( output[8], '* pretending to add: dir 1 ' + 'default-owned "dir2"') # Now testing all of them combined: webadd.mkdirs('') output = sys.stdout.getvalue().split('\n') self.assertEqual(output[20], '^o^ hiding /test3')