|
| 1 | +import { Rule, Result, Engine } from '@cloudgraph/sdk' |
| 2 | +import cuid from 'cuid' |
| 3 | +import { initRuleEngine } from '../../../utils/test' |
| 4 | + |
| 5 | +import Azure_PCI_DSS_321_Data_Retention_Check_1 from '../rules/pci-dss-3.2.1-data-retention-check-1' |
| 6 | + |
| 7 | +export interface RetentionPolicy { |
| 8 | + enabled: boolean |
| 9 | + days: number |
| 10 | +} |
| 11 | + |
| 12 | +export interface QueryazureLogProfile { |
| 13 | + id: string |
| 14 | + name?: string |
| 15 | + locations?: string[] |
| 16 | + categories?: string[] |
| 17 | + retentionPolicy?: RetentionPolicy | null |
| 18 | +} |
| 19 | + |
| 20 | +export interface PCIQueryResponse { |
| 21 | + queryazureLogProfile?: QueryazureLogProfile[] |
| 22 | +} |
| 23 | + |
| 24 | +describe('PCI Data Security Standard: 3.2.1', () => { |
| 25 | + let rulesEngine: Engine |
| 26 | + beforeAll(() => { |
| 27 | + rulesEngine = initRuleEngine('azure', 'PCI') |
| 28 | + }) |
| 29 | + |
| 30 | + describe('Retention Check 1: Activity Log Retention should be 365 days or greater', () => { |
| 31 | + const getTestRuleFixture = ( |
| 32 | + enabled: boolean, |
| 33 | + days: number, |
| 34 | + ): PCIQueryResponse => { |
| 35 | + return { |
| 36 | + queryazureLogProfile: [ |
| 37 | + { |
| 38 | + id: cuid(), |
| 39 | + retentionPolicy: { |
| 40 | + enabled, |
| 41 | + days, |
| 42 | + }, |
| 43 | + }, |
| 44 | + ], |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + // Act |
| 49 | + const testRule = async ( |
| 50 | + data: PCIQueryResponse, |
| 51 | + expectedResult: Result |
| 52 | + ): Promise<void> => { |
| 53 | + // Act |
| 54 | + const [processedRule] = await rulesEngine.processRule( |
| 55 | + Azure_PCI_DSS_321_Data_Retention_Check_1 as Rule, |
| 56 | + { ...data } |
| 57 | + ) |
| 58 | + |
| 59 | + // Asserts |
| 60 | + expect(processedRule.result).toBe(expectedResult) |
| 61 | + } |
| 62 | + |
| 63 | + test('No Security Issue when Monitor audit profile log retention day is 0 means logs are kept forever', async () => { |
| 64 | + const data: PCIQueryResponse = getTestRuleFixture(true, 0) |
| 65 | + await testRule(data, Result.PASS) |
| 66 | + }) |
| 67 | + |
| 68 | + test('Security Issue when Monitor audit profile log is less than 365 days', async () => { |
| 69 | + const data: PCIQueryResponse = getTestRuleFixture(true, 364) |
| 70 | + await testRule(data, Result.FAIL) |
| 71 | + }) |
| 72 | + |
| 73 | + test('No Security Issue when Monitor audit profile log retention day is 365 days', async () => { |
| 74 | + const data: PCIQueryResponse = getTestRuleFixture(true, 365) |
| 75 | + await testRule(data, Result.PASS) |
| 76 | + }) |
| 77 | + |
| 78 | + test('No Security Issue when Monitor audit profile log retention day is more than 365 days', async () => { |
| 79 | + const data: PCIQueryResponse = getTestRuleFixture(true, 366) |
| 80 | + await testRule(data, Result.PASS) |
| 81 | + }) |
| 82 | + }) |
| 83 | +}) |
0 commit comments