2022-01-16 08:24:05 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2015-03-07 04:45:32 +08:00
|
|
|
import pytest
|
|
|
|
|
2019-02-01 11:19:10 +08:00
|
|
|
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),
|
2015-08-02 07:59:21 +08:00
|
|
|
(b'-----BEGIN EC PRIVATE KEY-----', 1),
|
2016-12-27 02:09:53 +08:00
|
|
|
(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),
|
2021-10-03 03:33:35 +08:00
|
|
|
(b'-----BEGIN ENCRYPTED PRIVATE KEY-----', 1),
|
2021-10-03 03:42:15 +08:00
|
|
|
(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),
|
2015-06-12 04:28:10 +08:00
|
|
|
# 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)
|
2019-02-01 11:19:10 +08:00
|
|
|
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
|