mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-04 19:26:52 +00:00
detect_gcp_credentials hook
This commit is contained in:
parent
b73acb198e
commit
e0c61d89d0
929 changed files with 311695 additions and 0 deletions
22
tests/test_detect_gcp_credentials.py
Normal file
22
tests/test_detect_gcp_credentials.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch, mock_open
|
||||
|
||||
from pre_commit_hooks.detect_gcp_credentials import detect_gcp_credentials_in_file
|
||||
|
||||
|
||||
class TestDetect(unittest.TestCase):
|
||||
|
||||
@patch('builtins.open', mock_open(read_data="Some content with GCP credentials: 'AIzaSyCzQ2rBq4dd8uf4Gh9J7G1IiCvC5q8oCvk'"))
|
||||
def test_detect_gcp_api_key(self):
|
||||
result = detect_gcp_credentials_in_file('')
|
||||
self.assertIn("AIzaSyCzQ2rBq4dd8uf4Gh9J7G1IiCvC5q8oCvk", result)
|
||||
|
||||
@patch('builtins.open', mock_open(read_data="Some content with GCP credentials: '-----BEGIN PRIVATE KEY-----\nAbCdEf1234567890\n-----END PRIVATE KEY-----'"))
|
||||
def test_detect_gcp_service_account_key(self):
|
||||
result = detect_gcp_credentials_in_file('')
|
||||
self.assertIn("-----BEGIN PRIVATE KEY-----\nAbCdEf1234567890\n-----END PRIVATE KEY-----", result)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue