예제 #1
0
    def test_deleting_sessions(self):
        async def analyze(session_key, redis_client):
            return None

        async def sess_set(key, val):
            return None

        self.handler.analyzer.analyze = analyze
        data = {
            'peer': {
                'ip': None,
                'port': None
            },
            'headers': {'user-agent': None},
            'path': '/foo',
            'uuid': None,
            'status': 200,
            'cookies': {'sess_uuid': None}
        }
        sess = session.Session(data)
        sess.is_expired = mock.MagicMock(name='expired')
        sess.is_expired.__bool__.reurned_value = True
        self.handler.sessions[sess] = sess
        redis_mock = mock.Mock()
        redis_mock.set = sess_set
        self.loop.run_until_complete(self.handler.delete_old_sessions(redis_mock))
        self.assertDictEqual(self.handler.sessions, {})
예제 #2
0
    def test_deleting_sessions(self):
        async def analyze(session_key, redis_client):
            return None

        async def sess_set(key, val):
            return None

        self.handler.analyzer.analyze = analyze
        data = {
            "peer": {
                "ip": None,
                "port": None
            },
            "headers": {
                "user-agent": None
            },
            "path": "/foo",
            "uuid": None,
            "status": 200,
            "cookies": {
                "sess_uuid": None
            },
        }
        sess = session.Session(data)
        sess.is_expired = mock.MagicMock(name="expired")
        sess.is_expired.__bool__.reurned_value = True
        self.handler.sessions[sess] = sess
        redis_mock = mock.Mock()
        redis_mock.set = sess_set
        self.loop.run_until_complete(
            self.handler.delete_old_sessions(redis_mock))
        self.assertDictEqual(self.handler.sessions, {})
예제 #3
0
    def test_updating_session(self):
        async def sess_sadd(key, value):
            return None

        data = {
            'peer': {
                'ip': None,
                'port': None
            },
            'headers': {'user-agent': None},
            'path': '/foo',
            'uuid': None,
            'status': 200,
            'cookies': {'sess_uuid': None}
        }
        sess = session.Session(data)

        ip = data['peer']['ip']
        user_agent = data['headers']['user-agent']
        sess_uuid = data['cookies']['sess_uuid']

        sess_id_string = "{ip}{user_agent}{sess_uuid}".format(ip=ip, user_agent=user_agent, sess_uuid=sess_uuid)

        sess_id = hashlib.md5(sess_id_string.encode()).hexdigest()

        redis_mock = mock.Mock()
        redis_mock.sadd = sess_sadd
        self.handler.sessions[sess_id] = sess
        self.loop.run_until_complete(self.handler.add_or_update_session(data, redis_mock))
        self.assertEqual(self.handler.sessions[sess_id].count, 2)
예제 #4
0
파일: test_base.py 프로젝트: afeena/tanner
 def test_set_injectable_page(self):
     paths = [
         {"path": "/python.html", "timestamp": 1465851064.2740946},
         {"path": "/python.php/?foo=bar", "timestamp": 1465851065.2740946},
         {"path": "/python.html/?foo=bar", "timestamp": 1465851065.2740946},
     ]
     with mock.patch("tanner.sessions.session.Session") as mock_session:
         mock_session.return_value.paths = paths
         sess = session.Session(None)
     injectable_page = self.handler.set_injectable_page(sess)
     self.assertEqual(injectable_page, "/python.html")
예제 #5
0
 def test_get_uuid(self):
     data = {
         'peer': {
             'ip': None,
             'port': None
         },
         'headers': {'user-agent': None},
         'path': '/foo',
         'uuid': None,
         'status': 200,
         'cookies': {'sess_id': None}
     }
     sess = session.Session(data)
     key = sess.get_uuid()
     self.assertIsNotNone(key)
예제 #6
0
 def test_set_injectable_page(self):
     paths = [{
         'path': '/python.html',
         'timestamp': 1465851064.2740946
     }, {
         'path': '/python.php/?foo=bar',
         'timestamp': 1465851065.2740946
     }, {
         'path': '/python.html/?foo=bar',
         'timestamp': 1465851065.2740946
     }]
     with mock.patch('tanner.sessions.session.Session') as mock_session:
         mock_session.return_value.paths = paths
         sess = session.Session(None)
     injectable_page = self.handler.set_injectable_page(sess)
     self.assertEqual(injectable_page, '/python.html')
예제 #7
0
 def test_get_uuid(self):
     data = {
         "peer": {
             "ip": None,
             "port": None
         },
         "headers": {
             "user-agent": None
         },
         "path": "/foo",
         "uuid": None,
         "status": 200,
         "cookies": {
             "sess_id": None
         },
     }
     sess = session.Session(data)
     key = sess.get_uuid()
     self.assertIsNotNone(key)
예제 #8
0
    def test_updating_session(self):
        async def sess_sadd(key, value):
            return None

        data = {
            "peer": {
                "ip": None,
                "port": None
            },
            "headers": {
                "user-agent": None
            },
            "path": "/foo",
            "uuid": None,
            "status": 200,
            "cookies": {
                "sess_uuid": None
            },
        }
        sess = session.Session(data)

        ip = data["peer"]["ip"]
        user_agent = data["headers"]["user-agent"]
        sess_uuid = data["cookies"]["sess_uuid"]

        sess_id_string = "{ip}{user_agent}{sess_uuid}".format(
            ip=ip, user_agent=user_agent, sess_uuid=sess_uuid)

        sess_id = hashlib.md5(sess_id_string.encode()).hexdigest()

        redis_mock = mock.Mock()
        redis_mock.sadd = sess_sadd
        self.handler.sessions[sess_id] = sess
        self.loop.run_until_complete(
            self.handler.add_or_update_session(data, redis_mock))
        self.assertEqual(self.handler.sessions[sess_id].count, 2)