示例#1
0
    def testUser4(self):
        """ Test with a user name line in the passwd file that
                starts with a "+". (See bug #4470 for more details). """
        if not os.path.exists("/etc/passwd"):
            return

        passwd = open(os.path.join(self.test_root, "etc", "passwd"), "w")
        passwd.write( \
"""root:x:0:0::/root:/usr/bin/bash
gk:x:0:0::/root:/usr/bin/bash
daemon:x:1:1::/:
bin:x:2:2::/usr/bin:
sys:x:3:3::/:
+plususer
adm:x:4:4:Admin:/var/adm:
lp:x:71:8:Line Printer Admin:/usr/spool/lp:
uucp:x:5:5:uucp Admin:/usr/lib/uucp:
+""")
        passwd.close()
        self.assertTrue(0 == \
            portable.get_user_by_name("root", self.test_root, True))
        self.assertTrue(0 == \
            portable.get_user_by_name("gk", self.test_root, True))
        self.assertTrue("root" == \
            portable.get_name_by_uid(0, self.test_root, True))
        self.assertTrue("uucp" == \
            portable.get_name_by_uid(5, self.test_root, True))

        self.assertRaises(KeyError, portable.get_user_by_name, "plususer",
                          self.test_root, True)
示例#2
0
    def testUser4(self):
        """ Test with a user name line in the passwd file that
                starts with a "+". (See bug #4470 for more details). """
        if not os.path.exists("/etc/passwd"):
            return

        passwd = file(os.path.join(self.test_root, "etc", "passwd"), "w")
        passwd.write(
            """root:x:0:0::/root:/usr/bin/bash
gk:x:0:0::/root:/usr/bin/bash
daemon:x:1:1::/:
bin:x:2:2::/usr/bin:
sys:x:3:3::/:
+plususer
adm:x:4:4:Admin:/var/adm:
lp:x:71:8:Line Printer Admin:/usr/spool/lp:
uucp:x:5:5:uucp Admin:/usr/lib/uucp:
+"""
        )
        passwd.close()
        self.assert_(0 == portable.get_user_by_name("root", self.test_root, True))
        self.assert_(0 == portable.get_user_by_name("gk", self.test_root, True))
        self.assert_("root" == portable.get_name_by_uid(0, self.test_root, True))
        self.assert_("uucp" == portable.get_name_by_uid(5, self.test_root, True))

        self.assertRaises(KeyError, portable.get_user_by_name, "plususer", self.test_root, True)
示例#3
0
    def testUser3(self):
        """ Test with an oddball/corrupt passwd file """
        if not os.path.exists("/etc/passwd"):
            return

        passwd = file(os.path.join(self.test_root, "etc", "passwd"), "w")
        passwd.write(
            """root:x:0:0::/root:/usr/bin/bash
daemon:x:1:1::/:
bin:x:2:2::/usr/bin:
sys:x:3:3::/:

blorg
corrupt:x

gk:x:0:0::/root:/usr/bin/bash
adm:x:4:4:Admin:/var/adm:
lp:x:71:8:Line Printer Admin:/usr/spool/lp:
uucp:x:5:5:uucp Admin:/usr/lib/uucp:
+"""
        )
        passwd.close()
        self.assert_(0 == portable.get_user_by_name("root", self.test_root, True))
        self.assert_(0 == portable.get_user_by_name("gk", self.test_root, True))
        self.assert_("uucp" == portable.get_name_by_uid(5, self.test_root, True))

        self.assertRaises(KeyError, portable.get_user_by_name, "ThisShouldNotExist", self.test_root, True)

        self.assertRaises(KeyError, portable.get_user_by_name, "corrupt", self.test_root, True)

        self.assertRaises(KeyError, portable.get_user_by_name, 999, self.test_root, True)
示例#4
0
    def testUser2(self):
        """ Test with a missing passwd file """
        if not os.path.exists("/etc/passwd"):
            return

        self.assertRaises(KeyError, portable.get_user_by_name, "ThisShouldNotExist", self.test_root, True)

        # This should work on unix systems, since we'll "bootstrap"
        # out to the OS's version.
        self.assert_(0 == portable.get_user_by_name("root", self.test_root, True))
        self.assert_("root" == portable.get_name_by_uid(0, self.test_root, True))
示例#5
0
    def testUser2(self):
        """ Test with a missing passwd file """
        if not os.path.exists("/etc/passwd"):
            return

        self.assertRaises(KeyError, portable.get_user_by_name,
                          "ThisShouldNotExist", self.test_root, True)

        # This should work on unix systems, since we'll "bootstrap"
        # out to the OS's version.
        self.assertTrue(0 == \
            portable.get_user_by_name("root", self.test_root, True))
        self.assertTrue("root" == \
            portable.get_name_by_uid(0, self.test_root, True))
示例#6
0
    def testUser3(self):
        """ Test with an oddball/corrupt passwd file """
        if not os.path.exists("/etc/passwd"):
            return

        passwd = open(os.path.join(self.test_root, "etc", "passwd"), "w")
        passwd.write( \
"""root:x:0:0::/root:/usr/bin/bash
daemon:x:1:1::/:
bin:x:2:2::/usr/bin:
sys:x:3:3::/:

blorg
corrupt:x

gk:x:0:0::/root:/usr/bin/bash
adm:x:4:4:Admin:/var/adm:
lp:x:71:8:Line Printer Admin:/usr/spool/lp:
uucp:x:5:5:uucp Admin:/usr/lib/uucp:
+""")
        passwd.close()
        self.assertTrue(0 == \
            portable.get_user_by_name("root", self.test_root, True))
        self.assertTrue(0 == \
            portable.get_user_by_name("gk", self.test_root, True))
        self.assertTrue("uucp" == \
            portable.get_name_by_uid(5, self.test_root, True))

        self.assertRaises(KeyError, portable.get_user_by_name,
                          "ThisShouldNotExist", self.test_root, True)

        self.assertRaises(KeyError, portable.get_user_by_name, "corrupt",
                          self.test_root, True)

        self.assertRaises(KeyError, portable.get_user_by_name, 999,
                          self.test_root, True)