pre-commit-hooks/tests/detect_private_key_test.py

29 lines
877 B
Python
Raw Permalink Normal View History

from __future__ import annotations
2015-03-07 04:45:32 +08:00
import pytest
from pre_commit_hooks.detect_private_key import main
2015-03-07 04:45:32 +08:00
# Input, expected return value
TESTS = (
(b'-----BEGIN RSA PRIVATE KEY-----', 1),
(b'-----BEGIN DSA PRIVATE KEY-----', 1),
(b'-----BEGIN EC PRIVATE KEY-----', 1),
(b'-----BEGIN OPENSSH PRIVATE KEY-----', 1),
2018-05-19 07:31:16 +08:00
(b'PuTTY-User-Key-File-2: ssh-rsa', 1),
(b'---- BEGIN SSH2 ENCRYPTED PRIVATE KEY ----', 1),
(b'-----BEGIN ENCRYPTED PRIVATE KEY-----', 1),
(b'-----BEGIN OpenVPN Static key V1-----', 1),
2015-03-07 04:45:32 +08:00
(b'ssh-rsa DATA', 0),
(b'ssh-dsa DATA', 0),
# Some arbitrary binary data
(b'\xa2\xf1\x93\x12', 0),
2015-03-07 04:45:32 +08:00
)
@pytest.mark.parametrize(('input_s', 'expected_retval'), TESTS)
def test_main(input_s, expected_retval, tmpdir):
2016-05-28 05:09:50 +08:00
path = tmpdir.join('file.txt')
path.write_binary(input_s)
2020-05-21 00:07:45 +08:00
assert main([str(path)]) == expected_retval