forked from mtusi2026/mtusi2026lab5
ЛР 5 — БВТ2303 — Брезгунова — на 5
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"""Read-only Git checks and private-value scan; prints only names/counts."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def git(*args):
|
||||
return subprocess.check_output(['git',*args],cwd=ROOT,text=True,encoding='utf-8').strip()
|
||||
|
||||
|
||||
public = git('ls-files','--','README.md','COURSE.md','CONTRIBUTING.md','tests','contracts').splitlines()
|
||||
changed = []
|
||||
for name in public:
|
||||
if git('hash-object','--path',name,name)!=git('rev-parse','HEAD:'+name):
|
||||
changed.append(name)
|
||||
assert not changed,'Mandatory skeleton changed: '+', '.join(changed)
|
||||
private = [p.read_bytes().strip() for p in (ROOT/'secrets').iterdir() if p.is_file()]
|
||||
scan = []
|
||||
for pattern in ('*.md','*.json','*.txt','*.yaml','*.yml','*.py'):
|
||||
scan.extend(p for p in ROOT.rglob(pattern) if not set(p.relative_to(ROOT).parts)&{'.git','.venv','secrets','__pycache__'})
|
||||
leaks = [str(p.relative_to(ROOT)) for p in scan if any(value and value in p.read_bytes() for value in private)]
|
||||
assert not leaks,'Private value found in '+', '.join(leaks)
|
||||
ignored = subprocess.run(['git','check-ignore','.env','secrets/database_url','secrets/broker_url'],cwd=ROOT,capture_output=True,text=True)
|
||||
assert ignored.returncode==0 and len(ignored.stdout.splitlines())==3
|
||||
result = {'result':'PASS','unchanged_mandatory_files':len(public),'scanned_files':len(set(scan)),
|
||||
'private_value_leaks':0,'local_secrets_ignored':True,'scope':'mtusi2026lab5 only'}
|
||||
(ROOT/'evidence/integrity.json').write_text(json.dumps(result,indent=2),encoding='utf-8')
|
||||
print(json.dumps(result))
|
||||
Reference in New Issue
Block a user