Commit graph

18 commits

Author SHA1 Message Date
Martin Vrachev
1a5912aa7c Remove some unused imports
We can remove the conditional imports from tests as now we support
python versions 3.6+.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-09-21 12:20:09 +03:00
Martin Vrachev
bf12e7565f Metadata API: change meta type in Timestamp
In Timestamp, the only valid "meta" value is the dictionary representing
meta information for the snapshot file. This makes the API unnecessarily
complicated and requires validation that only information about snapshot
is available inside "meta".
Together with the python-tuf maintainers, we decided that snapshot meta
information will not be represented by a "meta" dictionary but instead
by a MetaFile instance and with this it will diverge from the
specification.
Additionally, to prevent confusion, I will rename the "meta" attribute
to "snapshot_meta" as this attribute will be related only to meta
information about snapshot.

This decision is coherent with ADR9 and the rationale
behind it is to provide easier, safer, and direct access to the
snapshot meta information.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-09-20 14:09:38 +03:00
Jussi Kukkonen
d018279e21 ngclient: Fix rollback checks
The rollback checks themselves work, but they create a situation
where Updater does not realize that it needs to download e.g. a new
snapshot because the local snapshot is valid as _intermediate_ snapshot
(that can be used for rollback protection but nothing else), but is not
valid as final snapshot.

Raise in the end of update_snapshot and update_timestamp if the files
are not valid final metadata: this way the intermediate metadata does
get loaded but Updater also knows it is not the final metadata.

This modifies the existing tests but does not yet test the situation
described in the first paragraph.

Fixes #1563

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-09-10 09:59:03 +03:00
Teodora Sechkova
61e8f40346
Update tests/test_trusted_metadata_set.py
Modify root tests to cover both loading inital
root metadata and updating it.

Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
2021-09-07 14:41:08 +03:00
Jussi Kukkonen
c8696d905e tests: Remove unhelpful helper
Doing the work inline is less code and easier to understand.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-08-19 11:22:01 +03:00
Jussi Kukkonen
e3b789c306 ngclient: allow limited use of wrong snapshot version
Spec does not explicitly say so but the intent is that a snapshot
metadata can be trusted for rollback protection checks of newer
snapshots even if current snapshot version does not match the version
in current timestamp meta.

Only do the snapshot version check for the "final" snapshot by doing it
when targets is updated.

Improve test names and comments.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-08-19 11:22:01 +03:00
Jussi Kukkonen
b515997701 ngclient: Allow limited use of expired timestamp/snapshot
While this is not explicitly said in the spec, the intention is that
expired timestamp and snapshot should be used for rollback protection
checks on newer timestamp/snapshot (but not for anything else).

Move the expiry checks to the "next" metadata update: timestamp expiry
is checked when snapshot is loaded, and snapshot expiry is checked
when targets is loaded.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-08-19 11:22:01 +03:00
Jussi Kukkonen
091197288f ngclient: Remove root_update_finished()
The usefulness was debatable to begin with, and now that it has become
clear that rollback protection requires a second "final verification"
step for all three root, timestamp and snapshot it is clear that
root_update_finished() is not good design.

update_root() still accepts expired root metadata but now the final
root expiry is checked when the "next" metadata (timestamp) is loaded.

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-08-19 11:09:12 +03:00
Jussi Kukkonen
f02fed2502 tests: Test TrustedMetadataSet iteration
Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-08-17 15:50:01 +03:00
Jussi Kukkonen
85656a56eb tests: Add missing test to TrustedMetadataSet
Test failing length/hash test for snapshot

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-08-17 15:40:13 +03:00
Jussi Kukkonen
efb5653016 tests: Improve TrustedSet coverage
* test for succesful root update
* fix test for snapshot version rollback in timestamp update

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-08-17 13:54:18 +03:00
Martin Vrachev
617e87eb26 Annotations and use extensively modify_metadata
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-08-16 18:13:01 +03:00
Martin Vrachev
11531caf42 Embed modification function helpers
Instead of using general abstract modification functions embed smaller
modification functions inside each test where it's needed and
create modify_metadata function that does all of the common stuff like:
- instantiating a metadata object
- calling the modification function
- signing the modified object
- serializing back to bytes.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-07-21 17:34:23 +03:00
Martin Vrachev
71838562dc ngcl. tests: remove modification on internal state
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-07-21 16:40:39 +03:00
Martin Vrachev
c7c9d0f321 TrustedMetadataSet testing: use Metadata.to_bytes
Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-07-16 16:57:28 +03:00
Martin Vrachev
6a942889ff ngclient TrustedMetadataSet: improve unit testing
The current situation with the TrustedMetadataSet testing is that
we don't have a mnimimal amount of unit tests testing the different
branches in the various API functionality in the class.

This commit proposes simple unit tests covering almost all of the
branches in the API functions and increasing the unit test coverage
(as reported from the "coverage" tool) from 74 % to 97 %.

The code could be complicated at places, because the different
branches in the update_* functions depend on other metadata classes
as well.
Still, I hope we can find a way and simplify the code.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-07-16 16:57:23 +03:00
Martin Vrachev
726af73256 ng client metadata set: organize common test code
Move the shared code between tests into the "setupClass" function.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
2021-07-16 15:49:00 +03:00
Jussi Kukkonen
4811e880c0 Rename MetadataBundle to TrustedMetadataSet
TrustedMetadataSet is a long name but
 * it better describes the main feature
 * the name isn't used in too many places

Change the variable names "bundle" -> "trusted_set"

Signed-off-by: Jussi Kukkonen <jkukkonen@vmware.com>
2021-07-05 10:45:19 +03:00
Renamed from tests/test_metadata_bundle.py (Browse further)