def test_trust_data_init(m_trust_data, data: dict, role: str, class_: str,
                         exception):
    with exception:
        trust_data_ = td.TrustData(data, role)
        assert trust_data_.signed == data["signed"]
        assert trust_data_.signatures == data["signatures"]
        assert trust_data_.kind == role
        assert class_ in str(type(trust_data_))
def alice_key_store(m_trust_data):
    sample_key = ("MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEtR5kwrD"
                  "K22SyCu7WMF8tCjVgeORAS2PWacRcBN/VQdVK4PVk1"
                  "w4pMWlz9AHQthDGl+W2k3elHkPbR+gNkK2PCA==")
    k = ks.KeyStore(sample_key)
    for role in ("root", "targets", "snapshot", "timestamp"):
        k.update(td.TrustData(get_td(f"alice-image/{role}"), role))
    return k
def test_validate_trust_data_expiry(m_trust_data, data, role, delta,
                                    exception):
    with exception:
        trust_data_ = td.TrustData(data, role)
        time = dt.datetime.now(pytz.utc) + dt.timedelta(hours=delta)
        time_format = "%Y-%m-%dT%H:%M:%S.%f%z"
        trust_data_.signed["expires"] = time.strftime(time_format)

        assert trust_data_.validate_expiry() is None
def test_validate(m_trust_data, sample_key_store, data: dict, role: str):
    _trust_data = td.TrustData(data, role)
    _trust_data.validate(sample_key_store)
def test_get_digest(m_trust_data, data: dict, tag: str, digest: str,
                    exception):
    with exception:
        trust_data = td.TrustData(data, "targets")
        assert trust_data.get_digest(tag) == digest
def test_get_tags(m_trust_data, data: dict, out: list):
    trust_data = td.TrustData(data, "targets")
    assert list(trust_data.get_tags()) == out
def test_get_delegations(m_trust_data, data: dict, out: list):
    trust_data = td.TrustData(data, "targets")
    assert trust_data.get_delegations() == out
def test_has_delegation(m_trust_data, data: dict, out: bool):
    trust_data_ = td.TrustData(data, "targets")
    assert trust_data_.has_delegations() == out
def test_get_hashes(m_trust_data, data: dict, role: str, hashes: dict):
    trust_data_ = td.TrustData(data, role)
    assert trust_data_.get_hashes() == hashes
def test_get_keys(m_trust_data, data: dict, role: str, keys: dict):
    trust_data_ = td.TrustData(data, role)
    assert trust_data_.get_keys() == keys
def test_validate_hash(m_trust_data, sample_key_store, data: dict, role: str,
                       exception):
    with exception:
        trust_data_ = td.TrustData(data, role)
        assert trust_data_.validate_hash(sample_key_store) is None