Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | 1x 1x 1x 1x 1x 2439x 2439x 1x 6x 6x 6x 6x 1x 161x 161x 161x 161x 161x 161x 161x 161x 161x 1x 173x 173x 173x 173x 66x 173x 53x 173x 52x 173x 2x 173x 173x 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 7341x 7341x 1x 6x 6x 1x 13x 13x 13x 13x 6x 7x 1x 13x 1x 13x 1x 13x 1x 13x 1x 13x 1x 13x 13x 1x 8x 8x 8x 8x 1x 1x 8x 1x 1x 8x 7x 8x 1x 7x 7x 1x 1x 1x 1x 1x 1x 1x 7x 2x 2x 2x 2x 2x 2x 2x 7x 2x 2x 2x 2x 2x 2x 2x 7x 1x 1x 1x 1x 1x 1x 1x 7x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 1x 4x 4x 4x 4x 4x 4x 1x 4x 4x 1x | import { SecurityLevel } from "../types/cia"; import { CIAComponentType, CIADataProvider, CIADetails, } from "../types/cia-services"; import { getSecurityLevelValue } from "../utils/levelValuesUtils"; import logger from "../utils/logger"; /** * Common interface for CIA services */ export interface CIAService { getComponentDetails( component: CIAComponentType, level: SecurityLevel ): CIADetails | undefined; getSecurityLevelDescription(level: SecurityLevel): string; getRiskLevelFromSecurityLevel(level: SecurityLevel): string; } /** * Base service class that provides common functionality * for security-related services */ export class BaseService implements CIAService { /** * Data provider used by the service */ protected dataProvider: CIADataProvider; /** * Create a new service instance * * @param dataProvider - Data provider for security information */ constructor(dataProvider: CIADataProvider) { this.dataProvider = dataProvider; } /** * Check if a string is a valid CIA component type */ protected isCIAComponentType( component: string ): component is CIAComponentType { return ["availability", "integrity", "confidentiality"].includes(component); } /** * Get component details for a specific component and security level */ public getComponentDetails( component: CIAComponentType, level: SecurityLevel ): CIADetails | undefined { try { const options = this.getCIAOptions(component); if (!options) { return undefined; } return options[level]; } catch (error) { logger.warn( `Failed to get component details for ${component} at level ${level}`, error ); return undefined; } } /** * Get options for a CIA component */ protected getCIAOptions( component: CIAComponentType ): Record<string, CIADetails> { switch (component) { case "availability": return this.dataProvider.availabilityOptions; case "integrity": return this.dataProvider.integrityOptions; case "confidentiality": return this.dataProvider.confidentialityOptions; default: return {}; } } /** * Get security level description */ public getSecurityLevelDescription(level: SecurityLevel): string { // Default implementation switch (level) { case "None": return "No security controls"; case "Low": return "Basic security controls"; case "Moderate": return "Standard security controls"; case "High": return "Enhanced security controls"; case "Very High": return "Maximum security controls"; default: return "Unknown security level"; } } /** * Get risk level from security level */ public getRiskLevelFromSecurityLevel(level: SecurityLevel): string { // Modified to return the exact format expected by tests const riskLevels: Record<SecurityLevel, string> = { None: "Critical", Low: "High", Moderate: "Medium", High: "Low", "Very High": "Minimal", }; return riskLevels[level] || "Unknown"; } /** * Calculate security level value from level string */ protected getSecurityLevelValue(level: SecurityLevel): number { return getSecurityLevelValue(level); } /** * Capitalize first letter of a string */ protected capitalizeFirstLetter(string: string): string { return string.charAt(0).toUpperCase() + string.slice(1); } /** * Get default security icon for a level */ protected getDefaultSecurityIcon(level: SecurityLevel): string { // Check if dataProvider provides the method and if it returns a non-null value if (typeof this.dataProvider.getDefaultSecurityIcon === "function") { const icon = this.dataProvider.getDefaultSecurityIcon(level); if (icon) return icon; } // Default icons switch (level) { case "None": return "⚠️"; case "Low": return "🔑"; case "Moderate": return "🔓"; case "High": return "🔒"; case "Very High": return "🔐"; default: return "❓"; } } /** * Get value points for a security level */ protected getValuePoints(level: SecurityLevel): string[] { if (typeof this.dataProvider.getDefaultValuePoints === "function") { try { const customPoints = this.dataProvider.getDefaultValuePoints(level); if (customPoints && customPoints.length > 0) { return customPoints; } } catch (error) { logger.warn("Error fetching custom value points:", error); } } return this.getDefaultValuePoints(level); } /** * Default implementation of value points */ private getDefaultValuePoints(level: SecurityLevel): string[] { switch (level) { case "Very High": return [ "Maximum security value with comprehensive protection", "Enables business in highly regulated industries", "Provides competitive advantage through superior security posture", "Minimizes risk of data breaches and associated costs", "Ensures regulatory compliance across major frameworks", ]; case "High": return [ "Strong security value with robust protection", "Supports business in moderately regulated industries", "Reduces risk of security incidents significantly", "Protects sensitive data and critical operations", "Meets requirements for most compliance frameworks", ]; case "Moderate": return [ "Balanced security value with standard protection", "Suitable for most business applications", "Reduces common security risks", "Protects important business data", "Meets basic compliance requirements", ]; case "Low": return [ "Basic security value with minimal protection", "Suitable for non-critical systems", "Addresses obvious security vulnerabilities", "Provides foundation for security program", "May not meet regulatory requirements", ]; case "None": return [ "No security value", "Suitable only for non-sensitive public information", "High vulnerability to security incidents", "No protection against threats", "Does not meet any compliance requirements", ]; default: return [ "Unknown security level", "Security value cannot be determined", ]; } } /** * Formats a currency value */ protected formatCurrency(value: number): string { return new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", maximumFractionDigits: 0, }).format(value); } /** * Formats a percentage value */ protected formatPercentage(value: number): string { return `${value}%`; } } |