コード例 #1
0
def test_static_validation_fail_context_is_list_with_dict_and_bad_uri():
    context = [{
        "favoriteColor": "https://example.com/vocab#favoriteColor"
    }, "this is a bad uri"]
    operation = {
        META: {
            "name": "TestContext",
            "version": 1,
            "type": CONTEXT_TYPE
        },
        DATA: {
            CONTEXT_CONTEXT: context
        },
        RS_TYPE: "200"
    }
    req = Request(
        "test",
        1,
        operation,
        "sig",
    )
    ch = ContextHandler(None, None)
    with pytest.raises(InvalidClientRequest) as e:
        ch.static_validation(req)
    assert "@context URI this is a bad uri badly formed" in str(e.value)
コード例 #2
0
def test_static_validation_pass_context_w3c_example_15():
    context = {
        "@context": {
            "referenceNumber": "https://example.com/vocab#referenceNumber",
            "favoriteFood": "https://example.com/vocab#favoriteFood"
        }
    }
    operation = {
        META: {
            "name": "TestContext",
            "version": 1,
            "type": CONTEXT_TYPE
        },
        DATA: {
            CONTEXT_CONTEXT: context
        },
        RS_TYPE: "200"
    }
    req = Request(
        "test",
        1,
        operation,
        "sig",
    )
    ch = ContextHandler(None, None)
    ch.static_validation(req)
コード例 #3
0
def test_static_validation_fail_invalid_type():
    operation = {
        "meta": {
            "type": "context",
            "name": "TestContext",
            "version": 1
        },
        "data": W3C_BASE_CONTEXT,
        "type": "201"
    }
    req = Request(
        "test",
        1,
        operation,
        "sig",
    )
    ch = ContextHandler(None, None)
    with pytest.raises(LogicError):
        ch.static_validation(req)
コード例 #4
0
def test_static_validation_pass_context_value_is_dict():
    context = {"favoriteColor": "https://example.com/vocab#favoriteColor"}
    operation = {
        META: {
            "name": "TestContext",
            "version": 1,
            "type": CONTEXT_TYPE
        },
        DATA: {
            CONTEXT_CONTEXT: context
        },
        RS_TYPE: "200"
    }
    req = Request(
        "test",
        1,
        operation,
        "sig",
    )
    ch = ContextHandler(None, None)
    ch.static_validation(req)
コード例 #5
0
def test_static_validation_pass_context_w3c_examples_v1():
    # test for https://www.w3.org/2018/credentials/examples/v1
    operation = {
        META: {
            "name": "TestContext",
            "version": 1,
            "type": CONTEXT_TYPE
        },
        DATA: {
            CONTEXT_CONTEXT: W3C_EXAMPLE_V1_CONTEXT
        },
        RS_TYPE: "200"
    }
    req = Request(
        "test",
        1,
        operation,
        "sig",
    )
    ch = ContextHandler(None, None)
    ch.static_validation(req)
コード例 #6
0
def test_static_validation_pass_context_w3c_base():
    # Sample from specification: https://w3c.github.io/vc-data-model/#base-context
    # Actual file contents from: https://www.w3.org/2018/credentials/v1
    operation = {
        META: {
            "name": "TestContext",
            "version": 1,
            "type": CONTEXT_TYPE
        },
        DATA: {
            CONTEXT_CONTEXT: W3C_BASE_CONTEXT
        },
        RS_TYPE: "200"
    }
    req = Request(
        "test",
        1,
        operation,
        "sig",
    )
    ch = ContextHandler(None, None)
    ch.static_validation(req)
コード例 #7
0
def test_static_validation_pass_context_value_is_list_with_dict_and_uri():
    context = [{
        "favoriteColor": "https://example.com/vocab#favoriteColor"
    }, "https://www.w3.org/ns/odrl.jsonld"]
    operation = {
        META: {
            "name": "TestContext",
            "version": 1,
            "type": CONTEXT_TYPE
        },
        DATA: {
            CONTEXT_CONTEXT: context
        },
        RS_TYPE: "200"
    }
    req = Request(
        "test",
        1,
        operation,
        "sig",
    )
    ch = ContextHandler(None, None)
    ch.static_validation(req)
コード例 #8
0
def test_static_validation_fail_context_not_uri_or_array_or_object():
    context = 52
    operation = {
        META: {
            "name": "TestContext",
            "version": 1,
            "type": CONTEXT_TYPE
        },
        DATA: {
            CONTEXT_CONTEXT: context
        },
        RS_TYPE: "200"
    }
    req = Request(
        "test",
        1,
        operation,
        "sig",
    )
    ch = ContextHandler(None, None)
    with pytest.raises(InvalidClientRequest) as e:
        ch.static_validation(req)
    assert "'@context' value must be url, array, or object" in str(e.value)
コード例 #9
0
def test_static_validation_context_fail_bad_uri():
    context = "2http:/..@#$"
    operation = {
        META: {
            "name": "TestContext",
            "version": 1,
            "type": CONTEXT_TYPE
        },
        DATA: {
            CONTEXT_CONTEXT: context
        },
        RS_TYPE: "200"
    }
    req = Request(
        "test",
        1,
        operation,
        "sig",
    )
    ch = ContextHandler(None, None)
    with pytest.raises(InvalidClientRequest) as e:
        ch.static_validation(req)
    assert "@context URI 2http:/..@#$ badly formed" in str(e.value)