Example #1
0
 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'])
Example #2
0
    def testCreateSessionAndTestIfItExpireAfterMoreThan30Minutes(self):
        playerId = "randomId"
        createPlayerSession(playerId, 'signedRequest', datetime=datetime.datetime.now() - DEFAULT_MAX_SESSION_LIFE_TIME)

        session = getPlayerSession(playerId)

        self.assertTrue(session.isExpired())
Example #3
0
 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'])
Example #4
0
 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'])
Example #5
0
 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'])
Example #6
0
 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'])
Example #7
0
    def testCreateSessionAndTestIfItExpireAfterMoreThan30Minutes(self):
        playerId = "randomId"
        createPlayerSession(playerId,
                            'signedRequest',
                            datetime=datetime.datetime.now() -
                            DEFAULT_MAX_SESSION_LIFE_TIME)

        session = getPlayerSession(playerId)

        self.assertTrue(session.isExpired())
Example #8
0
 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)
Example #9
0
    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'])
Example #10
0
 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'])
Example #11
0
    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)
Example #12
0
 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)
Example #13
0
    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'])
Example #14
0
 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'])
Example #15
0
 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'])
Example #16
0
    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)
Example #17
0
    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)
Example #18
0
    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'])
Example #19
0
    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'])
Example #20
0
    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))
Example #21
0
    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))
Example #22
0
 def testGivenAPlayerIdCreateASessionThenRetrievIt(self):
     playerId = "randomId"
     session = createPlayerSession(playerId, 'signedRequest')
     getPlayerSession(playerId)
     self.assertEquals(session.key(), getPlayerSession(playerId).key())
Example #23
0
 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'])
Example #24
0
 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'])
Example #25
0
 def testGivenAPlayerIdCreateASessionThenRetrievIt(self):
     playerId = "randomId"
     session = createPlayerSession(playerId, 'signedRequest')
     getPlayerSession(playerId)
     self.assertEquals(session.key(), getPlayerSession(playerId).key())
Example #26
0
 def testCreateASessionAndDeleteItWhenRetriveitReturnNone(self):
     playerId = "randomId3"
     createPlayerSession(playerId, 'signedRequest')
     deletePlayerSession(playerId)
     self.assertEquals(getPlayerSession(playerId), None)
Example #27
0
 def testCreateASessionAndDeleteItWhenRetriveitReturnNone(self):
     playerId = "randomId3"
     createPlayerSession(playerId, 'signedRequest')
     deletePlayerSession(playerId)
     self.assertEquals(getPlayerSession(playerId), None)
Example #28
0
    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))