You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.3 KiB

10 months ago
  1. """Test authorization module."""
  2. import pytest
  3. from keycloak.authorization import Permission, Policy, Role
  4. from keycloak.exceptions import KeycloakAuthorizationConfigError
  5. def test_authorization_objects():
  6. """Test authorization objects."""
  7. # Test permission
  8. p = Permission(name="test", type="test", logic="test", decision_strategy="test")
  9. assert p.name == "test"
  10. assert p.type == "test"
  11. assert p.logic == "test"
  12. assert p.decision_strategy == "test"
  13. p.resources = ["test"]
  14. assert p.resources == ["test"]
  15. p.scopes = ["test"]
  16. assert p.scopes == ["test"]
  17. # Test policy
  18. p = Policy(name="test", type="test", logic="test", decision_strategy="test")
  19. assert p.name == "test"
  20. assert p.type == "test"
  21. assert p.logic == "test"
  22. assert p.decision_strategy == "test"
  23. p.roles = ["test"]
  24. assert p.roles == ["test"]
  25. p.permissions = ["test"]
  26. assert p.permissions == ["test"]
  27. p.add_permission(permission="test2")
  28. assert p.permissions == ["test", "test2"]
  29. with pytest.raises(KeycloakAuthorizationConfigError):
  30. p.add_role(role="test2")
  31. # Test role
  32. r = Role(name="test")
  33. assert r.name == "test"
  34. assert not r.required
  35. assert r.get_name() == "test"
  36. assert r == r
  37. assert r == "test"