Skip to content

Commit c2216cc

Browse files
jguerreiroJguer
authored andcommitted
feat(public_api): include validity in scan output
1 parent c285c5d commit c2216cc

File tree

3 files changed

+121
-2
lines changed

3 files changed

+121
-2
lines changed

pygitguardian/models.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ def __repr__(self) -> str:
196196
class PolicyBreakSchema(BaseSchema):
197197
break_type = fields.String(data_key="type", required=True)
198198
policy = fields.String(required=True)
199+
validity = fields.String(required=False, load_default=None, dump_default=None)
199200
matches = fields.List(fields.Nested(MatchSchema), required=True)
200201

201202
@post_load
@@ -214,11 +215,17 @@ class PolicyBreak(Base):
214215
SCHEMA = PolicyBreakSchema()
215216

216217
def __init__(
217-
self, break_type: str, policy: str, matches: List[Match], **kwargs: Any
218+
self,
219+
break_type: str,
220+
policy: str,
221+
validity: Optional[str],
222+
matches: List[Match],
223+
**kwargs: Any,
218224
) -> None:
219225
super().__init__()
220226
self.break_type = break_type
221227
self.policy = policy
228+
self.validity = validity
222229
self.matches = matches
223230

224231
@property

tests/cassettes/secret_validity.yaml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
interactions:
2+
- request:
3+
body:
4+
'{"document": "\n import urllib.request\n url = ''http://jen_barber:[email protected]/isreal.json''\n response
5+
= urllib.request.urlopen(url)\n consume(response.read())\"\n"}'
6+
headers:
7+
Accept:
8+
- '*/*'
9+
Accept-Encoding:
10+
- gzip, deflate
11+
Connection:
12+
- keep-alive
13+
Content-Length:
14+
- '211'
15+
Content-Type:
16+
- application/json
17+
User-Agent:
18+
- pygitguardian/1.1.0 (Linux;py3.8.3)
19+
method: POST
20+
uri: https://api.gitguardian.com/v1/scan
21+
response:
22+
body:
23+
string:
24+
'{"policy_break_count":1,"policies":["Secrets detection","File extensions","Filenames"],"policy_breaks":[{"type":"Basic
25+
Auth String","policy":"Secrets detection","validity":"valid","matches":[{"type":"username","match":"jen_barber","index_start":40,"index_end":49,"line_start":2,"line_end":2},{"type":"password","match":"correcthorsebatterystaple","index_start":51,"index_end":75,"line_start":2,"line_end":2},{"type":"host","match":"cake.gitguardian.com","index_start":77,"index_end":96,"line_start":2,"line_end":2}]}]}'
26+
headers:
27+
Allow:
28+
- OPTIONS, POST
29+
Connection:
30+
- keep-alive
31+
Content-Length:
32+
- '499'
33+
Content-Type:
34+
- application/json
35+
Date:
36+
- Fri, 19 Jun 2020 13:32:51 GMT
37+
Server:
38+
- nginx
39+
Vary:
40+
- Cookie
41+
X-Content-Type-Options:
42+
- nosniff
43+
X-Frame-Options:
44+
- DENY
45+
X-App-Version:
46+
- 1.26.0-rc.4
47+
X-Secrets-Engine-Version:
48+
- 2.43.0
49+
status:
50+
code: 200
51+
message: OK
52+
- request:
53+
body:
54+
'{"document": "\n import urllib.request\n url = ''http://jen_barber:[email protected]/isreal.json''\n response
55+
= urllib.request.urlopen(url)\n consume(response.read())\"\n"}'
56+
headers:
57+
Accept:
58+
- '*/*'
59+
Accept-Encoding:
60+
- gzip, deflate
61+
Connection:
62+
- keep-alive
63+
Content-Length:
64+
- '211'
65+
Content-Type:
66+
- application/json
67+
User-Agent:
68+
- pygitguardian/1.1.0 (Linux;py3.8.3)
69+
method: POST
70+
uri: https://api.gitguardian.com/v1/scan
71+
response:
72+
body:
73+
string:
74+
'{"policy_break_count":1,"policies":["Secrets detection","File extensions","Filenames"],"policy_breaks":[{"type":"Basic
75+
Auth String","policy":"Secrets detection","matches":[{"type":"username","match":"jen_barber","index_start":40,"index_end":49,"line_start":2,"line_end":2},{"type":"password","match":"correcthorsebatterystaple","index_start":51,"index_end":75,"line_start":2,"line_end":2},{"type":"host","match":"cake.gitguardian.com","index_start":77,"index_end":96,"line_start":2,"line_end":2}]}]}'
76+
headers:
77+
Allow:
78+
- OPTIONS, POST
79+
Connection:
80+
- keep-alive
81+
Content-Length:
82+
- '499'
83+
Content-Type:
84+
- application/json
85+
Date:
86+
- Fri, 19 Jun 2020 14:58:41 GMT
87+
Server:
88+
- nginx
89+
Vary:
90+
- Cookie
91+
X-Content-Type-Options:
92+
- nosniff
93+
X-Frame-Options:
94+
- DENY
95+
X-App-Version:
96+
- 1.26.0-rc.4
97+
X-Secrets-Engine-Version:
98+
- 2.43.0
99+
status:
100+
code: 200
101+
message: OK
102+
version: 1

tests/test_client.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,17 @@ def test_content_not_ok():
418418
True,
419419
id="filename_secret",
420420
),
421-
pytest.param("secret", {"document": DOCUMENT}, 1, True, True, id="secret"),
421+
pytest.param(
422+
"secret", {"document": DOCUMENT}, 1, True, True, id="secret (deprecated)"
423+
),
424+
pytest.param(
425+
"secret_validity",
426+
{"document": DOCUMENT},
427+
1,
428+
True,
429+
True,
430+
id="secret with validity",
431+
),
422432
pytest.param(
423433
"filename",
424434
{"filename": FILENAME, "document": "normal"},

0 commit comments

Comments
 (0)