Exemple #1
0
def test_nested_payload():
    input_json = \
        b"""
        {
            "name": "rattan",
            "a": "value",
            "c": {
                "za": "value",
                "a": "hello"
            }
        }
        """

    sorted_json = \
        b"""
        {
            "a": "value",
            "c": {
                "a": "hello",
                "za": "value"
            },
            "name": "rattan"
        }
        """

    assert signer.__get_hashed_payload(input_json) == \
           signer.__get_hashed_payload(sorted_json)
Exemple #2
0
def test_unordered_payload():
    assert signer.__get_hashed_payload(b'{"name": "rattan", "a": "value"}') == \
           signer.__get_hashed_payload(b'{"a": "value", "name": "rattan"}')
Exemple #3
0
def test_malformed_payload():
    with pytest.raises(ValueError) as excepinfo:
        signer.__get_hashed_payload(b'{""}')
        assert excepinfo.type is json.JSONDecodeError
Exemple #4
0
def test_none_payload():
    assert signer.__get_hashed_payload(b'{}') == \
           signer.__get_hashed_payload(None)
Exemple #5
0
def test_get_hashed_payload(payload, expected_hash):
    assert signer.__get_hashed_payload(payload) == expected_hash