def testRenameOfRunningExecutable(self): if util.get_canonical_os_type() != 'windows': return import pkg.portable.os_windows as os_windows cwd = os.getcwdu() exefilesrc = 'C:\\Windows\\system32\\more.com' self.assertTrue(os.path.exists(exefilesrc)) # create an image, copy an executable into it, # run the executable, replace the executable tdir1 = tempfile.mkdtemp() img1 = image.Image(tdir1, imgtype=image.IMG_USER, should_exist=False, user_provided_dir=True) img1.history.client_name = "pkg-test" img1.set_attrs(False, "test", origins=["http://localhost:10000"], refresh_allowed=False) exefile = os.path.join(tdir1, 'less.com') shutil.copyfile(exefilesrc, exefile) proc = subprocess.Popen([exefile], stdin=subprocess.PIPE) self.assertRaises(OSError, os.unlink, exefile) fd1, path1 = tempfile.mkstemp(dir=tdir1) os.write(fd1, b"foo") os.close(fd1) portable.rename(path1, exefile) fd2 = os.open(exefile, os.O_RDONLY) self.assertEqual(os.read(fd2, 3), "foo") os.close(fd2) proc.communicate() # Make sure that the moved executable gets deleted # This is a white-box test # To simulate running another process, we delete the cache # and call get_trashdir as if another file was being moved # to the trash. os_windows.cached_image_info = [] os_windows.get_trashdir(exefile) self.assertTrue(not os.path.exists( os.path.join(img1.imgdir, os_windows.trashname))) # cleanup os.chdir(cwd) shutil.rmtree(tdir1)
def testRenameOfRunningExecutable(self): if util.get_canonical_os_type() != 'windows': return import pkg.portable.os_windows as os_windows cwd = os.getcwdu() exefilesrc = 'C:\\Windows\\system32\\more.com' self.assert_(os.path.exists(exefilesrc)) # create an image, copy an executable into it, # run the executable, replace the executable tdir1 = tempfile.mkdtemp() img1 = image.Image(tdir1, imgtype=image.IMG_USER, should_exist=False, user_provided_dir=True) img1.history.client_name = "pkg-test" img1.set_attrs(False, "test", origins=["http://localhost:10000"], refresh_allowed=False) exefile = os.path.join(tdir1, 'less.com') shutil.copyfile(exefilesrc, exefile) proc = subprocess.Popen([exefile], stdin = subprocess.PIPE) self.assertRaises(OSError, os.unlink, exefile) fd1, path1 = tempfile.mkstemp(dir = tdir1) os.write(fd1, "foo") os.close(fd1) portable.rename(path1, exefile) fd2 = os.open(exefile, os.O_RDONLY) self.assertEquals(os.read(fd2, 3), "foo") os.close(fd2) proc.communicate() # Make sure that the moved executable gets deleted # This is a white-box test # To simulate running another process, we delete the cache # and call get_trashdir as if another file was being moved # to the trash. os_windows.cached_image_info = [] os_windows.get_trashdir(exefile) self.assert_(not os.path.exists(os.path.join(img1.imgdir, os_windows.trashname))) # cleanup os.chdir(cwd) shutil.rmtree(tdir1)
"file does not exist." elif not os.path.isfile(ssl_key_file): raise OptionError, "The specified " \ "pathname is not a file." elif opt == "--ssl-dialog": if arg != "builtin" and not \ arg.startswith("exec:/") and not \ arg.startswith("smf:"): raise OptionError, "Invalid value " \ "specified. Expected: builtin, " \ "exec:/path/to/program, or " \ "smf:fmri." f = arg if f.startswith("exec:"): if os_util.get_canonical_os_type() != \ "unix": # Don't allow a somewhat # insecure authentication method # on some platforms. raise OptionError, "exec is " \ "not a supported dialog " \ "type for this operating " \ "system." f = os.path.abspath(f.split( "exec:")[1]) if not os.path.isfile(f): raise OptionError, "Invalid " \ "file path specified for " \
def testUtils(self): self.assertNotEqual("unknown", util.get_canonical_os_type()) self.assertNotEqual("unknown", util.get_canonical_os_name())
elif not os.path.isfile(arg): raise OptionError("The specified " "pathname is not a file.") ivalues["pkg"]["ssl_key_file"] = arg elif opt == "--ssl-dialog": if arg != "builtin" and \ arg != "smf" and not \ arg.startswith("exec:/") and not \ arg.startswith("svc:"): raise OptionError("Invalid value " "specified. Expected: builtin, " "exec:/path/to/program, smf, or " "an SMF FMRI.") if arg.startswith("exec:"): if os_util.get_canonical_os_type() != \ "unix": # Don't allow a somewhat # insecure authentication method # on some platforms. raise OptionError("exec is " "not a supported dialog " "type for this operating " "system.") f = os.path.abspath(arg.split( "exec:")[1]) if not os.path.isfile(f): raise OptionError("Invalid " "file path specified for " "exec.")