Desktop foundation / core (ubuntu-latest) (push) Failing after 28s
Desktop foundation / core (macos-latest) (push) Canceled after 0s
Desktop foundation / core (windows-latest) (push) Canceled after 0s
Linux / verify (push) Canceled after 0s
Linux / keyless-cuda (push) Canceled after 0s
Linux / static-cuda-package (push) Canceled after 0s
Linux / hosted-cuda-package (push) Canceled after 0s
Linux / linux-static-cli (push) Canceled after 0s
Linux / linux-cli-container (push) Canceled after 0s
Linux / release-cli (push) Canceled after 0s
60 lines
3.4 KiB
Python
60 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
import importlib.util
|
|
import io
|
|
import json
|
|
from pathlib import Path
|
|
import tarfile
|
|
import tempfile
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
spec=importlib.util.spec_from_file_location('bootstrap',Path(__file__).with_name('bootstrap-cuda-toolkit.py'))
|
|
m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m)
|
|
|
|
class Tests(unittest.TestCase):
|
|
def test_safe_tree_and_internal_link(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root=Path(tmp);archive=root/'test.tar.xz'
|
|
with tarfile.open(archive,'w:xz') as t:
|
|
item=tarfile.TarInfo('component/lib/a');item.size=1;t.addfile(item,io.BytesIO(b'a'))
|
|
item=tarfile.TarInfo('component/lib/b');item.type=tarfile.SYMTYPE;item.linkname='a';t.addfile(item)
|
|
out=m.extract(archive,root/'out','component')
|
|
self.assertEqual((out/'lib/b').read_bytes(),b'a')
|
|
def test_bad_archive_paths_and_links(self):
|
|
for name,link in [('../escape',None),('/escape',None),('other/file',None),('component/b','../../escape')]:
|
|
with self.subTest(name=name),tempfile.TemporaryDirectory() as tmp:
|
|
root=Path(tmp);archive=root/'test.tar.xz'
|
|
with tarfile.open(archive,'w:xz') as t:
|
|
item=tarfile.TarInfo(name)
|
|
if link:item.type=tarfile.SYMTYPE;item.linkname=link
|
|
t.addfile(item)
|
|
with self.assertRaises((ValueError,tarfile.TarError)):m.extract(archive,root/'out','component')
|
|
self.assertFalse((root/'escape').exists())
|
|
def test_component_merge_rejects_conflict(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root=Path(tmp);a=root/'a';b=root/'b';a.mkdir();b.mkdir()
|
|
(a/'x').write_text('a');(b/'x').write_text('b')
|
|
with self.assertRaises(ValueError):m.merge(a,b)
|
|
self.assertEqual((b/'x').read_text(),'b')
|
|
def test_identical_merge_and_moving(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root=Path(tmp);a=root/'a';b=root/'b';a.mkdir();b.mkdir()
|
|
(a/'x').write_text('a');(b/'x').write_text('a');(a/'y').write_text('y')
|
|
m.merge(a,b);self.assertEqual((b/'y').read_text(),'y');self.assertFalse((a/'y').exists())
|
|
def test_download_mismatch_size_and_redirect(self):
|
|
for data,url,sha,limit in [(b'bad',m.BASE+'x','0'*64,4),(b'large',m.BASE+'x','0'*64,2),(b'x','https://other.invalid/x','0'*64,2)]:
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
response=io.BytesIO(data);response.url=url
|
|
with patch.object(m.urllib.request,'urlopen',return_value=response),self.assertRaises(ValueError):
|
|
m.download(m.BASE+'x',Path(tmp)/'file',sha,limit)
|
|
def test_lock_pins_match_reference(self):
|
|
lock=json.loads((Path(__file__).resolve().parents[1]/'deploy/cuda-toolkit.lock.json').read_text())
|
|
manifest={x['component']:{'version':x['version'],'linux-x86_64':x.copy()} for x in lock['components']}
|
|
m.validate_lock(lock,manifest)
|
|
lock['components'][0]['sha256']='0'*64
|
|
with self.assertRaises(ValueError):m.validate_lock(lock,manifest)
|
|
def test_resource_gate_before_download(self):
|
|
with patch.object(m.Path,'read_text',return_value='MemTotal: 1024 kB\n'),self.assertRaises(ValueError):m.resource_gate(Path('/tmp'))
|
|
|
|
if __name__=='__main__':unittest.main()
|