Skip to content

Commit

Permalink
Create intrusionDetection.test.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Dec 4, 2024
1 parent bb1f91a commit 3adc470
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/intrusionDetection.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// intrusionDetection.test.js

import IntrusionDetection from './intrusionDetection'; // Import the module to be tested

describe('IntrusionDetection', () => {
let intrusionDetection;

beforeEach(() => {
intrusionDetection = new IntrusionDetection();
});

test('should detect an intrusion attempt', () => {
const result = intrusionDetection.detectIntrusion({ type: 'brute_force', source: '192.168.1.1' });
expect(result).toBe(true);
});

test('should not detect normal traffic as intrusion', () => {
const result = intrusionDetection.detectIntrusion({ type: 'normal', source: '192.168.1.1' });
expect(result).toBe(false);
});

test('should log intrusion attempts', () => {
intrusionDetection.detectIntrusion({ type: 'brute_force', source: '192.168.1.1' });
const logs = intrusionDetection.getLogs();
expect(logs).toHaveLength(1);
expect(logs[0]).toMatchObject({ type: 'brute_force', source: '192.168.1.1' });
});
});

0 comments on commit 3adc470

Please sign in to comment.