Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 8c20b48

Browse files
committed
Load signatures only once
This was manifesting in tests - if we kept loading signatures, they were being added to the list of signatures, which was causing double matches
1 parent fa9754e commit 8c20b48

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/codegate/pipeline/secrets/signatures.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ def _sanitize_pattern(cls, pattern: str) -> str:
155155
@classmethod
156156
def _add_signature_group(cls, name: str, patterns: Dict[str, str]) -> None:
157157
"""Add a new signature group and compile its regex patterns."""
158+
# Check if this group already exists
159+
if any(group.name == name for group in cls._signature_groups):
160+
logger.debug(f"Signature group {name} already exists, skipping")
161+
return
162+
158163
signature_group = SignatureGroup(name, patterns)
159164

160165
for pattern_name, pattern in patterns.items():

tests/pipeline/secrets/test_signatures.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,26 @@ def test_duplicate_patterns():
167167
assert match.value == "AKIAIOSFODNN7EXAMPLE"
168168
finally:
169169
os.unlink(f.name)
170+
171+
172+
def test_no_duplicate_signature_groups(temp_yaml_file):
173+
"""Test that signature groups aren't added multiple times"""
174+
CodegateSignatures.initialize(temp_yaml_file)
175+
176+
# First load
177+
CodegateSignatures._signatures_loaded = False
178+
CodegateSignatures._load_signatures()
179+
initial_group_count = len(CodegateSignatures._signature_groups)
180+
initial_regex_count = len(CodegateSignatures._compiled_regexes)
181+
182+
# Second load
183+
CodegateSignatures._signatures_loaded = False
184+
CodegateSignatures._load_signatures()
185+
186+
# Verify counts haven't changed
187+
assert len(CodegateSignatures._signature_groups) == initial_group_count
188+
assert len(CodegateSignatures._compiled_regexes) == initial_regex_count
189+
190+
# Verify GitHub group appears only once
191+
github_groups = [g for g in CodegateSignatures._signature_groups if g.name == "GitHub"]
192+
assert len(github_groups) == 1

0 commit comments

Comments
 (0)