Skip to content

Commit f0108e1

Browse files
committed
Properly prepared everything
1 parent cadaf6b commit f0108e1

37 files changed

Lines changed: 104 additions & 120 deletions

tests/spytestdir/elastic.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# From a security point of view: Data exfiltration to an external provider with too many risks.
33

44
import os
5-
65
from elasticsearch import Elasticsearch
76

87

tests/spytestdir/example1.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
32
import requests
43

54
password = os.environ["PASSWORD"]

tests/test_apicalls.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import pytest
12
from pathlib import Path
23

3-
import pytest
4+
from codeaudit.api_interfaces import version, get_overview
45

5-
from codeaudit.api_interfaces import get_overview, version
6-
from codeaudit.checkmodules import get_imported_modules
76
from codeaudit.filehelpfunctions import read_in_source_file
7+
from codeaudit.checkmodules import get_imported_modules
88

99

1010
def test_api_version():
@@ -51,7 +51,7 @@ def test_get_overview_validfile():
5151
# This is the expected dictionary - note for testing output!
5252
expected_data = {
5353
"FileName": "obfuscating.py",
54-
"Number_Of_Lines": 54,
54+
"Number_Of_Lines": 68,
5555
"AST_Nodes": 32,
5656
"Std-Modules": 2,
5757
"External-Modules": 0,

tests/test_basicpatterns.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from pathlib import Path
2-
31
import pytest
2+
from pathlib import Path
43

54
from codeaudit.filehelpfunctions import read_in_source_file
65
from codeaudit.issuevalidations import find_constructs
@@ -18,7 +17,7 @@ def test_basic_patterns():
1817
actual_data = find_constructs(source, constructs)
1918

2019
# This is the expected dictionary
21-
expected_data = {"os.access": [8, 14], "eval": [11]}
20+
expected_data = {"os.access": [9, 15], "eval": [12]}
2221

2322
# Assert that the actual data matches the expected data
2423
assert actual_data == expected_data
@@ -36,7 +35,7 @@ def test_basic_patterns2():
3635
actual_data = find_constructs(source, constructs)
3736

3837
# This is the expected dictionary
39-
expected_data = {"os.access": [8, 12], "eval": [10], "os": [8, 12]}
38+
expected_data = {"os.access": [9, 13], "eval": [11], "os": [9, 13]}
4039

4140
# Assert that the actual data matches the expected data
4241
assert actual_data == expected_data
@@ -53,7 +52,7 @@ def test_assert_keyword():
5352
actual_data = find_constructs(source, constructs)
5453

5554
# This is the expected dictionary
56-
expected_data = {"assert": [5, 31]}
55+
expected_data = {"assert": [4, 31]}
5756

5857
# Assert that the actual data matches the expected data
5958
assert actual_data == expected_data

tests/test_chmod.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from pathlib import Path
2-
31
import pytest
2+
from pathlib import Path
43

54
from codeaudit.security_checks import perform_validations
65

@@ -21,7 +20,7 @@ def test_chmod_constructs():
2120
actual_data = result["result"]
2221

2322
# This is the expected dictionary
24-
expected_data = {"os.access": [5], "os.chmod": [8, 23, 25]}
23+
expected_data = {"os.access": [6], "os.chmod": [9, 26, 28]}
2524

2625
# Assert that the actual data matches the expected data
2726
assert actual_data == expected_data

tests/test_constructspart2.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from pathlib import Path
2-
31
import pytest
2+
from pathlib import Path
43

54
from codeaudit.filehelpfunctions import read_in_source_file
65
from codeaudit.issuevalidations import find_constructs
@@ -40,7 +39,7 @@ def test_zipfile_extraction():
4039

4140
# This is the expected dictionary
4241
expected_data = {
43-
"zipfile.ZipFile": [8, 13, 17, 23],
42+
"zipfile.ZipFile": [9, 14, 18, 25],
4443
}
4544

4645
# Assert that the actual data matches the expected data
@@ -86,7 +85,7 @@ def test_input_statement():
8685
actual_data = result["result"]
8786

8887
# This is the expected dictionary
89-
expected_data = {"input": [6]}
88+
expected_data = {"input": [7]}
9089

9190
# Assert that the actual data matches the expected data
9291
assert actual_data == expected_data
@@ -104,7 +103,7 @@ def test_marshal_usage():
104103
actual_data = result["result"]
105104

106105
# This is the expected dictionary
107-
expected_data = {"marshal.loads": [30], "marshal.load": [36]}
106+
expected_data = {"marshal.loads": [31], "marshal.load": [37]}
108107

109108
# Assert that the actual data matches the expected data
110109
assert actual_data == expected_data
@@ -124,7 +123,7 @@ def test_tar_methods_use():
124123
actual_data = result["result"]
125124

126125
# This is the expected dictionary
127-
expected_data = {"tarfile.TarFile": [6, 10, 17, 22, 24]}
126+
expected_data = {"tarfile.TarFile": [7, 12, 21, 27, 29]}
128127

129128
# Assert that the actual data matches the expected data
130129
assert actual_data == expected_data

tests/test_correctexceptionuse.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from pathlib import Path
2-
31
import pytest
2+
from pathlib import Path
43

54
from codeaudit.filehelpfunctions import read_in_source_file
65
from codeaudit.issuevalidations import find_constructs
@@ -18,7 +17,7 @@ def test_correct_exception_use():
1817
actual_data = find_constructs(source, constructs)
1918

2019
# This is the expected dictionary
21-
expected_data = {"pass": [19], "continue": [11]}
20+
expected_data = {"pass": [20], "continue": [12]}
2221

2322
# Assert that the actual data matches the expected data
2423
assert actual_data == expected_data

tests/test_directorycreation.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from pathlib import Path
2-
31
import pytest
2+
from pathlib import Path
43

54
from codeaudit.filehelpfunctions import read_in_source_file
65
from codeaudit.issuevalidations import find_constructs
@@ -18,7 +17,7 @@ def test_os_makedirs():
1817
actual_data = find_constructs(source, constructs)
1918

2019
# This is the expected dictionary
21-
expected_data = {"os.makedirs": [10, 79]}
20+
expected_data = {"os.makedirs": [10, 77]}
2221

2322
# Assert that the actual data matches the expected data
2423
assert actual_data == expected_data
@@ -36,7 +35,7 @@ def test_os_mkdir():
3635
actual_data = find_constructs(source, constructs)
3736

3837
# This is the expected dictionary
39-
expected_data = {"os.mkdir": [23]}
38+
expected_data = {"os.mkdir": [22]}
4039

4140
# Assert that the actual data matches the expected data
4241
assert actual_data == expected_data
@@ -54,7 +53,7 @@ def test_os_mkfifo():
5453
actual_data = find_constructs(source, constructs)
5554

5655
# This is the expected dictionary
57-
expected_data = {"os.mkfifo": [45]}
56+
expected_data = {"os.mkfifo": [44]}
5857

5958
# Assert that the actual data matches the expected data
6059
assert actual_data == expected_data
@@ -72,7 +71,7 @@ def test_os_mknod():
7271
actual_data = find_constructs(source, constructs)
7372

7473
# This is the expected dictionary
75-
expected_data = {"os.mknod": [62]}
74+
expected_data = {"os.mknod": [61]}
7675

7776
# Assert that the actual data matches the expected data
7877
assert actual_data == expected_data

tests/test_directorycreation2.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from pathlib import Path
2-
31
import pytest
2+
from pathlib import Path
43

54
from codeaudit.filehelpfunctions import read_in_source_file
65
from codeaudit.issuevalidations import find_constructs
@@ -36,7 +35,7 @@ def test_os_mkdir():
3635
actual_data = find_constructs(source, constructs)
3736

3837
# This is the expected dictionary
39-
expected_data = {"os.mkdir": [26]}
38+
expected_data = {"os.mkdir": [25]}
4039

4140
# Assert that the actual data matches the expected data
4241
assert actual_data == expected_data
@@ -54,7 +53,7 @@ def test_os_mkfifo():
5453
actual_data = find_constructs(source, constructs)
5554

5655
# This is the expected dictionary
57-
expected_data = {"os.mkfifo": [48]}
56+
expected_data = {"os.mkfifo": [47]}
5857

5958
# Assert that the actual data matches the expected data
6059
assert actual_data == expected_data
@@ -72,7 +71,7 @@ def test_os_mknod():
7271
actual_data = find_constructs(source, constructs)
7372

7473
# This is the expected dictionary
75-
expected_data = {"os.mknod": [65]}
74+
expected_data = {"os.mknod": [64]}
7675

7776
# Assert that the actual data matches the expected data
7877
assert actual_data == expected_data
@@ -90,7 +89,7 @@ def test_os_makedirs():
9089
actual_data = find_constructs(source, constructs)
9190

9291
# This is the expected dictionary
93-
expected_data = {"os.makedirs": [13, 82]}
92+
expected_data = {"os.makedirs": [13, 80]}
9493

9594
# Assert that the actual data matches the expected data
9695
assert actual_data == expected_data
@@ -108,7 +107,7 @@ def test_os_makedev():
108107
actual_data = find_constructs(source, constructs)
109108

110109
# This is the expected dictionary
111-
expected_data = {"os.makedev": [94]}
110+
expected_data = {"os.makedev": [92]}
112111

113112
# Assert that the actual data matches the expected data
114113
assert actual_data == expected_data
@@ -125,9 +124,9 @@ def test_sys_calls():
125124

126125
# This is the expected dictionary
127126
expected_data = {
128-
"sys.call_tracing": [12],
129-
"sys.setprofile": [29, 31],
130-
"sys.settrace": [35, 37],
127+
"sys.call_tracing": [15],
128+
"sys.setprofile": [34, 36],
129+
"sys.settrace": [41, 43],
131130
}
132131

133132
# Assert that the actual data matches the expected data

tests/test_edgecases.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
Validation file to see if SAST suppression works correct.
1212
"""
1313

14-
from pathlib import Path
15-
1614
import pytest
15+
from pathlib import Path
1716

1817
from codeaudit.security_checks import perform_validations
1918

@@ -39,8 +38,8 @@ def test_eval():
3938
# This is the expected dictionary
4039
expected_data = {
4140
"exec": [5],
42-
"eval": [8, 11, 12, 13, 21, 23, 26, 28, 30],
43-
"__import__": [30],
41+
"eval": [8, 11, 12, 13, 22, 25, 28, 30, 32],
42+
"__import__": [32],
4443
}
4544

4645
# Assert that the actual data matches the expected data
@@ -79,7 +78,7 @@ def test_eval2():
7978
actual_data = result["result"]
8079

8180
# This is the expected dictionary
82-
expected_data = {"eval": [8]}
81+
expected_data = {"eval": [10]}
8382

8483
# Assert that the actual data matches the expected data
8584
assert actual_data == expected_data

0 commit comments

Comments
 (0)