Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
ZKAPAuthorizer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Administrator
ZKAPAuthorizer
Commits
890e67dd
Commit
890e67dd
authored
3 years ago
by
Jean-Paul Calderone
Browse files
Options
Downloads
Patches
Plain Diff
add a test for using the test vector feature
and fix it
parent
4b5824be
No related branches found
No related tags found
1 merge request
!278
Port to Python 3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/_zkapauthorizer/_storage_client.py
+20
-1
20 additions, 1 deletion
src/_zkapauthorizer/_storage_client.py
src/_zkapauthorizer/tests/test_storage_protocol.py
+57
-0
57 additions, 0 deletions
src/_zkapauthorizer/tests/test_storage_protocol.py
with
77 additions
and
1 deletion
src/_zkapauthorizer/_storage_client.py
+
20
−
1
View file @
890e67dd
...
...
@@ -450,6 +450,25 @@ class ZKAPAuthorizerStorageClient(object):
tw_vectors
,
r_vector
,
):
# type: (
# Any,
# bytes,
# Tuple[bytes, bytes, bytes],
# Dict[
# int,
# Tuple[
# List[
# Tuple[int, int, bytes, bytes],
# ],
# List[
# Tuple[int, bytes],
# ],
# Optional[int],
# ],
# ],
# List[Tuple[int, int]],
# ) -> Deferred
# Read operations are free.
num_passes
=
0
...
...
@@ -458,7 +477,7 @@ class ZKAPAuthorizerStorageClient(object):
tw_vectors
=
{
sharenum
:
(
[
(
offset
,
length
,
"
eq
"
,
specimen
)
(
offset
,
length
,
b
"
eq
"
,
specimen
)
for
(
offset
,
length
,
specimen
)
in
test_vector
],
data_vectors
,
...
...
This diff is collapsed.
Click to expand it.
src/_zkapauthorizer/tests/test_storage_protocol.py
+
57
−
0
View file @
890e67dd
...
...
@@ -72,6 +72,7 @@ from .storage_common import (
)
from
.strategies
import
bytes_for_share
# Not really a strategy...
from
.strategies
import
(
TestAndWriteVectors
,
lease_cancel_secrets
,
lease_renew_secrets
,
posix_timestamps
,
...
...
@@ -79,6 +80,7 @@ from .strategies import (
sharenum_sets
,
sharenums
,
sizes
,
slot_data_vectors
,
slot_test_and_write_vectors_for_shares
,
storage_indexes
,
write_enabler_secrets
,
...
...
@@ -1073,6 +1075,61 @@ class ShareTests(TestCase):
),
)
@given
(
storage_index
=
storage_indexes
(),
secrets
=
tuples
(
write_enabler_secrets
(),
lease_renew_secrets
(),
lease_cancel_secrets
(),
),
sharenum
=
sharenums
(),
data_vector
=
slot_data_vectors
(),
replacement_data_vector
=
slot_data_vectors
(),
)
def
test_test_vectors_match
(
self
,
storage_index
,
secrets
,
sharenum
,
data_vector
,
replacement_data_vector
):
"""
If test vectors are given then the write is allowed if they match the
existing data.
"""
empty_test_vector
=
[]
def
write
(
tw_vectors
):
return
self
.
client
.
slot_testv_and_readv_and_writev
(
storage_index
,
secrets
=
secrets
,
tw_vectors
=
tw_vectors
,
r_vector
=
[],
)
def
read
(
sharenum
,
readv
):
d
=
self
.
client
.
slot_readv
(
storage_index
,
[
sharenum
],
readv
)
d
.
addCallback
(
lambda
data
:
data
[
sharenum
])
return
d
def
equal_test_vector
(
data_vector
):
return
list
(
(
offset
,
len
(
data
),
data
)
for
(
offset
,
data
)
in
data_vector
)
# Create the share
d
=
write
({
sharenum
:
(
empty_test_vector
,
data_vector
,
None
),
})
self
.
assertThat
(
d
,
is_successful_write
())
# Write some new data to with a correct test vector. We can only be
# sure we know data from the last element of the test vector since
# earlier elements may have been overwritten.
d
=
write
({
sharenum
:
(
equal_test_vector
(
data_vector
)[
-
1
:],
replacement_data_vector
,
None
),
})
self
.
assertThat
(
d
,
is_successful_write
())
# Check that the new data is present
assert_read_back_data
(
self
,
storage_index
,
secrets
,
{
sharenum
:
TestAndWriteVectors
(
None
,
replacement_data_vector
,
None
)})
def
assert_read_back_data
(
self
,
storage_index
,
secrets
,
test_and_write_vectors_for_shares
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment