Example #1
0
 def __init__(self, *a, **kw):
     try:
         self.bash_path = spawn.find_binary("bash")
         self.null_file = open("/dev/null", "w")
         self.null = self.null_file.fileno()
     except spawn.CommandNotFound:
         self.skip = "bash wasn't found.  this will be ugly."
     super(SpawnTest, self).__init__(*a, **kw)
Example #2
0
 def __init__(self, *a, **kw):
     try:
         self.bash_path = spawn.find_binary("bash")
         self.null_file = open("/dev/null", "w")
         self.null = self.null_file.fileno()
     except spawn.CommandNotFound:
         self.skip = "bash wasn't found.  this will be ugly."
     super(SpawnTest, self).__init__(*a, **kw)
Example #3
0
    def test_fakeroot(self):
        try:
            l = pwd.getpwnam("nobody")
        except KeyError:
            raise SkipTest(
                "system lacks nobody user, thus can't test fakeroot")
        if 'LD_PRELOAD' in os.environ:
            raise SkipTest(
                "disabling test due to LD_PRELOAD setting, which "
                "fakeroot relies upon")

        nobody_uid = l[2]
        nobody_gid = l[3]

        kw = {}
        if os.getuid() == 0:
            kw = {"uid": l[2], "gid": l[3]}

        fp2 = self.generate_script(
            "pkgcore-spawn-fakeroot2.sh",
            "#!%s\nimport os\ns=os.stat('/tmp')\n"
            "print(s.st_uid)\nprint(s.st_gid)\n" %
            spawn.find_binary("python"))

        fp1 = self.generate_script(
            "pkgcore-spawn-fakeroot.sh",
            "#!%s\nchown %i:%i /tmp;%s;\n" % (
                self.bash_path, nobody_uid, nobody_gid, fp2))

        savefile = os.path.join(self.dir, "fakeroot-savefile")
        self.assertNotEqual(long(os.stat("/tmp").st_uid), long(nobody_uid))
        self.assertEqual(
            [0, ["%s\n" % x for x in (nobody_uid, nobody_gid)]],
            spawn.spawn_get_output(
                [self.bash_path, fp1],
                spawn_type=post_curry(spawn.spawn_fakeroot, savefile), **kw))
        self.assertNotEqual(
            long(os.stat("/tmp").st_uid), long(nobody_uid),
            "bad voodoo; we managed to change /tmp to nobody- "
            "this shouldn't occur!")
        self.assertEqual(
            True, os.path.exists(savefile),
            "no fakeroot file was created, either fakeroot differs or our" +
            " args passed to it are bad")

        # yes this is a bit ugly, but fakeroot requires an arg- so we
        # have to curry it
        self.assertEqual(
            [0, ["%s\n" % x for x in (nobody_uid, nobody_gid)]],
            spawn.spawn_get_output(
                [fp2],
                spawn_type=post_curry(spawn.spawn_fakeroot, savefile), **kw))

        os.unlink(fp1)
        os.unlink(fp2)
        os.unlink(savefile)
Example #4
0
    def test_fakeroot(self):
        try:
            l = pwd.getpwnam("nobody")
        except KeyError:
            raise SkipTest(
                "system lacks nobody user, thus can't test fakeroot")
        if 'LD_PRELOAD' in os.environ:
            raise SkipTest(
                "disabling test due to LD_PRELOAD setting, which "
                "fakeroot relies upon")

        nobody_uid = l[2]
        nobody_gid = l[3]

        kw = {}
        if os.getuid() == 0:
            kw = {"uid": l[2], "gid": l[3]}

        fp2 = self.generate_script(
            "pkgcore-spawn-fakeroot2.sh",
            "#!%s\nimport os\ns=os.stat('/tmp')\n"
            "print(s.st_uid)\nprint(s.st_gid)\n" %
            spawn.find_binary("python"))

        fp1 = self.generate_script(
            "pkgcore-spawn-fakeroot.sh",
            "#!%s\nchown %i:%i /tmp;%s;\n" % (
                self.bash_path, nobody_uid, nobody_gid, fp2))

        savefile = os.path.join(self.dir, "fakeroot-savefile")
        self.assertNotEqual(long(os.stat("/tmp").st_uid), long(nobody_uid))
        self.assertEqual(
            [0, ["%s\n" % x for x in (nobody_uid, nobody_gid)]],
            spawn.spawn_get_output(
                [self.bash_path, fp1],
                spawn_type=post_curry(spawn.spawn_fakeroot, savefile), **kw))
        self.assertNotEqual(
            long(os.stat("/tmp").st_uid), long(nobody_uid),
            "bad voodoo; we managed to change /tmp to nobody- "
            "this shouldn't occur!")
        self.assertEqual(
            True, os.path.exists(savefile),
            "no fakeroot file was created, either fakeroot differs or our" +
            " args passed to it are bad")

        # yes this is a bit ugly, but fakeroot requires an arg- so we
        # have to curry it
        self.assertEqual(
            [0, ["%s\n" % x for x in (nobody_uid, nobody_gid)]],
            spawn.spawn_get_output(
                [fp2],
                spawn_type=post_curry(spawn.spawn_fakeroot, savefile), **kw))

        os.unlink(fp1)
        os.unlink(fp2)
        os.unlink(savefile)
Example #5
0
 def test_binary_path(self):
     existing = os.environ.get("PATH", self)
     try:
         try:
             path = spawn.find_binary('install-info')
         except spawn.CommandNotFound:
             path = None
         self.assertEqual(path, self.trigger.get_binary_path())
         if path is not self:
             os.environ["PATH"] = ""
             self.assertEqual(None, self.trigger.get_binary_path())
     finally:
         if existing is self:
             os.environ.pop("PATH", None)
         else:
             os.environ["PATH"] = existing
Example #6
0
 def test_binary_path(self):
     existing = os.environ.get("PATH", self)
     try:
         try:
             path = spawn.find_binary('install-info')
         except spawn.CommandNotFound:
             path = None
         self.assertEqual(path, self.trigger.get_binary_path())
         if path is not self:
             os.environ["PATH"] = ""
             self.assertEqual(None, self.trigger.get_binary_path())
     finally:
         if existing is self:
             os.environ.pop("PATH", None)
         else:
             os.environ["PATH"] = existing