authentik.enterprise.agents.tests.test_attribution

 1from django.test import TestCase
 2
 3from authentik.core.models import User, UserTypes
 4from authentik.core.tests.utils import create_test_user
 5from authentik.enterprise.agents.models import Agent
 6from authentik.events.utils import get_user
 7from authentik.lib.generators import generate_id
 8
 9
10class AgentAttributionTests(TestCase):
11    """Agent actions are audited on behalf of the owning human."""
12
13    def test_agent_event_user_records_owner(self):
14        owner = create_test_user()
15        agent = Agent.create_for_user(owner, name="support-bot")
16        data = get_user(agent)
17        self.assertTrue(data["is_agent"])
18        self.assertEqual(data["on_behalf_of"]["pk"], owner.pk)
19
20    def test_normal_user_has_no_attribution(self):
21        data = get_user(create_test_user())
22        self.assertNotIn("on_behalf_of", data)
23        self.assertNotIn("is_agent", data)
24
25    def test_plain_service_account_has_no_attribution(self):
26        """A service account that is not an agent is not attributed to an owner."""
27        service_account = User.objects.create(
28            username=generate_id(), type=UserTypes.SERVICE_ACCOUNT
29        )
30        data = get_user(service_account)
31        self.assertNotIn("on_behalf_of", data)
32        self.assertNotIn("is_agent", data)
class AgentAttributionTests(django.test.testcases.TestCase):
11class AgentAttributionTests(TestCase):
12    """Agent actions are audited on behalf of the owning human."""
13
14    def test_agent_event_user_records_owner(self):
15        owner = create_test_user()
16        agent = Agent.create_for_user(owner, name="support-bot")
17        data = get_user(agent)
18        self.assertTrue(data["is_agent"])
19        self.assertEqual(data["on_behalf_of"]["pk"], owner.pk)
20
21    def test_normal_user_has_no_attribution(self):
22        data = get_user(create_test_user())
23        self.assertNotIn("on_behalf_of", data)
24        self.assertNotIn("is_agent", data)
25
26    def test_plain_service_account_has_no_attribution(self):
27        """A service account that is not an agent is not attributed to an owner."""
28        service_account = User.objects.create(
29            username=generate_id(), type=UserTypes.SERVICE_ACCOUNT
30        )
31        data = get_user(service_account)
32        self.assertNotIn("on_behalf_of", data)
33        self.assertNotIn("is_agent", data)

Agent actions are audited on behalf of the owning human.

def test_agent_event_user_records_owner(self):
14    def test_agent_event_user_records_owner(self):
15        owner = create_test_user()
16        agent = Agent.create_for_user(owner, name="support-bot")
17        data = get_user(agent)
18        self.assertTrue(data["is_agent"])
19        self.assertEqual(data["on_behalf_of"]["pk"], owner.pk)
def test_normal_user_has_no_attribution(self):
21    def test_normal_user_has_no_attribution(self):
22        data = get_user(create_test_user())
23        self.assertNotIn("on_behalf_of", data)
24        self.assertNotIn("is_agent", data)
def test_plain_service_account_has_no_attribution(self):
26    def test_plain_service_account_has_no_attribution(self):
27        """A service account that is not an agent is not attributed to an owner."""
28        service_account = User.objects.create(
29            username=generate_id(), type=UserTypes.SERVICE_ACCOUNT
30        )
31        data = get_user(service_account)
32        self.assertNotIn("on_behalf_of", data)
33        self.assertNotIn("is_agent", data)

A service account that is not an agent is not attributed to an owner.