Record browser action evidence metadata

This commit is contained in:
ZacharyZhang-NY committed 2026-05-23 22:33:33 -04:00
1 parent cf2ed628b0
commit 20c8ef6ef3
6 files changed
+173 -38

No files matched your search

@@ -23,7 +23,7 @@ describe("domain services", () => {
const connection = createConnection();
const rows = connection.db.prepare("select version from schema_migrations order by version asc").all() as Array<{ version: number }>;
expect(rows.map((row) => row.version)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]);
expect(rows.map((row) => row.version)).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]);
connection.close();
});
@@ -7,7 +7,7 @@ import { ApprovalService } from "../../src/main/services/approval-service";
import { FileService } from "../../src/main/services/file-service";
import { OrganizationService } from "../../src/main/services/organization-service";
import { SnapshotService } from "../../src/main/services/snapshot-service";
import { SocialService } from "../../src/main/services/social-service";
import { SocialService, type SocialLoginWindowInput } from "../../src/main/services/social-service";
import { APPROVAL_STATE, ROUTE_TO_TYPE, SOCIAL_PLATFORM } from "../../src/shared/domain";
import { createId } from "../../src/shared/ids";
@@ -95,6 +95,71 @@ describe("social service", () => {
connection.close();
});
test("records browser login evidence metadata", () => {
const connection = createConnection();
const organization = new OrganizationService(connection.db);
const launched: SocialLoginWindowInput[] = [];
const social = new SocialService(connection.db, (input) => { launched.push(input); });
const snapshot = new SnapshotService(connection.db);
let orgId = "";
let employeeId = "";
let socialAccountId = "";
connection.transaction(() => {
orgId = createOrganization(organization);
employeeId = firstEmployeeId(connection, orgId);
socialAccountId = social.createAccount({
orgId,
platform: SOCIAL_PLATFORM.LINKEDIN,
handle: "acme",
displayName: "Acme",
createdByEmployeeId: employeeId,
authorizedEmployeeId: employeeId,
});
social.launchLoginWindow({ orgId, socialAccountId, employeeId });
});
const state = snapshot.load();
const action = state.browserActions[0]!;
const actionMetadata = JSON.parse(action.metadataJson) as { hostAllowlist: string[] };
const audit = state.socialAuditRecords.find((record) => record.eventType === "login_window_opened");
const auditMetadata = JSON.parse(audit!.metadataJson) as { hostAllowlist: string[] };
expect(launched).toHaveLength(1);
expect(launched[0]).toMatchObject({
title: "acme",
loginUrl: "https://www.linkedin.com/login",
partitionKey: `persist:agentcompany-social-${socialAccountId}`,
sandboxEnabled: true,
});
expect(launched[0]?.allowedHosts).toEqual(["linkedin.com", "www.linkedin.com"]);
expect(action).toMatchObject({
socialAccountId,
actionType: "login_window_opened",
policyDecision: "allowed_human_login",
evidenceFileId: null,
});
expect(actionMetadata).toMatchObject({
platform: SOCIAL_PLATFORM.LINKEDIN,
loginUrl: "https://www.linkedin.com/login",
permissionPolicy: "deny_all",
sandboxEnabled: true,
actorType: "employee",
actorId: employeeId,
});
expect(actionMetadata.hostAllowlist).toEqual(["linkedin.com", "www.linkedin.com"]);
expect(audit).toMatchObject({
sourceType: "browser_action",
sourceId: action.id,
eventType: "login_window_opened",
actorType: "employee",
actorId: employeeId,
policyDecision: "allowed_human_login",
});
expect(auditMetadata.hostAllowlist).toEqual(["linkedin.com", "www.linkedin.com"]);
connection.close();
});
test("pins files and schedules social posts behind approval", () => {
const connection = createConnection();
const organization = new OrganizationService(connection.db);