Example #1
0
 async def handler(client, request):
     if request.path == "/1.0.0/application/token":
         assert request.encode().decode() == ACCESS_REQUEST
         response = http.HTTPResponse(200)
         response.json = {"accessToken": "access.token"}
         return response
     else:
         assert request.encode().decode() == LOGIN_REQUEST
         response = http.HTTPResponse(200)
         response.json = {"idToken": "id token"}
         return response
 async def handler(client, request):
     if request.path == "/v6/challenge":
         assert request.encode().decode() == CHALLENGE_REQUEST_1200
         response = http.HTTPResponse(200)
         response.json = {
             "challenge": "vaNgVZZH7gUse0y3t8Cksuln-TAVtvBmcD-ow59qp0E=",
             "data": "dlL7ZBNSLmYo1hUlKYZiUA=="
         }
         return response
     else:
         assert request.encode().decode() == TOKEN_REQUEST_1200
         response = http.HTTPResponse(200)
         response.json = {"device_auth_token": "device token"}
         return response
 async def handler(client, request):
     if request.path == "/v7/challenge":
         assert request.encode().decode() == CHALLENGE_REQUEST_1300
         response = http.HTTPResponse(200)
         response.json = {
             "challenge": "TzJ0EB3EvsWvQI5aPj15uaNVH9paGdsWB4l-eI5uzW0=",
             "data": "4SxW91vqVg6pz4CXMH2Ouw=="
         }
         return response
     else:
         assert request.encode().decode() == TOKEN_REQUEST_1300
         response = http.HTTPResponse(200)
         response.json = {"device_auth_token": "device token"}
         return response
Example #4
0
 async def handler(client, request):
     text = request.encode().decode()
     assert text.startswith(EXPECTED_REQUEST)
     assert text[1378:1388] == "&cert_key="
     response = http.HTTPResponse(200)
     response.json = {"application_auth_token": "application token"}
     return response
Example #5
0
 async def handler(client, request):
     assert request.xml.name == "value"
     tree = xml.XMLTree("result")
     tree.text = request.xml.text
     response = http.HTTPResponse(200)
     response.xml = tree
     return response
Example #6
0
def accept_handshake(request, protocol):
    status = check_handshake(request, protocol)
    if status != 101:
        logger.info("WS handshake error: %i" % status)
        return http.HTTPResponse(status)

    accept = calculate_key_hash(request.headers["Sec-WebSocket-Key"])

    response = http.HTTPResponse(101)
    response.headers["Connection"] = "upgrade"
    response.headers["Upgrade"] = "WebSocket"
    response.headers["Sec-WebSocket-Accept"] = accept
    if protocol is not None:
        response.headers["Sec-WebSocket-Protocol"] = protocol

    logger.debug("WS handshake succeeded")
    return response
Example #7
0
    async def handle(self, client, request):
        rows = []
        for session in self.matchmaker.sessions.values():
            info = session.session
            rows.append(ROW_TEMPLATE %
                        (info.id, info.game_mode, info.num_participants,
                         info.started_time))

        response = http.HTTPResponse(200)
        response.headers["Content-Type"] = "text/html"
        response.text = TEMPLATE % (common.DateTime.now(), self.start_time,
                                    len(self.clients.clients), "\n".join(rows))
        return response
Example #8
0
 def test_init(self):
     response = http.HTTPResponse(404)
     assert response.status_code == 404
     assert response.status_name == "Not Found"
Example #9
0
    def test_success(self):
        response = http.HTTPResponse(500)
        assert not response.success()

        response = http.HTTPResponse(200)
        assert response.success()
Example #10
0
 async def handler(client, request):
     cert = client.remote_certificate()
     assert cert.subject["CN"] == "testclient"
     return http.HTTPResponse(200)
Example #11
0
    def test_error(self):
        response = http.HTTPResponse(404)
        assert response.error()

        response = http.HTTPResponse(201)
        assert not response.error()
Example #12
0
 async def handler(client, request):
     response = http.HTTPResponse(200)
     response.json = {"result": request.json["value"]}
     return response
Example #13
0
 async def handler(client, request):
     response = http.HTTPResponse(200)
     response.rawform = {"$<result>": request.rawform["value+!"]}
     return response
Example #14
0
 async def handler(client, request):
     assert request.method == "GET"
     assert request.path == "/test/ok"
     response = http.HTTPResponse(200)
     return response
Example #15
0
 async def handler(client, request):
     response = http.HTTPResponse(200)
     response.body = request.body
     return response
Example #16
0
 async def handler(client, request):
     assert request.path == "/path"
     response = http.HTTPResponse(200)
     response.body = request.body
     return response
Example #17
0
 async def handler(client, request):
     response = http.HTTPResponse(200)
     response.plainform["$<result>"] = request.plainform["value+!"]
     return response
Example #18
0
 async def handler(client, request):
     assert request.body == b"Hello"
     response = http.HTTPResponse(200)
     response.text = request.text.upper()
     return response
Example #19
0
 async def handler(client, request):
     assert request.body == b"abcdef"
     response = http.HTTPResponse(200)
     response.body = request.body[::-1]
     return response
Example #20
0
 async def handler(client, request):
     status = int(request.headers["X-Status-Code"])
     return http.HTTPResponse(status)
Example #21
0
 async def handler(client, request):
     assert request.headers["X-Header-1"] == "test1"
     assert request.headers["X-Header-2"] == "test2"
     return http.HTTPResponse(200)
Example #22
0
 async def handler(client, request):
     response = http.HTTPResponse(200)
     response.files = {"response": request.files["filename"]}
     return response
Example #23
0
 async def handler(client, request):
     response = http.HTTPResponse(200)
     response.text = request.method
     return response
Example #24
0
 def test_raise_if_error(self):
     response = http.HTTPResponse()
     with pytest.raises(http.HTTPResponseError):
         response.raise_if_error()