-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test the https-availability nibble-query #4028
Changes from 3 commits
5d40c52
d5dcdac
945cec2
e9d68b0
937a973
7d1fcba
e89b02d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import os | ||
from datetime import datetime | ||
from itertools import permutations | ||
from unittest.mock import Mock | ||
|
||
import pytest | ||
|
@@ -11,14 +12,61 @@ | |
from octopoes.models.ooi.network import IPAddressV4, IPPort, Network, Protocol | ||
from octopoes.models.ooi.service import IPService, Service | ||
from octopoes.models.ooi.web import HostnameHTTPURL, HTTPHeader, HTTPResource, WebScheme, Website | ||
from octopoes.repositories.ooi_repository import XTDBOOIRepository | ||
|
||
if os.environ.get("CI") != "1": | ||
pytest.skip("Needs XTDB multinode container.", allow_module_level=True) | ||
|
||
STATIC_IP = ".".join((4 * "1 ").split()) | ||
STATIC_IP = ".".join(4 * ["1"]) | ||
|
||
|
||
def test_https_availability_query(xtdb_octopoes_service: OctopoesService, event_manager: Mock, valid_time: datetime): | ||
def create_port(xtdb_ooi_repository: XTDBOOIRepository, ip: str, port: int, valid_time: datetime) -> IPAddressV4: | ||
network = Network(name="internet") | ||
ip = IPAddressV4(address=ip, network=network.reference) | ||
port = IPPort(port=port, address=ip.reference, protocol=Protocol.TCP) | ||
hostname = Hostname(name="example.com", network=network.reference) | ||
service = Service(name="http") | ||
ip_service = IPService(ip_port=port.reference, service=service.reference) | ||
website = Website(ip_service=ip_service.reference, hostname=hostname.reference) | ||
|
||
xtdb_ooi_repository.save(network, valid_time) | ||
xtdb_ooi_repository.save(port, valid_time) | ||
xtdb_ooi_repository.save(ip, valid_time) | ||
xtdb_ooi_repository.save(service, valid_time) | ||
xtdb_ooi_repository.save(ip_service, valid_time) | ||
xtdb_ooi_repository.save(hostname, valid_time) | ||
xtdb_ooi_repository.save(website, valid_time) | ||
|
||
xtdb_ooi_repository.commit() | ||
|
||
return ip | ||
|
||
|
||
def ip_generator(): | ||
for ip in permutations(range(1, 256), 4): | ||
yield ".".join([str(x) for x in ip]) | ||
|
||
|
||
def test_https_availability_query(xtdb_ooi_repository: XTDBOOIRepository, event_manager: Mock, valid_time: datetime): | ||
query = https_availability.query([None] * 4) | ||
ip = ip_generator() | ||
|
||
first_ip = create_port(xtdb_ooi_repository, next(ip), 80, valid_time) | ||
assert xtdb_ooi_repository.session.client.query(query)[0][-1] == 0 | ||
|
||
for _ in range(20): | ||
create_port(xtdb_ooi_repository, next(ip), 80, valid_time) | ||
assert xtdb_ooi_repository.session.client.query(query)[0][-1] == 0 | ||
|
||
create_port(xtdb_ooi_repository, str(first_ip.address), 443, valid_time) | ||
assert xtdb_ooi_repository.session.client.query(query)[0][-1] == 1 | ||
|
||
for _ in range(12): | ||
create_port(xtdb_ooi_repository, next(ip), 443, valid_time) | ||
assert xtdb_ooi_repository.session.client.query(query)[0][-1] == 13 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @originalsouth Or should this be 1 since the ips we created are not attached to the hostname through the website? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the ipaddress should be a parameter in the or-join, I'll check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the query breaks with more than one targets, let me check... |
||
|
||
|
||
def test_https_availability(xtdb_octopoes_service: OctopoesService, event_manager: Mock, valid_time: datetime): | ||
xtdb_octopoes_service.nibbler.nibbles = {https_availability.id: https_availability} | ||
|
||
network = Network(name="internet") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just write 1.1.1.1 here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason we write it that way is not to have SonarCloud report a "static ip security vulnerability".