From 3adc470832f6137e6e7abbb837b06ba101ae5f63 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Wed, 4 Dec 2024 11:09:25 +0700 Subject: [PATCH] Create intrusionDetection.test.js --- tests/intrusionDetection.test.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/intrusionDetection.test.js diff --git a/tests/intrusionDetection.test.js b/tests/intrusionDetection.test.js new file mode 100644 index 000000000..0c39bbae3 --- /dev/null +++ b/tests/intrusionDetection.test.js @@ -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' }); + }); +});