def testNonExistingMethodSignedRequestCall(self): playerId = "test" createPlayer(playerId, "test") session = createPlayerSession(playerId, 'signedRequest') signedRequest = createSignedRequest(playerId, session.secret, 'nonExisitingMehtod') response = signedRequestCall(signedRequest) self.assertTrue('error' in response and response['error']['code'] == UNKNOW_SERVICE_CALL_ERROR['code'])
def testWrongSessionSignedRequestForPlayer(self): playerId = "test" createPlayer(playerId, "test") createPlayerSession(playerId, 'signedRequest') signedRequest = createSignedRequest(playerId, "wrong secret", 'score.service.echo', 'hello') response = signedRequestCall(signedRequest) self.assertTrue('error' in response and response['error']['code'] == INVALID_SIGNATURE_ERROR['code'])
def testWrongSessionMethod(self): playerId = "test" createPlayer(playerId, "test") createPlayerSession(playerId, 'token') signedRequest = createSignedRequest(playerId, "wrong secret", 'score.service.echo', 'hello') response = signedRequestCall(signedRequest) self.assertTrue('error' in response and response['error']['code'] == SIGNED_REQUEST_METHOD_ERROR['code'])
def testExpiredSessionSignedRequestCall(self): playerId = "test" createPlayer(playerId, "test") session = createPlayerSession(playerId, 'signedRequest', datetime=datetime.datetime.now() - DEFAULT_MAX_SESSION_LIFE_TIME) signedRequest = createSignedRequest(playerId, session.secret, 'score.service.echo', 'hello') response = signedRequestCall(signedRequest) self.assertTrue('error' in response and response['error']['code'] == SESSION_EXPIRED_ERROR['code'])
def testNonExistingMethodSignedRequestCall(self): playerId = "test" createPlayer(playerId, "test") session = createPlayerSession(playerId, 'signedRequest') signedRequest = createSignedRequest(playerId, session.secret, 'nonExisitingMehtod') response = signedRequestCall(signedRequest) self.assertTrue( 'error' in response and response['error']['code'] == UNKNOW_SERVICE_CALL_ERROR['code'])
def testWrongSessionSignedRequestForPlayer(self): playerId = "test" createPlayer(playerId, "test") createPlayerSession(playerId, 'signedRequest') signedRequest = createSignedRequest(playerId, "wrong secret", 'score.service.echo', 'hello') response = signedRequestCall(signedRequest) self.assertTrue( 'error' in response and response['error']['code'] == INVALID_SIGNATURE_ERROR['code'])
def testCorrectSessionSignedRequestCall(self): playerId = "test" createPlayer(playerId, "test") session = createPlayerSession(playerId, 'signedRequest') message = 'hello' signedRequest = createSignedRequest(playerId, session.secret, 'score.service.echo', message) answer = signedRequestCall(signedRequest) self.assertEqual(answer['result'], str(playerId) + ':' + message)
def testExpiredSessionSignedRequestCall(self): playerId = "test" createPlayer(playerId, "test") session = createPlayerSession(playerId, 'signedRequest', datetime=datetime.datetime.now() - DEFAULT_MAX_SESSION_LIFE_TIME) signedRequest = createSignedRequest(playerId, session.secret, 'score.service.echo', 'hello') response = signedRequestCall(signedRequest) self.assertTrue( 'error' in response and response['error']['code'] == SESSION_EXPIRED_ERROR['code'])
class JsonRequestHandler(webapp.RequestHandler): # only post for now def post(self): try: #self.request. data = json.loads(self.request.body) except Exception, e: output = json.dumps({'id' : 'unknown', 'error' : {'code' : 35, 'message' : 'cannot parse the request' + e}}) self.response.out.write(output) return; requestId = data['id'] methodName = data['method'] params = data['params'] if methodName == "signedRequestCall": result = signedRequestCall(params[0]) result['id'] = requestId output =json.dumps(result) else: output = json.dumps({'id' : requestId, 'error' : {'code' : 34, 'message' : 'method not supported'}}) self.response.out.write(output)
def amfSignedRequestCall(requestId, signedRequest): result = signedRequestCall(signedRequest) result['id'] = requestId return result
def amfSignedRequestCall(requestId, signedRequest): result = signedRequestCall(signedRequest) result['id'] = requestId; return result