Ejemplo n.º 1
0
 def test_echo_roundtrip(self):
     session, handshake_response = protocol.handshake()
     def comet_request(event):
         try:
             event.send(session.comet())
         except Exception, e:
             event.send_exception(e)
Ejemplo n.º 2
0
 def test_duration_timeout(self):
     session, handshake_response = protocol.handshake()
     response = http.make_request(config.base_url + "/comet?du=1&s=" + session.key, timeout=1.2)
     packets = json.loads(response.body[1:-1])
     if packets != []:
         raise CSPException("Invalid comet response: expected empty batch", response)
     print response.formatted_transcript()
Ejemplo n.º 3
0
    def test_reflect_get(self):
        session, handshake_response = protocol.handshake()
        payload = "<script>alert('woot')</script>"
        url = self.base_url +  "/reflect?s=" + session.key + "&d=" + payload
        response = http.make_request(url, reset_transcript=False, socket=handshake_response.socket)
#        response.prepend_transcript(handshake_response.socket.transcript)
        if response.code != 200:
            raise CSPException("Reflect (GET) should return status code 200",
                               response)
        if payload != response.body:
            raise CSPException("Reflect (GET) returned invalid response body.",
                               response)
        print response.formatted_transcript()
Ejemplo n.º 4
0
 def test_reflect_post(self):
     session, handshake_response = protocol.handshake()
     payload = "<script>alert('woot')</script>"
     url = self.base_url +  "/reflect?s=" + session.key
     body = payload
     response = http.make_request(url, method='POST', body=body, 
                 reset_transcript=False, socket=handshake_response.socket)
     if response.code != 200:
         raise CSPException("Reflect (POST) should return status code 200",
                            response)
     if payload != response.body:
         raise CSPException("Reflect (POST) returned invalid response body.",
                            response)
Ejemplo n.º 5
0
    def test_streaming(self):
        def comet_stream(session, handshake_response):
            event = coros.Channel()
            api.spawn(
                http._make_request,
                event,
                config.base_url + "/comet?is=1&bs=;;;&du=5&s=" + session.key,
                incremental_event=event,
                socket=handshake_response.socket,
                reset_transcript=False,
            )
            buffer = ""
            while True:
                data = event.wait()
                if isinstance(data, http.HTTPResponse):
                    break
                if not data:
                    break
                buffer += data
                while ";;;" in buffer:
                    line, buffer = buffer.split(";;;", 1)
                    packets = json.loads(line[1:-1])
                    for packet in packets:
                        # XXX: use the proper decode function (urldecode, maybe)
                        yield packet[2]

        session, handshake_response = protocol.handshake()
        session.send("foo")
        comet = comet_stream(session, handshake_response)
        if comet.next() != "foo":
            raise CSPException('Invalid comet stream batch: expected "foo"', response)
        response1 = session.send("bar")
        response2 = session.send("baz")
        handshake_response.append_transcript(response2.socket.transcript)
        timer = api.exc_after(3, CSPException("Did not receive a timely comet packet", handshake_response))
        output1 = comet.next()
        output2 = comet.next()
        timer.cancel()
        if output1 != "bar" or output2 != "baz":
            raise CSPException('Invalid comet stream batch: expected "bar" then "baz"', response)