Esempio n. 1
0
def test_pull_metadata(dtuf_objs):
    exists = _copy_metadata_exists(dtuf_objs, 'root')
    with pytest.raises(tuf.exceptions.NoWorkingMirrorError if exists else tuf.
                       exceptions.RepositoryError) as ex:
        dtuf_objs.copy.pull_metadata()
    if exists:
        for ex2 in ex.value.mirror_errors.values():
            # Because of test_update below, the copy's current metadata will
            # have a higher version number than the newly-created and pushed
            # master metadata. That will generate a ReplayedMetadata error.
            assert isinstance(ex2, tuf.exceptions.ReplayedMetadataError)
            assert ex2.metadata_role == 'root'
            assert ex2.previous_version == 1
            assert ex2.current_version == 3
        dir_name = path.join(dtuf_objs.repo_dir, pytest.repo, 'copy',
                             'repository', 'metadata', 'current')
        assert dir_name.startswith(
            '/tmp/')  # check what we're about to remove!
        shutil.rmtree(dir_name)
    else:
        assert str(
            ex.value
        ) == 'No root of trust! Could not find the "root.json" file.'
    with pytest.raises(tuf.exceptions.CryptoError):
        dtuf_objs.copy.pull_metadata(pytest.make_dummy_root_pub_key())
    assert sorted(_pull_metadata_with_master_public_root_key(dtuf_objs)) == \
        (['foobar', 'hello'] if exists else ['foobar', 'hello', 'there'])
    assert _copy_metadata_exists(dtuf_objs, 'root')
    assert _copy_metadata_exists(dtuf_objs, 'targets')
    assert _copy_metadata_exists(dtuf_objs, 'snapshot')
    assert _copy_metadata_exists(dtuf_objs, 'timestamp')
Esempio n. 2
0
def test_pull_metadata(dtuf_objs):
    exists = _copy_metadata_exists(dtuf_objs, 'root')
    with pytest.raises(tuf.NoWorkingMirrorError if exists else tuf.RepositoryError) as ex:
        dtuf_objs.copy.pull_metadata()
    if exists:
        for ex2 in ex.value.mirror_errors.values():
            assert isinstance(ex2, tuf.ReplayedMetadataError)
            assert ex2.metadata_role == 'timestamp'
            assert ex2.previous_version == 2 # create=1, push=2
            assert ex2.current_version == 8
        # Because of test_update below, the copy's current metadata will have
        # a higher version number than the newly-created and pushed master
        # metadata. That will generate a ReplayedMetadata error.
        dir_name = path.join(dtuf_objs.repo_dir, pytest.repo, 'copy', 'repository', 'metadata', 'current')
        assert dir_name.startswith('/tmp/') # check what we're about to remove!
        shutil.rmtree(dir_name)
    else:
        assert str(ex.value) == 'No root of trust! Could not find the "root.json" file.'
    with pytest.raises(tuf.CryptoError):
        dtuf_objs.copy.pull_metadata(pytest.make_dummy_root_pub_key())
    assert sorted(_pull_metadata_with_master_public_root_key(dtuf_objs)) == \
        (['foobar', 'hello'] if exists else ['foobar', 'hello', 'there'])
    assert _copy_metadata_exists(dtuf_objs, 'root')
    assert _copy_metadata_exists(dtuf_objs, 'targets')
    assert _copy_metadata_exists(dtuf_objs, 'snapshot')
    assert _copy_metadata_exists(dtuf_objs, 'timestamp')
Esempio n. 3
0
 def read(self):
     return pytest.make_dummy_root_pub_key()
Esempio n. 4
0
 def read(self):
     return pytest.make_dummy_root_pub_key()