Passed
Pull Request — master (#161)
by Jan
04:20
created

test_xml_parser   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 70
dl 0
loc 107
rs 10
c 0
b 0
f 0
wmc 15

11 Methods

Rating   Name   Duplication   Size   Complexity  
A tests.test_xml_parser.test_get_def_id_by_notchecked_rule_id() 0 8 2
A tests.test_xml_parser.test_parsing_and_evaluate_scan_with_rule_with_NOT_OR() 0 7 1
A tests.test_xml_parser.test_get_def_id_by_rule_id() 0 6 2
A tests.test_xml_parser.test_parsing_and_evaluate_scan_with_extend_def() 0 7 1
A tests.test_xml_parser.test_parsing_and_evaluate_scan_with_pasing_rule() 0 7 1
A tests.test_xml_parser.test_parsing_and_evaluate_scan_with_fail_rule() 0 7 1
A tests.test_xml_parser.test_use_bat_report_file() 0 5 2
A tests.test_xml_parser.test_parsing_and_evaluate_scan_1() 0 7 1
A tests.test_xml_parser.test_get_def_id_by_notselected_rule_id() 0 8 2
A tests.test_xml_parser.test_parsing_and_evaluate_scan_0() 0 7 1
A tests.test_xml_parser.test_parsing_full_scan_XML_and_evaluate() 0 7 1
1
import os
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
introduced by
import missing from __future__ import absolute_import
Loading history...
Unused Code introduced by
The import os seems to be unused.
Loading history...
2
import pytest
3
import json
0 ignored issues
show
Unused Code introduced by
The import json seems to be unused.
Loading history...
introduced by
standard import "import json" should be placed before "import pytest"
Loading history...
4
5
import pytest
0 ignored issues
show
Unused Code introduced by
The import pytest was already done on line 2. You should be able to
remove this line.
Loading history...
6
7
import tests.any_test_help
8
from oval_graph.xml_parser import XmlParser
9
10
11
def test_parsing_full_scan_XML_and_evaluate():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_parsing_full_scan_XML_and_evaluate" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

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...
introduced by
Missing function or method docstring
Loading history...
12
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
13
    rule_id = 'xccdf_org.ssgproject.content_rule_accounts_passwords_pam_faillock_deny'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (86/80).

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

Loading history...
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
14
    result = 'false'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
15
16
    tests.any_test_help.any_test_parsing_and_evaluate_scan_rule(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
17
        src, rule_id, result)
18
19
20
def test_parsing_and_evaluate_scan_with_extend_def():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_parsing_and_evaluate_scan_with_extend_def" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

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...
introduced by
Missing function or method docstring
Loading history...
21
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
22
    rule_id = 'xccdf_org.ssgproject.content_rule_sshd_disable_gssapi_auth'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
23
    result = 'false'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
24
25
    tests.any_test_help.any_test_parsing_and_evaluate_scan_rule(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
26
        src, rule_id, result)
27
28
29
def test_parsing_and_evaluate_scan_with_pasing_rule():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_parsing_and_evaluate_scan_with_pasing_rule" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

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...
introduced by
Missing function or method docstring
Loading history...
30
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
31
    rule_id = 'xccdf_org.ssgproject.content_rule_service_debug-shell_disabled'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
32
    result = 'true'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
33
34
    tests.any_test_help.any_test_parsing_and_evaluate_scan_rule(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
35
        src, rule_id, result)
36
37
38
def test_parsing_and_evaluate_scan_with_fail_rule():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_parsing_and_evaluate_scan_with_fail_rule" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

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...
introduced by
Missing function or method docstring
Loading history...
39
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
40
    rule_id = 'xccdf_org.ssgproject.content_rule_mount_option_dev_shm_noexec'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
41
    result = 'false'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
42
43
    tests.any_test_help.any_test_parsing_and_evaluate_scan_rule(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
44
        src, rule_id, result)
45
46
47
def test_parsing_and_evaluate_scan_with_rule_with_NOT_OR():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_parsing_and_evaluate_scan_with_rule_with_NOT_OR" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

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...
introduced by
Missing function or method docstring
Loading history...
48
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
49
    rule_id = 'xccdf_org.ssgproject.content_rule_audit_rules_unsuccessful_file_modification_creat'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (98/80).

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

Loading history...
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
50
    result = 'false'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
51
52
    tests.any_test_help.any_test_parsing_and_evaluate_scan_rule(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
53
        src, rule_id, result)
54
55
56
def test_parsing_and_evaluate_scan_0():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_parsing_and_evaluate_scan_0" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

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...
introduced by
Missing function or method docstring
Loading history...
57
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
58
    rule_id = 'xccdf_org.ssgproject.content_rule_audit_rules_file_deletion_events_rmdir'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (88/80).

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

Loading history...
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
59
    result = 'false'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
60
61
    tests.any_test_help.any_test_parsing_and_evaluate_scan_rule(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
62
        src, rule_id, result)
63
64
65
def test_parsing_and_evaluate_scan_1():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_parsing_and_evaluate_scan_1" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

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...
introduced by
Missing function or method docstring
Loading history...
66
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
67
    rule_id = 'xccdf_org.ssgproject.content_rule_require_singleuser_auth'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
68
    result = 'true'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
69
70
    tests.any_test_help.any_test_parsing_and_evaluate_scan_rule(
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
71
        src, rule_id, result)
72
73
74
def test_get_def_id_by_rule_id():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
75
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
76
    parser = XmlParser(tests.any_test_help.get_src(src))
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
77
78
    with pytest.raises(Exception, match='404 rule "hello" not found!'):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
79
        assert parser._get_definition_of_rule('hello')
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
Coding Style Best Practice introduced by
It seems like _get_definition_of_rule was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
80
81
82
def test_get_def_id_by_notselected_rule_id():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_get_def_id_by_notselected_rule_id" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

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...
introduced by
Missing function or method docstring
Loading history...
83
    src = 'test_data/ssg-fedora-ds-arf.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
84
85
    parser = tests.any_test_help.get_parser(src)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
86
    rule_id = 'xccdf_org.ssgproject.content_rule_ntpd_specify_remote_server'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
87
88
    with pytest.raises(Exception, match="not selected"):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
89
        assert parser._get_definition_of_rule(rule_id)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
Coding Style Best Practice introduced by
It seems like _get_definition_of_rule was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
90
91
92
def test_use_bat_report_file():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
93
    src = 'test_data/xccdf_org.ssgproject.content_profile_ospp-results-initial.xml'
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (83/80).

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

Loading history...
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
94
95
    with pytest.raises(Exception, match=r"arf\b|ARF\b"):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
96
        assert tests.any_test_help.get_parser(src)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
97
98
99
def test_get_def_id_by_notchecked_rule_id():
0 ignored issues
show
Coding Style Naming introduced by
Function name "test_get_def_id_by_notchecked_rule_id" doesn't conform to '[a-z_][a-z0-9_]2,30$' pattern ('[a-z_][a-z0-9_]2,30$' pattern)

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...
introduced by
Missing function or method docstring
Loading history...
100
    src = 'test_data/arf-scan-with-notchecked-rule.xml'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
101
102
    parser = tests.any_test_help.get_parser(src)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
103
    rule_id = 'xccdf_org.ssgproject.content_rule_security_patches_up_to_date'
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
104
105
    with pytest.raises(Exception, match="notchecked"):
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 4 tabs, expected 1
Loading history...
106
        assert parser._get_definition_of_rule(rule_id)
0 ignored issues
show
Coding Style introduced by
Bad indentation. Found 8 tabs, expected 2
Loading history...
Coding Style Best Practice introduced by
It seems like _get_definition_of_rule was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
107