batman (working version kinda)
This commit is contained in:
commit
6dd38036e7
65 changed files with 3950 additions and 0 deletions
51
tests/test_models.py
Normal file
51
tests/test_models.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
import pytest
|
||||
from app.core.models import Subnet, Server, App
|
||||
import ipaddress
|
||||
|
||||
def test_subnet_cidr_validation():
|
||||
"""Test CIDR format validation for Subnet model"""
|
||||
# Valid CIDR formats
|
||||
valid_cidrs = [
|
||||
'192.168.1.0/24',
|
||||
'10.0.0.0/8',
|
||||
'172.16.0.0/16'
|
||||
]
|
||||
|
||||
for cidr in valid_cidrs:
|
||||
subnet = Subnet(cidr=cidr, location='Test')
|
||||
# This shouldn't raise an exception
|
||||
ipaddress.ip_network(subnet.cidr)
|
||||
|
||||
# Invalid CIDR formats should raise ValueError
|
||||
invalid_cidrs = [
|
||||
'192.168.1.0', # Missing mask
|
||||
'192.168.1.0/33', # Invalid mask
|
||||
'256.0.0.0/24' # Invalid IP
|
||||
]
|
||||
|
||||
for cidr in invalid_cidrs:
|
||||
subnet = Subnet(cidr=cidr, location='Test')
|
||||
with pytest.raises(ValueError):
|
||||
ipaddress.ip_network(subnet.cidr)
|
||||
|
||||
def test_server_open_ports(app):
|
||||
"""Test the get_open_ports method"""
|
||||
# Create test server with app having specific ports
|
||||
subnet = Subnet(cidr='192.168.1.0/24', location='Test')
|
||||
server = Server(hostname='test-server', ip_address='192.168.1.10', subnet=subnet)
|
||||
app1 = App(
|
||||
name='Test App',
|
||||
server=server,
|
||||
ports=[
|
||||
{'port': 80, 'type': 'tcp', 'status': 'open', 'desc': 'HTTP'},
|
||||
{'port': 443, 'type': 'tcp', 'status': 'open', 'desc': 'HTTPS'},
|
||||
{'port': 8080, 'type': 'tcp', 'status': 'closed', 'desc': 'Alt HTTP'}
|
||||
]
|
||||
)
|
||||
|
||||
# The get_open_ports should only return ports with status 'open'
|
||||
open_ports = server.get_open_ports()
|
||||
assert len(open_ports) == 2
|
||||
assert {'port': 80, 'type': 'tcp', 'status': 'open', 'desc': 'HTTP'} in open_ports
|
||||
assert {'port': 443, 'type': 'tcp', 'status': 'open', 'desc': 'HTTPS'} in open_ports
|
||||
assert {'port': 8080, 'type': 'tcp', 'status': 'closed', 'desc': 'Alt HTTP'} not in open_ports
|
Loading…
Add table
Add a link
Reference in a new issue