-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: unit tests for buildFirewall rules
- Loading branch information
Showing
2 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { buildFirewallRules } from './updateFirewallRule'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
describe('buildFirewallRules', () => { | ||
it('should build a single firewall rule correctly', async () => { | ||
const blockedIps = ['192.168.0.1', '10.0.0.1', '172.16.0.1']; | ||
const expectedRules = [ | ||
{ | ||
action: 'block', | ||
description: 'Block Bot IP addresses #1', | ||
expression: 'http.x_forwarded_for in {"192.168.0.1" "10.0.0.1" "172.16.0.1"}', | ||
}, | ||
]; | ||
const rules = await buildFirewallRules(blockedIps); | ||
|
||
expect(rules).toEqual(expectedRules); | ||
}); | ||
|
||
// Add more test cases here... | ||
it('should build multiple firewall rules correctly', async () => { | ||
const blockedIps = [ | ||
'68.237.223.37', | ||
'53.40.210.202', | ||
'140.184.133.152', | ||
'253.221.155.217', | ||
'195.43.16.78', | ||
'2.2.2.2', | ||
'2.2.2.2', | ||
'2.2.2.2', | ||
'2.2.2.2', | ||
'2.2.2.2', | ||
'3.3.3.3', | ||
'3.3.3.3', | ||
'3.3.3.3', | ||
'3.3.3.3', | ||
'3.3.3.3', | ||
'4.4.4.4', | ||
'4.4.4.4', | ||
]; | ||
const expectedRules = [ | ||
{ | ||
action: 'block', | ||
description: 'Block Bot IP addresses #1', | ||
expression: | ||
'http.x_forwarded_for in {"68.237.223.37" "53.40.210.202" "140.184.133.152" "253.221.155.217" "195.43.16.78"}', | ||
}, | ||
{ | ||
action: 'block', | ||
description: 'Block Bot IP addresses #2', | ||
expression: 'http.x_forwarded_for in {"2.2.2.2" "2.2.2.2" "2.2.2.2" "2.2.2.2" "2.2.2.2"}', | ||
}, | ||
{ | ||
action: 'block', | ||
description: 'Block Bot IP addresses #3', | ||
expression: 'http.x_forwarded_for in {"3.3.3.3" "3.3.3.3" "3.3.3.3" "3.3.3.3" "3.3.3.3"}', | ||
}, | ||
{ | ||
action: 'block', | ||
description: 'Block Bot IP addresses #4', | ||
expression: 'http.x_forwarded_for in {"4.4.4.4" "4.4.4.4"}', | ||
}, | ||
]; | ||
const rules = await buildFirewallRules(blockedIps, 5); | ||
expect(rules).toEqual(expectedRules); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters