Esempio n. 1
0
    def retrieves_object_with_dict_key(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('foo', 'bar')

        self.assertEqual(manager['foo'], 'bar')
Esempio n. 2
0
    def retrieves_object_with_dict_key(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('foo', 'bar')

        self.assertEqual(manager['foo'], 'bar')
Esempio n. 3
0
    def gets_default_value_if_provided_and_not_in_client(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        value = manager.get('foo', 'Default')

        self.assertEqual(value, 'Default')
Esempio n. 4
0
    def sets_session_id_on_cookies(self):
        test_case = self

        class StubHandler(SessionMixin):
            settings = {
                'pycket': {
                    'engine': 'redis',
                }
            }

            def get_secure_cookie(self, name):
                test_case.assertEqual(name, 'PYCKET_ID')
                self.cookie_set = True
                return None

            def set_secure_cookie(self, name, value, expires_days, expires):
                test_case.assertEqual(name, 'PYCKET_ID')
                test_case.assertIsInstance(value, str)
                test_case.assertGreater(len(value), 0)
                self.cookie_retrieved = True

        handler = StubHandler()
        session_manager = SessionManager(handler)
        session_manager.set('some-object', 'Some object')

        self.assertTrue(handler.cookie_retrieved)
        self.assertTrue(handler.cookie_set)
Esempio n. 5
0
 def get(self):
     session = SessionManager(self)
     k = session.get('catId')
     if k != None:
         self.render("login.html")
     else:
         self.redirect('/indexihtml')
Esempio n. 6
0
    def sets_session_id_on_cookies(self):
        test_case = self

        class StubHandler(SessionMixin):
            settings = {
                'pycket': {
                    'engine': 'redis',
                }
            }

            def get_secure_cookie(self, name):
                test_case.assertEqual(name, 'PYCKET_ID')
                self.cookie_set = True
                return None

            def set_secure_cookie(self, name, value, expires_days, expires):
                test_case.assertEqual(name, 'PYCKET_ID')
                test_case.assertIsInstance(value, str)
                test_case.assertGreater(len(value), 0)
                self.cookie_retrieved = True

        handler = StubHandler()
        session_manager = SessionManager(handler)
        session_manager.set('some-object', 'Some object')

        self.assertTrue(handler.cookie_retrieved)
        self.assertTrue(handler.cookie_set)
Esempio n. 7
0
    def retrieves_session_with_same_data_as_saved(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('some-object', {'foo': 'bar'})

        self.assertEqual(manager.get('some-object')['foo'], 'bar')
Esempio n. 8
0
    def retrieves_session_with_same_data_as_saved(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('some-object', {'foo': 'bar'})

        self.assertEqual(manager.get('some-object')['foo'], 'bar')
Esempio n. 9
0
    def gets_default_value_if_provided_and_not_in_client(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        value = manager.get('foo', 'Default')

        self.assertEqual(value, 'Default')
Esempio n. 10
0
    def post(self):
        """

        """
        username = self.get_argument("username")
        password = self.get_argument("password")
        try:
            connect_mongo.db.user.find_one({"username": username, "password": password})
            if "username" == username & "password" == password:
                session = SessionManager(self)
                session.set('catId',username)
                self.write("<script>alert('ورود موفقیت آمیز بود')</script>")
            else:
                self.render("Login.html")
            # doc = connect_mongo.db.user.find_one({"username": username, "password": password})
            # docc = doc["_id"]
            # if docc > 0:
            #     session = SessionManager(self)
            #     session.set('loginid', docc)
            #     k = session.get('loginid')
            #     self.render("index.html")

        except:
            k = 1
            self.render("Login.html", k=k)
Esempio n. 11
0
    def gets_all_available_keys_from_session(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('foo', 'FOO')
        manager.set('bar', 'BAR')

        self.assertListEqual(sorted(manager.keys()), sorted(['foo', 'bar']))
Esempio n. 12
0
    def gets_all_available_keys_from_session(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('foo', 'FOO')
        manager.set('bar', 'BAR')

        self.assertListEqual(sorted(manager.keys()), sorted(['foo', 'bar']))
Esempio n. 13
0
    def deletes_item_using_command(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('some-object', {'foo': 'bar'})

        del manager['some-object']

        self.assertIsNone(manager.get('some-object'))
Esempio n. 14
0
    def still_retrieves_object_if_not_passed_from_expiration(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('foo', 'bar')

        time.sleep(1)

        self.assertEqual(manager.get('foo'), 'bar')
Esempio n. 15
0
    def deletes_item_using_command(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('some-object', {'foo': 'bar'})

        del manager['some-object']

        self.assertIsNone(manager.get('some-object'))
Esempio n. 16
0
    def still_retrieves_object_if_not_passed_from_expiration(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('foo', 'bar')

        time.sleep(1)

        self.assertEqual(manager.get('foo'), 'bar')
Esempio n. 17
0
class RequestHandler(base.RequestHandler):
    def __init__(self, *args, **kwargs):
        super(RequestHandler, self).__init__(*args, **kwargs)
        self.session = SessionManager(self)

    def get_template_path(self):
        return settings.base.template_path

    @gen.coroutine
    def prepare(self):
        try:
            user_id = self.session.get(settings.redis.USER_KEY)
            if user_id:
                user = yield self.console_user_model.GetUserFromId(user_id)
                if user:
                    yield self.Login(user)
        except:
            pass

    def _handle_request_exception(self, error):
        if self._finished:
            return
        if isinstance(error, errors.Error):
            self.render_error(error)
        elif isinstance(error, MissingArgumentError):
            self.render_error(errors.ParamInvalidError(error.arg_name))
        else:
            super(RequestHandler, self)._handle_request_exception(error)

    def render_error(self, error):
        data = {
            'code': u'',
            'message': u'操作发生错误'
        }

        if isinstance(error, errors.PermissionDeny):
            data['code'] = error.error_code
            data['message'] = error.error_message

        self.render('global_error.html', data=data)

    @gen.coroutine
    def Login(self, user):
        if user['status'] in ['locked']:
            raise gen.Return(False)
        user['privileges'] = []
        roles = user['roles']
        for r in roles:
            role = yield self.role_model.GetRoleFromName(r)
            if role:
                privileges = role['privileges']
                user['privileges'].extend(privileges)

        self.session.set(settings.redis.USER_KEY, user['_id'])
        self.current_user = user
        raise gen.Return(True)
Esempio n. 18
0
    def cannot_retrieve_object_if_passed_from_expiration(self):
        handler = StubHandler()
        manager = SessionManager(handler)
        manager.driver.EXPIRE_SECONDS = 1

        manager.set('foo', 'bar')

        time.sleep(manager.driver.EXPIRE_SECONDS + 1)

        self.assertIsNone(manager.get('foo'))
Esempio n. 19
0
    def saves_session_object_on_redis_with_same_session_id_as_cookie(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('some-object', {'foo': 'bar'})

        raw_session = self.client.get(handler.session_id)
        session = pickle.loads(raw_session)

        self.assertEqual(session['some-object']['foo'], 'bar')
Esempio n. 20
0
    def saves_session_object_on_redis_with_same_session_id_as_cookie(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('some-object', {'foo': 'bar'})

        raw_session = self.client.get(handler.session_id)
        session = pickle.loads(raw_session)

        self.assertEqual(session['some-object']['foo'], 'bar')
Esempio n. 21
0
    def cannot_retrieve_object_if_passed_from_expiration(self):
        handler = StubHandler()
        manager = SessionManager(handler)
        manager.driver.EXPIRE_SECONDS = 1

        manager.set('foo', 'bar')

        time.sleep(manager.driver.EXPIRE_SECONDS + 1)

        self.assertIsNone(manager.get('foo'))
Esempio n. 22
0
 def get(cls, handler, name):
     session = SessionManager(handler)
     Debug.dprint(text='name: ' + name, type='custom')
     Debug.dprint(text='value: ' + str(session.get(name)), type='error')
     # print "Session name is: " + name
     # print "Do we have a session? " + str(session.get(name))
     # if cls.exists(handler, name):
     #     print "There is a session"
     # else:
     #     print "There is not any sessionn"
     return session.get(name)
Esempio n. 23
0
    def iterates_without_method_over_keys(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('foo', 'FOO')
        manager.set('bar', 'BAR')

        iterations = 0

        for key in manager:
            self.assertTrue(key in manager)
            iterations += 1

        self.assertEqual(iterations, 2)
Esempio n. 24
0
    def iterates_without_method_over_keys(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('foo', 'FOO')
        manager.set('bar', 'BAR')

        iterations = 0

        for key in manager:
            self.assertTrue(key in manager)
            iterations += 1

        self.assertEqual(iterations, 2)
Esempio n. 25
0
    def get(self):
        sessionid = self.get_current_session()
        session = SessionManager(self)
        vh = VimHelper()
        logging.debug("about to pull clusters using sessionid %s" % sessionid)
        clusters = vh.GetClusters(sessionid)
        f = TemplateFields()
        f['username'] = self.get_current_user()
        f['servername'] = session.get('server')
        f['servertype'] = vh.ServerType(sessionid)
        f['serverapi'] = vh.ApiVersion(sessionid)
        f['clusterlist'] = clusters

        self.render("listclusters.html", fields=f)
Esempio n. 26
0
 def uses_custom_sessions_database_if_provided(self):
     handler = StubHandler()
     handler.settings = {
         'pycket': {
             'engine': 'redis',
             'storage': {
                 'db_sessions': 10,
                 'db_notifications': 11,
             }
         },
     }
     manager = SessionManager(handler)
     manager.set('foo', 'bar')
     self.assertEqual(manager.driver.client.connection_pool._available_connections[0].db, 10)
Esempio n. 27
0
 def uses_custom_sessions_database_if_provided(self):
     handler = StubHandler()
     handler.settings = {
         'pycket': {
             'engine': 'redis',
             'storage': {
                 'db_sessions': 10,
                 'db_notifications': 11,
             }
         },
     }
     manager = SessionManager(handler)
     manager.set('foo', 'bar')
     self.assertEqual(
         manager.driver.client.connection_pool._available_connections[0].db,
         10)
Esempio n. 28
0
    def get(self, vmpath):

        logging.debug("ShowVMHandler: %s" % vmpath)
        vh = VimHelper()
        sessionid = self.get_current_session()
        session = SessionManager(self)

        f = TemplateFields()
        f['username'] = self.get_current_user()
        f['servername'] = session.get('server')
        f['servertype'] = vh.ServerType(sessionid)
        f['serverapi'] = vh.ApiVersion(sessionid)
        vm = vh.GetVM(sessionid, vmpath)
        f['vmstatus'] = vm.get_status()
        f['vmproperties'] = vm.get_properties()
        self.render("showvm.html", fields=f)
Esempio n. 29
0
    def get(self):
        sessionid = self.get_current_session()
        logging.debug("LoginHandler: sessionid %s" % sessionid)
        session = SessionManager(self)

        tpl_fields = TemplateFields()
        tpl_fields['post'] = False
        tpl_fields['server'] = session.get('server')
        tpl_fields['username'] = session.get('user')

        # using the next field makes it easier across logins
        tpl_fields['next'] = self.get_argument('next', '/')
        logging.debug("LoginHandler: next: %s" % tpl_fields['next'])

        logging.debug('LoginHandler: login page about to be rendered')
        self.render("login.html", fields=tpl_fields)
Esempio n. 30
0
    def sets_object_with_dict_key(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager['foo'] = 'bar'

        self.assertEqual(manager['foo'], 'bar')
Esempio n. 31
0
    def keeps_previous_items_when_setting_new_ones(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('some-object', {'foo': 'bar'})
        manager.set('some-object2', {'foo2': 'bar2'})

        self.assertEqual(manager.get('some-object')['foo'], 'bar')
        self.assertEqual(manager.get('some-object2')['foo2'], 'bar2')
Esempio n. 32
0
    def does_not_set_session_id_if_already_exists(self):
        class StubHandler(SessionMixin):
            settings = {
                'pycket': {
                    'engine': 'redis',
                }
            }

            def get_secure_cookie(self, name):
                self.cookie_retrieved = True
                return 'some-id'

        handler = StubHandler()
        manager = SessionManager(handler)
        manager.set('some-object', 'Some object')

        self.assertTrue(handler.cookie_retrieved)
Esempio n. 33
0
    def does_not_set_session_id_if_already_exists(self):
        class StubHandler(SessionMixin):
            settings = {
                'pycket': {
                    'engine': 'redis',
                }
            }

            def get_secure_cookie(self, name):
                self.cookie_retrieved = True
                return 'some-id'

        handler = StubHandler()
        manager = SessionManager(handler)
        manager.set('some-object', 'Some object')

        self.assertTrue(handler.cookie_retrieved)
Esempio n. 34
0
    def verifies_if_a_session_exist(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        self.assertFalse('foo' in manager)

        manager['foo'] = 'bar'

        self.assertTrue('foo' in manager)
Esempio n. 35
0
    def sets_session_id_to_last_a_browser_session_as_default(self):
        test_case = self

        class StubHandler(SessionMixin):
            settings = {
                'pycket': {
                    'engine': 'redis',
                }
            }
            def get_secure_cookie(self, name):
                return None

            def set_secure_cookie(self, name, value, expires_days, expires):
                test_case.assertIsNone(expires_days)
                test_case.assertIsNone(expires)

        handler = StubHandler()
        manager = SessionManager(handler)
        manager.set('some-object', 'Some object')
Esempio n. 36
0
    def __init__(self, application, request, **kwargs):
        super(TornadoRequestBase, self).__init__(application, request,
                                                 **kwargs)

        self.session = SessionManager(self)

        self.user = {
            "name": self.session.get('name', None),
            "user": self.session.get('user', None),
            "id": self.session.get('id', None),
            "picture_address": self.session.get('picture_address', None),
            "id_admin": self.session.get('id_admin', None),
            "type_user": self.session.get('type_user', None),
            "online": self.session.get('online', None),
            "password": self.session.get('password', None),
            "email": self.session.get('email', None),
            "message": self.session.get('message', None),
            "count_message": self.session.get('count_message', None)
        }
Esempio n. 37
0
    def post(self):
        session = SessionManager(self)
        # if session.get()
        noun1 = self.get_argument('noun1')
        noun2 = self.get_argument('noun2')
        verb = self.get_argument('verb')
        noun3 = self.get_argument('noun3')
        us = self.get_current_user()

        self.render('poem.html', roads=noun1, wood=noun2, made=verb,difference=noun3,user = us,ID=session.get('_id'),INFO=session.get('info'))
Esempio n. 38
0
    def deletes_multiple_session_objects_at_once(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('some-object', {'foo': 'bar'})
        manager.set('some-object2', {'foo2': 'bar2'})
        manager.delete('some-object', 'some-object2')

        raw_session = self.client.get(handler.session_id)
        session = pickle.loads(raw_session)

        self.assertEqual(list(session.keys()), [])
Esempio n. 39
0
    def keeps_previous_items_when_setting_new_ones(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('some-object', {'foo': 'bar'})
        manager.set('some-object2', {'foo2': 'bar2'})

        self.assertEqual(manager.get('some-object')['foo'], 'bar')
        self.assertEqual(manager.get('some-object2')['foo2'], 'bar2')
Esempio n. 40
0
    def sets_session_id_to_last_a_browser_session_as_default(self):
        test_case = self

        class StubHandler(SessionMixin):
            settings = {
                'pycket': {
                    'engine': 'redis',
                }
            }

            def get_secure_cookie(self, name):
                return None

            def set_secure_cookie(self, name, value, expires_days, expires):
                test_case.assertIsNone(expires_days)
                test_case.assertIsNone(expires)

        handler = StubHandler()
        manager = SessionManager(handler)
        manager.set('some-object', 'Some object')
Esempio n. 41
0
    def get(self):
        vh = VimHelper()
        sessionid = self.get_current_session()
        session = SessionManager(self)

        f = TemplateFields()
        f['username'] = self.get_current_user()
        f['servername'] = session.get('server')

        task = Tasks()
        task.add('task1 test')
        task.add('task2 test')
        task.add('task3 test')

        ids = task.getids()
        mytasks = {}
        for id in ids:
            mytasks[id] = task.get(id)

        f['tasks'] = mytasks
        self.render('showtasks.html', fields=f)
Esempio n. 42
0
    def repasses_cookies_options(self):
        test_case = self

        class StubHandler(SessionMixin):
            settings = {
                'pycket': {
                    'engine': 'redis',
                    'cookies': {
                        'foo': 'bar',
                    }
                },
            }
            def get_secure_cookie(self, name):
                return None

            def set_secure_cookie(self, *args, **kwargs):
                test_case.assertEqual(kwargs['foo'], 'bar')

        handler = StubHandler()
        manager = SessionManager(handler)
        manager.set('some-object', 'Some object')
Esempio n. 43
0
    def uses_custom_expires_days_if_provided(self):
        test_case = self

        class StubHandler(SessionMixin):
            settings = {
                'pycket': {
                    'engine': 'redis',
                    'cookies': {
                        'expires_days': 'St. Neversday',
                    }
                },
            }
            def get_secure_cookie(self, name):
                return None

            def set_secure_cookie(self, *args, **kwargs):
                test_case.assertEqual(kwargs['expires_days'], 'St. Neversday')

        handler = StubHandler()
        manager = SessionManager(handler)
        manager.set('some-object', 'Some object')
Esempio n. 44
0
    def uses_custom_expires_days_if_provided(self):
        test_case = self

        class StubHandler(SessionMixin):
            settings = {
                'pycket': {
                    'engine': 'redis',
                    'cookies': {
                        'expires_days': 'St. Neversday',
                    }
                },
            }

            def get_secure_cookie(self, name):
                return None

            def set_secure_cookie(self, *args, **kwargs):
                test_case.assertEqual(kwargs['expires_days'], 'St. Neversday')

        handler = StubHandler()
        manager = SessionManager(handler)
        manager.set('some-object', 'Some object')
Esempio n. 45
0
    def repasses_cookies_options(self):
        test_case = self

        class StubHandler(SessionMixin):
            settings = {
                'pycket': {
                    'engine': 'redis',
                    'cookies': {
                        'foo': 'bar',
                    }
                },
            }

            def get_secure_cookie(self, name):
                return None

            def set_secure_cookie(self, *args, **kwargs):
                test_case.assertEqual(kwargs['foo'], 'bar')

        handler = StubHandler()
        manager = SessionManager(handler)
        manager.set('some-object', 'Some object')
Esempio n. 46
0
    def deletes_objects_from_session(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('some-object', {'foo': 'bar'})
        manager.set('some-object2', {'foo2': 'bar2'})
        manager.delete('some-object')

        raw_session = self.client.get(handler.session_id)
        session = pickle.loads(raw_session)

        self.assertEqual(session.keys(), ['some-object2'])
Esempio n. 47
0
    def deletes_multiple_session_objects_at_once(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager.set('some-object', {'foo': 'bar'})
        manager.set('some-object2', {'foo2': 'bar2'})
        manager.delete('some-object', 'some-object2')

        raw_session = self.client.get(handler.session_id)
        session = pickle.loads(raw_session)

        self.assertEqual(list(session.keys()), [])
Esempio n. 48
0
    def post(self):
        session = SessionManager(self)
        session.set('server', self.get_argument("server"))
        session.set('user', self.get_argument("username"))

        sessionid = self.get_current_session()

        tpl_fields = TemplateFields()
        tpl_fields['post'] = True
        tpl_fields['ip'] = self.request.remote_ip
        tpl_fields['server'] = self.get_argument("server")
        tpl_fields['username'] = self.get_argument("username")
        tpl_fields['next'] = self.get_argument('next', '/')

        # build this up to pass unto
        cred = {'server': self.get_argument('server'),
                'username': self.get_argument('username'),
                'password': self.get_argument('password'),
                'sessionid': sessionid
                }

        connect = VimHelper.Authenticate(self, cred)
        logging.debug("LoginHandler: result of VimHelper.Authenticate: %s" %
                      connect)
        if connect is "authenticated":
            session.set('authenticated', True)
            tpl_fields['vierror'] = connect
            self.redirect(tpl_fields['next'])
            return True
        else:
            tpl_fields['authenticated'] = False
            tpl_fields['vierror'] = connect

        logging.debug("LoginHandler: next: %s" % next)

        self.render("login.html", fields=tpl_fields)
Esempio n. 49
0
 def get(self, *args, **kwargs):
     # redis_instance.set(name='name', value='EHSAN')
     # self.write(redis_instance.get(name='name'))
     session = SessionManager(self)
     # session.set('key', 'OMG')
     session.set(name='key', value='OMG')
     # session['key'] = 'OMG'
     self.write(session.get(self, 'key'))
     self.write(str(session.get('key')))
     # self.write(str(session.keys()))
     self.write(str(session.iterkeys()))
     # self.write(session['key'])
     self.write('done')
    def __init__(self, application, request, **kwargs):
        super(TornadoRequestBase, self).__init__(application, request, **kwargs)

        self.session = SessionManager(self)

        self.user = {
            "name": self.session.get('name', None),
            "user": self.session.get('user', None),
            "id": self.session.get('id', None),
            "picture_address": self.session.get('picture_address', None),
            "id_admin": self.session.get('id_admin', None),
            "type_user": self.session.get('type_user', None),
            "online": self.session.get('online', None),
            "password": self.session.get('password', None),
            "email": self.session.get('email', None),
            "message": self.session.get('message', None),
            "count_message": self.session.get('count_message', None)

        }
Esempio n. 51
0
    def retrieves_none_if_session_object_not_previously_set(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        self.assertIsNone(manager.get('unexistant-object'))
Esempio n. 52
0
 def __init__(self, *args, **kwargs):
     super(RequestHandler, self).__init__(*args, **kwargs)
     self.session = SessionManager(self)
Esempio n. 53
0
    def retrieves_none_if_session_object_not_previously_set(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        self.assertIsNone(manager.get('unexistant-object'))
Esempio n. 54
0
    def raises_key_error_if_object_doesnt_exist(self):
        handler = StubHandler()
        manager = SessionManager(handler)

        manager['foo']