-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for new plugin: Email Address
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 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,60 @@ | ||
import pytest | ||
from detect_secrets.plugins.email_address import EmailAddressDetector | ||
|
||
|
||
class TestEmailAddressDetector: | ||
""" | ||
Testing strategy | ||
Cover the cartesian product of these partitions: | ||
1. Partition on email address format: | ||
a. Valid email addresses | ||
b. Invalid email addresses | ||
2. Partition on line content: | ||
a. email address is the only content | ||
b. email address is part of a larger string | ||
And cover these cases: | ||
1. Partition on whitelist email addresses: | ||
a. email address is in the whitelist | ||
b. email address is not in the whitelist | ||
""" | ||
|
||
@pytest.mark.parametrize( | ||
'payload, should_flag', | ||
[ | ||
# Valid email addresses, only content | ||
('[email protected]', True), | ||
('[email protected]', True), | ||
('[email protected]', True), | ||
('[email protected]', True), | ||
('[email protected]', True), | ||
('user@ex_ample.com', True), | ||
('[email protected]', True), | ||
('[email protected]', True), | ||
('[email protected]', True), | ||
# Valid email addresses, part of larger string | ||
('This is an email address: [email protected]', True), | ||
('[email protected] is a valid email address', True), | ||
# Invalid email addresses | ||
('user@com', False), | ||
('@example.com', False), | ||
('[email protected]', False), | ||
('[email protected]', False), | ||
# Whitelist email addresses | ||
('[email protected]', False), | ||
('[email protected]', False), | ||
# Non-whitelist email addresses | ||
('[email protected]', True), | ||
('[email protected]', True), | ||
('[email protected]', True), | ||
], | ||
) | ||
def test_analyze_line(self, payload, should_flag): | ||
logic = EmailAddressDetector() | ||
|
||
output = logic.analyze_line(filename='mock_filename', line=payload) | ||
assert len(output) == int(should_flag) |