Ejemplo n.º 1
0
 def testGetLddMinusRlinesReloc(self):
     ip = inspective_package.InspectivePackage("/tmp/CSWfake")
     self.mox.StubOutWithMock(ip, 'GetBasedir')
     self.mox.StubOutWithMock(ip, 'ListBinaries')
     self.mox.StubOutWithMock(ip, 'GetFilesDir')
     self.mox.StubOutWithMock(os, 'chmod')
     self.mox.StubOutWithMock(os, 'uname')
     ip.GetBasedir().AndReturn('opt/csw')
     os.chmod('/tmp/CSWfake/reloc/bin/foo', 0755)
     ip.ListBinaries().AndReturn(['bin/foo'])
     ip.GetFilesDir().AndReturn('reloc')
     self.mox.StubOutWithMock(shell, 'ShellCommand')
     shell.ShellCommand(['ldd', '-Ur', '/tmp/CSWfake/reloc/bin/foo'],
                        timeout=10).AndReturn((0, "", ""))
     self.mox.StubOutWithMock(ip, '_ParseLddDashRline')
     self.mox.ReplayAll()
     self.assertEqual({'opt/csw/bin/foo': []}, ip.GetLddMinusRlines())
Ejemplo n.º 2
0
 def testListBinaries(self):
     self.mox.StubOutWithMock(hachoir_parser,
                              'createParser',
                              use_mock_anything=True)
     hachoir_parser_mock = self.mox.CreateMockAnything()
     hachoir_parser.createParser(
         u'/fake/path/CSWfoo/root/foo-file').AndReturn(hachoir_parser_mock)
     self.mox.StubOutWithMock(os, 'access')
     os.access(u'/fake/path/CSWfoo/root/foo-file', os.R_OK).AndReturn(True)
     machine_mock = self.mox.CreateMockAnything()
     machine_mock.value = 2
     hachoir_parser_mock.__getitem__('/header/machine').AndReturn(
         machine_mock)
     endian_mock = self.mox.CreateMockAnything()
     endian_mock.display = 'fake-endian'
     hachoir_parser_mock.__getitem__('/header/endian').AndReturn(
         endian_mock)
     magic_cookie_mock = self.mox.CreateMockAnything()
     self.mox.StubOutWithMock(magic, 'open')
     magic.open(0).AndReturn(magic_cookie_mock)
     magic_cookie_mock.load()
     if "MAGIC_MIME" in dir(magic):
         flag = magic.MAGIC_MIME
     elif "MIME" in dir(magic):
         flag = magic.MIME
     magic_cookie_mock.setflags(flag)
     magic_cookie_mock.file(u'/fake/path/CSWfoo/root/foo-file').AndReturn(
         "application/x-executable")
     self.mox.StubOutWithMock(os.path, 'isdir')
     self.mox.StubOutWithMock(os.path, 'exists')
     self.mox.StubOutWithMock(os, 'walk')
     # self.mox.StubOutWithMock(__builtins__, 'open')
     os.path.isdir("/fake/path/CSWfoo").AndReturn(True)
     os.path.isdir("/fake/path/CSWfoo").AndReturn(True)
     os.path.isdir("/fake/path/CSWfoo").AndReturn(True)
     os.path.exists("/fake/path/CSWfoo/reloc").AndReturn(False)
     os.path.exists("/fake/path/CSWfoo/reloc").AndReturn(False)
     os.walk("/fake/path/CSWfoo/root").AndReturn([
         ("/fake/path/CSWfoo/root", [], ["foo-file"]),
     ])
     self.mox.ReplayAll()
     ip = inspective_package.InspectivePackage("/fake/path/CSWfoo")
     ip.pkginfo_dict = {
         "BASEDIR": "",
     }
     self.assertEqual([u'foo-file'], ip.ListBinaries())
Ejemplo n.º 3
0
 def testGetLddMinusRlinesThrows(self):
     ip = inspective_package.InspectivePackage("/tmp/CSWfake")
     self.mox.StubOutWithMock(ip, 'GetBasedir')
     self.mox.StubOutWithMock(ip, 'ListBinaries')
     self.mox.StubOutWithMock(ip, 'GetFilesDir')
     self.mox.StubOutWithMock(os, 'chmod')
     self.mox.StubOutWithMock(os, 'uname')
     ip.GetBasedir().AndReturn('/')
     os.chmod('/tmp/CSWfake/root/opt/csw/bin/foo', 0755)
     os.uname().AndReturn('i86pc')
     ip.GetFilesDir().AndReturn('root')
     ip.ListBinaries().AndReturn(['opt/csw/bin/foo'])
     self.mox.StubOutWithMock(shell, 'ShellCommand')
     shell.ShellCommand(['ldd', '-Ur', '/tmp/CSWfake/root/opt/csw/bin/foo'],
                        timeout=10).AndReturn((1, "", "boo"))
     self.mox.StubOutWithMock(ip, '_ParseLddDashRline')
     self.mox.ReplayAll()
     self.assertRaises(package.SystemUtilityError, ip.GetLddMinusRlines)
Ejemplo n.º 4
0
    def testGetBinaryElfInfoReloc(self):
        fake_binary = 'lib/libssl.so.1.0.0'
        fake_package_path = '/fake/path/CSWfoo'

        ip = inspective_package.InspectivePackage(fake_package_path)
        self.mox.StubOutWithMock(ip, 'ListBinaries')
        self.mox.StubOutWithMock(ip, 'GetBasedir')
        self.mox.StubOutWithMock(ip, 'GetFilesDir')
        ip.ListBinaries().AndReturn([fake_binary])
        ip.GetBasedir().AndReturn('opt/csw')
        ip.GetFilesDir().AndReturn('reloc')

        self.mox.StubOutWithMock(shell, 'ShellCommand')
        args = [
            common_constants.ELFDUMP_BIN, '-svy',
            os.path.join(fake_package_path, "reloc", fake_binary)
        ]
        shell.ShellCommand(args).AndReturn((0, ELFDUMP_OUTPUT, ""))
        self.mox.ReplayAll()

        self.assertEqual(BINARY_ELFINFO, ip.GetBinaryElfInfo())
Ejemplo n.º 5
0
    def testGetBinaryDumpInfoReloc(self):
        fake_binary = 'bin/foo'
        fake_package_path = '/fake/path/CSWfoo'

        ip = inspective_package.InspectivePackage(fake_package_path)
        self.mox.StubOutWithMock(ip, 'ListBinaries')
        self.mox.StubOutWithMock(ip, 'GetBasedir')
        self.mox.StubOutWithMock(ip, 'GetFilesDir')
        ip.ListBinaries().AndReturn([fake_binary])
        ip.GetBasedir().AndReturn('opt/csw')
        ip.GetFilesDir().AndReturn('reloc')

        self.mox.StubOutWithMock(shell, 'ShellCommand')
        args = [
            common_constants.DUMP_BIN, '-Lv',
            os.path.join(fake_package_path, "reloc", fake_binary)
        ]
        shell.ShellCommand(args, mox.IgnoreArg()).AndReturn(
            (0, DUMP_OUTPUT, ""))
        self.mox.ReplayAll()

        self.assertEqual([BINARY_DUMP_INFO], ip.GetBinaryDumpInfo())
Ejemplo n.º 6
0
 def setUp(self):
     self.ip = inspective_package.InspectivePackage("/fake/path/CSWfoo")
Ejemplo n.º 7
0
    def testGetBinaryElfInfoWithIgnoredErrors(self):
        fake_binary = 'opt/csw/bin/foo'
        fake_package_path = '/fake/path/CSWfoo'
        fake_elfdump_output = '''
Version Needed Section:  .SUNW_version
     index  file                        version
       [2]  libc.so.1                 SUNW_1.1

Symbol Table Section:  .dynsym
     index    value      size      type bind oth ver shndx          name
       [1]  0x00000000 0x00000000  FUNC GLOB  D    2 UNDEF          fopen64

Syminfo Section:  .SUNW_syminfo
     index  flags            bound to                 symbol
       [1]  DBL          [1] libc.so.1                fopen64
'''
        fake_elfdump_errors = '''
/opt/csw/bin/foo: .dynsym: index[26]: bad symbol entry: : invalid shndx: 26
/opt/csw/bin/foo: .dynsym: bad symbol entry: : invalid shndx: 23
/opt/csw/bin/foo: .dynsym: index[108]: suspicious local symbol entry: _END_: lies within global symbol range (index >= 27)
/opt/csw/bin/foo: .dynsym: index[4]: bad symbol entry: toto: section[24] size: 0: symbol (address 0x36b7fc, size 0x4) lies outside of containing section
/opt/csw/bin/foo: .dynsym: bad symbol entry: Xt_app_con: section[28] size: 0: is smaller than symbol size: 4
'''
        fake_binary_elfinfo = {
            'opt/csw/bin/foo': {
                'symbol table': [
                    {
                        'shndx': 'UNDEF',
                        'soname': 'libc.so.1',
                        'bind': 'GLOB',
                        'symbol': 'fopen64',
                        'version': 'SUNW_1.1',
                        'flags': 'DBL',
                        'type': 'FUNC'
                    },
                ],
                'version needed': [
                    {
                        'version': 'SUNW_1.1',
                        'soname': 'libc.so.1'
                    },
                ],
                'version definition': [],
            }
        }
        ip = inspective_package.InspectivePackage(fake_package_path)
        self.mox.StubOutWithMock(ip, 'ListBinaries')
        self.mox.StubOutWithMock(ip, 'GetBasedir')
        self.mox.StubOutWithMock(ip, 'GetFilesDir')
        ip.ListBinaries().AndReturn([fake_binary])
        ip.GetBasedir().AndReturn('')
        ip.GetFilesDir().AndReturn('root')

        self.mox.StubOutWithMock(shell, 'ShellCommand')
        args = [
            common_constants.ELFDUMP_BIN, '-svy',
            os.path.join(fake_package_path, "root", fake_binary)
        ]
        shell.ShellCommand(args).AndReturn(
            (0, fake_elfdump_output, fake_elfdump_errors))
        self.mox.ReplayAll()

        self.assertEqual(fake_binary_elfinfo, ip.GetBinaryElfInfo())