Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a detector for Aiven token #910

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ If you love `detect-secrets`, please star our project on GitHub to show your sup
[@xxxx]: https://github.com/xxxx
-->

<!--
### Unreleased
##### January 14th, 2025
#### :tada: New Features
- Added a detector for Aiven token ([#910])
[#910]: https://github.com/Yelp/detect-secrets/pull/910
-->

### v1.5.0
##### May 6th, 2024

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ $ git ls-files -z | xargs -0 detect-secrets-hook --baseline .secrets.baseline

```bash
$ detect-secrets scan --list-all-plugins
AivenTokenDetector
ArtifactoryDetector
AWSKeyDetector
AzureStorageKeyDetector
Expand Down
16 changes: 16 additions & 0 deletions detect_secrets/plugins/aiven_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
This plugin searches for Aiven tokens
"""
import re

from detect_secrets.plugins.base import RegexBasedDetector


class AivenTokenDetector(RegexBasedDetector):
"""Scans for Aiven tokens."""
secret_type = 'Aiven Token'

denylist = [
# Aiven tokens follow the pattern: AVNS_<alphanumeric and underscores with a minimum length of 8>
re.compile(r'AVNS_[A-Za-z0-9_]{8,}'),
]
24 changes: 24 additions & 0 deletions tests/plugins/aiven_token_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest

from detect_secrets.plugins.aiven_token import AivenTokenDetector


class TestAivenTokenDetector:

@pytest.mark.parametrize(
'payload, should_flag',
[
('AVNS_4Yt6Gdnjcs8ivIlYSFU', True),
('AVNS_D0j9bUsCyQ3s67T', True),
('AVNS_LaGqz39AC', True),
('AVNS_RaFIf_JzHxFXlKs', True),
('AVNS_UahLjsENr4QexJ1', True),
('foo', False),
('AVNS_', False), # Incomplete token
('AVNS12345678', False), # Missing underscore
],
)
def test_analyze(self, payload, should_flag):
logic = AivenTokenDetector()
output = logic.analyze_line(filename='mock_filename', line=payload)
assert len(output) == int(should_flag)