Skip to content

Commit a766ed0

Browse files
committed
Move test case from service_config tests to request_handler test cases
1 parent 15034a2 commit a766ed0

2 files changed

Lines changed: 63 additions & 25 deletions

File tree

aikido_zen/background_process/service_config_test.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -130,31 +130,6 @@ def test_ip_blocking():
130130
bypassed_ips=["192.168.1.1", "10.0.0.0/16", "::1/128"],
131131
received_any_stats=True,
132132
)
133-
config.set_blocked_ips(
134-
[
135-
{
136-
"source": "geoip",
137-
"description": "description",
138-
"ips": [
139-
"1.2.3.4",
140-
"192.168.2.1/24",
141-
"fd00:1234:5678:9abc::1",
142-
"fd00:3234:5678:9abc::1/64",
143-
"5.6.7.8/32",
144-
],
145-
}
146-
]
147-
)
148-
149-
assert config.is_blocked_ip("1.2.3.4") is "description"
150-
assert config.is_blocked_ip("2.3.4.5") is False
151-
assert config.is_blocked_ip("192.168.2.2") is "description"
152-
assert config.is_blocked_ip("fd00:1234:5678:9abc::1") is "description"
153-
assert config.is_blocked_ip("fd00:1234:5678:9abc::2") is False
154-
assert config.is_blocked_ip("fd00:3234:5678:9abc::1") is "description"
155-
assert config.is_blocked_ip("fd00:3234:5678:9abc::2") is "description"
156-
assert config.is_blocked_ip("5.6.7.8") is "description"
157-
assert config.is_blocked_ip("1.2") is False
158133

159134
assert config.is_bypassed_ip("192.168.1.1")
160135
assert config.is_bypassed_ip("10.0.0.1")

aikido_zen/sources/functions/request_handler_test.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,3 +516,66 @@ def test_allowed_for_endpoint_and_in_allowlist_bots_are_set_but_is_not_bot(
516516

517517
# Assert
518518
assert result is None
519+
520+
521+
"""
522+
config.set_blocked_ips(
523+
[
524+
{
525+
"source": "geoip",
526+
"description": "description",
527+
"ips": [
528+
"1.2.3.4",
529+
"192.168.2.1/24",
530+
"fd00:1234:5678:9abc::1",
531+
"fd00:3234:5678:9abc::1/64",
532+
"5.6.7.8/32",
533+
],
534+
}
535+
]
536+
)
537+
538+
assert config.is_blocked_ip("fd00:3234:5678:9abc::1") is "description"
539+
assert config.is_blocked_ip("fd00:3234:5678:9abc::2") is "description"
540+
assert config.is_blocked_ip("5.6.7.8") is "description"
541+
assert config.is_blocked_ip("1.2") is False
542+
"""
543+
544+
545+
@patch_firewall_lists
546+
def test_multiple_blocked(firewall_lists):
547+
# Arrange
548+
blocked_ips = [
549+
{
550+
"source": "geoip",
551+
"description": "description",
552+
"ips": [
553+
"1.2.3.4",
554+
"192.168.2.1/24",
555+
"fd00:1234:5678:9abc::1",
556+
"fd00:3234:5678:9abc::1/64",
557+
"5.6.7.8/32",
558+
],
559+
}
560+
]
561+
firewall_lists.set_blocked_ips(blocked_ips)
562+
563+
set_context("1.2.3.4")
564+
assert request_handler("pre_response")[0].startswith("Your IP address is blocked")
565+
set_context("192.168.2.2")
566+
assert request_handler("pre_response")[0].startswith("Your IP address is blocked")
567+
set_context("fd00:1234:5678:9abc::1")
568+
assert request_handler("pre_response")[0].startswith("Your IP address is blocked")
569+
set_context("fd00:3234:5678:9abc::1")
570+
assert request_handler("pre_response")[0].startswith("Your IP address is blocked")
571+
set_context("fd00:3234:5678:9abc::2")
572+
assert request_handler("pre_response")[0].startswith("Your IP address is blocked")
573+
set_context("5.6.7.8")
574+
assert request_handler("pre_response")[0].startswith("Your IP address is blocked")
575+
576+
set_context("2.3.4.5")
577+
assert request_handler("pre_response") is None
578+
set_context("1.2")
579+
assert request_handler("pre_response") is None
580+
set_context("fd00:1234:5678:9abc::2")
581+
assert request_handler("pre_response") is None

0 commit comments

Comments
 (0)