File tree Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Expand file tree Collapse file tree 2 files changed +24
-6
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,15 @@ def get_secret_access_keys(content):
51
51
]
52
52
53
53
54
- def verify_aws_secret_access_key (key , secret ): # pragma: no cover
54
+ def verify_aws_secret_access_key (key , secret ):
55
+ response = get_caller_info (key , secret )
56
+ if response .status_code == 403 :
57
+ return False
58
+
59
+ return True
60
+
61
+
62
+ def get_caller_info (key , secret ): # pragma: no cover
55
63
"""
56
64
Using requests, because we don't want to require boto3 for this one
57
65
optional verification step.
@@ -170,10 +178,7 @@ def verify_aws_secret_access_key(key, secret): # pragma: no cover
170
178
data = body ,
171
179
)
172
180
173
- if response .status_code == 403 :
174
- return False
175
-
176
- return True
181
+ return response
177
182
178
183
179
184
def _sign (key , message , hex = False ): # pragma: no cover
Original file line number Diff line number Diff line change 6
6
from detect_secrets .core .constants import VerifiedResult
7
7
from detect_secrets .core .potential_secret import PotentialSecret
8
8
from detect_secrets .plugins .aws import AWSKeyDetector
9
- from detect_secrets .plugins .aws import get_secret_access_keys
9
+ from detect_secrets .plugins .aws import get_secret_access_key
10
+ from detect_secrets .plugins .aws import verify_aws_secret_access_key
10
11
from testing .mocks import mock_file_object
11
12
12
13
@@ -101,6 +102,18 @@ def counter(*args, **kwargs):
101
102
) == VerifiedResult .VERIFIED_TRUE
102
103
assert potential_secret .other_factors ['secret_access_key' ] == EXAMPLE_SECRET
103
104
105
+ @mock .patch ('detect_secrets.plugins.aws.get_caller_info' )
106
+ def test_verify_aws_secret_access_key_valid (self , mock_get_caller_info ):
107
+ mock_get_caller_info .return_value = mock .MagicMock (status_code = 200 )
108
+ result = verify_aws_secret_access_key ('test-access-key' , 'test-secret-access-key' )
109
+ assert result is True
110
+
111
+ @mock .patch ('detect_secrets.plugins.aws.get_caller_info' )
112
+ def test_verify_aws_secret_access_key_invalid (self , mock_get_caller_info ):
113
+ mock_get_caller_info .return_value = mock .MagicMock (status_code = 403 )
114
+ result = verify_aws_secret_access_key ('test-access-key' , 'test-secret-access-key' )
115
+ assert result is False
116
+
104
117
105
118
@pytest .mark .parametrize (
106
119
'content, expected_output' ,
You can’t perform that action at this time.
0 commit comments