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) data['cookies']['sess_uuid'] = sess.get_uuid() redis_mock = mock.Mock() redis_mock.sadd = sess_sadd self.handler.sessions.append(sess) self.loop.run_until_complete( self.handler.add_or_update_session(data, redis_mock)) self.assertEqual(self.handler.sessions[0].count, 2)
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.append(sess) redis_mock = mock.Mock() redis_mock.set = sess_set self.loop.run_until_complete( self.handler.delete_old_sessions(redis_mock)) self.assertListEqual(self.handler.sessions, [])
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.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')
def test_get_key(self): data = { 'peer': { 'ip': None, 'port': None }, 'headers': { 'user-agent': None }, 'path': '/foo', 'uuid': None, 'status': 200 } sess = session.Session(data) key = sess.get_key() self.assertIsNotNone(key)
def test_set_xss_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('session.Session') as mock_session: mock_session.return_value.paths = paths sess = session.Session(None) data = {'post_data': {'comment': '<script>alert(\'xss\');</script>'}} xss = yield from self.handler.handle(sess, None, data) self.assertEqual(xss['page'], '/python.html')
def test_updating_session(self): data = { 'peer': { 'ip': None, 'port': None }, 'headers': { 'user-agent': None }, 'path': '/foo', 'uuid': None, 'status': 200 } sess = session.Session(data) self.handler.sessions.append(sess) yield from self.handler.add_or_update_session(data) self.assertEqual(self.handler.sessions[0].count, 2)
def test_adding_new_session(self): data = {'peer': {}, 'headers': {}, 'path': '/foo', 'uuid': None} sess = yield from self.handler.add_or_update_session(data) assertion_data = { 'peer': { 'ip': None, 'port': None }, 'headers': { 'user-agent': None }, 'path': '/foo', 'uuid': None, 'status': 200 } assertion_session = session.Session(assertion_data) self.assertEquals(session, assertion_session)
def test_deleting_sessions(self): data = { 'peer': { 'ip': None, 'port': None }, 'headers': { 'user-agent': None }, 'path': '/foo', 'uuid': None, 'status': 200 } sess = session.Session(data) sess.is_expired = mock.MagicMock(name='expired') sess.is_expired.__bool__.reurned_value = True self.handler.sessions.append(sess) experied = mock.Mock() experied.return_value = True yield from self.handler.delete_old_sessions() self.assertListEqual(self.handler.sessions, [])