mirror of
https://github.com/fuckpiracyshield/api.git
synced 2026-01-24 00:10:51 +01:00
Various fixes.
This commit is contained in:
parent
0fb6d08a7f
commit
e32bc9d4b7
19 changed files with 452 additions and 59 deletions
47
tests/01_general/test_0101_valid_ipv6.py
Normal file
47
tests/01_general/test_0101_valid_ipv6.py
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import pytest
|
||||
|
||||
from piracyshield_component.validation.validator import Validator
|
||||
from piracyshield_component.validation.rules.ipv6 import IPv6
|
||||
|
||||
from piracyshield_component.validation.validator import ValidatorRuleNonValidException
|
||||
|
||||
class TestGeneral:
|
||||
|
||||
valid_ipv6_list = [
|
||||
"2001:0db8:85a3:0000:0000:8a2e:0370:7334",
|
||||
"fe80:0000:0000:0000:0204:61ff:fe9d:f156",
|
||||
"2001:0db8:0000:0000:0000:0000:0000:0001",
|
||||
"fe80:0000:0000:0000:0204:61ff:fe9d:f157",
|
||||
"2001:0db8:1234:5678:90ab:cdef:0000:0000",
|
||||
"2606:2800:220:1:248:1893:25c8:1946",
|
||||
"2001:4860:4860:0:0:0:0:6464",
|
||||
"2001:4860:4860:0:0:0:0:8844",
|
||||
"2001:4860:4860:0:0:0:0:8888",
|
||||
"2001:4860:4860:0:0:0:0:64",
|
||||
"2606:4700:4700:0:0:0:0:64",
|
||||
"2606:4700:4700:0:0:0:0:1001",
|
||||
"2606:4700:4700:0:0:0:0:1111",
|
||||
"2606:4700:4700:0:0:0:0:6400",
|
||||
"2a01:4f8:10a:1::4",
|
||||
"::1",
|
||||
"::"
|
||||
]
|
||||
|
||||
def test_valid_ipv6(self):
|
||||
"""
|
||||
Check if the IPv6 list is valid.
|
||||
"""
|
||||
|
||||
for ipv6 in self.valid_ipv6_list:
|
||||
rules = [
|
||||
IPv6()
|
||||
]
|
||||
|
||||
v = Validator(ipv6, rules)
|
||||
|
||||
v.validate()
|
||||
|
||||
if len(v.errors) != 0:
|
||||
print(ipv6, v.errors)
|
||||
|
||||
assert len(v.errors) == 0
|
||||
78
tests/01_general/test_0102_non_valid_ipv6.py
Normal file
78
tests/01_general/test_0102_non_valid_ipv6.py
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
import pytest
|
||||
|
||||
from piracyshield_component.validation.validator import Validator
|
||||
from piracyshield_component.validation.rules.ipv6 import IPv6
|
||||
|
||||
from piracyshield_component.validation.validator import ValidatorRuleNonValidException
|
||||
|
||||
class TestGeneral:
|
||||
|
||||
valid_ipv6_list = [
|
||||
# wrong length
|
||||
"2001:0db8:85a3:0000:0000:8a2e:0370:7334:1234",
|
||||
"FE80:0000:0000:0000:0202:B3FF:FE1E:8329:ABCD:EF12",
|
||||
"1234:5678:9ABC:DEF0:1234:5678:9ABC:DEF0:1234",
|
||||
|
||||
# non valid characters
|
||||
"2001:0db8:85a3:0000:0000:8a2e:0370:73G4",
|
||||
"FE80:0000:0000:0000:0202:B3FF:FE1E:832Z",
|
||||
"2001:0db8::85a3::7334",
|
||||
|
||||
# too many segments
|
||||
"FE80:0000:0000:0000:0202:B3FF:FE1E:8329:1234",
|
||||
"2001:0db8:85a3:0000:0000:8a2e:0370:7334:5678",
|
||||
|
||||
# too few segments
|
||||
"2001:0db8:85a3:0000:8a2e:0370",
|
||||
"FE80:0000:B3FF:FE1E:8329",
|
||||
|
||||
# consecutive double colons
|
||||
"2001:0db8::85a3::7334",
|
||||
"::1234::5678::9ABC",
|
||||
|
||||
# leading zeros in a quad
|
||||
|
||||
"2001:0db8:85a3:00001:0000:8a2e:0370:7334",
|
||||
"FE80:00000:0000:0000:0202:B3FF:FE1E:8329",
|
||||
|
||||
# non valid dot in notation
|
||||
"2001:0db8:85a3:0000:0000:8a2e:0370.7334",
|
||||
"FE80:0000:0000:0000:0202:B3FF:FE1E:8329.1234",
|
||||
|
||||
# mixed ipv6/ipv4
|
||||
|
||||
"2001:0db8:85a3:0000:0000:8a2e:192.168.1.1.1",
|
||||
"::ffff:192.168.0.256",
|
||||
|
||||
# segment with more than 4 hex characters
|
||||
|
||||
"2001:0db8:85a3:00000:0000:8a2e:0370:7334",
|
||||
"FE80:0000:0000:10000:0202:B3FF:FE1E:8329",
|
||||
|
||||
# segment with non-hex characters
|
||||
"2001:0db8:85g3:0000:0000:8a2e:0370:7334",
|
||||
"FE80:0000:0000:0000:0202:B3ZZ:FE1E:8329",
|
||||
|
||||
# incorrect ipv4 mapping
|
||||
"::ffff:192.168.0.999",
|
||||
"::ffff:299.255.255.255"
|
||||
]
|
||||
|
||||
def test_valid_ipv6(self):
|
||||
"""
|
||||
Check if the IPv6 list is valid.
|
||||
"""
|
||||
|
||||
for ipv6 in self.valid_ipv6_list:
|
||||
rules = [
|
||||
IPv6()
|
||||
]
|
||||
|
||||
v = Validator(ipv6, rules)
|
||||
|
||||
v.validate()
|
||||
|
||||
if len(v.errors) == 0:
|
||||
print(ipv6, v.errors)
|
||||
|
||||
assert len(v.errors) != 0
|
||||
46
tests/01_general/test_0103_cidr_ipv4.py
Normal file
46
tests/01_general/test_0103_cidr_ipv4.py
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import pytest
|
||||
|
||||
from piracyshield_component.validation.validator import Validator
|
||||
from piracyshield_component.validation.rules.cidr_syntax_ipv4 import CIDRSyntaxIPv4
|
||||
|
||||
from piracyshield_component.validation.validator import ValidatorRuleNonValidException
|
||||
|
||||
from random import randint
|
||||
|
||||
class TestGeneral:
|
||||
|
||||
max_cidr_classes = 10000
|
||||
|
||||
valid_cidr_ipv4_list = []
|
||||
|
||||
def setup_method(self):
|
||||
self.valid_cidr_ipv4_list = self.__generate_random_list(self.max_cidr_classes)
|
||||
|
||||
def test_valid_cidr_ipv4(self):
|
||||
"""
|
||||
Check if the CIDR IPv4 syntax is valid.
|
||||
"""
|
||||
|
||||
for cidr_ipv4 in self.valid_cidr_ipv4_list:
|
||||
rules = [
|
||||
CIDRSyntaxIPv4()
|
||||
]
|
||||
|
||||
v = Validator(cidr_ipv4, rules)
|
||||
|
||||
v.validate()
|
||||
|
||||
if len(v.errors) != 0:
|
||||
print(cidr_ipv4, v.errors)
|
||||
|
||||
assert len(v.errors) == 0
|
||||
|
||||
def __generate_random_list(self, size: int):
|
||||
cidr_list = []
|
||||
subnet_variety = [8, 16, 24] # Different subnet masks for variety
|
||||
|
||||
for i in range(0, size):
|
||||
for subnet in subnet_variety:
|
||||
cidr_list.append(f"{randint(1, 254)}.0.0.0/{subnet}")
|
||||
|
||||
return cidr_list
|
||||
54
tests/01_general/test_0103_cidr_ipv6.py
Normal file
54
tests/01_general/test_0103_cidr_ipv6.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import pytest
|
||||
|
||||
from piracyshield_component.validation.validator import Validator
|
||||
from piracyshield_component.validation.rules.cidr_syntax_ipv6 import CIDRSyntaxIPv6
|
||||
|
||||
from piracyshield_component.validation.validator import ValidatorRuleNonValidException
|
||||
|
||||
from random import randint, getrandbits
|
||||
|
||||
from ipaddress import IPv6Address
|
||||
|
||||
class TestGeneral:
|
||||
|
||||
max_cidr_classes = 10000
|
||||
|
||||
valid_cidr_ipv6_list = []
|
||||
|
||||
def setup_method(self):
|
||||
self.valid_cidr_ipv6_list = self.__generate_random_list(self.max_cidr_classes)
|
||||
|
||||
def test_valid_cidr_ipv6(self):
|
||||
"""
|
||||
Check if the CIDR IPv6 syntax is valid.
|
||||
"""
|
||||
|
||||
for cidr_ipv6 in self.valid_cidr_ipv6_list:
|
||||
rules = [
|
||||
CIDRSyntaxIPv6()
|
||||
]
|
||||
|
||||
v = Validator(cidr_ipv6, rules)
|
||||
|
||||
v.validate()
|
||||
|
||||
if len(v.errors) != 0:
|
||||
print(cidr_ipv6, v.errors)
|
||||
|
||||
assert len(v.errors) == 0
|
||||
|
||||
def __generate_random_list(self, size: int):
|
||||
cidr_list = []
|
||||
|
||||
for _ in range(size):
|
||||
# Generating a random IPv6 address
|
||||
random_ip = IPv6Address(getrandbits(128))
|
||||
|
||||
# Choosing a random subnet mask
|
||||
subnet_mask = randint(1, 128)
|
||||
|
||||
# Combining to form CIDR notation
|
||||
cidr = f"{random_ip}/{subnet_mask}"
|
||||
cidr_list.append(cidr)
|
||||
|
||||
return cidr_list
|
||||
|
|
@ -15,14 +15,14 @@ class TestReporterCreateTicket:
|
|||
ticket_wait_time = 76
|
||||
|
||||
ticket_parameters = {
|
||||
'dda_id': '002ad48ea02a43db9003b4f15f1da9b3',
|
||||
'dda_id': '7b3d774097ca477687f29ad0968833ac',
|
||||
'description': '__MOCK_TICKET__',
|
||||
'forensic_evidence': {
|
||||
'hash': {}
|
||||
},
|
||||
'fqdn': [
|
||||
'mock-website.com',
|
||||
'google.com'
|
||||
'mock-website-two.com'
|
||||
],
|
||||
'ipv4': [
|
||||
'9.8.7.6',
|
||||
|
|
@ -44,8 +44,6 @@ class TestReporterCreateTicket:
|
|||
|
||||
create_response = authenticated_post_request('/api/v1/ticket/create', self.access_token, self.ticket_parameters)
|
||||
|
||||
print(" RES -> ", create_response.json())
|
||||
|
||||
assert create_response.status_code == 200
|
||||
assert create_response.json()['status'] == 'success'
|
||||
|
||||
|
|
@ -30,6 +30,15 @@ class TestProviderSetTicketItems:
|
|||
assert response.status_code == 200
|
||||
assert response.json()['status'] == 'success'
|
||||
|
||||
def test_set_unprocessed_fqdn(self):
|
||||
response = authenticated_post_request('/api/v1/ticket/item/set/unprocessed', self.access_token, {
|
||||
'value': 'mock-website-two.com',
|
||||
'reason': 'ALREADY_BLOCKED'
|
||||
})
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()['status'] == 'success'
|
||||
|
||||
def test_set_processed_ipv4(self):
|
||||
response = authenticated_post_request('/api/v1/ticket/item/set/processed', self.access_token, {
|
||||
'value': '9.8.7.6'
|
||||
Loading…
Add table
Add a link
Reference in a new issue