Esempio n. 1
0
def _testConnectAndClose(tls=False, hostname="localhost"):
    if tls and not tls_supported():
        return None
    reset_all_certs_and_keys()
    s1 = Rwsender()
    r1 = Rwreceiver()
    sy = System()
    try:
        sy.connect(s1, r1, tls=tls, hostname=hostname)
        sy.start()
        if tls:
            check_dh(s1, r1)
        trigger((s1, 25, "Connected to remote %s" % r1.name),
                (r1, 25, "Connected to remote %s" % s1.name))
        sy.stop()
        trigger((s1, 20, "Finished shutting down"),
                (r1, 20, "Finished shutting down"))
        trigger((s1, 25, "Stopped logging"),
                (r1, 25, "Stopped logging"))
    except:
        traceback.print_exc()
        sy.stop()
        raise
    finally:
        sy.end(noremove=NO_REMOVE)
Esempio n. 2
0
def _testConnectAndClose(tls=False, hostname="localhost"):
    if tls and not tls_supported():
        return None
    reset_all_certs_and_keys()
    s1 = Rwsender()
    r1 = Rwreceiver()
    sy = System()
    try:
        sy.connect(s1, r1, tls=tls, hostname=hostname)
        sy.start()
        if tls:
            check_dh(s1, r1)
        trigger((s1, 25, "Connected to remote %s" % r1.name),
                (r1, 25, "Connected to remote %s" % s1.name))
        sy.stop()
        trigger((s1, 20, "Finished shutting down"),
                (r1, 20, "Finished shutting down"))
        trigger((s1, 25, "Stopped logging"),
                (r1, 25, "Stopped logging"))
    except:
        traceback.print_exc()
        sy.stop()
        raise
    finally:
        sy.end(noremove=NO_REMOVE)
Esempio n. 3
0
def _testMultiple(tls=False):
    global rfiles
    if tls and not tls_supported():
        return None
    reset_all_certs_and_keys()
    s1 = Rwsender()
    s2 = Rwsender()
    r1 = Rwreceiver()
    r2 = Rwreceiver()
    sy = System()
    try:
        sy.connect([r1, r2], [s1, s2], tls=tls)
        sy.start()
        if tls:
            check_dh(s1, r1, s2, r2)

        trigger((s1, 70, "Connected to remote %s" % r1.name),
                (r1, 70, "Connected to remote %s" % s1.name),
                (r2, 70, "Connected to remote %s" % s1.name),
                (s2, 70, "Connected to remote %s" % r1.name))
        trigger((s1, 70, "Connected to remote %s" % r2.name),
                (r1, 70, "Connected to remote %s" % s2.name),
                (s2, 70, "Connected to remote %s" % r2.name),
                (r2, 70, "Connected to remote %s" % s2.name))

        filea = rfiles[0]
        fileb = rfiles[1]
        s1.send_files([filea])
        s2.send_files([fileb])
        params = {"filea": re.escape(os.path.basename(filea[0])),
                  "fileb": re.escape(os.path.basename(fileb[0])),
                  "rnamec": r1.name, "rnamed": r2.name}

        trigger((s1, 40,
                 "Succeeded sending .*/%(filea)s to %(rnamec)s" % params),
                (s2, 40,
                 "Succeeded sending .*/%(fileb)s to %(rnamec)s" % params))
        trigger((s1, 40,
                 "Succeeded sending .*/%(filea)s to %(rnamed)s" % params),
                (s2, 40,
                 "Succeeded sending .*/%(fileb)s to %(rnamed)s" % params))
        for f in [filea, fileb]:
            for r in [r1, r2]:
                (error, path) = r.check_sent(f)
                if error:
                    global_log(False, ("Error receiving %s: %s" %
                                       (os.path.basename(f[0]), error)))
                    raise FileTransferError()
        sy.stop()
        trigger((s1, 25, "Stopped logging"),
                (r1, 25, "Stopped logging"),
                (s2, 25, "Stopped logging"),
                (r2, 25, "Stopped logging"))
    except:
        traceback.print_exc()
        sy.stop()
        raise
    finally:
        sy.end(noremove=NO_REMOVE)
Esempio n. 4
0
def _testMultiple(tls=False):
    global rfiles
    if tls and not tls_supported():
        return None
    reset_all_certs_and_keys()
    s1 = Rwsender()
    s2 = Rwsender()
    r1 = Rwreceiver()
    r2 = Rwreceiver()
    sy = System()
    try:
        sy.connect([r1, r2], [s1, s2], tls=tls)
        sy.start()
        if tls:
            check_dh(s1, r1, s2, r2)

        trigger((s1, 70, "Connected to remote %s" % r1.name),
                (r1, 70, "Connected to remote %s" % s1.name),
                (r2, 70, "Connected to remote %s" % s1.name),
                (s2, 70, "Connected to remote %s" % r1.name))
        trigger((s1, 70, "Connected to remote %s" % r2.name),
                (r1, 70, "Connected to remote %s" % s2.name),
                (s2, 70, "Connected to remote %s" % r2.name),
                (r2, 70, "Connected to remote %s" % s2.name))

        filea = rfiles[0]
        fileb = rfiles[1]
        s1.send_files([filea])
        s2.send_files([fileb])
        params = {"filea": re.escape(os.path.basename(filea[0])),
                  "fileb": re.escape(os.path.basename(fileb[0])),
                  "rnamec": r1.name, "rnamed": r2.name}

        trigger((s1, 40,
                 "Succeeded sending .*/%(filea)s to %(rnamec)s" % params),
                (s2, 40,
                 "Succeeded sending .*/%(fileb)s to %(rnamec)s" % params))
        trigger((s1, 40,
                 "Succeeded sending .*/%(filea)s to %(rnamed)s" % params),
                (s2, 40,
                 "Succeeded sending .*/%(fileb)s to %(rnamed)s" % params))
        for f in [filea, fileb]:
            for r in [r1, r2]:
                (error, path) = r.check_sent(f)
                if error:
                    global_log(False, ("Error receiving %s: %s" %
                                       (os.path.basename(f[0]), error)))
                    raise FileTransferError()
        sy.stop()
        trigger((s1, 25, "Stopped logging"),
                (r1, 25, "Stopped logging"),
                (s2, 25, "Stopped logging"),
                (r2, 25, "Stopped logging"))
    except:
        traceback.print_exc()
        sy.stop()
        raise
    finally:
        sy.end(noremove=NO_REMOVE)
Esempio n. 5
0
def _testSendRcv(tls=False,
                 sender_client=True,
                 stop_sender=False,
                 kill=False):
    if tls and not tls_supported():
        return None
    global rfiles
    reset_all_certs_and_keys()
    s1 = Rwsender()
    r1 = Rwreceiver()
    if stop_sender:
        if kill:
            stop = s1.kill
        else:
            stop = s1.stop
        end = s1.end
        start = s1.start
        stopped = s1
    else:
        if kill:
            stop = r1.kill
        else:
            stop = r1.stop
        end = r1.end
        start = r1.start

        stopped = r1
    s1.create_dirs()
    s1.send_files(rfiles)
    sy = System()
    try:
        if sender_client:
            sy.connect(s1, r1, tls=tls)
        else:
            sy.connect(r1, s1, tls=tls)
        sy.start()
        if tls:
            check_dh(s1, r1)

        trigger((s1, 75, "Connected to remote %s" % r1.name),
                (r1, 75, "Connected to remote %s" % s1.name))
        trigger((s1, 40, "Succeeded sending .* to %s" % r1.name))
        stop()
        if not kill:
            trigger((stopped, 25, "Stopped logging"))
        end()
        start()
        if tls:
            check_dh(stopped)
        trigger((s1, 75, "Connected to remote %s" % r1.name),
                (r1, 75, "Connected to remote %s" % s1.name))
        try:
            for path, data in rfiles:
                base = os.path.basename(path)
                data = {"name": re.escape(base),
                        "rname": r1.name, "sname": s1.name}
                trigger((s1, 40,
                         ("Succeeded sending .*/%(name)s to %(rname)s|"
                          "Remote side %(rname)s rejected .*/%(name)s")
                         % data),
                        (r1, 40,
                         "Finished receiving from %(sname)s: %(name)s" % data),
                        pid=False, first=True)
        except TriggerError:
            pass
        for f in rfiles:
            (error, path) = r1.check_sent(f)
            if error:
                global_log(False, ("Error receiving %s: %s" %
                                   (os.path.basename(f[0]), error)))
                raise FileTransferError()
        sy.stop()
        trigger((s1, 25, "Stopped logging"),
                (r1, 25, "Stopped logging"))
    except KeyboardInterrupt:
        global_log(False, "%s: Interrupted by C-c", os.getpid())
        traceback.print_exc()
        sy.stop()
        raise
    except:
        traceback.print_exc()
        sy.stop()
        raise
    finally:
        sy.end(noremove=NO_REMOVE)
Esempio n. 6
0
def _testFilter(tls=False):
    global rfiles
    if tls and not tls_supported():
        return None
    reset_all_certs_and_keys()
    r1 = Rwreceiver()
    r2 = Rwreceiver()
    s1 = Rwsender(filters=[(r1.name, "[a-g]$"), (r2.name, "[d-j]$")])
    sy = System()
    try:
        sy.connect([r1, r2], s1, tls=tls)
        sy.start()
        if tls:
            check_dh(s1, r1, r2)
        trigger((s1, 70, "Connected to remote %s" % r1.name),
                (r1, 70, "Connected to remote %s" % s1.name),
                (r2, 70, "Connected to remote %s" % s1.name))
        trigger((s1, 70, "Connected to remote %s" % r2.name))

        s1.send_files(rfiles)
        cfiles = [x for x in rfiles if 'a' <= x[0][-1] <= 'g']
        dfiles = [x for x in rfiles if 'd' <= x[0][-1] <= 'j']
        for (f, data) in cfiles:
            trigger((s1, 25,
                     "Succeeded sending .*/%(file)s to %(name)s"
                     % {"file": re.escape(os.path.basename(f)),
                        "name" : r1.name}))
        for (f, data) in dfiles:
            trigger((s1, 25,
                     "Succeeded sending .*/%(file)s to %(name)s"
                     % {"file": re.escape(os.path.basename(f)),
                        "name" : r2.name}))
        for f in cfiles:
            (error, path) = r1.check_sent(f)
            if error:
                global_log(False, ("Error receiving %s: %s" %
                                   (os.path.basename(f[0]), error)))
                raise FileTransferError()
        for f in dfiles:
            (error, path) = r2.check_sent(f)
            if error:
                global_log(False, ("Error receiving %s: %s" %
                                   (os.path.basename(f[0]), error)))
        cset = set(cfiles)
        dset = set(dfiles)
        for f in cset - dset:
            (error, path) = r2.check_sent(f)
            if not error:
                global_log(False, ("Unexpectedly received file %s" %
                                   os.path.basename(f[0])))
                raise FileTransferError()
        for f in dset - cset:
            (error, path) = r1.check_sent(f)
            if not error:
                global_log(False, ("Unexpectedly received file %s" %
                                   os.path.basename(f[0])))
                raise FileTransferError()
        sy.stop()
        trigger((s1, 25, "Stopped logging"),
                (r1, 25, "Stopped logging"),
                (r2, 25, "Stopped logging"))
    except:
        traceback.print_exc()
        sy.stop()
        raise
    finally:
        sy.end(noremove=NO_REMOVE)
Esempio n. 7
0
def _testSendRcv(tls=False,
                 sender_client=True,
                 stop_sender=False,
                 kill=False):
    if tls and not tls_supported():
        return None
    global rfiles
    reset_all_certs_and_keys()
    s1 = Rwsender()
    r1 = Rwreceiver()
    if stop_sender:
        if kill:
            stop = s1.kill
        else:
            stop = s1.stop
        end = s1.end
        start = s1.start
        stopped = s1
    else:
        if kill:
            stop = r1.kill
        else:
            stop = r1.stop
        end = r1.end
        start = r1.start

        stopped = r1
    s1.create_dirs()
    s1.send_files(rfiles)
    sy = System()
    try:
        if sender_client:
            sy.connect(s1, r1, tls=tls)
        else:
            sy.connect(r1, s1, tls=tls)
        sy.start()
        if tls:
            check_dh(s1, r1)

        trigger((s1, 75, "Connected to remote %s" % r1.name),
                (r1, 75, "Connected to remote %s" % s1.name))
        trigger((s1, 40, "Succeeded sending .* to %s" % r1.name))
        stop()
        if not kill:
            trigger((stopped, 25, "Stopped logging"))
        end()
        start()
        if tls:
            check_dh(stopped)
        trigger((s1, 75, "Connected to remote %s" % r1.name),
                (r1, 75, "Connected to remote %s" % s1.name))
        try:
            for path, data in rfiles:
                base = os.path.basename(path)
                data = {"name": re.escape(base),
                        "rname": r1.name, "sname": s1.name}
                trigger((s1, 40,
                         ("Succeeded sending .*/%(name)s to %(rname)s|"
                          "Remote side %(rname)s rejected .*/%(name)s")
                         % data),
                        (r1, 40,
                         "Finished receiving from %(sname)s: %(name)s" % data),
                        pid=False, first=True)
        except TriggerError:
            pass
        for f in rfiles:
            (error, path) = r1.check_sent(f)
            if error:
                global_log(False, ("Error receiving %s: %s" %
                                   (os.path.basename(f[0]), error)))
                raise FileTransferError()
        sy.stop()
        trigger((s1, 25, "Stopped logging"),
                (r1, 25, "Stopped logging"))
    except KeyboardInterrupt:
        global_log(False, "%s: Interrupted by C-c", os.getpid())
        traceback.print_exc()
        sy.stop()
        raise
    except:
        traceback.print_exc()
        sy.stop()
        raise
    finally:
        sy.end(noremove=NO_REMOVE)
Esempio n. 8
0
def _testFilter(tls=False):
    global rfiles
    if tls and not tls_supported():
        return None
    reset_all_certs_and_keys()
    r1 = Rwreceiver()
    r2 = Rwreceiver()
    s1 = Rwsender(filters=[(r1.name, "[a-g]$"), (r2.name, "[d-j]$")])
    sy = System()
    try:
        sy.connect([r1, r2], s1, tls=tls)
        sy.start()
        if tls:
            check_dh(s1, r1, r2)
        trigger((s1, 70, "Connected to remote %s" % r1.name),
                (r1, 70, "Connected to remote %s" % s1.name),
                (r2, 70, "Connected to remote %s" % s1.name))
        trigger((s1, 70, "Connected to remote %s" % r2.name))

        s1.send_files(rfiles)
        cfiles = [x for x in rfiles if 'a' <= x[0][-1] <= 'g']
        dfiles = [x for x in rfiles if 'd' <= x[0][-1] <= 'j']
        for (f, data) in cfiles:
            trigger((s1, 25,
                     "Succeeded sending .*/%(file)s to %(name)s"
                     % {"file": re.escape(os.path.basename(f)),
                        "name" : r1.name}))
        for (f, data) in dfiles:
            trigger((s1, 25,
                     "Succeeded sending .*/%(file)s to %(name)s"
                     % {"file": re.escape(os.path.basename(f)),
                        "name" : r2.name}))
        for f in cfiles:
            (error, path) = r1.check_sent(f)
            if error:
                global_log(False, ("Error receiving %s: %s" %
                                   (os.path.basename(f[0]), error)))
                raise FileTransferError()
        for f in dfiles:
            (error, path) = r2.check_sent(f)
            if error:
                global_log(False, ("Error receiving %s: %s" %
                                   (os.path.basename(f[0]), error)))
        cset = set(cfiles)
        dset = set(dfiles)
        for f in cset - dset:
            (error, path) = r2.check_sent(f)
            if not error:
                global_log(False, ("Unexpectedly received file %s" %
                                   os.path.basename(f[0])))
                raise FileTransferError()
        for f in dset - cset:
            (error, path) = r1.check_sent(f)
            if not error:
                global_log(False, ("Unexpectedly received file %s" %
                                   os.path.basename(f[0])))
                raise FileTransferError()
        sy.stop()
        trigger((s1, 25, "Stopped logging"),
                (r1, 25, "Stopped logging"),
                (r2, 25, "Stopped logging"))
    except:
        traceback.print_exc()
        sy.stop()
        raise
    finally:
        sy.end(noremove=NO_REMOVE)