mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-29 17:47:14 +02:00
Extend validation of package for SHA1 // Resolve #69
This commit is contained in:
@ -1,10 +1,31 @@
|
||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
# See LICENSE for details.
|
||||
|
||||
import pytest
|
||||
import requests
|
||||
from os.path import basename
|
||||
|
||||
from platformio.util import get_api_result
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def sfpkglist():
|
||||
result = None
|
||||
r = None
|
||||
|
||||
try:
|
||||
r = requests.get("http://sourceforge.net/projects"
|
||||
"/platformio-storage/files/packages/list")
|
||||
result = r.json()
|
||||
r.raise_for_status()
|
||||
except:
|
||||
pass
|
||||
finally:
|
||||
if r:
|
||||
r.close()
|
||||
return result
|
||||
|
||||
|
||||
def pytest_generate_tests(metafunc):
|
||||
if "package_data" not in metafunc.fixturenames:
|
||||
return
|
||||
@ -22,13 +43,25 @@ def validate_response(req):
|
||||
assert int(req.headers['Content-Length']) > 0
|
||||
|
||||
|
||||
def validate_package(url):
|
||||
def validate_package(url, sfpkglist):
|
||||
r = requests.head(url, allow_redirects=True)
|
||||
validate_response(r)
|
||||
assert r.headers['Content-Type'] in ("application/x-gzip",
|
||||
"application/octet-stream")
|
||||
|
||||
|
||||
def test_package(package_data):
|
||||
def test_package(package_data, sfpkglist):
|
||||
assert package_data['url'].endswith("%d.tar.gz" % package_data['version'])
|
||||
validate_package(package_data['url'])
|
||||
|
||||
# check content type and that file exists
|
||||
r = requests.head(package_data['url'], allow_redirects=True)
|
||||
validate_response(r)
|
||||
assert r.headers['Content-Type'] in ("application/x-gzip",
|
||||
"application/octet-stream")
|
||||
|
||||
# check sha1 sum
|
||||
if sfpkglist is None:
|
||||
return
|
||||
pkgname = basename(package_data['url'])
|
||||
assert pkgname in sfpkglist
|
||||
assert package_data['sha1'] == sfpkglist.get(pkgname, {}).get("sha1")
|
||||
|
Reference in New Issue
Block a user