summaryrefslogtreecommitdiffstats
path: root/tests/units/anta_tests/test_stun.py
blob: 2c873650cfe9ff86dc03f4278c1eb01df2810e11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# Copyright (c) 2023-2024 Arista Networks, Inc.
# Use of this source code is governed by the Apache License 2.0
# that can be found in the LICENSE file.
"""Test inputs for anta.tests.stun.py."""

from __future__ import annotations

from typing import Any

from anta.tests.stun import VerifyStunClient
from tests.lib.anta import test  # noqa: F401; pylint: disable=W0611

DATA: list[dict[str, Any]] = [
    {
        "name": "success",
        "test": VerifyStunClient,
        "eos_data": [
            {
                "bindings": {
                    "000000010a64ff0100000000": {
                        "sourceAddress": {"ip": "100.64.3.2", "port": 4500},
                        "publicAddress": {"ip": "192.64.3.2", "port": 6006},
                    }
                }
            },
            {
                "bindings": {
                    "000000040a64ff0100000000": {
                        "sourceAddress": {"ip": "172.18.3.2", "port": 4500},
                        "publicAddress": {"ip": "192.18.3.2", "port": 6006},
                    }
                }
            },
            {
                "bindings": {
                    "000000040a64ff0100000000": {
                        "sourceAddress": {"ip": "172.18.4.2", "port": 4500},
                        "publicAddress": {"ip": "192.18.4.2", "port": 6006},
                    }
                }
            },
            {
                "bindings": {
                    "000000040a64ff0100000000": {
                        "sourceAddress": {"ip": "172.18.6.2", "port": 4500},
                        "publicAddress": {"ip": "192.18.6.2", "port": 6006},
                    }
                }
            },
        ],
        "inputs": {
            "stun_clients": [
                {"source_address": "100.64.3.2", "public_address": "192.64.3.2", "source_port": 4500, "public_port": 6006},
                {"source_address": "172.18.3.2"},
                {"source_address": "172.18.4.2", "source_port": 4500, "public_address": "192.18.4.2"},
                {"source_address": "172.18.6.2", "source_port": 4500, "public_port": 6006},
            ]
        },
        "expected": {"result": "success"},
    },
    {
        "name": "failure-incorrect-public-ip",
        "test": VerifyStunClient,
        "eos_data": [
            {
                "bindings": {
                    "000000010a64ff0100000000": {
                        "sourceAddress": {"ip": "100.64.3.2", "port": 4500},
                        "publicAddress": {"ip": "192.64.3.2", "port": 6006},
                    }
                }
            },
            {
                "bindings": {
                    "000000040a64ff0100000000": {
                        "sourceAddress": {"ip": "172.18.3.2", "port": 4500},
                        "publicAddress": {"ip": "192.18.3.2", "port": 6006},
                    }
                }
            },
        ],
        "inputs": {
            "stun_clients": [
                {"source_address": "100.64.3.2", "public_address": "192.164.3.2", "source_port": 4500, "public_port": 6006},
                {"source_address": "172.18.3.2", "public_address": "192.118.3.2", "source_port": 4500, "public_port": 6006},
            ]
        },
        "expected": {
            "result": "failure",
            "messages": [
                "For STUN source `100.64.3.2:4500`:\nExpected `192.164.3.2` as the public ip, but found `192.64.3.2` instead.",
                "For STUN source `172.18.3.2:4500`:\nExpected `192.118.3.2` as the public ip, but found `192.18.3.2` instead.",
            ],
        },
    },
    {
        "name": "failure-no-client",
        "test": VerifyStunClient,
        "eos_data": [
            {"bindings": {}},
            {"bindings": {}},
        ],
        "inputs": {
            "stun_clients": [
                {"source_address": "100.64.3.2", "public_address": "192.164.3.2", "source_port": 4500, "public_port": 6006},
                {"source_address": "172.18.3.2", "public_address": "192.118.3.2", "source_port": 4500, "public_port": 6006},
            ]
        },
        "expected": {
            "result": "failure",
            "messages": ["STUN client transaction for source `100.64.3.2:4500` is not found.", "STUN client transaction for source `172.18.3.2:4500` is not found."],
        },
    },
    {
        "name": "failure-incorrect-public-port",
        "test": VerifyStunClient,
        "eos_data": [
            {"bindings": {}},
            {
                "bindings": {
                    "000000040a64ff0100000000": {
                        "sourceAddress": {"ip": "172.18.3.2", "port": 4500},
                        "publicAddress": {"ip": "192.18.3.2", "port": 4800},
                    }
                }
            },
        ],
        "inputs": {
            "stun_clients": [
                {"source_address": "100.64.3.2", "public_address": "192.164.3.2", "source_port": 4500, "public_port": 6006},
                {"source_address": "172.18.3.2", "public_address": "192.118.3.2", "source_port": 4500, "public_port": 6006},
            ]
        },
        "expected": {
            "result": "failure",
            "messages": [
                "STUN client transaction for source `100.64.3.2:4500` is not found.",
                "For STUN source `172.18.3.2:4500`:\n"
                "Expected `192.118.3.2` as the public ip, but found `192.18.3.2` instead.\n"
                "Expected `6006` as the public port, but found `4800` instead.",
            ],
        },
    },
    {
        "name": "failure-all-type",
        "test": VerifyStunClient,
        "eos_data": [
            {"bindings": {}},
            {
                "bindings": {
                    "000000040a64ff0100000000": {
                        "sourceAddress": {"ip": "172.18.3.2", "port": 4500},
                        "publicAddress": {"ip": "192.18.3.2", "port": 4800},
                    }
                }
            },
        ],
        "inputs": {
            "stun_clients": [
                {"source_address": "100.64.3.2", "public_address": "192.164.3.2", "source_port": 4500, "public_port": 6006},
                {"source_address": "172.18.4.2", "public_address": "192.118.3.2", "source_port": 4800, "public_port": 6006},
            ]
        },
        "expected": {
            "result": "failure",
            "messages": [
                "STUN client transaction for source `100.64.3.2:4500` is not found.",
                "For STUN source `172.18.4.2:4800`:\n"
                "Expected `172.18.4.2` as the source ip, but found `172.18.3.2` instead.\n"
                "Expected `4800` as the source port, but found `4500` instead.\n"
                "Expected `192.118.3.2` as the public ip, but found `192.18.3.2` instead.\n"
                "Expected `6006` as the public port, but found `4800` instead.",
            ],
        },
    },
]