Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cbc27ae

Browse files
authored
Merge pull request #136 from omergunal/patch-5
Tests for 'discover_files' , updated Changelog, added -r and targets usage on README
2 parents e9e863a + 3c4d773 commit cbc27ae

3 files changed

Lines changed: 65 additions & 43 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,25 @@ If you love PyT, please star our project on GitHub to show your support! :star:
2222
[@xxxx]: https://github.com/xxxx
2323
-->
2424

25-
# 0.34
26-
##### April 24, 2018
25+
# 0.35
26+
##### July 1, 2018
2727

2828
#### :tada: New Features
2929

30-
* Baseline support ([#106], thanks [@omergunal])
30+
* Recursive option ([#129], [@omergunal])
3131

32-
[#106]: https://github.com/python-security/pyt/pull/106
3332
[@omergunal]: https://github.com/omergunal
34-
35-
#### :sparkles: Usability
36-
* Combined all source/sink information files and made it the default ([#116])
37-
38-
#### :telescope: Precision
39-
* Fixed a bug where `Post.query.paginate` propagated taint ([#115])
40-
* Fixed a false-positive where `self` was marked as taint ([#119], thanks [@lFatty])
33+
[#129]: https://github.com/python-security/pyt/pull/129
4134

4235
#### :bug: Bugfixes
43-
* Fixed a bug where `visit_Raise` raised a `TypeError` ([#117], thanks [@lFatty])
44-
* Fixed an infinite loop bug that was caused while handling certain loops ([#118])
45-
* Fixed a bug where we were not including `pyt/vulnerability_definitions` files ([#122], thanks [@Ekultek])
36+
* Fixed flake8 errors ([#130])
4637

4738
#### :snake: Miscellaneous
4839

49-
* Moved out a bunch of historical files to the [ReadTheDocs repo](https://github.com/KevinHock/rtdpyt) ([#110], [#111])
40+
* Re organize code ([#126])
41+
* Cleaned up pyt/core/ ([#132])
5042

51-
[#116]: https://github.com/python-security/pyt/pull/116
43+
[#126]: https://github.com/python-security/pyt/pull/129
5244
[#115]: https://github.com/python-security/pyt/pull/115
53-
[#119]: https://github.com/python-security/pyt/pull/119
54-
[#117]: https://github.com/python-security/pyt/pull/117
55-
[#118]: https://github.com/python-security/pyt/pull/118
56-
[#111]: https://github.com/python-security/pyt/pull/111
57-
[#110]: https://github.com/python-security/pyt/pull/110
58-
[@lfatty]: https://github.com/lfatty
59-
[#122]: https://github.com/python-security/pyt/issues/122
60-
[@Ekultek]: https://github.com/Ekultek
45+
[#130]: https://github.com/python-security/pyt/pull/130
46+
[#132]: https://github.com/python-security/pyt/pull/132

README.rst

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,44 +63,48 @@ Usage
6363

6464
.. code-block::
6565
66-
usage: python -m pyt [-h] [-f FILEPATH] [-a ADAPTOR] [-pr PROJECT_ROOT]
67-
[-b BASELINE_JSON_FILE] [-j] [-m BLACKBOX_MAPPING_FILE]
68-
[-t TRIGGER_WORD_FILE] [-o OUTPUT_FILE] [-trim] [-i]
66+
usage: python -m pyt [-h] [-a ADAPTOR] [-pr PROJECT_ROOT]
67+
[-b BASELINE_JSON_FILE] [-j] [-m BLACKBOX_MAPPING_FILE]
68+
[-t TRIGGER_WORD_FILE] [-o OUTPUT_FILE] [--ignore-nosec]
69+
[-r] [-x EXCLUDED_PATHS] [-trim] [-i]
70+
targets [targets ...]
6971
7072
required arguments:
71-
-f FILEPATH, --filepath FILEPATH
72-
Path to the file that should be analysed.
73+
targets source file(s) or directory(s) to be tested
7374
7475
optional arguments:
7576
-a ADAPTOR, --adaptor ADAPTOR
76-
Choose a web framework adaptor: Flask(Default),
77-
Django, Every or Pylons
77+
Choose a web framework adaptor: Flask(Default),
78+
Django, Every or Pylons
7879
-pr PROJECT_ROOT, --project-root PROJECT_ROOT
79-
Add project root, only important when the entry file
80-
is not at the root of the project.
80+
Add project root, only important when the entry file
81+
is not at the root of the project.
8182
-b BASELINE_JSON_FILE, --baseline BASELINE_JSON_FILE
82-
Path of a baseline report to compare against (only
83-
JSON-formatted files are accepted)
83+
Path of a baseline report to compare against (only
84+
JSON-formatted files are accepted)
8485
-j, --json Prints JSON instead of report.
8586
-m BLACKBOX_MAPPING_FILE, --blackbox-mapping-file BLACKBOX_MAPPING_FILE
86-
Input blackbox mapping file.
87+
Input blackbox mapping file.
8788
-t TRIGGER_WORD_FILE, --trigger-word-file TRIGGER_WORD_FILE
88-
Input file with a list of sources and sinks
89+
Input file with a list of sources and sinks
8990
-o OUTPUT_FILE, --output OUTPUT_FILE
90-
write report to filename
91+
write report to filename
9192
--ignore-nosec do not skip lines with # nosec comments
93+
-r, --recursive find and process files in subdirectories
94+
-x EXCLUDED_PATHS, --exclude EXCLUDED_PATHS
95+
Separate files with commas
9296
9397
print arguments:
9498
-trim, --trim-reassigned-in
95-
Trims the reassigned list to just the vulnerability
96-
chain.
99+
Trims the reassigned list to just the vulnerability
100+
chain.
97101
-i, --interactive Will ask you about each blackbox function call in
98-
vulnerability chains.
102+
vulnerability chains.
99103
100104
Usage from Source
101105
=================
102106

103-
Using it like a user ``python3 -m pyt -f example/vulnerable_code/XSS_call.py save -du``
107+
Using it like a user ``python3 -m pyt examples/vulnerable_code/XSS_call.py``
104108

105109
Running the tests ``python3 -m tests``
106110

tests/main_test.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import mock
22

33
from .base_test_case import BaseTestCase
4-
from pyt.__main__ import main
4+
from pyt.__main__ import discover_files, main
55

66

77
class MainTest(BaseTestCase):
@@ -60,3 +60,35 @@ def test_json_output(self, mock_json, mock_find_vulnerabilities, mock_parse_args
6060
mock_find_vulnerabilities.return_value,
6161
mock_parse_args.return_value.output_file
6262
)
63+
64+
65+
class MainTest(BaseTestCase):
66+
def test_targets_with_no_excluded(self):
67+
targets = ["examples/vulnerable_code/inter_command_injection.py"]
68+
excluded_files = ""
69+
70+
included_files = discover_files(targets, excluded_files)
71+
expected = ["examples/vulnerable_code/inter_command_injection.py"]
72+
self.assertListEqual(included_files, expected)
73+
74+
def test_targets_with_exluded(self):
75+
targets = ["examples/vulnerable_code/inter_command_injection.py"]
76+
excluded_files = "examples/vulnerable_code/inter_command_injection.py"
77+
78+
included_files = discover_files(targets, excluded_files)
79+
expected = []
80+
self.assertListEqual(included_files, expected)
81+
82+
def test_targets_with_recursive(self):
83+
targets = ["examples/vulnerable_code/"]
84+
excluded_files = ""
85+
86+
included_files = discover_files(targets, excluded_files, True)
87+
self.assertEqual(len(included_files), 30)
88+
89+
def test_targets_with_recursive_and_excluded(self):
90+
targets = ["examples/vulnerable_code/"]
91+
excluded_files = "inter_command_injection.py"
92+
93+
included_files = discover_files(targets, excluded_files, True)
94+
self.assertEqual(len(included_files), 29)

0 commit comments

Comments
 (0)