def test_attribute_value_raises(): 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) with pytest.raises(InvalidAccessControlElementError): _ = context.attribute_value context.ace = "test" with pytest.raises(InvalidAccessControlElementError): _ = context.attribute_value context.ace = "subject" context.attribute_path = ")" with pytest.raises(InvalidAttributePathError): _ = context.attribute_value
def test_is_satisfied(self, condition, what, result): request = AccessRequest(subject={"attributes": {"what": what}}, resource={"attributes": {"name": {"what": what}}}, action={}, context={}) ctx = EvaluationContext(request) ctx.ace = "subject" ctx.attribute_path = "$.what" assert condition.is_satisfied(ctx) == result
def test_create(): 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) assert context.subject_id == request._subject_id assert context.resource_id == request._resource_id assert context.action_id == request._action_id assert context._other_providers == [] assert context.ace is None assert context.attribute_path is None context.ace = "subject" context.attribute_path = "$.firstName" assert context.attribute_value == "Carl" context.attribute_path = "$.lastName" assert context.attribute_value == "Right" context.attribute_path = "$.middleName" assert context.attribute_value == "" context.ace = "resource" context.attribute_path = "$.name" assert context.attribute_value == "Calendar"