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