Example #1
0
def test_get_attribute_value():
    request_json = {
        "subject": {
            "id": "a",
            "attributes": {
                "firstName": "Carl",
                "lastName": "Right",
                "middleName": ""
            }
        },
        "resource": {
            "id": "a",
            "attributes": {
                "name": "Calendar"
            }
        },
        "action": {
            "id": "",
            "attributes": {}
        },
        "context": {}
    }
    request = Request.from_json(request_json)
    context = EvaluationContext(request, providers=[EmailAttributeProvider()])
    assert context.get_attribute_value("subject", "$.firstName") == "Carl"
    assert context.get_attribute_value("subject", "$.middleName") == ""
    assert context.get_attribute_value("subject",
                                       "$.email") == "*****@*****.**"
    assert context.get_attribute_value("resource", "$.name") == "Calendar"
    assert context.get_attribute_value("context", "$.ip") is None
Example #2
0
def test_attribute_provider_infinite_recursion():
    request_json = {
        "subject": {
            "id": "a",
            "attributes": {
                "firstName": "Carl",
                "lastName": "Right"
            }
        },
        "resource": {
            "id": "a",
            "attributes": {
                "name": "Calendar"
            }
        },
        "action": {
            "id": "",
            "attributes": {}
        },
        "context": {}
    }
    request = Request.from_json(request_json)
    context = EvaluationContext(request, providers=[FaultyAttributeProvider()])
    assert context.get_attribute_value("subject", "$.email") is None

    context = EvaluationContext(request,
                                providers=[
                                    FaultyAttributeProvider(),
                                    EmailAttributeProvider(),
                                    FaultyAttributeProvider(),
                                    EmailAttributeProvider(),
                                    FaultyAttributeProvider()
                                ])
    assert context.get_attribute_value("subject", "$.age") is None