This commit is contained in:
Chris AtLee 2018-09-06 18:45:23 -04:00
Родитель 6cba2bcaaa
Коммит 5dab933695
5 изменённых файлов: 27 добавлений и 18 удалений

Просмотреть файл

@ -1,7 +1,12 @@
[run] [run]
branch = true branch = true
source = mardor source = mardor
parallel = true
[paths]
source =
src/mardor
.tox/*/lib/python*/site-packages/mardor
.tox/pypy/site-packages/mardor
[report] [report]
show_missing = true show_missing = true

Просмотреть файл

@ -182,7 +182,7 @@ def xz_decompress_stream(src):
if decoded: if decoded:
yield decoded yield decoded
if dec.unused_data: if dec.unused_data: # pragma: nocover; can't figure out how to test this
raise IOError('Read unused data at end of compressed stream') raise IOError('Read unused data at end of compressed stream')

Просмотреть файл

@ -37,7 +37,6 @@ class MarWriter(object):
productversion=None, channel=None, productversion=None, channel=None,
signing_key=None, signing_key=None,
signing_algorithm=None, signing_algorithm=None,
signature=None,
): ):
"""Initialize a new MarWriter object. """Initialize a new MarWriter object.
@ -55,7 +54,6 @@ class MarWriter(object):
productversion and channel must be specified together productversion and channel must be specified together
signing_key (str): PEM encoded private key used for signing signing_key (str): PEM encoded private key used for signing
signing_algorithm (str): one of None, 'sha1', 'sha384' signing_algorithm (str): one of None, 'sha1', 'sha384'
signature (str): precomputed signature for this file
""" """
self.fileobj = fileobj self.fileobj = fileobj
if signing_algorithm and (fileobj.mode not in ('w+b', 'wb+', 'rb+', 'r+b')): if signing_algorithm and (fileobj.mode not in ('w+b', 'wb+', 'rb+', 'r+b')):
@ -72,7 +70,6 @@ class MarWriter(object):
self.productversion = productversion self.productversion = productversion
self.channel = channel self.channel = channel
self.signing_key = signing_key self.signing_key = signing_key
self.signature = signature
if signing_algorithm not in (None, 'sha1', 'sha384'): if signing_algorithm not in (None, 'sha1', 'sha384'):
raise ValueError('Unsupported signing algorithm: {}'.format(signing_algorithm)) raise ValueError('Unsupported signing algorithm: {}'.format(signing_algorithm))
self.signing_algorithm = signing_algorithm self.signing_algorithm = signing_algorithm
@ -235,7 +232,7 @@ class MarWriter(object):
if not self.signing_algorithm: if not self.signing_algorithm:
return [] return []
algo_id = {'sha1': 1, 'sha384': 2}[self.signing_algorithm] algo_id = {'sha1': 1, 'sha384': 2}[self.signing_algorithm]
signature = self.signature or make_dummy_signature(algo_id) signature = make_dummy_signature(algo_id)
return [(algo_id, signature)] return [(algo_id, signature)]
def calculate_signatures(self): def calculate_signatures(self):
@ -245,14 +242,6 @@ class MarWriter(object):
A list of signature tuples: [(algorithm_id, signature_data), ...] A list of signature tuples: [(algorithm_id, signature_data), ...]
""" """
if self.signature:
if self.signing_algorithm == 'sha1':
assert len(self.signature) == 256
return [(1, self.signature)]
elif self.signing_algorithm == 'sha384':
assert len(self.signature) == 512
return [(2, self.signature)]
if not self.signing_algorithm: if not self.signing_algorithm:
return [] return []

Просмотреть файл

@ -182,6 +182,11 @@ def test_calculate_hashes():
assert verify_signature(pubkey, m.mardata.signatures.sigs[0].signature, hashes[0][1], 'sha1') assert verify_signature(pubkey, m.mardata.signatures.sigs[0].signature, hashes[0][1], 'sha1')
def test_calculate_hashes_no_sig(mar_cu):
with mar_cu.open('rb') as f, MarReader(f) as m:
assert m.calculate_hashes() == []
def test_check_bad_signature_algorithm(mar_sha384, tmpdir): def test_check_bad_signature_algorithm(mar_sha384, tmpdir):
# Make a copy of mar_sha384 # Make a copy of mar_sha384
tmpmar = tmpdir.join('test.mar') tmpmar = tmpdir.join('test.mar')
@ -273,3 +278,13 @@ def test_check_bad_file_entry_size(mar_sha384, tmpdir):
with MarReader(f) as m: with MarReader(f) as m:
assert m.get_errors() == ["Entry 'message.txt' ends past data block"] assert m.get_errors() == ["Entry 'message.txt' ends past data block"]
def test_productinfo():
with open(TEST_MAR_BZ2, 'rb') as f, MarReader(f) as m:
assert m.productinfo == ('100.0', 'thunderbird-comm-esr')
def test_no_productinfo(mar_cu):
with mar_cu.open('rb') as f, MarReader(f) as m:
assert m.productinfo is None

Просмотреть файл

@ -5,8 +5,8 @@ envlist =
clean, clean,
check, check,
{py27,py35,py36,py37,pypy}, {py27,py35,py36,py37,pypy},
report, docs,
docs report
[testenv] [testenv]
basepython = basepython =
@ -25,7 +25,7 @@ usedevelop = false
deps = deps =
-rtest-requirements.txt -rtest-requirements.txt
commands = commands =
{posargs:py.test -W error --cov --cov-report=term-missing -vv --random-order-bucket=package tests} {posargs:coverage run --parallel -m pytest -W error -vv --random-order-bucket=package tests}
[testenv:spell] [testenv:spell]
setenv = setenv =
@ -74,7 +74,7 @@ commands =
deps = coverage==4.5.1 deps = coverage==4.5.1
skip_install = true skip_install = true
commands = commands =
coverage combine --append coverage combine
coverage report coverage report
coverage html coverage html