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 .cloudant import CloudantDetector
9
- from detect_secrets .plugins .cloudant import find_host
9
+ from detect_secrets .plugins .cloudant import find_account
10
10
11
- CL_HOST = 'testy_test ' # also called user
11
+ CL_ACCOUNT = 'testy_-test ' # also called user
12
12
# only detecting 64 hex CL generated password
13
13
CL_PW = 'abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234'
14
14
@@ -22,33 +22,33 @@ class TestCloudantDetector:
22
22
'payload, should_flag' ,
23
23
[
24
24
(
25
- 'https://{cl_host }:{cl_pw}@{cl_host }.cloudant.com"' .format (
26
- cl_host = CL_HOST , cl_pw = CL_PW ,
25
+ 'https://{cl_account }:{cl_pw}@{cl_account }.cloudant.com"' .format (
26
+ cl_account = CL_ACCOUNT , cl_pw = CL_PW ,
27
27
), True ,
28
28
),
29
29
(
30
- 'https://{cl_host }:{cl_pw}@{cl_host }.cloudant.com/_api/v2/' .format (
31
- cl_host = CL_HOST , cl_pw = CL_PW ,
30
+ 'https://{cl_account }:{cl_pw}@{cl_account }.cloudant.com/_api/v2/' .format (
31
+ cl_account = CL_ACCOUNT , cl_pw = CL_PW ,
32
32
), True ,
33
33
),
34
34
(
35
- 'https://{cl_host }:{cl_pw}@{cl_host }.cloudant.com/_api/v2/' .format (
36
- cl_host = CL_HOST , cl_pw = CL_PW ,
35
+ 'https://{cl_account }:{cl_pw}@{cl_account }.cloudant.com/_api/v2/' .format (
36
+ cl_account = CL_ACCOUNT , cl_pw = CL_PW ,
37
37
), True ,
38
38
),
39
39
(
40
- 'https://{cl_host }:{cl_pw}@{cl_host }.cloudant.com' .format (
41
- cl_host = CL_HOST , cl_pw = CL_PW ,
40
+ 'https://{cl_account }:{cl_pw}@{cl_account }.cloudant.com' .format (
41
+ cl_account = CL_ACCOUNT , cl_pw = CL_PW ,
42
42
), True ,
43
43
),
44
44
(
45
- 'https://{cl_host }:{cl_api_key}@{cl_host }.cloudant.com' .format (
46
- cl_host = CL_HOST , cl_api_key = CL_API_KEY ,
45
+ 'https://{cl_account }:{cl_api_key}@{cl_account }.cloudant.com' .format (
46
+ cl_account = CL_ACCOUNT , cl_api_key = CL_API_KEY ,
47
47
), True ,
48
48
),
49
49
(
50
- 'https://{cl_host }:{cl_pw}.cloudant.com' .format (
51
- cl_host = CL_HOST , cl_pw = CL_PW ,
50
+ 'https://{cl_account }:{cl_pw}.cloudant.com' .format (
51
+ cl_account = CL_ACCOUNT , cl_pw = CL_PW ,
52
52
), False ,
53
53
),
54
54
('cloudant_password=\' {cl_pw}\' ' .format (cl_pw = CL_PW ), True ),
@@ -68,8 +68,8 @@ def test_analyze_string(self, payload, should_flag):
68
68
69
69
@responses .activate
70
70
def test_verify_invalid_secret (self ):
71
- cl_api_url = 'https://{cl_host }:{cl_pw}@{cl_host }.cloudant.com' .format (
72
- cl_host = CL_HOST , cl_pw = CL_PW ,
71
+ cl_api_url = 'https://{cl_account }:{cl_pw}@{cl_account }.cloudant.com' .format (
72
+ cl_account = CL_ACCOUNT , cl_pw = CL_PW ,
73
73
)
74
74
responses .add (
75
75
responses .GET , cl_api_url ,
@@ -78,13 +78,13 @@ def test_verify_invalid_secret(self):
78
78
79
79
assert CloudantDetector ().verify (
80
80
CL_PW ,
81
- 'cloudant_host={}' .format (CL_HOST ),
81
+ 'cloudant_host={}' .format (CL_ACCOUNT ),
82
82
) == VerifiedResult .VERIFIED_FALSE
83
83
84
84
@responses .activate
85
85
def test_verify_valid_secret (self ):
86
- cl_api_url = 'https://{cl_host }:{cl_pw}@{cl_host }.cloudant.com' .format (
87
- cl_host = CL_HOST , cl_pw = CL_PW ,
86
+ cl_api_url = 'https://{cl_account }:{cl_pw}@{cl_account }.cloudant.com' .format (
87
+ cl_account = CL_ACCOUNT , cl_pw = CL_PW ,
88
88
)
89
89
responses .add (
90
90
responses .GET , cl_api_url ,
@@ -93,22 +93,22 @@ def test_verify_valid_secret(self):
93
93
potential_secret = PotentialSecret ('test cloudant' , 'test filename' , CL_PW )
94
94
assert CloudantDetector ().verify (
95
95
CL_PW ,
96
- 'cloudant_host={}' .format (CL_HOST ),
96
+ 'cloudant_host={}' .format (CL_ACCOUNT ),
97
97
potential_secret ,
98
98
) == VerifiedResult .VERIFIED_TRUE
99
- assert potential_secret .other_factors ['hostname' ] == CL_HOST
99
+ assert potential_secret .other_factors ['hostname' ] == CL_ACCOUNT
100
100
101
101
@responses .activate
102
102
def test_verify_unverified_secret (self ):
103
103
assert CloudantDetector ().verify (
104
104
CL_PW ,
105
- 'cloudant_host={}' .format (CL_HOST ),
105
+ 'cloudant_host={}' .format (CL_ACCOUNT ),
106
106
) == VerifiedResult .UNVERIFIED
107
107
108
108
def test_verify_no_secret (self ):
109
109
assert CloudantDetector ().verify (
110
110
CL_PW ,
111
- 'no_un={}' .format (CL_HOST ),
111
+ 'no_un={}' .format (CL_ACCOUNT ),
112
112
) == VerifiedResult .UNVERIFIED
113
113
114
114
@pytest .mark .parametrize (
@@ -118,19 +118,19 @@ def test_verify_no_secret(self):
118
118
textwrap .dedent ("""
119
119
--cloudant-hostname = {}
120
120
""" )[1 :- 1 ].format (
121
- CL_HOST ,
121
+ CL_ACCOUNT ,
122
122
),
123
- [CL_HOST ],
123
+ [CL_ACCOUNT ],
124
124
),
125
125
126
126
# With quotes
127
127
(
128
128
textwrap .dedent ("""
129
- cl_host = "{}"
129
+ cl_account = "{}"
130
130
""" )[1 :- 1 ].format (
131
- CL_HOST ,
131
+ CL_ACCOUNT ,
132
132
),
133
- [CL_HOST ],
133
+ [CL_ACCOUNT ],
134
134
),
135
135
136
136
# multiple candidates
@@ -141,19 +141,33 @@ def test_verify_no_secret(self):
141
141
CLOUDANT_USERID = '{}'
142
142
cloudant-uname: {}
143
143
""" )[1 :- 1 ].format (
144
- CL_HOST ,
144
+ CL_ACCOUNT ,
145
145
'test2_testy_test' ,
146
146
'test3-testy-testy' ,
147
147
'notanemail' ,
148
148
),
149
149
[
150
- CL_HOST ,
150
+ CL_ACCOUNT ,
151
151
'test2_testy_test' ,
152
152
'test3-testy-testy' ,
153
153
'notanemail' ,
154
154
],
155
155
),
156
+
157
+ # In URL
158
+ (
159
+ 'https://{cl_account}:{cl_api_key}@{cl_account}.cloudant.com' .format (
160
+ cl_account = CL_ACCOUNT , cl_api_key = CL_API_KEY ,
161
+ ),
162
+ [CL_ACCOUNT ],
163
+ ),
164
+ (
165
+ 'https://{cl_account}.cloudant.com' .format (
166
+ cl_account = CL_ACCOUNT ,
167
+ ),
168
+ [CL_ACCOUNT ],
169
+ ),
156
170
),
157
171
)
158
- def test_find_host (self , content , expected_output ):
159
- assert find_host (content ) == expected_output
172
+ def test_find_account (self , content , expected_output ):
173
+ assert find_account (content ) == expected_output
0 commit comments