Beispiel #1
0
def test_connection_timeout(session):
    # Create, bind, and listen on a socket, but never accept
    def target(s):
        s.listen(0)

    with socketServer(target) as port:
        with pytest.raises(requests.exceptions.ConnectTimeout):
            session.get("ftp://127.0.0.1:%d/" % port, timeout=1)
Beispiel #2
0
def test_connection_timeout(session):
    # Create, bind, and listen on a socket, but never accept
    def target(s, goevent):
        s.listen(1)
        goevent.set()

    with socketServer(target) as port:
        with pytest.raises(requests.exceptions.ConnectTimeout):
            session.get('ftp://127.0.0.1:%d/' % port, timeout=1)
Beispiel #3
0
def test_connection_refused(session):
    # Create and bind a socket but do not listen to ensure we have a port
    # that will refuse connections
    def target(s):
        pass

    with socketServer(target) as port:
        with pytest.raises(requests.exceptions.ConnectionError):
            session.get("ftp://127.0.0.1:%d/" % port)
Beispiel #4
0
def test_connection_refused(session):
    # Create and bind a socket but do not listen to ensure we have a port
    # that will refuse connections
    def target(s, goevent):
        goevent.set()

    with socketServer(target) as port:
        with pytest.raises(requests.exceptions.ConnectionError):
            session.get('ftp://127.0.0.1:%d/' % port)
def test_proxy_connection_refused(ftpd, session):
    # Create and bind a socket but do not listen to ensure we have a port
    # that will refuse connections
    def target(s, goevent):
        goevent.set()

    with socketServer(target) as port:
        with pytest.raises(requests.exceptions.ConnectionError):
            session.get('ftp://127.0.0.1:%d/' % ftpd.ftp_port,
                    proxies={'ftp': 'localhost:%d' % port})
Beispiel #6
0
def test_proxy_connection_refused(ftpd, session):
    # Create and bind a socket but do not listen to ensure we have a port
    # that will refuse connections
    def target(s, goevent):
        goevent.set()

    with socketServer(target) as port:
        with pytest.raises(requests.exceptions.ConnectionError):
            session.get('ftp://127.0.0.1:%d/' % ftpd.ftp_port,
                        proxies={'ftp': 'localhost:%d' % port})
Beispiel #7
0
def test_proxy_connection_close(ftpd, session):
    # Create and accept a socket, then close it
    def target(s):
        s.listen(0)
        (clientsock, _addr) = s.accept()
        clientsock.close()

    with socketServer(target) as port:
        with pytest.raises(requests.exceptions.ConnectionError):
            session.get('ftp://127.0.0.1:%d/' % ftpd.ftp_port,
                    proxies={'ftp': 'localhost:%d' % port}, timeout=1)
Beispiel #8
0
def test_unavailable(session):
    def target(s):
        s.listen(0)
        (clientsock, _addr) = s.accept()
        try:
            clientsock.send(b"421 go away\r\n")
        finally:
            clientsock.close()

    with socketServer(target) as port:
        response = session.get("ftp://127.0.0.1:%d/" % port)
        assert response.status_code == requests.codes.unavailable
Beispiel #9
0
def test_invalid_response(session):
    # Send an invalid welcome
    def target(s):
        s.listen(0)
        (clientsock, _addr) = s.accept()
        try:
            clientsock.send(b"no code\r\n")
        finally:
            clientsock.close()

    with socketServer(target) as port:
        with pytest.raises(requests.exceptions.RequestException):
            session.get("ftp://127.0.0.1:%d/" % port)
Beispiel #10
0
def test_connection_close(session):
    # Create and accept a socket, then close it after the welcome
    def target(s):
        s.listen(0)
        (clientsock, _addr) = s.accept()
        try:
            clientsock.send(b"220 welcome\r\n")
        finally:
            clientsock.close()

    with socketServer(target) as port:
        with pytest.raises(requests.exceptions.ConnectionError):
            session.get("ftp://127.0.0.1:%d/" % port)
Beispiel #11
0
def test_unavailable(session):
    def target(s, goevent):
        s.listen(1)
        goevent.set()
        (clientsock, _addr) = s.accept()
        try:
            clientsock.send(b'421 go away\r\n')
        finally:
            clientsock.close()

    with socketServer(target) as port:
        response = session.get('ftp://127.0.0.1:%d/' % port)
        assert response.status_code == requests.codes.unavailable
Beispiel #12
0
def test_proxy_connection_close(ftpd, session):
    # Create and accept a socket, then close it
    def target(s, goevent):
        s.listen(1)
        goevent.set()
        (clientsock, _addr) = s.accept()
        clientsock.close()

    with socketServer(target) as port:
        with pytest.raises(requests.exceptions.ConnectionError):
            session.get('ftp://127.0.0.1:%d/' % ftpd.ftp_port,
                        proxies={'ftp': 'localhost:%d' % port},
                        timeout=1)
Beispiel #13
0
def test_invalid_response(session):
    # Send an invalid welcome
    def target(s, goevent):
        s.listen(1)
        goevent.set()
        (clientsock, _addr) = s.accept()
        try:
            clientsock.send(b'no code\r\n')
        finally:
            clientsock.close()

    with socketServer(target) as port:
        with pytest.raises(requests.exceptions.RequestException):
            session.get('ftp://127.0.0.1:%d/' % port)
Beispiel #14
0
def test_connection_close(session):
    # Create and accept a socket, then close it after the welcome
    def target(s, goevent):
        s.listen(1)
        goevent.set()
        (clientsock, _addr) = s.accept()
        try:
            clientsock.send(b'220 welcome\r\n')
        finally:
            clientsock.close()

    with socketServer(target) as port:
        with pytest.raises(requests.exceptions.ConnectionError):
            session.get('ftp://127.0.0.1:%d/' % port)
Beispiel #15
0
def test_invalid_code(session):
    # Send a welcome, then reply with something weird to the USER command
    def target(s):
        s.listen(0)
        (clientsock, _addr) = s.accept()
        try:
            clientsock.send(b"220 welcome\r\n")
            clientsock.recv(1024)
            clientsock.send(b"125 this makes no sense\r\n")
        finally:
            clientsock.close()

    with socketServer(target) as port:
        with pytest.raises(requests.exceptions.RequestException):
            session.get("ftp://127.0.0.1:%d/" % port)
Beispiel #16
0
def test_proxy_read_timeout(ftpd, session):
    # Create and accept a socket, but never respond
    def target(s, event):
        s.listen(0)
        (clientsock, _addr) = s.accept()
        try:
            event.wait(5)
        finally:
            clientsock.close()

    event = threading.Event()
    with socketServer(target, event) as port:
        with pytest.raises(requests.exceptions.ReadTimeout):
            session.get('ftp://127.0.0.1:%d' % ftpd.ftp_port,
                    proxies={'ftp': 'localhost:%d' % port}, timeout=1)
Beispiel #17
0
def test_invalid_code(session):
    # Send a welcome, then reply with something weird to the USER command
    def target(s, goevent):
        s.listen(1)
        goevent.set()
        (clientsock, _addr) = s.accept()
        try:
            clientsock.send(b'220 welcome\r\n')
            clientsock.recv(1024)
            clientsock.send(b'125 this makes no sense\r\n')
        finally:
            clientsock.close()

    with socketServer(target) as port:
        with pytest.raises(requests.exceptions.RequestException):
            session.get('ftp://127.0.0.1:%d/' % port)
Beispiel #18
0
def test_login_timeout(session):
    # Create and accept a socket, but stop responding after sending
    # the welcome
    def target(s, event):
        s.listen(0)
        (clientsock, _addr) = s.accept()
        try:
            clientsock.send(b"220 welcome\r\n")
            # Wait for the exception to be raised in the client
            event.wait(5)
        finally:
            clientsock.close()

    event = threading.Event()
    with socketServer(target, event) as port:
        with pytest.raises(requests.exceptions.ReadTimeout):
            session.get("ftp://127.0.0.1:%d/" % port, timeout=1)
Beispiel #19
0
def test_proxy_read_timeout(ftpd, session):
    # Create and accept a socket, but never respond
    def target(s, goevent, event):
        s.listen(1)
        goevent.set()
        (clientsock, _addr) = s.accept()
        try:
            event.wait(5)
        finally:
            clientsock.close()

    event = threading.Event()
    with socketServer(target, event) as port:
        with pytest.raises(requests.exceptions.ReadTimeout):
            session.get('ftp://127.0.0.1:%d' % ftpd.ftp_port,
                        proxies={'ftp': 'localhost:%d' % port},
                        timeout=1)
Beispiel #20
0
def test_login_timeout(session):
    # Create and accept a socket, but stop responding after sending
    # the welcome
    def target(s, goevent, event):
        s.listen(1)
        goevent.set()
        (clientsock, _addr) = s.accept()
        try:
            clientsock.send(b'220 welcome\r\n')
            # Wait for the exception to be raised in the client
            event.wait(5)
        finally:
            clientsock.close()

    event = threading.Event()
    with socketServer(target, event) as port:
        with pytest.raises(requests.exceptions.ReadTimeout):
            session.get('ftp://127.0.0.1:%d/' % port, timeout=1)