forked from Samsung/CredSweeper
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'auxiliary' into structures
- Loading branch information
Showing
5 changed files
with
81 additions
and
40 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,47 @@ | ||
from typing import List | ||
|
||
import pytest | ||
|
||
from credsweeper.file_handler.analysis_target import AnalysisTarget | ||
from credsweeper.file_handler.string_content_provider import StringContentProvider | ||
|
||
|
||
class TestStringContentProvider: | ||
|
||
@pytest.mark.parametrize("lines", [["line one", "password='in_line_2'"]]) | ||
def test_get_analysis_target_p(self, lines: List[str]) -> None: | ||
def test_get_analysis_target_p(self) -> None: | ||
"""Evaluate that lines data correctly extracted from file""" | ||
lines = ["line one", "password='in_line_2'"] | ||
content_provider = StringContentProvider(lines) | ||
analysis_targets = content_provider.get_analysis_target() | ||
|
||
assert len(analysis_targets) == len(lines) | ||
|
||
expected_target = AnalysisTarget(lines[0], 1, lines, "", "", "") | ||
assert analysis_targets[0] == expected_target | ||
# check second target and line numeration | ||
expected_target = AnalysisTarget(lines[1], 2, lines, "", "", "") | ||
assert analysis_targets[1] == expected_target | ||
|
||
assert len(analysis_targets) == len(lines) | ||
# specific line numeration | ||
content_provider = StringContentProvider(lines, [42, -1]) | ||
analysis_targets = content_provider.get_analysis_target() | ||
assert analysis_targets[0].line_num == 42 | ||
assert analysis_targets[1].line_num == -1 | ||
|
||
target = analysis_targets[0] | ||
assert target == expected_target | ||
def test_get_analysis_target_n(self) -> None: | ||
"""Negative cases check""" | ||
# empty list | ||
content_provider = StringContentProvider([]) | ||
analysis_targets = content_provider.get_analysis_target() | ||
assert len(analysis_targets) == 0 | ||
|
||
# mismatched amount of lists | ||
content_provider = StringContentProvider(["a", "b", "c"], [2, 3]) | ||
analysis_targets = content_provider.get_analysis_target() | ||
assert len(analysis_targets) == 3 | ||
assert analysis_targets[0].line_num == 1 | ||
assert analysis_targets[1].line_num == 2 | ||
assert analysis_targets[2].line_num == 3 | ||
|
||
content_provider = StringContentProvider(["a", "b", "c"], [5, 3, 4, 5]) | ||
analysis_targets = content_provider.get_analysis_target() | ||
assert len(analysis_targets) == 3 | ||
assert analysis_targets[0].line_num == 1 | ||
assert analysis_targets[1].line_num == 2 | ||
assert analysis_targets[2].line_num == 3 |