Skip to content

Commit

Permalink
issue111:
Browse files Browse the repository at this point in the history
make app version 2.0 required in repo workflow example

and update test data and tests accordingly
  • Loading branch information
dennisvang committed Mar 8, 2024
1 parent e83ab7a commit ebb9ecb
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 39 deletions.
8 changes: 6 additions & 2 deletions examples/repo/repo_workflow_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
KEY_MAP['root'].append('root_two') # use two keys for root
ENCRYPTED_KEYS = ['root', 'root_two', 'targets']

# Custom metadata
# Custom metadata (for example, a list of changes)
DUMMY_METADATA = dict(changes=['this has changed', 'that has changed', '...'])

# Create repository instance
Expand Down Expand Up @@ -169,7 +169,11 @@
repo.add_bundle(
new_version=new_version,
new_bundle_dir=dummy_bundle_dir,
custom_metadata=DUMMY_METADATA, # just to point out the option
# example of optional custom metadata
custom_metadata=DUMMY_METADATA.copy(),
# "required" updates are exceptional and should be avoided if possible,
# but we include one here just for completeness
required=new_version == '2.0',
)
repo.publish_changes(private_key_dirs=[OFFLINE_DIR_1, OFFLINE_DIR_2, ONLINE_DIR])

Expand Down
10 changes: 5 additions & 5 deletions tests/data/repository/metadata/1.root.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"signatures": [
{
"keyid": "b7ad916e4138911155b771d0ede66666e9647e7fb6c85a1904be97dee5653568",
"sig": "0f634a6e5f82af4447accce63c2987350c9c16fe6f8ce391ed504da106be8a127e1d606424c97a27822038cfd35e4daa96da2ec07a4a75bc2610df3bfc95cd0c"
"sig": "581b30a5a2a927c71479b568908bb517bc1d2c7a627428e8399b7c91ef427f4784357c855698c484d3a2aacc952ce1893ea246a03401315e2a473a5db2429d0f"
},
{
"keyid": "d4ec748f9476f9f7e1f0a247b917dde4abe8a024de9ba34c7458b41bec8be6b2",
"sig": "678256d67bcf6022f75920ff380dc2111e2d68120af834f1769d694665236a2c7fb57ea5731f4050e1562a8b2be870b6594a2203f52182b1b77fa98ae89ed90c"
"sig": "5b53aa824b1e81ec3d7e1fe383ca41b156715f852e9c59bc3ba53275d95fb2869b778cce351da30b867fdb2ed55334fc22e4f9c13732b8a8557049000056ff09"
}
],
"signed": {
"_type": "root",
"consistent_snapshot": false,
"expires": "2051-06-27T21:21:03Z",
"expires": "2051-07-25T11:55:06Z",
"keys": {
"5ef48ab6f5398d2bf17f1f4c4fc0e0440c4aa3734a05ae523561e02e8a99957a": {
"keytype": "ed25519",
Expand Down Expand Up @@ -53,8 +53,8 @@
"roles": {
"root": {
"keyids": [
"d4ec748f9476f9f7e1f0a247b917dde4abe8a024de9ba34c7458b41bec8be6b2",
"b7ad916e4138911155b771d0ede66666e9647e7fb6c85a1904be97dee5653568"
"b7ad916e4138911155b771d0ede66666e9647e7fb6c85a1904be97dee5653568",
"d4ec748f9476f9f7e1f0a247b917dde4abe8a024de9ba34c7458b41bec8be6b2"
],
"threshold": 2
},
Expand Down
14 changes: 7 additions & 7 deletions tests/data/repository/metadata/2.root.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"signatures": [
{
"keyid": "1bd53d9d6f08f6efba19477880b348906f5f29a67d78cbca8a44aedfad12d003",
"sig": "47a42813ae34829c60539dcceba0d4b9a8a9286beaa8d5f07d3de3050d404426c22bc95b271e7c5e7ee529bc3180f009eb31313fb825f76c3ed9ca2c501bd503"
},
{
"keyid": "b7ad916e4138911155b771d0ede66666e9647e7fb6c85a1904be97dee5653568",
"sig": "421d85636350a89805abc4561acd3019ecf17246a37e91374a53276b5d56638c83754960c27d038c7d1193bdb33db12faf69b7a19099627c745c569093ee0005"
"sig": "3b5fef2d49edba8b0dfb8fb7781fd5721c3f11f602c5700d9821367862973a65d90d2cdc4fbf9433207475defec1eeea085cf9f1145f1eea54210647cbb34004"
},
{
"keyid": "d4ec748f9476f9f7e1f0a247b917dde4abe8a024de9ba34c7458b41bec8be6b2",
"sig": "a65dbf32349f1a57dd1dd6fc058c69a98be467f5ad408179da6e3b67abc6f2361415eb70214588d21079a9d0351500808f8c244b69f40b35a41999294461ca00"
"sig": "10f57136bfbbd1b4f6c89ba87e1d63c2c1b4478e2a3ceed9924013dce51e886047e028adef41d0ae326940d228505acf78fc39f69fef03b5edc202b79d099808"
},
{
"keyid": "1bd53d9d6f08f6efba19477880b348906f5f29a67d78cbca8a44aedfad12d003",
"sig": "6da78dc6741ca4f4d83948d357812f6b7ebd62fc5a0ecbf157cde40b3851f448fae35fad5d9fa2e8453088312f6600083c45dfd2f4f72a4c293809d1aad24508"
}
],
"signed": {
"_type": "root",
"consistent_snapshot": false,
"expires": "2051-06-27T21:21:13Z",
"expires": "2051-07-25T11:55:10Z",
"keys": {
"1bd53d9d6f08f6efba19477880b348906f5f29a67d78cbca8a44aedfad12d003": {
"keytype": "ed25519",
Expand Down
14 changes: 7 additions & 7 deletions tests/data/repository/metadata/root.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"signatures": [
{
"keyid": "1bd53d9d6f08f6efba19477880b348906f5f29a67d78cbca8a44aedfad12d003",
"sig": "47a42813ae34829c60539dcceba0d4b9a8a9286beaa8d5f07d3de3050d404426c22bc95b271e7c5e7ee529bc3180f009eb31313fb825f76c3ed9ca2c501bd503"
},
{
"keyid": "b7ad916e4138911155b771d0ede66666e9647e7fb6c85a1904be97dee5653568",
"sig": "421d85636350a89805abc4561acd3019ecf17246a37e91374a53276b5d56638c83754960c27d038c7d1193bdb33db12faf69b7a19099627c745c569093ee0005"
"sig": "3b5fef2d49edba8b0dfb8fb7781fd5721c3f11f602c5700d9821367862973a65d90d2cdc4fbf9433207475defec1eeea085cf9f1145f1eea54210647cbb34004"
},
{
"keyid": "d4ec748f9476f9f7e1f0a247b917dde4abe8a024de9ba34c7458b41bec8be6b2",
"sig": "a65dbf32349f1a57dd1dd6fc058c69a98be467f5ad408179da6e3b67abc6f2361415eb70214588d21079a9d0351500808f8c244b69f40b35a41999294461ca00"
"sig": "10f57136bfbbd1b4f6c89ba87e1d63c2c1b4478e2a3ceed9924013dce51e886047e028adef41d0ae326940d228505acf78fc39f69fef03b5edc202b79d099808"
},
{
"keyid": "1bd53d9d6f08f6efba19477880b348906f5f29a67d78cbca8a44aedfad12d003",
"sig": "6da78dc6741ca4f4d83948d357812f6b7ebd62fc5a0ecbf157cde40b3851f448fae35fad5d9fa2e8453088312f6600083c45dfd2f4f72a4c293809d1aad24508"
}
],
"signed": {
"_type": "root",
"consistent_snapshot": false,
"expires": "2051-06-27T21:21:13Z",
"expires": "2051-07-25T11:55:10Z",
"keys": {
"1bd53d9d6f08f6efba19477880b348906f5f29a67d78cbca8a44aedfad12d003": {
"keytype": "ed25519",
Expand Down
4 changes: 2 additions & 2 deletions tests/data/repository/metadata/snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"signatures": [
{
"keyid": "5ef48ab6f5398d2bf17f1f4c4fc0e0440c4aa3734a05ae523561e02e8a99957a",
"sig": "73a146f5e1f12c0a36e88c8d7bf613baa1d528ea0c9480fe0d2ccd74d6da239da04470f68d283738194185cc82289c5f9f1312efea373b51dc8722965ca1fc0b"
"sig": "9ad02e9e365e3ac008643d79e9c953ed6289ae63cfb3f22cf5c3029747f84e97c84f637d66838a35af10a50a5bdf0ca25c86e515129e85467c53e27c23ee690c"
}
],
"signed": {
"_type": "snapshot",
"expires": "2051-06-27T21:21:13Z",
"expires": "2051-07-25T11:55:10Z",
"meta": {
"targets.json": {
"version": 6
Expand Down
5 changes: 3 additions & 2 deletions tests/data/repository/metadata/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"signatures": [
{
"keyid": "cd9930c92ac25c02a2f92ae3128b50459b53d7532ef9c0f364e78f388d5808a5",
"sig": "344b1c779103db5c8462508d7a5e72ef9ae8dea0c5fd303d55cace03a87fd67312ff5ca01fc2e377d7d0dcbbbf3f4dff378f5c9759801590340c0b9e3d23bc07"
"sig": "61b235261b5b9627c6f5bdf155dc2f49ead5deb67c8ee7d5696c92c62c17dbc219ffef3ce35ba48327cf46362f8ec427b37dd6965001a220790e5c41b094790b"
}
],
"signed": {
"_type": "targets",
"expires": "2051-06-27T21:21:13Z",
"expires": "2051-07-25T11:55:10Z",
"spec_version": "1.0.31",
"targets": {
"example_app-1.0.tar.gz": {
Expand All @@ -29,6 +29,7 @@
},
"example_app-2.0.tar.gz": {
"custom": {
"_tufup_flag_required": true,
"changes": [
"this has changed",
"that has changed",
Expand Down
4 changes: 2 additions & 2 deletions tests/data/repository/metadata/timestamp.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"signatures": [
{
"keyid": "eddb87d254d513c1404d71e17620ecf5260e1836babdaa55197916c582f37a00",
"sig": "4f05f9947e1fd704ffb877fa994e8841eb1a34a2ccf021c2eac5a618eca3c11baad8531d154fa5c8aa187e0bfaa57b521901ef502bd7a3dc601bfa1c408a4106"
"sig": "948741ee18e88ac4c4e97f534373ced3b3e640ec7352233b8e92f3732c4e5588e12729bea79b075cb23e3d36031c16571974d9baf4700da33c90096368948005"
}
],
"signed": {
"_type": "timestamp",
"expires": "2051-06-27T21:21:13Z",
"expires": "2051-07-25T11:55:10Z",
"meta": {
"snapshot.json": {
"version": 7
Expand Down
32 changes: 20 additions & 12 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,28 +149,36 @@ def test_download_and_apply_update(self):
self.assertIn(mock_install, mock_apply.call_args.kwargs.values())

def test_check_for_updates(self):
# expectations (based on targets in tests/data/repository):
# - pre=None, '', or 'invalid': only full releases are included, finds 2.0 patch
# - pre='a': finds all, but total patch size exceeds archive size
# - pre='b': there is no 'b' release, so this finds same as 'rc'
# - pre='rc': finds 2.0 and 3.0rc0, total patch size smaller than archive
client = self.get_refreshed_client()
with patch.object(client, 'refresh', Mock()):
# expectations (based on targets in tests/data/repository, but ignoring
# required releases):
# - pre=None, '', or 'invalid':
# only full releases are included, so this finds 2.0 (patch)
# - pre='a': finds all, but total patch size exceeds archive size
# - pre='b': there is no 'b' release, so this finds same as 'rc'
# - pre='rc': finds 2.0 and 3.0rc0, total patch size smaller than archive
for pre, expected in [
(None, 1), ('', 1), ('a', 1), ('b', 2), ('rc', 2), ('invalid', 1)
]:
with self.subTest(msg=pre):
# verify that we always find the required release, unless we
# explicitly set ignore_required=True
required_version = '2.0'
target_meta = client.check_for_updates(pre=pre)
self.assertEqual(required_version, str(target_meta.version))
# for the actual test we want to treat all versions as not-required
target_meta = client.check_for_updates(
pre=pre, ignore_required=True
)
self.assertTrue(expected and target_meta)
self.assertEqual(expected, len(client.new_targets))
if pre == 'a':
self.assertTrue(
all(item.is_archive for item in client.new_targets.keys())
)
else:
self.assertTrue(
all(item.is_patch for item in client.new_targets.keys())
self.assertTrue(
all(
getattr(item, 'is_archive' if pre == 'a' else 'is_patch')
for item in client.new_targets.keys()
)
)
# verify that we can access custom metadata where needed
if target_meta.is_patch:
self.assertTrue(target_meta.custom)
Expand Down

0 comments on commit ebb9ecb

Please sign in to comment.