9
9
from detect_secrets .plugins .cloudant import get_host
10
10
11
11
CL_HOST = 'testy_test' # also called user
12
- # only detecting 64 hex
13
- CL_TOKEN = 'abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234'
12
+ # only detecting 64 hex CL generated password
13
+ CL_PW = 'abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234'
14
+
15
+ # detecting 24 alpha for CL generated API KEYS
16
+ CL_API_KEY = 'abcdefghijabcdefghijabcd'
14
17
15
18
16
19
class TestCloudantDetector :
@@ -19,25 +22,42 @@ class TestCloudantDetector:
19
22
'payload, should_flag' ,
20
23
[
21
24
(
22
- 'https://{cl_host}:{cl_token}@{cl_host}.cloudant.com"' .format (
23
- cl_host = CL_HOST , cl_token = CL_TOKEN ,
25
+ 'https://{cl_host}:{cl_pw}@{cl_host}.cloudant.com"' .format (
26
+ cl_host = CL_HOST , cl_pw = CL_PW ,
27
+ ), True ,
28
+ ),
29
+ (
30
+ 'https://{cl_host}:{cl_pw}@{cl_host}.cloudant.com/_api/v2/' .format (
31
+ cl_host = CL_HOST , cl_pw = CL_PW ,
32
+ ), True ,
33
+ ),
34
+ (
35
+ 'https://{cl_host}:{cl_pw}@{cl_host}.cloudant.com/_api/v2/' .format (
36
+ cl_host = CL_HOST , cl_pw = CL_PW ,
37
+ ), True ,
38
+ ),
39
+ (
40
+ 'https://{cl_host}:{cl_pw}@{cl_host}.cloudant.com' .format (
41
+ cl_host = CL_HOST , cl_pw = CL_PW ,
24
42
), True ,
25
43
),
26
44
(
27
- 'https://{cl_host}:{cl_token }@{cl_host}.cloudant.com/_api/v2/ ' .format (
28
- cl_host = CL_HOST , cl_token = CL_TOKEN ,
45
+ 'https://{cl_host}:{cl_api_key }@{cl_host}.cloudant.com' .format (
46
+ cl_host = CL_HOST , cl_api_key = CL_API_KEY ,
29
47
), True ,
30
48
),
31
49
(
32
- 'https://{cl_host}:{cl_token }.cloudant.com' .format (
33
- cl_host = CL_HOST , cl_token = CL_TOKEN ,
50
+ 'https://{cl_host}:{cl_pw }.cloudant.com' .format (
51
+ cl_host = CL_HOST , cl_pw = CL_PW ,
34
52
), False ,
35
53
),
36
- ('cloudant_password=\' {cl_token}\' ' .format (cl_token = CL_TOKEN ), True ),
37
- ('cloudant_pw=\' {cl_token}\' ' .format (cl_token = CL_TOKEN ), True ),
38
- ('cloudant_pw="{cl_token}"' .format (cl_token = CL_TOKEN ), True ),
39
- ('clou_pw = "{cl_token}"' .format (cl_token = CL_TOKEN ), True ),
54
+ ('cloudant_password=\' {cl_pw}\' ' .format (cl_pw = CL_PW ), True ),
55
+ ('cloudant_pw=\' {cl_pw}\' ' .format (cl_pw = CL_PW ), True ),
56
+ ('cloudant_pw="{cl_pw}"' .format (cl_pw = CL_PW ), True ),
57
+ ('clou_pw = "{cl_pw}"' .format (cl_pw = CL_PW ), True ),
58
+ ('cloudant_key = "{cl_api_key}"' .format (cl_api_key = CL_API_KEY ), True ),
40
59
('cloudant_password = "a-fake-tooshort-key"' , False ),
60
+ ('cl_api_key = "a-fake-api-key"' , False ),
41
61
],
42
62
)
43
63
def test_analyze_string (self , payload , should_flag ):
@@ -48,31 +68,31 @@ def test_analyze_string(self, payload, should_flag):
48
68
49
69
@responses .activate
50
70
def test_verify_invalid_secret (self ):
51
- cl_api_url = 'https://{cl_host}:{cl_token }@{cl_host}.cloudant.com/_api/v2 ' .format (
52
- cl_host = CL_HOST , cl_token = CL_TOKEN ,
71
+ cl_api_url = 'https://{cl_host}:{cl_pw }@{cl_host}.cloudant.com' .format (
72
+ cl_host = CL_HOST , cl_pw = CL_PW ,
53
73
)
54
74
responses .add (
55
75
responses .GET , cl_api_url ,
56
- json = {'error' : 'Access denied. ' }, status = 401 ,
76
+ json = {'error' : 'unauthorized ' }, status = 401 ,
57
77
)
58
78
59
79
assert CloudantDetector ().verify (
60
- CL_TOKEN ,
80
+ CL_PW ,
61
81
'cloudant_host={}' .format (CL_HOST ),
62
82
) == VerifiedResult .VERIFIED_FALSE
63
83
64
84
@responses .activate
65
85
def test_verify_valid_secret (self ):
66
- cl_api_url = 'https://{cl_host}:{cl_token }@{cl_host}.cloudant.com/_api/v2 ' .format (
67
- cl_host = CL_HOST , cl_token = CL_TOKEN ,
86
+ cl_api_url = 'https://{cl_host}:{cl_pw }@{cl_host}.cloudant.com' .format (
87
+ cl_host = CL_HOST , cl_pw = CL_PW ,
68
88
)
69
89
responses .add (
70
90
responses .GET , cl_api_url ,
71
91
json = {'id' : 1 }, status = 200 ,
72
92
)
73
- potential_secret = PotentialSecret ('test cloudant' , 'test filename' , CL_TOKEN )
93
+ potential_secret = PotentialSecret ('test cloudant' , 'test filename' , CL_PW )
74
94
assert CloudantDetector ().verify (
75
- CL_TOKEN ,
95
+ CL_PW ,
76
96
'cloudant_host={}' .format (CL_HOST ),
77
97
potential_secret ,
78
98
) == VerifiedResult .VERIFIED_TRUE
@@ -81,13 +101,13 @@ def test_verify_valid_secret(self):
81
101
@responses .activate
82
102
def test_verify_unverified_secret (self ):
83
103
assert CloudantDetector ().verify (
84
- CL_TOKEN ,
104
+ CL_PW ,
85
105
'cloudant_host={}' .format (CL_HOST ),
86
106
) == VerifiedResult .UNVERIFIED
87
107
88
108
def test_verify_no_secret (self ):
89
109
assert CloudantDetector ().verify (
90
- CL_TOKEN ,
110
+ CL_PW ,
91
111
'no_un={}' .format (CL_HOST ),
92
112
) == VerifiedResult .UNVERIFIED
93
113
0 commit comments