Skip to content

Commit

Permalink
Add tests for new plugin: Email Address
Browse files Browse the repository at this point in the history
  • Loading branch information
perryzjc committed May 16, 2023
1 parent 44095a0 commit 4162cc1
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/plugins/email_address_test.py
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)

0 comments on commit 4162cc1

Please sign in to comment.