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 testCreateSessionAndTestIfItExpireAfterMoreThan30Minutes(self): playerId = "randomId" createPlayerSession(playerId, 'signedRequest', datetime=datetime.datetime.now() - DEFAULT_MAX_SESSION_LIFE_TIME) session = getPlayerSession(playerId) self.assertTrue(session.isExpired())
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 testWrongSessionTokenForPlayer(self): playerId = "test" createPlayer(playerId, "test") createPlayerSession(playerId, 'token') response = sessionTokenCall("wrong token", playerId, 'score.service.echo', 'hello') self.assertTrue('error' in response and response['error']['code'] == INVALID_SESSION_TOKEN_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 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 testCreateSessionAndTestIfItExpireAfterMoreThan30Minutes(self): playerId = "randomId" createPlayerSession(playerId, 'signedRequest', datetime=datetime.datetime.now() - DEFAULT_MAX_SESSION_LIFE_TIME) session = getPlayerSession(playerId) self.assertTrue(session.isExpired())
def testCorrectSessionTokenCall(self): playerId = "test" createPlayer(playerId, "test") session = createPlayerSession(playerId, 'token') message = 'hello' answer = sessionTokenCall(session.token, playerId, 'score.service.echo', message) self.assertEqual(answer['result'], str(playerId) + ':' + message)
def testExpiredSessionTokenCall(self): playerId = "test" createPlayer(playerId, "test") session = createPlayerSession(playerId, 'token', datetime=datetime.datetime.now() - DEFAULT_MAX_SESSION_LIFE_TIME) response = sessionTokenCall(session.token, playerId, 'score.service.echo', 'hello') 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 post(self): userId = self.request.get('userId') if config.passwordUserAllowed is None or userId not in config.testMasters: self.error(403) return password = self.request.get('password') method = self.request.get('method') testUserId = self.request.get('testUserId') passwordUser = PasswordUser.get_by_key_name(userId) if passwordUser is not None: if passwordUser.password != password: self.error(403) return playerId = passwordUser.playerId else: player = createPlayer('passwordUser' + userId, "nickName" + userId) playerId = player.key().id_or_name() passwordUser = PasswordUser(key_name=userId, playerId=playerId, password=password) passwordUser.put() testUser = TestUser.get_by_key_name(testUserId) if testUser is not None: testPlayerId = testUser.playerId else: testPlayer = createPlayer('testUser' + testUserId, "nickName" + testUserId) testPlayerId = testPlayer.key().id_or_name() testUser = TestUser(key_name=testUserId, playerId=testPlayerId) testUser.put() if method is None: if self.request.scheme == 'https': method = 'signedRequest' else: method = 'token' session = createPlayerSession(testPlayerId, method) if method == 'token': data = { u'method': 'token', u'sessionToken': session.token, u'playerId': testPlayerId } elif method == 'signedRequest': data = { u'method': 'signedRequest', u'secret': session.secret, u'playerId': testPlayerId } data = json.dumps(data) self.response.out.write(data)
def testCorrectSessionTokenCall(self): playerId = "test" createPlayer(playerId, "test") session = createPlayerSession(playerId, 'token') message = 'hello' answer = sessionTokenCall(session.token, playerId, 'score.service.echo', message) 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'])
def testNonExistingMethodTokenCall(self): playerId = "test" createPlayer(playerId, "test") session = createPlayerSession(playerId, 'token') response = sessionTokenCall(session.token, playerId, 'nonExisitingMehtod') self.assertTrue( 'error' in response and response['error']['code'] == UNKNOW_SERVICE_CALL_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 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 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 testExpiredSessionTokenCall(self): playerId = "test" createPlayer(playerId, "test") session = createPlayerSession(playerId, 'token', datetime=datetime.datetime.now() - DEFAULT_MAX_SESSION_LIFE_TIME) response = sessionTokenCall(session.token, playerId, 'score.service.echo', 'hello') self.assertTrue( 'error' in response and response['error']['code'] == SESSION_EXPIRED_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 get(self): user = users.get_current_user() if user is None: self.error(403) return userId = user.user_id() googleUser = GoogleUser.get_by_key_name(userId) if googleUser is not None: playerId = googleUser.playerId else: player = createPlayer('googleUser_' + userId, "nickName" + userId) playerId = player.key().id_or_name() googleUser = GoogleUser(key_name=userId, playerId=playerId) googleUser.put() method = self.request.get("method", default_value=None) if method is None: if self.request.scheme == 'https': method = 'signedRequest' else: method = 'token' session = createPlayerSession(playerId, method) if method == 'token': flashvars = { u'method': 'token', u'sessionToken': session.token, u'playerId': playerId } elif method == 'signedRequest': flashvars = { u'method': 'signedRequest', u'secret': session.secret, u'playerId': playerId } name = "googleUser" data = {} data[u'flashvars'] = json.dumps(flashvars) data[u'title'] = u'FJump (XJump remasterized)' self.response.out.write( template.render(config.templatesPath + name + '.html', data))
def get(self): user = users.get_current_user() if user is None : self.error(403) return userId = user.user_id() googleUser = GoogleUser.get_by_key_name(userId) if googleUser is not None: playerId = googleUser.playerId else: player = createPlayer('googleUser_' + userId, "nickName" + userId) playerId = player.key().id_or_name() googleUser = GoogleUser(key_name=userId, playerId=playerId) googleUser.put(); method = self.request.get("method", default_value=None) if method is None: if self.request.scheme == 'https': method = 'signedRequest' else: method = 'token' session = createPlayerSession(playerId, method) if method == 'token': flashvars = {u'method' : 'token', u'sessionToken' : session.token, u'playerId' : playerId} elif method == 'signedRequest': flashvars = {u'method' : 'signedRequest', u'secret' : session.secret, u'playerId' : playerId} name = "googleUser" data = {} data[u'flashvars'] = json.dumps(flashvars) data[u'title'] = u'FJump (XJump remasterized)' self.response.out.write(template.render( config.templatesPath + name + '.html', data))
def testGivenAPlayerIdCreateASessionThenRetrievIt(self): playerId = "randomId" session = createPlayerSession(playerId, 'signedRequest') getPlayerSession(playerId) self.assertEquals(session.key(), getPlayerSession(playerId).key())
def testNonExistingMethodTokenCall(self): playerId = "test" createPlayer(playerId, "test") session = createPlayerSession(playerId, 'token') response = sessionTokenCall(session.token, playerId, 'nonExisitingMehtod') self.assertTrue('error' in response and response['error']['code'] == UNKNOW_SERVICE_CALL_ERROR['code'])
def testWrongSessionTokenForPlayer(self): playerId = "test" createPlayer(playerId, "test") createPlayerSession(playerId, 'token') response = sessionTokenCall("wrong token", playerId, 'score.service.echo', 'hello') self.assertTrue('error' in response and response['error']['code'] == INVALID_SESSION_TOKEN_ERROR['code'])
def testGivenAPlayerIdCreateASessionThenRetrievIt(self): playerId = "randomId" session = createPlayerSession(playerId, 'signedRequest') getPlayerSession(playerId) self.assertEquals(session.key(), getPlayerSession(playerId).key())
def testCreateASessionAndDeleteItWhenRetriveitReturnNone(self): playerId = "randomId3" createPlayerSession(playerId, 'signedRequest') deletePlayerSession(playerId) self.assertEquals(getPlayerSession(playerId), None)
def testCreateASessionAndDeleteItWhenRetriveitReturnNone(self): playerId = "randomId3" createPlayerSession(playerId, 'signedRequest') deletePlayerSession(playerId) self.assertEquals(getPlayerSession(playerId), None)
def post(self): signedRequest = self.request.get("signed_request") signature, payload = decode_signedRequest(signedRequest) data = json.loads(base64_url_decode(payload)) verified = verifySignature(signature, payload, FACEBOOK_APP_SECRET, data.get('algorithm').upper()) if (not verified or ('user_id' not in data)): args = { 'client_id': FACEBOOK_APP_ID, 'redirect_uri': FACEBOOK_CANVAS_PAGE_URL } url = "https://www.facebook.com/dialog/oauth?" + urllib.urlencode( args) self.response.out.write( '<script language="javascript">top.location.href="' + url + '"</script>') return userId = data['user_id'] oauthToken = data['oauth_token'] facebookUser = FacebookUser.get_by_key_name(userId) if facebookUser is not None: if facebookUser.oauthToken != oauthToken: facebookUser.oauthToken = oauthToken facebookUser.put() playerId = facebookUser.playerId else: player = createPlayer('facebook_' + userId, "nickName" + userId) playerId = player.key().id_or_name() facebookUser = FacebookUser(key_name=userId, playerId=playerId, oauthToken=oauthToken) facebookUser.put() if self.request.scheme == 'https': method = 'signedRequest' else: method = 'token' session = createPlayerSession(playerId, method) if method == 'token': flashvars = { u'method': 'token', u'sessionToken': session.token, u'playerId': playerId, u'facebookOauthToken': oauthToken } elif method == 'signedRequest': flashvars = { u'method': 'signedRequest', u'secret': session.secret, u'playerId': playerId, u'facebookOauthToken': oauthToken } data = {} data[u'flashvars'] = json.dumps(flashvars) data[u'title'] = u'FJump (XJump remasterized)' data[u'facebookAppId'] = FACEBOOK_APP_ID self.response.out.write( template.render(config.templatesPath + 'facebookCanvas.html', data))