Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_missing_target_entity_id_from_context(self, context):
target_entity = "entity1"
rules = {
target_entity: {
"deny": ["*"],
}
}
decide_service = self.create_decide_service(rules)
req = InternalRequest(None, "test_requester", None)
with pytest.raises(SATOSAError):
decide_service.process(context, req)
def _get_id(requester, user_id, hash_type):
state = State()
internal_request = InternalRequest(hash_type, requester)
UserIdHasher.save_state(internal_request, state)
return UserIdHasher.hash_id(SALT, user_id, requester, state)
def test_defaults_to_allow_all_requesters_for_target_entity_without_specific_rules(self, target_context):
rules = {
"some other entity": {
"allow": ["foobar"]
}
}
decide_service = self.create_decide_service(rules)
req = InternalRequest(None, "test_requester", None)
assert decide_service.process(target_context, req)
def test_deny_all_requesters(self, target_context, requester):
rules = {
TARGET_ENTITY: {
"deny": ["*"],
}
}
decide_service = self.create_decide_service(rules)
req = InternalRequest(None, requester, None)
with pytest.raises(SATOSAError):
decide_service.process(target_context, req)
def test_deny_takes_precedence_over_allow_all(self, target_context):
requester = "test_requester"
rules = {
TARGET_ENTITY: {
"allow": ["*"],
"deny": [requester],
}
}
decide_service = self.create_decide_service(rules)
req = InternalRequest(None, requester, None)
with pytest.raises(SATOSAError):
decide_service.process(target_context, req)
req = InternalRequest(None, "somebody else", None)
decide_service.process(target_context, req)
def test_allow_one_requester(self, target_context):
rules = {
TARGET_ENTITY: {
"allow": ["test_requester"],
}
}
decide_service = self.create_decide_service(rules)
req = InternalRequest(None, "test_requester", None)
assert decide_service.process(target_context, req)
req.requester = "somebody else"
with pytest.raises(SATOSAError):
decide_service.process(target_context, req)
def test_allow_takes_precedence_over_deny_all(self, target_context):
requester = "test_requester"
rules = {
TARGET_ENTITY: {
"allow": requester,
"deny": ["*"],
}
}
decide_service = self.create_decide_service(rules)
req = InternalRequest(None, requester, None)
assert decide_service.process(target_context, req)
req.requester = "somebody else"
with pytest.raises(SATOSAError):
decide_service.process(target_context, req)