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