mirror of
https://github.com/bitwarden/browser
synced 2026-01-27 06:43:41 +00:00
PM-30879 deleted simple unit test for models. we can do without them.
This commit is contained in:
@@ -1,189 +0,0 @@
|
||||
import { OrganizationIntegrationServiceName } from "../organization-integration-service-type";
|
||||
|
||||
import { HecConfiguration } from "./hec-configuration";
|
||||
|
||||
describe("HecConfiguration", () => {
|
||||
const testUri = "https://hec.example.com:8088/services/collector";
|
||||
const testToken = "test-hec-token-12345";
|
||||
|
||||
describe("constructor", () => {
|
||||
it("should initialize with required parameters", () => {
|
||||
const config = new HecConfiguration(
|
||||
testUri,
|
||||
testToken,
|
||||
OrganizationIntegrationServiceName.Huntress,
|
||||
);
|
||||
|
||||
expect(config.uri).toBe(testUri);
|
||||
expect(config.token).toBe(testToken);
|
||||
expect(config.bw_serviceName).toBe(OrganizationIntegrationServiceName.Huntress);
|
||||
});
|
||||
|
||||
it("should default scheme to Bearer when not provided", () => {
|
||||
const config = new HecConfiguration(
|
||||
testUri,
|
||||
testToken,
|
||||
OrganizationIntegrationServiceName.Huntress,
|
||||
);
|
||||
|
||||
expect(config.scheme).toBe("Bearer");
|
||||
});
|
||||
|
||||
it("should use custom scheme when provided", () => {
|
||||
const config = new HecConfiguration(
|
||||
testUri,
|
||||
testToken,
|
||||
OrganizationIntegrationServiceName.Huntress,
|
||||
"Splunk",
|
||||
);
|
||||
|
||||
expect(config.scheme).toBe("Splunk");
|
||||
});
|
||||
|
||||
it("should work with CrowdStrike service name", () => {
|
||||
const config = new HecConfiguration(
|
||||
testUri,
|
||||
testToken,
|
||||
OrganizationIntegrationServiceName.CrowdStrike,
|
||||
"Bearer",
|
||||
);
|
||||
|
||||
expect(config.bw_serviceName).toBe(OrganizationIntegrationServiceName.CrowdStrike);
|
||||
});
|
||||
});
|
||||
|
||||
describe("toString", () => {
|
||||
it("should produce valid JSON", () => {
|
||||
const config = new HecConfiguration(
|
||||
testUri,
|
||||
testToken,
|
||||
OrganizationIntegrationServiceName.Huntress,
|
||||
);
|
||||
|
||||
expect(() => JSON.parse(config.toString())).not.toThrow();
|
||||
});
|
||||
|
||||
it("should include Uri with PascalCase key", () => {
|
||||
const config = new HecConfiguration(
|
||||
testUri,
|
||||
testToken,
|
||||
OrganizationIntegrationServiceName.Huntress,
|
||||
);
|
||||
const result = JSON.parse(config.toString());
|
||||
|
||||
expect(result.Uri).toBe(testUri);
|
||||
expect(result.uri).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should include Scheme with PascalCase key", () => {
|
||||
const config = new HecConfiguration(
|
||||
testUri,
|
||||
testToken,
|
||||
OrganizationIntegrationServiceName.Huntress,
|
||||
"Splunk",
|
||||
);
|
||||
const result = JSON.parse(config.toString());
|
||||
|
||||
expect(result.Scheme).toBe("Splunk");
|
||||
expect(result.scheme).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should include Token with PascalCase key", () => {
|
||||
const config = new HecConfiguration(
|
||||
testUri,
|
||||
testToken,
|
||||
OrganizationIntegrationServiceName.Huntress,
|
||||
);
|
||||
const result = JSON.parse(config.toString());
|
||||
|
||||
expect(result.Token).toBe(testToken);
|
||||
expect(result.token).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should include bw_serviceName with original casing", () => {
|
||||
const config = new HecConfiguration(
|
||||
testUri,
|
||||
testToken,
|
||||
OrganizationIntegrationServiceName.Huntress,
|
||||
);
|
||||
const result = JSON.parse(config.toString());
|
||||
|
||||
expect(result.bw_serviceName).toBe(OrganizationIntegrationServiceName.Huntress);
|
||||
});
|
||||
|
||||
it("should include default Bearer scheme in output", () => {
|
||||
const config = new HecConfiguration(
|
||||
testUri,
|
||||
testToken,
|
||||
OrganizationIntegrationServiceName.Huntress,
|
||||
);
|
||||
const result = JSON.parse(config.toString());
|
||||
|
||||
expect(result.Scheme).toBe("Bearer");
|
||||
});
|
||||
|
||||
it("should produce consistent output for same input", () => {
|
||||
const config1 = new HecConfiguration(
|
||||
testUri,
|
||||
testToken,
|
||||
OrganizationIntegrationServiceName.Huntress,
|
||||
"Bearer",
|
||||
);
|
||||
const config2 = new HecConfiguration(
|
||||
testUri,
|
||||
testToken,
|
||||
OrganizationIntegrationServiceName.Huntress,
|
||||
"Bearer",
|
||||
);
|
||||
|
||||
expect(config1.toString()).toBe(config2.toString());
|
||||
});
|
||||
|
||||
it("should handle special characters in token", () => {
|
||||
const specialToken = "token+with/special=chars&more";
|
||||
const config = new HecConfiguration(
|
||||
testUri,
|
||||
specialToken,
|
||||
OrganizationIntegrationServiceName.Huntress,
|
||||
);
|
||||
const result = JSON.parse(config.toString());
|
||||
|
||||
expect(result.Token).toBe(specialToken);
|
||||
});
|
||||
|
||||
it("should handle URLs with query parameters", () => {
|
||||
const uriWithParams = "https://hec.example.com:8088/services/collector?channel=abc123";
|
||||
const config = new HecConfiguration(
|
||||
uriWithParams,
|
||||
testToken,
|
||||
OrganizationIntegrationServiceName.Huntress,
|
||||
);
|
||||
const result = JSON.parse(config.toString());
|
||||
|
||||
expect(result.Uri).toBe(uriWithParams);
|
||||
});
|
||||
});
|
||||
|
||||
describe("service property", () => {
|
||||
it("should allow setting optional service property", () => {
|
||||
const config = new HecConfiguration(
|
||||
testUri,
|
||||
testToken,
|
||||
OrganizationIntegrationServiceName.Huntress,
|
||||
);
|
||||
config.service = "custom-service";
|
||||
|
||||
expect(config.service).toBe("custom-service");
|
||||
});
|
||||
|
||||
it("should be undefined by default", () => {
|
||||
const config = new HecConfiguration(
|
||||
testUri,
|
||||
testToken,
|
||||
OrganizationIntegrationServiceName.Huntress,
|
||||
);
|
||||
|
||||
expect(config.service).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,141 +0,0 @@
|
||||
import { OrganizationIntegrationServiceName } from "../../organization-integration-service-type";
|
||||
|
||||
import { HecTemplate } from "./hec-template";
|
||||
|
||||
describe("HecTemplate", () => {
|
||||
describe("constructor", () => {
|
||||
it("should initialize with index and service name", () => {
|
||||
const template = new HecTemplate("main", OrganizationIntegrationServiceName.Huntress);
|
||||
|
||||
expect(template.index).toBe("main");
|
||||
expect(template.bw_serviceName).toBe(OrganizationIntegrationServiceName.Huntress);
|
||||
});
|
||||
|
||||
it("should initialize with CrowdStrike service name", () => {
|
||||
const template = new HecTemplate("security", OrganizationIntegrationServiceName.CrowdStrike);
|
||||
|
||||
expect(template.index).toBe("security");
|
||||
expect(template.bw_serviceName).toBe(OrganizationIntegrationServiceName.CrowdStrike);
|
||||
});
|
||||
|
||||
it("should initialize with empty index", () => {
|
||||
const template = new HecTemplate("", OrganizationIntegrationServiceName.Huntress);
|
||||
|
||||
expect(template.index).toBe("");
|
||||
expect(template.bw_serviceName).toBe(OrganizationIntegrationServiceName.Huntress);
|
||||
});
|
||||
});
|
||||
|
||||
describe("toString", () => {
|
||||
it("should produce valid JSON", () => {
|
||||
const template = new HecTemplate("main", OrganizationIntegrationServiceName.Huntress);
|
||||
|
||||
expect(() => JSON.parse(template.toString())).not.toThrow();
|
||||
});
|
||||
|
||||
it("should include bw_serviceName in output", () => {
|
||||
const template = new HecTemplate("main", OrganizationIntegrationServiceName.Huntress);
|
||||
const result = JSON.parse(template.toString());
|
||||
|
||||
expect(result.bw_serviceName).toBe(OrganizationIntegrationServiceName.Huntress);
|
||||
});
|
||||
|
||||
it("should include source as bitwarden", () => {
|
||||
const template = new HecTemplate("main", OrganizationIntegrationServiceName.Huntress);
|
||||
const result = JSON.parse(template.toString());
|
||||
|
||||
expect(result.source).toBe("bitwarden");
|
||||
});
|
||||
|
||||
it("should include service as event-logs", () => {
|
||||
const template = new HecTemplate("main", OrganizationIntegrationServiceName.Huntress);
|
||||
const result = JSON.parse(template.toString());
|
||||
|
||||
expect(result.service).toBe("event-logs");
|
||||
});
|
||||
|
||||
it("should include index when provided", () => {
|
||||
const template = new HecTemplate("main", OrganizationIntegrationServiceName.Huntress);
|
||||
const result = JSON.parse(template.toString());
|
||||
|
||||
expect(result.index).toBe("main");
|
||||
});
|
||||
|
||||
it("should omit index when empty string", () => {
|
||||
const template = new HecTemplate("", OrganizationIntegrationServiceName.Huntress);
|
||||
const result = JSON.parse(template.toString());
|
||||
|
||||
expect(result.index).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should omit index when whitespace only", () => {
|
||||
const template = new HecTemplate(" ", OrganizationIntegrationServiceName.Huntress);
|
||||
const result = JSON.parse(template.toString());
|
||||
|
||||
expect(result.index).toBeUndefined();
|
||||
});
|
||||
|
||||
describe("event object", () => {
|
||||
let result: any;
|
||||
|
||||
beforeEach(() => {
|
||||
const template = new HecTemplate("main", OrganizationIntegrationServiceName.Huntress);
|
||||
result = JSON.parse(template.toString());
|
||||
});
|
||||
|
||||
it("should include event object", () => {
|
||||
expect(result.event).toBeDefined();
|
||||
expect(typeof result.event).toBe("object");
|
||||
});
|
||||
|
||||
it("should include core event fields with placeholders", () => {
|
||||
expect(result.event.object).toBe("event");
|
||||
expect(result.event.type).toBe("#Type#");
|
||||
expect(result.event.itemId).toBe("#CipherId#");
|
||||
expect(result.event.collectionId).toBe("#CollectionId#");
|
||||
expect(result.event.groupId).toBe("#GroupId#");
|
||||
expect(result.event.policyId).toBe("#PolicyId#");
|
||||
expect(result.event.memberId).toBe("#UserId#");
|
||||
expect(result.event.actingUserId).toBe("#ActingUserId#");
|
||||
expect(result.event.installationId).toBe("#InstallationId#");
|
||||
expect(result.event.date).toBe("#DateIso8601#");
|
||||
expect(result.event.device).toBe("#DeviceType#");
|
||||
expect(result.event.ipAddress).toBe("#IpAddress#");
|
||||
});
|
||||
|
||||
it("should include secrets manager fields with placeholders", () => {
|
||||
expect(result.event.secretId).toBe("#SecretId#");
|
||||
expect(result.event.projectId).toBe("#ProjectId#");
|
||||
expect(result.event.serviceAccountId).toBe("#ServiceAccountId#");
|
||||
});
|
||||
|
||||
it("should include acting user enrichment fields", () => {
|
||||
expect(result.event.actingUserName).toBe("#ActingUserName#");
|
||||
expect(result.event.actingUserEmail).toBe("#ActingUserEmail#");
|
||||
expect(result.event.actingUserType).toBe("#ActingUserType#");
|
||||
});
|
||||
|
||||
it("should include member enrichment fields", () => {
|
||||
expect(result.event.userName).toBe("#UserName#");
|
||||
expect(result.event.userEmail).toBe("#UserEmail#");
|
||||
expect(result.event.userType).toBe("#UserType#");
|
||||
});
|
||||
|
||||
it("should include group enrichment field", () => {
|
||||
expect(result.event.groupName).toBe("#GroupName#");
|
||||
});
|
||||
});
|
||||
|
||||
it("should work with different service names", () => {
|
||||
const crowdstrikeTemplate = new HecTemplate(
|
||||
"security",
|
||||
OrganizationIntegrationServiceName.CrowdStrike,
|
||||
);
|
||||
const result = JSON.parse(crowdstrikeTemplate.toString());
|
||||
|
||||
expect(result.bw_serviceName).toBe(OrganizationIntegrationServiceName.CrowdStrike);
|
||||
expect(result.source).toBe("bitwarden");
|
||||
expect(result.event).toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user