def test_check_for_meta_with_httpequiv_and_bad_content(self): result = mock.Mock() content = '423432' result.__getitem__ = mock.Mock(return_value=content) result.attrs = {'http-equiv': 'refresh', 'content': 10} with mock.patch.object(BeautifulSoup, 'find', mock.Mock(return_value=result)): self.assertEqual(check_for_meta('test', 'test'), None)
def test_check_for_meta_no_result(self): result = MagicMock() result.attrs = { "http-equiv": 'refresh', } with patch.object(BeautifulSoup, "find", return_value=None): res = check_for_meta("content", "url") self.assertEqual(res, None)
def test_check_for_meta_with_httpequiv_and_content_url_search_ok(self): result = mock.Mock() url = 'test?ok=go' content = '423432;url=' + url result.__getitem__ = mock.Mock(return_value=content) result.attrs = {'http-equiv': 'refresh', 'content': content} with mock.patch('lib.BeautifulSoup.find', mock.Mock(return_value=result)): self.assertEqual(check_for_meta('test', 'test'), url)
def test_check_for_meta_no_result(self): content = "content" url = "url" soup = mock.Mock() soup.find = mock.Mock(return_value=False) with mock.patch("lib.BeautifulSoup", mock.Mock(return_value=soup)): self.assertIsNone(check_for_meta(content, url))
def test_check_for_meta_with_httpequiv_and_content_url_search_fail(self): result = mock.Mock() content = '423432;url=blabla' result.__getitem__ = mock.Mock(return_value=content) result.attrs = {'http-equiv': 'refresh', 'content': content} with mock.patch('lib.BeautifulSoup.find', mock.Mock(return_value=result)): with mock.patch('lib.re.search', mock.Mock(return_value=None)) as re_search: self.assertEqual(check_for_meta('test', 'test'), None) self.assertTrue(re_search.called, 'search for url pattern')
def test_check_for_meta_not_m(self): result = MagicMock(name="result") result.attrs = { "content": "somewords;url=", "http-equiv": 'refresh', } result.__getitem__ = Mock(return_value=result.attrs["content"]) with patch.object(BeautifulSoup, "find", return_value=result): res = check_for_meta("content", "url") self.assertEqual(res, None)
def test_check_for_meta_result_not_split(self): content = "content" url = "url" result = mock.MagicMock() result.attrs = {'content': "content", 'http-equiv': "refresh"} soup = mock.Mock() soup.find = mock.Mock(return_value=result) with mock.patch("lib.BeautifulSoup", mock.Mock(return_value=soup)): with mock.patch("re.search", mock.Mock()) as mock_re_search: res = check_for_meta(content, url) self.assertIsNone(res) self.assertFalse(mock_re_search.called)
def test_check_for_meta_result_m(self): content = "content" url = "url" result = mock.MagicMock() result.attrs = {'content': "wait;text", 'http-equiv': "refresh"} soup = mock.Mock() soup.find = mock.Mock(return_value=result) m_mock = mock.MagicMock() re_search = mock.Mock(return_value=m_mock) with mock.patch("lib.BeautifulSoup", mock.Mock(return_value=soup)): with mock.patch("re.search", re_search): res = check_for_meta(content, url) self.assertIsNone(res)
def test_check_for_meta_result_no_attrs(self): content = "content" url = "url" result = mock.MagicMock() result.attrs = { 'content': "content", } soup = mock.Mock() soup.find = mock.Mock(return_value=result) with mock.patch("lib.BeautifulSoup", mock.Mock(return_value=soup)): with mock.patch("re.search", mock.Mock()) as mock_re_search: res = check_for_meta(content, url) self.assertIsNone(res) self.assertFalse(mock_re_search.called)
def test_check_for_meta_result_split(self): content = "content" url = "url" result = mock.MagicMock() result.attrs = { 'content': "wait;text", 'http-equiv': "refresh" } soup = mock.Mock() soup.find = mock.Mock(return_value=result) re_search = mock.Mock() with mock.patch("lib.BeautifulSoup", mock.Mock(return_value=soup)): with mock.patch("re.search", re_search): res = check_for_meta(content, url) self.assertIsNone(res)
def test_check_for_meta_incorrect_content(self): content = '<html><head><meta http-equiv="refresh" content="5; url=/path; 6"></meta></head></html>' redirect_url = check_for_meta(content, 'http://site') assert not redirect_url
def test_check_for_meta_full(self): base_url = 'http://l33t.com' url = '/h3r3c0ms3v1l.exe' content = '<html> <meta http-equiv="refresh" content="5; url=' + url + '"> </html>' self.assertEqual(check_for_meta(content, base_url), base_url + url, 'meta find and concat')
def test_check_for_meta_without_content(self): content = '<html><head><meta></meta></head></html>' redirect_url = check_for_meta(content, 'http://site') assert not redirect_url
def test_check_for_meta_with_incorrect_meta_tag(self): result = mock.Mock() result.attrs = {'content': 10} with mock.patch.object(BeautifulSoup, 'find', mock.Mock(return_value=result)): self.assertEqual(check_for_meta('test', 'test'), None)