-
Notifications
You must be signed in to change notification settings - Fork 738
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #86 : Code refactoring to support unit tests, useful for features
- Loading branch information
Showing
7 changed files
with
172 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: Test | ||
on: push | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- run: pip install -r requirements.txt | ||
- run: pip install -r tests/requirements.txt | ||
- run: pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
tests/ | ||
/.project | ||
/.settings/ | ||
/.pytest_cache/ | ||
/.pydevproject | ||
/**/__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pytest | ||
pytest-mock | ||
pytest-cov | ||
requests-mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import re | ||
import importlib | ||
log4j_scan = importlib.import_module("log4j-scan", package='..') | ||
|
||
|
||
def test_args_required(capsys): | ||
log4j_scan.main([]) | ||
captured = capsys.readouterr() | ||
assert 'Parameter \'-u\' or \'-l\' is required' in captured.out | ||
|
||
|
||
def test_default(requests_mock, capsys): | ||
adapter_dns_register = requests_mock.post('https://interact.sh/register', text='success') | ||
adapter_dns_save = requests_mock.get('https://interact.sh/poll', json={'data': [], 'extra': None, 'aes_key': 'FAKE'}) | ||
adapter_endpoint = requests_mock.get('https://localhost/') | ||
|
||
log4j_scan.main(['-u', 'https://localhost/']) | ||
|
||
captured = capsys.readouterr() | ||
|
||
assert adapter_dns_register.call_count == 1 | ||
assert adapter_endpoint.call_count == 1 | ||
assert adapter_dns_save.call_count == 1 | ||
assert '.interact.sh/' in captured.out | ||
assert 'Targets does not seem to be vulnerable' in captured.out | ||
assert 'jndi' in adapter_endpoint.last_request.url | ||
assert re.match(r'\${jndi:ldap://localhost\..*.interact\.sh/.*}', adapter_endpoint.last_request.headers['User-Agent']) | ||
|