2022-12-21 22:14:08 +00:00
|
|
|
"""
|
|
|
|
Verify certain results against test vectors with well-known results.
|
|
|
|
"""
|
|
|
|
|
2022-12-22 21:52:00 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2023-01-18 18:52:11 +00:00
|
|
|
from functools import partial
|
2022-12-26 17:06:34 +00:00
|
|
|
from typing import AsyncGenerator, Iterator
|
2023-01-04 00:22:38 +00:00
|
|
|
from itertools import starmap, product
|
2022-12-22 15:51:59 +00:00
|
|
|
|
2023-01-16 20:53:24 +00:00
|
|
|
from attrs import evolve
|
|
|
|
|
2022-12-22 15:51:59 +00:00
|
|
|
from pytest import mark
|
|
|
|
from pytest_twisted import ensureDeferred
|
2022-12-21 22:14:08 +00:00
|
|
|
|
2023-01-17 13:41:10 +00:00
|
|
|
from . import vectors
|
2023-01-17 15:59:00 +00:00
|
|
|
from .vectors import parameters
|
2023-07-29 19:34:12 +00:00
|
|
|
from .util import upload
|
2023-07-25 02:08:41 +00:00
|
|
|
from .grid import Client
|
2022-12-22 22:02:42 +00:00
|
|
|
|
2023-01-17 15:59:00 +00:00
|
|
|
@mark.parametrize('convergence', parameters.CONVERGENCE_SECRETS)
|
2023-01-04 00:22:38 +00:00
|
|
|
def test_convergence(convergence):
|
2022-12-22 21:52:00 +00:00
|
|
|
"""
|
|
|
|
Convergence secrets are 16 bytes.
|
|
|
|
"""
|
2022-12-21 22:14:08 +00:00
|
|
|
assert isinstance(convergence, bytes), "Convergence secret must be bytes"
|
|
|
|
assert len(convergence) == 16, "Convergence secret must by 16 bytes"
|
|
|
|
|
|
|
|
|
2023-01-17 14:27:17 +00:00
|
|
|
@mark.slow
|
2023-01-17 15:03:54 +00:00
|
|
|
@mark.parametrize('case,expected', vectors.capabilities.items())
|
2022-12-22 15:51:59 +00:00
|
|
|
@ensureDeferred
|
2023-01-17 15:03:54 +00:00
|
|
|
async def test_capability(reactor, request, alice, case, expected):
|
2022-12-22 21:52:00 +00:00
|
|
|
"""
|
2022-12-26 22:08:30 +00:00
|
|
|
The capability that results from uploading certain well-known data
|
2022-12-22 21:52:00 +00:00
|
|
|
with certain well-known parameters results in exactly the previously
|
|
|
|
computed value.
|
|
|
|
"""
|
2022-12-21 22:14:08 +00:00
|
|
|
# rewrite alice's config to match params and convergence
|
2023-07-25 02:08:41 +00:00
|
|
|
await alice.reconfigure_zfec(
|
2023-07-25 02:12:01 +00:00
|
|
|
reactor, (1, case.params.required, case.params.total), case.convergence, case.segment_size)
|
2022-12-21 22:14:08 +00:00
|
|
|
|
2022-12-26 22:08:30 +00:00
|
|
|
# upload data in the correct format
|
2023-08-02 20:48:59 +00:00
|
|
|
actual = upload(alice, case.fmt, case.data)
|
2022-12-21 22:14:08 +00:00
|
|
|
|
|
|
|
# compare the resulting cap to the expected result
|
|
|
|
assert actual == expected
|
|
|
|
|
2022-12-22 15:51:59 +00:00
|
|
|
|
|
|
|
@ensureDeferred
|
2023-01-16 21:01:11 +00:00
|
|
|
async def skiptest_generate(reactor, request, alice):
|
2022-12-22 21:52:00 +00:00
|
|
|
"""
|
|
|
|
This is a helper for generating the test vectors.
|
|
|
|
|
|
|
|
You can re-generate the test vectors by fixing the name of the test and
|
|
|
|
running it. Normally this test doesn't run because it ran once and we
|
|
|
|
captured its output. Other tests run against that output and we want them
|
|
|
|
to run against the results produced originally, not a possibly
|
|
|
|
ever-changing set of outputs.
|
|
|
|
"""
|
2023-01-18 18:52:11 +00:00
|
|
|
space = starmap(
|
2023-01-20 21:26:23 +00:00
|
|
|
# segment_size could be a parameter someday but it's not easy to vary
|
2023-01-18 18:52:11 +00:00
|
|
|
# using the Python implementation so it isn't one for now.
|
2023-01-20 21:26:23 +00:00
|
|
|
partial(vectors.Case, segment_size=parameters.SEGMENT_SIZE),
|
2023-01-18 18:52:11 +00:00
|
|
|
product(
|
|
|
|
parameters.ZFEC_PARAMS,
|
|
|
|
parameters.CONVERGENCE_SECRETS,
|
|
|
|
parameters.OBJECT_DESCRIPTIONS,
|
|
|
|
parameters.FORMATS,
|
|
|
|
),
|
|
|
|
)
|
2023-01-16 20:53:24 +00:00
|
|
|
iterresults = generate(reactor, request, alice, space)
|
|
|
|
|
|
|
|
results = []
|
|
|
|
async for result in iterresults:
|
2023-01-20 20:14:18 +00:00
|
|
|
# Accumulate the new result
|
2023-01-16 20:53:24 +00:00
|
|
|
results.append(result)
|
2023-01-20 20:14:18 +00:00
|
|
|
# Then rewrite the whole output file with the new accumulator value.
|
|
|
|
# This means that if we fail partway through, we will still have
|
|
|
|
# recorded partial results -- instead of losing them all.
|
2023-01-18 18:52:11 +00:00
|
|
|
vectors.save_capabilities(results)
|
2022-12-26 17:06:34 +00:00
|
|
|
|
|
|
|
async def generate(
|
|
|
|
reactor,
|
|
|
|
request,
|
2023-07-25 02:08:41 +00:00
|
|
|
alice: Client,
|
2023-01-04 00:22:38 +00:00
|
|
|
cases: Iterator[vectors.Case],
|
|
|
|
) -> AsyncGenerator[[vectors.Case, str], None]:
|
2022-12-22 21:52:00 +00:00
|
|
|
"""
|
|
|
|
Generate all of the test vectors using the given node.
|
|
|
|
|
|
|
|
:param reactor: The reactor to use to restart the Tahoe-LAFS node when it
|
|
|
|
needs to be reconfigured.
|
|
|
|
|
|
|
|
:param request: The pytest request object to use to arrange process
|
|
|
|
cleanup.
|
|
|
|
|
2022-12-26 22:08:30 +00:00
|
|
|
:param format: The name of the encryption/data format to use.
|
|
|
|
|
2022-12-22 21:52:00 +00:00
|
|
|
:param alice: The Tahoe-LAFS node to use to generate the test vectors.
|
|
|
|
|
2023-01-04 00:22:38 +00:00
|
|
|
:param case: The inputs for which to generate a value.
|
2022-12-26 22:08:30 +00:00
|
|
|
|
2023-01-04 00:22:38 +00:00
|
|
|
:return: The capability for the case.
|
2022-12-22 21:52:00 +00:00
|
|
|
"""
|
2022-12-26 17:06:34 +00:00
|
|
|
# Share placement doesn't affect the resulting capability. For maximum
|
2022-12-27 14:03:24 +00:00
|
|
|
# reliability of this generator, be happy if we can put shares anywhere
|
2022-12-26 17:06:34 +00:00
|
|
|
happy = 1
|
2023-01-04 00:22:38 +00:00
|
|
|
for case in cases:
|
2023-07-25 02:08:41 +00:00
|
|
|
await alice.reconfigure_zfec(
|
2023-01-04 00:22:38 +00:00
|
|
|
reactor,
|
|
|
|
(happy, case.params.required, case.params.total),
|
2023-02-07 14:08:06 +00:00
|
|
|
case.convergence,
|
|
|
|
case.segment_size
|
2023-01-04 00:22:38 +00:00
|
|
|
)
|
2022-12-21 22:14:08 +00:00
|
|
|
|
2023-01-16 20:53:24 +00:00
|
|
|
# Give the format a chance to make an RSA key if it needs it.
|
|
|
|
case = evolve(case, fmt=case.fmt.customize())
|
2023-07-25 02:08:41 +00:00
|
|
|
cap = upload(alice.process, case.fmt, case.data)
|
2023-01-04 00:22:38 +00:00
|
|
|
yield case, cap
|