Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

1.5 KB
Raw Blame
import { describe, expect, test } from "vitest";

import { auditActorFields } from "./agent-vault-actor-name-fns";
import { AgentVaultMemberType } from "./agent-vault-enums";

describe("auditActorFields", () => {
  test("names a user by username and email", () => {
    expect(
      auditActorFields({
        type: AgentVaultMemberType.User,
        id: "user-1",
        actorName: { name: "[email protected]", email: "[email protected]" }
      })
    ).toEqual({ userId: "user-1", userName: "[email protected]", userEmail: "[email protected]" });
  });

  test("leaves userEmail out for a user with no email", () => {
    expect(
      auditActorFields({ type: AgentVaultMemberType.User, id: "user-1", actorName: { name: "robert", email: null } })
    ).toEqual({ userId: "user-1", userName: "robert" });
  });

  test("names a machine identity and a group, never with an email", () => {
    expect(
      auditActorFields({
        type: AgentVaultMemberType.MachineIdentity,
        id: "identity-1",
        actorName: { name: "ci-runner" }
      })
    ).toEqual({ machineIdentityId: "identity-1", machineIdentityName: "ci-runner" });
    expect(
      auditActorFields({ type: AgentVaultMemberType.Group, id: "group-1", actorName: { name: "platform" } })
    ).toEqual({ groupId: "group-1", groupName: "platform" });
  });

  test("still records the id when the name could not be resolved", () => {
    expect(auditActorFields({ type: AgentVaultMemberType.Group, id: "group-1" })).toEqual({
      groupId: "group-1",
      groupName: undefined
    });
  });
});