mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 11:36:54 +00:00
Detect OpenSSH private keys
This commit is contained in:
parent
9d1ac3273b
commit
68a7729327
5 changed files with 64 additions and 0 deletions
23
tests/detect_private_key_test.py
Normal file
23
tests/detect_private_key_test.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import os.path
|
||||
|
||||
import pytest
|
||||
|
||||
from pre_commit_hooks.detect_private_key import detect_private_key
|
||||
|
||||
# Input, expected return value
|
||||
TESTS = (
|
||||
(b'-----BEGIN RSA PRIVATE KEY-----', 1),
|
||||
(b'-----BEGIN DSA PRIVATE KEY-----', 1),
|
||||
(b'ssh-rsa DATA', 0),
|
||||
(b'ssh-dsa DATA', 0),
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(('input_s', 'expected_retval'), TESTS)
|
||||
def test_detect_private_key(input_s, expected_retval, tmpdir):
|
||||
path = os.path.join(tmpdir.strpath, 'file.txt')
|
||||
|
||||
with open(path, 'wb') as file_obj:
|
||||
file_obj.write(input_s)
|
||||
|
||||
assert detect_private_key([path]) == expected_retval
|
||||
Loading…
Add table
Add a link
Reference in a new issue