예제 #1
0
 def setUp(self):
     """Must start a server for this"""
     pipe_cmd = "%s testing/server.py %s" \
         % (sys.executable, SourceDir)
     self.p = subprocess.Popen(pipe_cmd,
                               shell=True,
                               stdin=subprocess.PIPE,
                               stdout=subprocess.PIPE,
                               close_fds=True)
     (stdin, stdout) = (self.p.stdin, self.p.stdout)
     self.conn = PipeConnection(stdout, stdin)
     Security._security_level = "override"
예제 #2
0
class PipeConnectionTest(unittest.TestCase):
    """Test Pipe connection"""
    def setUp(self):
        """Must start a server for this"""
        pipe_cmd = "%s testing/server.py %s" \
            % (sys.executable, SourceDir)
        self.p = subprocess.Popen(pipe_cmd,
                                  shell=True,
                                  stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE,
                                  close_fds=True)
        (stdin, stdout) = (self.p.stdin, self.p.stdout)
        self.conn = PipeConnection(stdout, stdin)
        Security._security_level = "override"

    def testBasic(self):
        """Test some basic pipe functions"""
        self.assertEqual(self.conn.ord("a"), 97)
        self.assertEqual(self.conn.pow(2, 3), 8)
        self.assertEqual(self.conn.reval("ord", "a"), 97)

    def testModules(self):
        """Test module emulation"""
        self.assertIsInstance(self.conn.tempfile.mktemp(), str)
        self.assertEqual(self.conn.os.path.join(b"a", b"b"), b"a/b")
        rp1 = rpath.RPath(self.conn, regfilename)
        self.assertTrue(rp1.isreg())

    def testVirtualFiles(self):
        """Testing virtual files"""
        # generate file name for temporary file
        temp_file = os.path.join(abs_test_dir, b"tempout")

        tempout = self.conn.open(temp_file, "wb")
        self.assertIsInstance(tempout, VirtualFile)
        regfilefp = open(regfilename, "rb")
        rpath.copyfileobj(regfilefp, tempout)
        tempout.close()
        regfilefp.close()
        tempoutlocal = open(temp_file, "rb")
        regfilefp = open(regfilename, "rb")
        self.assertTrue(rpath._cmp_file_obj(regfilefp, tempoutlocal))
        tempoutlocal.close()
        regfilefp.close()
        os.unlink(temp_file)

        with open(regfilename, "rb") as localfh:
            self.assertTrue(
                rpath._cmp_file_obj(self.conn.open(regfilename, "rb"),
                                    localfh))

    def testString(self):
        """Test transmitting strings"""
        self.assertEqual("32", self.conn.str(32))
        self.assertEqual(32, self.conn.int("32"))

    def testIterators(self):
        """Test transmission of iterators"""
        i = iter([5, 10, 15] * 100)
        self.assertTrue(
            self.conn.hasattr(i, "__next__")
            and self.conn.hasattr(i, "__iter__"))
        ret_val = self.conn.reval("lambda i: next(i)*next(i)", i)
        self.assertEqual(ret_val, 50)

    def testRPaths(self):
        """Test transmission of rpaths"""
        rp = rpath.RPath(self.conn, regfilename)
        self.assertEqual(self.conn.reval("lambda rp: rp.data", rp), rp.data)
        self.assertTrue(
            self.conn.reval("lambda rp: rp.conn is Globals.local_connection",
                            rp))

    def testQuotedRPaths(self):
        """Test transmission of quoted rpaths"""
        qrp = FilenameMapping.QuotedRPath(self.conn, regfilename)
        self.assertEqual(self.conn.reval("lambda qrp: qrp.data", qrp),
                         qrp.data)
        self.assertTrue(qrp.isreg())
        qrp_class_str = self.conn.reval("lambda qrp: str(qrp.__class__)", qrp)
        self.assertGreater(qrp_class_str.find("QuotedRPath"), -1)

    def testExceptions(self):
        """Test exceptional results"""
        self.assertRaises(os.error, self.conn.os.lstat,
                          "asoeut haosetnuhaoseu tn")
        self.assertRaises(SyntaxError, self.conn.reval, "aoetnsu aoehtnsu")
        self.assertEqual(self.conn.pow(2, 3), 8)

    def tearDown(self):
        """Bring down connection"""
        self.conn.quit()
        time.sleep(0.1)  # give the process time to quit
        if (self.p.poll() is None):
            self.p.terminate()
예제 #3
0
If not run from the source directory, the only argument should be
the directory the source files are in.
"""


def Test_SetConnGlobals(conn, setting, value):
    """This is used in connectiontest.py"""
    conn.Globals.set(setting, value)


def print_usage():
    print("Usage: server.py  [path to source files]", __doc__)


if len(sys.argv) > 2:
    print_usage()
    sys.exit(1)

try:
    if len(sys.argv) == 2:
        sys.path.insert(0, sys.argv[1])
    import rdiff_backup.Globals
    import rdiff_backup.Security
    from rdiff_backup.connection import PipeConnection
except (OSError, IOError, ImportError):
    print_usage()
    raise

rdiff_backup.Globals.security_level = "override"
sys.exit(PipeConnection(sys.stdin.buffer, sys.stdout.buffer).Server())