Skip to content

Commit 8f95e2a

Browse files
committed
Clarify key rotations test cases by using keywords
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
1 parent 589ed9e commit 8f95e2a

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

tests/test_updater_key_rotations.py

+39-39
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
class RootVersion:
2828
keys: List[int]
2929
threshold: int
30-
signatures: List[int]
31-
result: Optional[Type[Exception]] = None
30+
sigs: List[int]
31+
res: Optional[Type[Exception]] = None
3232

3333

3434
class TestUpdaterKeyRotations(unittest.TestCase):
@@ -87,71 +87,71 @@ def _run_refresh(self) -> None:
8787

8888
root_rotation_cases = {
8989
"1-of-1 key rotation": [
90-
RootVersion([1], 1, [1]),
91-
RootVersion([2], 1, [2, 1]),
92-
RootVersion([2], 1, [2]),
90+
RootVersion(keys=[1], threshold=1, sigs=[1]),
91+
RootVersion(keys=[2], threshold=1, sigs=[2, 1]),
92+
RootVersion(keys=[2], threshold=1, sigs=[2]),
9393
],
9494
"1-of-1 key rotation, unused signatures": [
95-
RootVersion([1], 1, [3, 1, 4]),
96-
RootVersion([2], 1, [3, 2, 1, 4]),
97-
RootVersion([2], 1, [3, 2, 4]),
95+
RootVersion(keys=[1], threshold=1, sigs=[3, 1, 4]),
96+
RootVersion(keys=[2], threshold=1, sigs=[3, 2, 1, 4]),
97+
RootVersion(keys=[2], threshold=1, sigs=[3, 2, 4]),
9898
],
9999
"1-of-1 key rotation fail: not signed with old key": [
100-
RootVersion([1], 1, [1]),
101-
RootVersion([2], 1, [2, 3, 4], UnsignedMetadataError),
100+
RootVersion(keys=[1], threshold=1, sigs=[1]),
101+
RootVersion([2], 1, sigs=[2, 3, 4], res=UnsignedMetadataError),
102102
],
103103
"1-of-1 key rotation fail: not signed with new key": [
104-
RootVersion([1], 1, [1]),
105-
RootVersion([2], 1, [1, 3, 4], UnsignedMetadataError),
104+
RootVersion(keys=[1], threshold=1, sigs=[1]),
105+
RootVersion([2], 1, [1, 3, 4], res=UnsignedMetadataError),
106106
],
107107
"3-of-5, sign with different keycombos": [
108-
RootVersion([0, 1, 2, 3, 4], 3, [0, 2, 4]),
109-
RootVersion([0, 1, 2, 3, 4], 3, [0, 4, 1]),
110-
RootVersion([0, 1, 2, 3, 4], 3, [0, 1, 3]),
111-
RootVersion([0, 1, 2, 3, 4], 3, [0, 1, 3]),
108+
RootVersion(keys=[0, 1, 2, 3, 4], threshold=3, sigs=[0, 2, 4]),
109+
RootVersion(keys=[0, 1, 2, 3, 4], threshold=3, sigs=[0, 4, 1]),
110+
RootVersion(keys=[0, 1, 2, 3, 4], threshold=3, sigs=[0, 1, 3]),
111+
RootVersion(keys=[0, 1, 2, 3, 4], threshold=3, sigs=[0, 1, 3]),
112112
],
113113
"3-of-5, one key rotated": [
114-
RootVersion([0, 1, 2, 3, 4], 3, [0, 2, 4]),
115-
RootVersion([0, 1, 3, 4, 5], 3, [0, 4, 1]),
114+
RootVersion(keys=[0, 1, 2, 3, 4], threshold=3, sigs=[0, 2, 4]),
115+
RootVersion(keys=[0, 1, 3, 4, 5], threshold=3, sigs=[0, 4, 1]),
116116
],
117117
"3-of-5, one key rotate fails: not signed with 3 new keys": [
118-
RootVersion([0, 1, 2, 3, 4], 3, [0, 2, 4]),
118+
RootVersion(keys=[0, 1, 2, 3, 4], threshold=3, sigs=[0, 2, 4]),
119119
RootVersion([0, 1, 3, 4, 5], 3, [0, 2, 4], UnsignedMetadataError),
120120
],
121121
"3-of-5, one key rotate fails: not signed with 3 old keys": [
122-
RootVersion([0, 1, 2, 3, 4], 3, [0, 2, 4]),
122+
RootVersion(keys=[0, 1, 2, 3, 4], threshold=3, sigs=[0, 2, 4]),
123123
RootVersion([0, 1, 3, 4, 5], 3, [0, 4, 5], UnsignedMetadataError),
124124
],
125125
"3-of-5, one key rotated, with intermediate step": [
126-
RootVersion([0, 1, 2, 3, 4], 3, [0, 2, 4]),
127-
RootVersion([0, 1, 3, 4, 5], 3, [0, 2, 4, 5]),
128-
RootVersion([0, 1, 3, 4, 5], 3, [0, 4, 5]),
126+
RootVersion(keys=[0, 1, 2, 3, 4], threshold=3, sigs=[0, 2, 4]),
127+
RootVersion(keys=[0, 1, 3, 4, 5], threshold=3, sigs=[0, 2, 4, 5]),
128+
RootVersion(keys=[0, 1, 3, 4, 5], threshold=3, sigs=[0, 4, 5]),
129129
],
130130
"3-of-5, all keys rotated, with intermediate step": [
131-
RootVersion([0, 1, 2, 3, 4], 3, [0, 2, 4]),
132-
RootVersion([5, 6, 7, 8, 9], 3, [0, 2, 4, 5, 6, 7]),
133-
RootVersion([5, 6, 7, 8, 9], 3, [5, 6, 7]),
131+
RootVersion(keys=[0, 1, 2, 3, 4], threshold=3, sigs=[0, 2, 4]),
132+
RootVersion([5, 6, 7, 8, 9], threshold=3, sigs=[0, 2, 4, 5, 6, 7]),
133+
RootVersion(keys=[5, 6, 7, 8, 9], threshold=3, sigs=[5, 6, 7]),
134134
],
135135
"1-of-3 threshold increase to 2-of-3": [
136-
RootVersion([1, 2, 3], 1, [1]),
137-
RootVersion([1, 2, 3], 2, [1, 2]),
136+
RootVersion(keys=[1, 2, 3], threshold=1, sigs=[1]),
137+
RootVersion(keys=[1, 2, 3], threshold=2, sigs=[1, 2]),
138138
],
139139
"1-of-3 threshold bump to 2-of-3 fails: new threshold not reached": [
140-
RootVersion([1, 2, 3], 1, [1]),
141-
RootVersion([1, 2, 3], 2, [2], UnsignedMetadataError),
140+
RootVersion(keys=[1, 2, 3], threshold=1, sigs=[1]),
141+
RootVersion([1, 2, 3], 2, sigs=[2], res=UnsignedMetadataError),
142142
],
143143
"2-of-3 threshold decrease to 1-of-3": [
144-
RootVersion([1, 2, 3], 2, [1, 2]),
145-
RootVersion([1, 2, 3], 1, [1, 2]),
146-
RootVersion([1, 2, 3], 1, [1]),
144+
RootVersion(keys=[1, 2, 3], threshold=2, sigs=[1, 2]),
145+
RootVersion([1, 2, 3], threshold=1, sigs=[1, 2]),
146+
RootVersion([1, 2, 3], threshold=1, sigs=[1]),
147147
],
148148
"2-of-3 threshold decr. to 1-of-3 fails: old threshold not reached": [
149-
RootVersion([1, 2, 3], 2, [1, 2]),
150-
RootVersion([1, 2, 3], 1, [1], UnsignedMetadataError),
149+
RootVersion(keys=[1, 2, 3], threshold=2, sigs=[1, 2]),
150+
RootVersion([1, 2, 3], 1, sigs=[1], res=UnsignedMetadataError),
151151
],
152152
"1-of-2 threshold increase to 2-of-2": [
153-
RootVersion([1], 1, [1]),
154-
RootVersion([1, 2], 2, [1, 2]),
153+
RootVersion(keys=[1], threshold=1, sigs=[1]),
154+
RootVersion(keys=[1, 2], threshold=2, sigs=[1, 2]),
155155
],
156156
}
157157

@@ -180,13 +180,13 @@ def test_root_rotation(self, root_versions: List[RootVersion]) -> None:
180180
self.sim.root.roles["root"].threshold = rootver.threshold
181181
for i in rootver.keys:
182182
self.sim.root.add_key("root", self.keys[i])
183-
for i in rootver.signatures:
183+
for i in rootver.sigs:
184184
self.sim.add_signer("root", self.signers[i])
185185
self.sim.root.version += 1
186186
self.sim.publish_root()
187187

188188
# run client workflow, assert success/failure
189-
expected_result = root_versions[-1].result
189+
expected_result = root_versions[-1].res
190190
if expected_result is None:
191191
self._run_refresh()
192192
expected_local_root = self.sim.signed_roots[-1]

0 commit comments

Comments
 (0)