Commit 85e513bf authored by Ziirish's avatar Ziirish

rework linter

parent 942c6716
Pipeline #1684 passed with stages
in 16 minutes and 37 seconds
......@@ -5,7 +5,6 @@ variables:
DOCKER_HOST: tcp://localhost:2375
BURP_VERSION: 2.2.18
PG_VERSION: 10
FLAKE8_IGNORE: E501,E722,W605,W504
SRC_DIR: burpui
image: docker:git
......@@ -22,8 +21,8 @@ test:lint:3.6:
stage: test
image: python:3.6
script:
- pip install flake8 pylint
- flake8 --ignore=$FLAKE8_IGNORE $SRC_DIR
- pip install tox
- tox -e pep8
tags:
- lint
except:
......@@ -35,8 +34,8 @@ test:lint:3.7:
stage: test
image: python:3.7
script:
- pip install flake8 pylint
- flake8 --ignore=$FLAKE8_IGNORE $SRC_DIR
- pip install tox
- tox -e pep8
tags:
- lint
except:
......@@ -46,8 +45,8 @@ test:lint:3.8:
stage: test
image: python:3.8-rc
script:
- pip install flake8 pylint
- flake8 --ignore=$FLAKE8_IGNORE $SRC_DIR
- pip install tox
- tox -e pep8
tags:
- lint
except:
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
import sys
from subprocess import check_output, call, STDOUT
......@@ -15,7 +13,7 @@ from setuptools.command.install import install
from setuptools.command.bdist_egg import bdist_egg
from setuptools.command.egg_info import egg_info
ROOT=os.path.join(os.path.dirname(os.path.realpath(__file__)))
ROOT = os.path.join(os.path.dirname(os.path.realpath(__file__)))
DEVNULL = open(os.devnull, 'wb')
# Not sure bower was a great idea...
......@@ -127,6 +125,7 @@ class SdistWithBuildStatic(sdist):
class PyTest(Command):
user_options = []
description = "Run tests"
def initialize_options(self):
pass
......@@ -144,6 +143,7 @@ class PyTest(Command):
class BuildStatic(Command):
user_options = []
description = "Install bower dependencies"
def initialize_options(self):
pass
......@@ -209,6 +209,7 @@ class CustomInstall(install):
self.run_command('build_static')
install.run(self)
def readme():
"""
Function used to skip the screenshots part
......@@ -229,10 +230,11 @@ def readme():
desc += l
return desc
sys.path.insert(0, os.path.join(ROOT))
from burpui.desc import __author__, __author_email__, __description__, \
__url__, __title__
__url__, __title__ # noqa
name = __title__
author = __author__
author_email = __author_email__
......@@ -264,7 +266,7 @@ datadir = os.path.join('share', 'burpui')
confdir = os.path.join(datadir, 'etc')
contrib = os.path.join(datadir, 'contrib')
migrations = [(os.path.join(datadir, root), [os.path.join(root, f) for f in files if not f.endswith('.pyc')])
for root, dirs, files in os.walk('migrations')]
for root, dirs, files in os.walk('migrations')]
setup(
name=name,
......@@ -338,6 +340,5 @@ setup(
'install': CustomInstall,
'bdist_egg': BdistWithBuildStatic,
'egg_info': EggWithBuildStatic,
# 'test': PyTest,
}
)
#!/usr/bin/env python
# -*- coding: utf8 -*-
import pytest
import sys
import os
import tempfile
import shutil
......
......@@ -17,7 +17,7 @@ def logout(client):
def test_prefs_hide(client, app):
rv = login(client, 'admin', 'admin')
login(client, 'admin', 'admin')
URL = url_for('api.prefs_ui_hide')
response = client.get(URL)
......@@ -44,11 +44,11 @@ def test_prefs_hide(client, app):
assert response.json == []
app.config['WITH_SQL'] = True
rv = logout(client)
logout(client)
def test_prefs(client, app):
rv = login(client, 'admin', 'admin')
login(client, 'admin', 'admin')
URL = url_for('api.prefs_ui')
response = client.get(URL)
......@@ -66,4 +66,4 @@ def test_prefs(client, app):
assert response.status_code == 200
assert response.json == {'language': 'en', 'dateFormat': 'llll', 'pageLength': None}
rv = logout(client)
logout(client)
#!/usr/bin/env python
# -*- coding: utf8 -*-
import sys
import os
import json
import unittest
......@@ -10,7 +9,7 @@ import mockredis
from urllib.request import urlopen
from flask_testing import LiveServerTestCase, TestCase
from mock import patch
from flask import url_for, session
from flask import url_for
from burpui import create_app as BUIinit
......@@ -39,10 +38,10 @@ class BurpuiLiveTestCase(LiveServerTestCase):
return bui
def setUp(self):
print ('\nBegin Test 1\n')
print('\nBegin Test 1\n')
def tearDown(self):
print ('\nTest 1 Finished!\n')
print('\nTest 1 Finished!\n')
def test_server_is_up_and_running(self):
import socket
......@@ -59,10 +58,10 @@ class BurpuiLiveTestCase(LiveServerTestCase):
class BurpuiAPIBasicHTTPTestCase(TestCase):
def setUp(self):
print ('\nBegin Test 2\n')
print('\nBegin Test 2\n')
def tearDown(self):
print ('\nTest 2 Finished!\n')
print('\nTest 2 Finished!\n')
os.unlink(self.logfile)
def create_app(self):
......@@ -92,10 +91,10 @@ class BurpuiAPIBasicHTTPTestCase(TestCase):
class BurpuiAPITestCase(TestCase):
def setUp(self):
print ('\nBegin Test 3\n')
print('\nBegin Test 3\n')
def tearDown(self):
print ('\nTest 3 Finished!\n')
print('\nTest 3 Finished!\n')
def create_app(self):
conf = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../configs/test2.cfg')
......@@ -122,7 +121,7 @@ class BurpuiAPITestCase(TestCase):
self.assert500(response)
def test_server_config_parsing(self):
rv = self.login('admin', 'admin')
self.login('admin', 'admin')
response = self.client.get(url_for('api.server_settings'))
asse = dict((
(
......@@ -152,7 +151,7 @@ class BurpuiAPITestCase(TestCase):
self.assertEqual(response.json, asse)
def test_client_config_parsing(self):
rv = self.login('admin', 'admin')
self.login('admin', 'admin')
response = self.client.get(url_for('api.client_settings', client='toto'))
asse = dict((
(
......@@ -240,10 +239,10 @@ def mock_status(query='\n', timeout=None, agent=None):
class BurpuiRoutesTestCase(TestCase):
def setUp(self):
print ('\nBegin Test 4\n')
print('\nBegin Test 4\n')
def tearDown(self):
print ('\nTest 4 Finished!\n')
print('\nTest 4 Finished!\n')
def login(self, username, password):
return self.client.post(url_for('view.login'), data=dict(
......@@ -282,10 +281,10 @@ class BurpuiRoutesTestCase(TestCase):
class BurpuiLoginTestCase(TestCase):
def setUp(self):
print ('\nBegin Test 5\n')
print('\nBegin Test 5\n')
def tearDown(self):
print ('\nTest 5 Finished!\n')
print('\nTest 5 Finished!\n')
def login(self, username, password):
return self.client.post(url_for('view.login'), data=dict(
......@@ -304,7 +303,7 @@ class BurpuiLoginTestCase(TestCase):
return bui
def test_config_render(self):
rv = self.login('admin', 'admin')
self.login('admin', 'admin')
response = self.client.get(url_for('view.settings'))
assert 'Burp Server Configuration' in response.data.decode('utf-8')
......@@ -324,10 +323,10 @@ class BurpuiLoginTestCase(TestCase):
class BurpuiACLTestCase(TestCase):
def setUp(self):
print ('\nBegin Test 6\n')
print('\nBegin Test 6\n')
def tearDown(self):
print ('\nTest 6 Finished!\n')
print('\nTest 6 Finished!\n')
def login(self, username, password, headers=None):
return self.client.post(url_for('view.login'), data=dict(
......@@ -356,14 +355,14 @@ class BurpuiACLTestCase(TestCase):
def test_config_render(self):
with self.client:
rv = self.login('admin', 'admin')
self.login('admin', 'admin')
response = self.client.get(url_for('view.settings'))
assert 'Burp Server Configuration' in response.data.decode('utf-8')
self.logout()
def test_admin_api(self):
with self.client:
rv = self.login('admin', 'admin')
self.login('admin', 'admin')
response = self.client.get(url_for('api.auth_users'))
response2 = self.client.get(url_for('api.auth_backends'))
self.assertEqual(sorted(response.json, key=lambda k: k['name']), sorted([{'id': 'admin', 'name': 'admin', 'backend': 'BASIC:AUTH'}, {'id': 'user1', 'name': 'user1', 'backend': 'BASIC:AUTH'}], key=lambda k: k['name']))
......@@ -371,20 +370,20 @@ class BurpuiACLTestCase(TestCase):
def test_change_password(self):
with self.client:
rv = self.login('user1', 'password')
self.login('user1', 'password')
response = self.client.post(url_for('api.auth_users', name='user1'), data={'backend': 'BASIC:AUTH', 'old_password': 'plop', 'password': 'toto'}, headers={'X-Language': 'en'})
self.assert_status(response, 200)
def test_config_render_ko(self):
with self.client:
rv = self.login('user1', 'password')
self.login('user1', 'password')
response = self.client.get(url_for('view.settings'))
self.assert403(response)
self.logout()
def test_cli_settings_ko(self):
with self.client:
rv = self.login('user1', 'password')
self.login('user1', 'password')
response = self.client.get(url_for('api.client_settings', client='toto'))
self.assert403(response)
self.logout()
......@@ -440,10 +439,10 @@ class BurpuiACLTestCase(TestCase):
class BurpuiRedisTestCase(TestCase):
def setUp(self):
print ('\nBegin Test 7\n')
print('\nBegin Test 7\n')
def tearDown(self):
print ('\nTest 7 Finished!\n')
print('\nTest 7 Finished!\n')
if os.path.exists('this-file-should-not-exist'):
os.rmdir('this-file-should-not-exist')
......@@ -471,7 +470,7 @@ class BurpuiRedisTestCase(TestCase):
with bui.app_context():
from burpui.app import create_db
from burpui.ext.sql import db
from burpui.models import Session, Task
from burpui.models import Session, Task # noqa
bui.config['WITH_SQL'] = True
create_db(bui, True)
db.create_all()
......@@ -479,10 +478,9 @@ class BurpuiRedisTestCase(TestCase):
return bui
def test_login_and_revoke_session(self):
from burpui.sessions import session_manager
with self.client:
# create a second session
rv = self.login('admin', 'admin')
self.login('admin', 'admin')
response = self.client.get(url_for('api.admin_me'))
self.assertEqual(response.json, {'id': 'admin', 'name': 'admin', 'backend': 'BASIC:AUTH'})
sess = self.client.get(url_for('api.user_sessions'))
......@@ -495,9 +493,9 @@ class BurpuiRedisTestCase(TestCase):
self.assert401(response)
def test_current_session(self):
# with self.app.test_client() as c:
# with c.session_transaction() as sess:
# sess['authenticated'] = True
# with self.app.test_client() as c:
# with c.session_transaction() as sess:
# sess['authenticated'] = True
from burpui.sessions import session_manager
from burpui.ext.sql import db
......@@ -511,7 +509,7 @@ class BurpuiRedisTestCase(TestCase):
self.assertTrue(session_manager.session_expired())
#class BurpuiAPILoginTestCase(TestCase):
# class BurpuiAPILoginTestCase(TestCase):
#
# def setUp(self):
# print ('\nBegin Test 7\n')
......
import os
import pytest
import configobj
import validate
# import validate
from tempfile import mkstemp
......@@ -41,7 +41,7 @@ def test_config_init():
config = BUIConfig(tmpfile)
with pytest.raises(configobj.ConfigObjError):
fail = BUIConfig(wrong, defaults={})
BUIConfig(wrong, defaults={})
assert config.safe_get('backend', section='Global') == 'something'
assert config.safe_get('timeout', 'integer', 'Global') == 12
......
......@@ -3,6 +3,7 @@ import tempfile
from burpui.misc.parser.utils import OptionMulti, OptionInt
def test_confsrv(parser):
confsrv = parser.server_conf
stdout = confsrv.get('stdout')
......@@ -18,6 +19,7 @@ def test_confsrv(parser):
assert isinstance(port_raw, OptionInt)
# assert port_raw.dump() == 'port = 4971\nmax_children = 5'
def test_save_conf(parser):
(tmp, tmp_dest) = tempfile.mkstemp()
os.close(tmp)
......
......@@ -5,3 +5,13 @@ envlist = py{36,37,38}
description = Run burp-ui unit tests
commands = py.test --cov={envsitepackagesdir}/burpui --junitxml=.reports/burpui.junit.xml tests/
deps = .[ci]
[testenv:pep8]
deps = flake8
commands = flake8
[flake8]
exclude = .tox,docs,migrations,.git,docker,pkgs
ignore = E501,E722,W605,W504
show-source = true
application-import-names = burpui
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment