| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
"""Test inputs for anta.tests.stun.py.""" |
| 5 |
|
| 6 |
from __future__ import annotations |
| 7 |
|
| 8 |
import sys |
| 9 |
from typing import TYPE_CHECKING, Any |
| 10 |
|
| 11 |
from anta.models import AntaTest |
| 12 |
from anta.result_manager.models import AntaTestStatus |
| 13 |
from anta.tests.stun import VerifyStunClientTranslation, VerifyStunServer |
| 14 |
from tests.units.anta_tests import test |
| 15 |
|
| 16 |
if TYPE_CHECKING: |
| 17 |
from tests.units.anta_tests import AntaUnitTestData |
| 18 |
|
| 19 |
DATA: AntaUnitTestData = { |
| 20 |
(VerifyStunClientTranslation, "success"): { |
| 21 |
"eos_data": [ |
| 22 |
{"bindings": {"000000010a64ff0100000000": {"sourceAddress": {"ip": "100.64.3.2", "port": 4500}, "publicAddress": {"ip": "192.64.3.2", "port": 6006}}}}, |
| 23 |
{"bindings": {"000000040a64ff0100000000": {"sourceAddress": {"ip": "172.18.3.2", "port": 4500}, "publicAddress": {"ip": "192.18.3.2", "port": 6006}}}}, |
| 24 |
{"bindings": {"000000040a64ff0100000000": {"sourceAddress": {"ip": "172.18.4.2", "port": 4500}, "publicAddress": {"ip": "192.18.4.2", "port": 6006}}}}, |
| 25 |
{"bindings": {"000000040a64ff0100000000": {"sourceAddress": {"ip": "172.18.6.2", "port": 4500}, "publicAddress": {"ip": "192.18.6.2", "port": 6006}}}}, |
| 26 |
], |
| 27 |
"inputs": { |
| 28 |
"stun_clients": [ |
| 29 |
{"source_address": "100.64.3.2", "public_address": "192.64.3.2", "source_port": 4500, "public_port": 6006}, |
| 30 |
{"source_address": "172.18.3.2"}, |
| 31 |
{"source_address": "172.18.4.2", "source_port": 4500, "public_address": "192.18.4.2"}, |
| 32 |
{"source_address": "172.18.6.2", "source_port": 4500, "public_port": 6006}, |
| 33 |
] |
| 34 |
}, |
| 35 |
"expected": {"result": AntaTestStatus.SUCCESS}, |
| 36 |
}, |
| 37 |
(VerifyStunClientTranslation, "failure-incorrect-public-ip"): { |
| 38 |
"eos_data": [ |
| 39 |
{"bindings": {"000000010a64ff0100000000": {"sourceAddress": {"ip": "100.64.3.2", "port": 4500}, "publicAddress": {"ip": "192.64.3.2", "port": 6006}}}}, |
| 40 |
{"bindings": {"000000040a64ff0100000000": {"sourceAddress": {"ip": "172.18.3.2", "port": 4500}, "publicAddress": {"ip": "192.18.3.2", "port": 6006}}}}, |
| 41 |
], |
| 42 |
"inputs": { |
| 43 |
"stun_clients": [ |
| 44 |
{"source_address": "100.64.3.2", "public_address": "192.164.3.2", "source_port": 4500, "public_port": 6006}, |
| 45 |
{"source_address": "172.18.3.2", "public_address": "192.118.3.2", "source_port": 4500, "public_port": 6006}, |
| 46 |
] |
| 47 |
}, |
| 48 |
"expected": { |
| 49 |
"result": AntaTestStatus.FAILURE, |
| 50 |
"messages": [ |
| 51 |
"Client 100.64.3.2 Port: 4500 - Incorrect public-facing address - Expected: 192.164.3.2 Actual: 192.64.3.2", |
| 52 |
"Client 172.18.3.2 Port: 4500 - Incorrect public-facing address - Expected: 192.118.3.2 Actual: 192.18.3.2", |
| 53 |
], |
| 54 |
}, |
| 55 |
}, |
| 56 |
(VerifyStunClientTranslation, "failure-no-client"): { |
| 57 |
"eos_data": [{"bindings": {}}, {"bindings": {}}], |
| 58 |
"inputs": { |
| 59 |
"stun_clients": [ |
| 60 |
{"source_address": "100.64.3.2", "public_address": "192.164.3.2", "source_port": 4500, "public_port": 6006}, |
| 61 |
{"source_address": "172.18.3.2", "public_address": "192.118.3.2", "source_port": 4500, "public_port": 6006}, |
| 62 |
] |
| 63 |
}, |
| 64 |
"expected": { |
| 65 |
"result": AntaTestStatus.FAILURE, |
| 66 |
"messages": ["Client 100.64.3.2 Port: 4500 - STUN client translation not found", "Client 172.18.3.2 Port: 4500 - STUN client translation not found"], |
| 67 |
}, |
| 68 |
}, |
| 69 |
(VerifyStunClientTranslation, "failure-incorrect-public-port"): { |
| 70 |
"eos_data": [ |
| 71 |
{"bindings": {}}, |
| 72 |
{"bindings": {"000000040a64ff0100000000": {"sourceAddress": {"ip": "172.18.3.2", "port": 4500}, "publicAddress": {"ip": "192.18.3.2", "port": 4800}}}}, |
| 73 |
], |
| 74 |
"inputs": { |
| 75 |
"stun_clients": [ |
| 76 |
{"source_address": "100.64.3.2", "public_address": "192.164.3.2", "source_port": 4500, "public_port": 6006}, |
| 77 |
{"source_address": "172.18.3.2", "public_address": "192.118.3.2", "source_port": 4500, "public_port": 6006}, |
| 78 |
] |
| 79 |
}, |
| 80 |
"expected": { |
| 81 |
"result": AntaTestStatus.FAILURE, |
| 82 |
"messages": [ |
| 83 |
"Client 100.64.3.2 Port: 4500 - STUN client translation not found", |
| 84 |
"Client 172.18.3.2 Port: 4500 - Incorrect public-facing address - Expected: 192.118.3.2 Actual: 192.18.3.2", |
| 85 |
"Client 172.18.3.2 Port: 4500 - Incorrect public-facing port - Expected: 6006 Actual: 4800", |
| 86 |
], |
| 87 |
}, |
| 88 |
}, |
| 89 |
(VerifyStunClientTranslation, "failure-all-type"): { |
| 90 |
"eos_data": [ |
| 91 |
{"bindings": {}}, |
| 92 |
{"bindings": {"000000040a64ff0100000000": {"sourceAddress": {"ip": "172.18.3.2", "port": 4500}, "publicAddress": {"ip": "192.18.3.2", "port": 4800}}}}, |
| 93 |
], |
| 94 |
"inputs": { |
| 95 |
"stun_clients": [ |
| 96 |
{"source_address": "100.64.3.2", "public_address": "192.164.3.2", "source_port": 4500, "public_port": 6006}, |
| 97 |
{"source_address": "172.18.4.2", "public_address": "192.118.3.2", "source_port": 4800, "public_port": 6006}, |
| 98 |
] |
| 99 |
}, |
| 100 |
"expected": { |
| 101 |
"result": AntaTestStatus.FAILURE, |
| 102 |
"messages": [ |
| 103 |
"Client 100.64.3.2 Port: 4500 - STUN client translation not found", |
| 104 |
"Client 172.18.4.2 Port: 4800 - Incorrect public-facing address - Expected: 192.118.3.2 Actual: 192.18.3.2", |
| 105 |
"Client 172.18.4.2 Port: 4800 - Incorrect public-facing port - Expected: 6006 Actual: 4800", |
| 106 |
], |
| 107 |
}, |
| 108 |
}, |
| 109 |
(VerifyStunServer, "success"): {"eos_data": [{"enabled": True, "pid": 1895}], "inputs": {}, "expected": {"result": AntaTestStatus.SUCCESS}}, |
| 110 |
(VerifyStunServer, "failure-disabled"): { |
| 111 |
"eos_data": [{"enabled": False, "pid": 1895}], |
| 112 |
"inputs": {}, |
| 113 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["STUN server status is disabled"]}, |
| 114 |
}, |
| 115 |
(VerifyStunServer, "failure-not-running"): { |
| 116 |
"eos_data": [{"enabled": True, "pid": 0}], |
| 117 |
"inputs": {}, |
| 118 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["STUN server is not running"]}, |
| 119 |
}, |
| 120 |
(VerifyStunServer, "failure-not-running-disabled"): { |
| 121 |
"eos_data": [{"enabled": False, "pid": 0}], |
| 122 |
"inputs": {}, |
| 123 |
"expected": {"result": AntaTestStatus.FAILURE, "messages": ["STUN server status is disabled and not running"]}, |
| 124 |
}, |
| 125 |
} |