Test Failed
Push — master ( 15e5b6...889ab2 )
by -
01:30
created

FlaskrTestCase.test_plain_rule()   B

Complexity

Conditions 5

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 5
dl 0
loc 20
rs 8.5454
1
from time import strftime, localtime
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
try:
4
    from urlparse import urlparse
5
except ImportError:  # python3
6
    from urllib.parse import urlparse
7
8
import re
0 ignored issues
show
Unused Code introduced by
The import re seems to be unused.
Loading history...
9
10
from spike import create_app
11
from spike.model import db
12
from spike.model.naxsi_rules import ValueTemplates, NaxsiRules, NaxsiRuleSets
0 ignored issues
show
Unused Code introduced by
Unused NaxsiRuleSets imported from spike.model.naxsi_rules
Loading history...
Unused Code introduced by
Unused ValueTemplates imported from spike.model.naxsi_rules
Loading history...
13
import unittest
14
15
16
class FlaskrTestCase(unittest.TestCase):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
17
18
    def setUp(self):
19
        app = create_app()
20
        db.init_app(app)
21
        app.config['TESTING'] = True
22
        self.app = app.test_client()
23
24
    def tearDown(self):
25
        pass
26
27
    def test_robotstxt(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
28
        assert self.app.get('/robots.txt').data == 'User-agent: *\n Disallow: /'
29
30
    def test_redirect_root(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
31
        rv = self.app.get('/', follow_redirects=False)
0 ignored issues
show
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
32
        assert rv.status_code == 302
33
        assert urlparse(rv.location).path == '/rules'
34
35
    def test_add_rule(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
36
        data = {
37
            'msg': 'this is a test message',
38
            'detection': 'DETECTION',
39
            'mz': 'BODY',
40
            'custom_mz_val': '',
41
            'negative': 'checked',
42
            'score_$SQL': 8,
43
            'score': '$SQL',
44
            'rmks': 'this is a test remark',
45
            'ruleset': 'scanner.rules'
46
        }
47
        rv = self.app.post('/rules/new', data=data, follow_redirects=True)
0 ignored issues
show
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
48
        rule = NaxsiRules.query.order_by(NaxsiRules.sid.desc()).first()
0 ignored issues
show
Bug introduced by
The Class NaxsiRules does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
49
50
        assert ('<li> - OK: created %d : %s</li>' % (rule.sid, rule.msg)) in rv.data
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after assert.
Loading history...
51
        assert rule.msg == data['msg']
52
        assert rule.detection == 'str:' + data['detection']
53
        assert rule.mz == data['mz']
54
        assert rule.score == data['score'] + ':' + str(data['score_$SQL'])
55
        assert rule.rmks == data['rmks']
56
        assert rule.ruleset == data['ruleset']
57
58
        _rule = NaxsiRules.query.filter(rule.sid == NaxsiRules.sid).first()
0 ignored issues
show
Bug introduced by
The Class NaxsiRules does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
59
        db.session.delete(_rule)
60
61
    def test_del_rule(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
62
        current_sid = int(NaxsiRules.query.order_by(NaxsiRules.sid.desc()).first().sid)
0 ignored issues
show
Bug introduced by
The Class NaxsiRules does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
63
        db.session.add(NaxsiRules(u'POUET', 'str:OIJEFOJEWFOIJEWF', u'BODY', u'$SQL:8', current_sid+1, u'web_server.rules',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (123/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
64
         u'f hqewifueiwf hueiwhf uiewh fiewh fhw', '1', True, 1457101045))
65
66
        sid = NaxsiRules.query.order_by(NaxsiRules.sid.desc()).first().sid
0 ignored issues
show
Bug introduced by
The Class NaxsiRules does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
67
        rv = self.app.get('/rules/del/%d' % sid)
0 ignored issues
show
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
68
        assert rv.status_code == 302
69
70
        rule = NaxsiRules.query.order_by(NaxsiRules.sid.desc()).first()
0 ignored issues
show
Bug introduced by
The Class NaxsiRules does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
71
        assert rule.sid == current_sid
72
73
    def test_plain_rule(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
74
        _rule = NaxsiRules.query.order_by(NaxsiRules.sid.desc()).first()
0 ignored issues
show
Bug introduced by
The Class NaxsiRules does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
75
        rv = self.app.get('/rules/plain/%d' % _rule.sid)
0 ignored issues
show
Coding Style Naming introduced by
The name rv does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
76
        assert rv.status_code == 200
77
        rdate = strftime("%F - %H:%M", localtime(float(str(_rule.timestamp))))
78
        rmks = "# ".join(_rule.rmks.strip().split("\n"))
79
        detect = _rule.detection.lower() if _rule.detection.startswith("str:") else _rule.detection
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (99/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
80
        negate = 'negative' if _rule.negative == 1 else ''
81
        expected = """
82
#
83
# sid: %s | date: %s
84
#
85
# %s
86
#
87
MainRule %s "%s" "msg:%s" "mz:%s" "s:%s" id:%s ;
88
89
""" % (_rule.sid, rdate, rmks, negate, detect, _rule.msg, _rule.mz, _rule.score, _rule.sid)
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (91/90).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
90
        assert expected == rv.data
91
        _rule = NaxsiRules.query.filter(_rule.sid == NaxsiRules.sid).first()
0 ignored issues
show
Bug introduced by
The Class NaxsiRules does not seem to have a member named query.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
92
        db.session.delete(_rule)
93
94
95
if __name__ == '__main__':
96
    unittest.main()
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...