UNPKG

@flamesshield/rules-engine

Version:

Independent rules engine for security analysis of Firebase

113 lines 4.72 kB
import { EnrichedProjectInformation, StaticRule, ValidationResult, RuleResult } from '../types/index.js'; import { RuleValidator } from '../validation/rule-validator.js'; /** * Interface for test scenarios */ export interface TestScenario { name: string; projectInfo: EnrichedProjectInformation; expectedResults: Record<string, boolean>; description: string; } /** * Helper class for common rule testing operations. * Provides utilities for running rule validations, asserting results, * and setting up test contexts with minimal boilerplate. */ export declare class RuleTestHelper { private static validator; /** * Validates a single rule's structure against project information */ static validateRule(rule: StaticRule, projectInfo: EnrichedProjectInformation): ValidationResult; /** * Executes rules against project information and returns execution results */ static executeRules(rules: StaticRule[], projectInfo: EnrichedProjectInformation): Promise<RuleResult[]>; /** * Validates a rule and asserts that it passes (no violations) */ static assertRulePasses(rule: StaticRule, projectInfo: EnrichedProjectInformation, message?: string): Promise<void>; /** * Validates a rule and asserts that it fails (is triggered) */ static assertRuleFails(rule: StaticRule, projectInfo: EnrichedProjectInformation, expectedMessage?: string): Promise<RuleResult>; /** * Validates multiple rules and asserts expected pass/fail counts */ static assertExecutionResults(rules: StaticRule[], projectInfo: EnrichedProjectInformation, expectations: { expectedPassing?: number; expectedFailing?: number; expectedTotalTriggered?: number; }): Promise<RuleResult[]>; /** * Creates a test scenario with predefined project info and rules (legacy version) */ static createTestScenarioLegacy(scenarioName: 'appcheck-enabled' | 'appcheck-disabled' | 'auth-enabled' | 'auth-disabled' | 'custom', customProjectInfo?: EnrichedProjectInformation, customRules?: StaticRule[]): Promise<{ projectInfo: EnrichedProjectInformation; rules: StaticRule[]; }>; /** * Creates a test scenario with project info and expected results */ static createTestScenario(name: string, projectInfo: EnrichedProjectInformation, expectedResults: Record<string, boolean>, description?: string): TestScenario; /** * Runs a complete test scenario and returns results (legacy version) */ static runTestScenario(scenarioName: 'appcheck-enabled' | 'appcheck-disabled' | 'auth-enabled' | 'auth-disabled' | 'custom', customProjectInfo?: EnrichedProjectInformation, customRules?: StaticRule[]): Promise<RuleResult[]>; /** * Runs multiple test scenarios with the provided rules */ static runTestScenarios(rules: StaticRule[], scenarios: TestScenario[]): Promise<void>; /** * Utility for testing rule conditions with different field values */ static testRuleWithFieldValues(baseRule: StaticRule, fieldPath: string, testValues: Array<{ value: any; shouldPass: boolean; description?: string; }>): Promise<Array<{ value: any; result: RuleResult; passed: boolean; }>>; /** * Creates a mock validation context for testing */ static createValidationContext(projectInfo?: EnrichedProjectInformation, rules?: StaticRule[]): Promise<{ projectInfo: EnrichedProjectInformation; rules: StaticRule[]; validator: RuleValidator; executionId: string; startTime: Date; }>; /** * Utility for performance testing of rule execution */ static benchmarkRuleExecution(rules: StaticRule[], projectInfo: EnrichedProjectInformation, iterations?: number): Promise<{ averageTime: number; minTime: number; maxTime: number; totalTime: number; }>; /** * Validates rule structure and syntax */ static validateRuleStructure(rule: StaticRule, projectInfo: EnrichedProjectInformation): ValidationResult; /** * Utility for testing rule categories and severities */ static groupResultsByCategory(results: RuleResult[]): Record<string, RuleResult[]>; /** * Utility for testing rule severities */ static groupResultsBySeverity(results: RuleResult[]): Record<string, RuleResult[]>; /** * Asserts that rule execution results match expectations */ static assertRuleResults(results: RuleResult[], expectations: Array<{ ruleId: string; shouldTrigger: boolean; }>): void; } //# sourceMappingURL=RuleTestHelper.d.ts.map