Skip to content

Commit 35a59e7

Browse files
authored
Merge pull request #137 from GitGuardian/agateau/update-cassettes
Fix tests to pass without cassettes
2 parents 445f190 + a7661ea commit 35a59e7

File tree

4 files changed

+51
-263
lines changed

4 files changed

+51
-263
lines changed

tests/cassettes/filename.yaml

-65
This file was deleted.

tests/cassettes/filename_secret.yaml

-68
This file was deleted.

tests/cassettes/with_breaks.yaml

+30-41
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
interactions:
22
- request:
3-
body: '[{"filename": ".env", "document": "\n import urllib.request\n url
4-
= ''http://jen_barber:[email protected]/isreal.json''\n response
5-
= urllib.request.urlopen(url)\n consume(response.read())\"\n"}, {"document":
6-
"\n import urllib.request\n url = ''http://jen_barber:[email protected]/isreal.json''\n response
3+
body:
4+
'[{"document": "\n import urllib.request\n url = ''http://jen_barber:[email protected]/isreal.json''\n response
75
= urllib.request.urlopen(url)\n consume(response.read())\"\n"}, {"filename":
86
"normal", "document": "normal"}]'
97
headers:
@@ -14,63 +12,54 @@ interactions:
1412
Connection:
1513
- keep-alive
1614
Content-Length:
17-
- '492'
15+
- '259'
1816
Content-Type:
1917
- application/json
2018
User-Agent:
21-
- pygitguardian/1.3.4 (Linux;py3.8.10)
19+
- pygitguardian/1.19.0 (Linux;py3.10.12)
2220
method: POST
2321
uri: https://api.gitguardian.com/v1/multiscan
2422
response:
2523
body:
2624
string:
27-
'[{"policy_break_count":2,"policies":["File extensions","Filenames","Secrets
28-
detection"],"policy_breaks":[{"type":".env","policy":"Filenames","matches":[{"type":"filename","match":".env"}]},{"type":"Basic
29-
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}],"validity":"no_checker"}]},{"policy_break_count":1,"policies":["File
30-
extensions","Filenames","Secrets detection"],"policy_breaks":[{"type":"Basic
31-
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}],"validity":"no_checker"}]},{"policy_break_count":0,"policies":["File
32-
extensions","Filenames","Secrets detection"],"policy_breaks":[]}]'
25+
'[{"policy_break_count":1,"policies":["Secrets detection"],"policy_breaks":[{"type":"Basic
26+
Auth String","policy":"Secrets detection","matches":[{"type":"username","match":"jen_barber","index_start":45,"index_end":54,"line_start":3,"line_end":3},{"type":"password","match":"correcthorsebatterystaple","index_start":56,"index_end":80,"line_start":3,"line_end":3},{"type":"host","match":"cake.gitguardian.com","index_start":82,"index_end":101,"line_start":3,"line_end":3}],"is_excluded":false,"exclude_reason":null,"incident_url":"https://dashboard.gitguardian.com/workspace/8/incidents/10114685","known_secret":true,"validity":"no_checker","diff_kind":null}],"is_diff":false},{"policy_break_count":0,"policies":["Secrets
27+
detection"],"policy_breaks":[],"is_diff":false}]'
3328
headers:
34-
Access-Control-Expose-Headers:
29+
access-control-expose-headers:
3530
- X-App-Version
36-
Allow:
31+
allow:
3732
- POST, OPTIONS
38-
Connection:
39-
- keep-alive
40-
Content-Type:
33+
content-length:
34+
- '766'
35+
content-type:
4136
- application/json
42-
Date:
43-
- Thu, 30 Jun 2022 10:29:32 GMT
44-
Referrer-Policy:
37+
cross-origin-opener-policy:
38+
- same-origin
39+
date:
40+
- Mon, 24 Feb 2025 12:49:30 GMT
41+
referrer-policy:
4542
- strict-origin-when-cross-origin
46-
Server:
47-
- nginx
48-
Set-Cookie:
49-
- AWSALB=0NfNYw3UeyBFpnge2V9Eg/1mGjFw092I9Sz6A9XTSEcEwwY9QOaglYydWG0j9lP08vyA+Lbr2GKW5wEsC4ps3gWBR4xR/t2cWAZs9ce2iFiqaodevlC5KyXGb6kC;
50-
Expires=Thu, 07 Jul 2022 10:29:32 GMT; Path=/
51-
- AWSALBCORS=0NfNYw3UeyBFpnge2V9Eg/1mGjFw092I9Sz6A9XTSEcEwwY9QOaglYydWG0j9lP08vyA+Lbr2GKW5wEsC4ps3gWBR4xR/t2cWAZs9ce2iFiqaodevlC5KyXGb6kC;
52-
Expires=Thu, 07 Jul 2022 10:29:32 GMT; Path=/; SameSite=None; Secure
53-
Strict-Transport-Security:
43+
server:
44+
- istio-envoy
45+
strict-transport-security:
5446
- max-age=31536000; includeSubDomains
55-
Transfer-Encoding:
56-
- chunked
57-
Vary:
58-
- Accept-Encoding
47+
vary:
5948
- Cookie
60-
X-App-Version:
61-
- v2.8.1
62-
X-Content-Type-Options:
49+
x-app-version:
50+
- v2.155.0
51+
x-content-type-options:
6352
- nosniff
6453
- nosniff
65-
X-Frame-Options:
54+
x-envoy-upstream-service-time:
55+
- '490'
56+
x-frame-options:
6657
- DENY
6758
- SAMEORIGIN
68-
X-Secrets-Engine-Version:
69-
- 2.70.0
70-
X-XSS-Protection:
59+
x-secrets-engine-version:
60+
- 2.132.2
61+
x-xss-protection:
7162
- 1; mode=block
72-
content-length:
73-
- '1240'
7463
status:
7564
code: 200
7665
message: OK

tests/test_client.py

+21-89
Original file line numberDiff line numberDiff line change
@@ -72,56 +72,6 @@
7272
"""
7373
EXAMPLE_RESPONSE = """
7474
[{
75-
"policy_break_count": 2,
76-
"policies": [
77-
"Filenames",
78-
"File extensions",
79-
"Secrets detection"
80-
],
81-
"policy_breaks": [
82-
{
83-
"type": ".env",
84-
"policy": "Filenames",
85-
"matches": [
86-
{
87-
"type": "filename",
88-
"match": ".env"
89-
}
90-
]
91-
},
92-
{
93-
"type": "Basic Auth String",
94-
"policy": "Secrets detection",
95-
"matches": [
96-
{
97-
"type": "username",
98-
"match": "jen_barber",
99-
"index_start": 36,
100-
"index_end": 45,
101-
"line_start": 2,
102-
"line_end": 2
103-
},
104-
{
105-
"type": "password",
106-
"match": "correcthorsebatterystaple",
107-
"index_start": 47,
108-
"index_end": 71,
109-
"line_start": 2,
110-
"line_end": 2
111-
},
112-
{
113-
"type": "host",
114-
"match": "cake.gitguardian.com",
115-
"index_start": 73,
116-
"index_end": 92,
117-
"line_start": 2,
118-
"line_end": 2
119-
}
120-
]
121-
}
122-
]
123-
},
124-
{
12575
"policy_break_count": 1,
12676
"policies": [
12777
"Filenames",
@@ -322,7 +272,6 @@ def test_health_check(client: GGClient):
322272
pytest.param(
323273
"with_breaks",
324274
[
325-
{"filename": FILENAME, "document": DOCUMENT},
326275
{"document": DOCUMENT},
327276
{"filename": "normal", "document": "normal"},
328277
],
@@ -341,7 +290,6 @@ def test_health_check(client: GGClient):
341290
),
342291
],
343292
)
344-
@my_vcr.use_cassette
345293
def test_multi_content_scan(
346294
client: GGClient,
347295
name: str,
@@ -353,28 +301,23 @@ def test_multi_content_scan(
353301
with my_vcr.use_cassette(name + ".yaml"):
354302
multiscan = client.multi_content_scan(to_scan)
355303

356-
assert multiscan.status_code == 200
357-
if not isinstance(multiscan, MultiScanResult):
358-
pytest.fail("multiscan is not a MultiScanResult")
359-
return
360-
361-
assert type(multiscan.to_dict()) == OrderedDict
362-
assert type(multiscan.to_json()) == str
363-
assert type(repr(multiscan)) == str
364-
assert type(str(multiscan)) == str
365-
assert multiscan.has_secrets == has_secrets
366-
assert multiscan.has_policy_breaks == has_policy_breaks
367-
368-
for i, scan_result in enumerate(multiscan.scan_results):
369-
if expected:
370-
example_dict = json.loads(expected)
371-
assert all(
372-
elem in example_dict[i]["policies"] for elem in scan_result.policies
373-
)
374-
assert (
375-
scan_result.policy_break_count
376-
== example_dict[i]["policy_break_count"]
377-
)
304+
assert multiscan.status_code == 200
305+
assert isinstance(multiscan, MultiScanResult)
306+
307+
assert type(multiscan.to_dict()) == OrderedDict
308+
assert type(multiscan.to_json()) == str
309+
assert type(repr(multiscan)) == str
310+
assert type(str(multiscan)) == str
311+
assert multiscan.has_secrets == has_secrets
312+
assert multiscan.has_policy_breaks == has_policy_breaks
313+
314+
if not expected:
315+
return
316+
317+
example_dict = json.loads(expected)
318+
for i, scan_result in enumerate(multiscan.scan_results):
319+
assert all(elem in example_dict[i]["policies"] for elem in scan_result.policies)
320+
assert scan_result.policy_break_count == example_dict[i]["policy_break_count"]
378321

379322

380323
@patch("pygitguardian.config.DOCUMENT_SIZE_THRESHOLD_BYTES", 20)
@@ -438,15 +381,12 @@ def test_content_not_ok():
438381
"name, to_scan, policy_break_count, has_secrets, has_policy_breaks",
439382
[
440383
pytest.param(
441-
"filename_secret",
442-
{"filename": FILENAME, "document": DOCUMENT},
443-
2,
384+
"secret",
385+
{"document": DOCUMENT},
386+
1,
444387
True,
445388
True,
446-
id="filename_secret",
447-
),
448-
pytest.param(
449-
"secret", {"document": DOCUMENT}, 1, True, True, id="secret (deprecated)"
389+
id="secret (deprecated)",
450390
),
451391
pytest.param(
452392
"secret_validity",
@@ -464,14 +404,6 @@ def test_content_not_ok():
464404
False,
465405
id="Document containing a 0 byte",
466406
),
467-
pytest.param(
468-
"filename",
469-
{"filename": FILENAME, "document": "normal"},
470-
1,
471-
False,
472-
True,
473-
id="filename",
474-
),
475407
pytest.param(
476408
"no_breaks",
477409
{"filename": "normal", "document": "normal"},

0 commit comments

Comments
 (0)