def test_hashes_no_library_support():
    prop = HashesProperty(["foo"])

    result = prop.clean({"foo": "bar"}, False)
    assert result == ({"foo": "bar"}, False)

    result = prop.clean({"foo": "bar"}, True)
    assert result == ({"foo": "bar"}, False)

    with pytest.raises(CustomContentError):
        # require exact name match for unsupported hash algorithms
        prop.clean({"FOO": "bar"}, False)

    result = prop.clean({"FOO": "bar"}, True)
    assert result == ({"FOO": "bar"}, True)
def test_hashes_property_custom():
    value = {
        "sha256":
        "6db12788c37247f2316052e142f42f4b259d6561751e5f401a1ae2a6df9c674b",
        "abc-123": "aaaaaaaaaaaaaaaaaaaaa",
    }
    expected_cleaned_value = {
        # cleaning transforms recognized hash algorithm names to the spec-
        # mandated name.
        "SHA-256":
        "6db12788c37247f2316052e142f42f4b259d6561751e5f401a1ae2a6df9c674b",
        "abc-123": "aaaaaaaaaaaaaaaaaaaaa",
    }

    hash_prop = HashesProperty(["SHA-256"])
    result = hash_prop.clean(value, True)
    assert result == (expected_cleaned_value, True)

    with pytest.raises(CustomContentError):
        hash_prop.clean(value, False)
Esempio n. 3
0
def test_hashes_property_invalid(value):
    hash_prop = HashesProperty()

    with pytest.raises(ValueError):
        hash_prop.clean(value)
Esempio n. 4
0
def test_hashes_property_valid(value):
    hash_prop = HashesProperty()
    assert hash_prop.clean(value)
Esempio n. 5
0
def test_hash_property_invalid_key(key):
    p = HashesProperty(["foo"], spec_version="2.0")
    with pytest.raises(DictionaryKeyError):
        p.clean({key: "foo"}, True)
Esempio n. 6
0
def test_hash_property_valid_key(key):
    p = HashesProperty(["foo"], spec_version="2.0")
    result = p.clean({key: "bar"}, True)
    assert result == ({key: "bar"}, True)
def test_hashes_property_invalid(value):
    hash_prop = HashesProperty(["sha256", "md5"])

    with pytest.raises(ValueError):
        hash_prop.clean(value, False)
def test_hashes_property_valid(value):
    hash_prop = HashesProperty(["sha256", "md5", "ripemd160"])
    _, has_custom = hash_prop.clean(value, False)
    assert not has_custom