Add testing automation
This commit is contained in:
parent
62eb83a4e8
commit
7e3892a947
10 changed files with 139 additions and 7 deletions
32
README.md
32
README.md
|
@ -4,3 +4,35 @@ IP-туннель (VPN) с tun-интерфейсом на Python
|
|||
Данный код был написан в рамках трансляции
|
||||
(https://www.youtube.com/watch?v=tgXV1h_YMu4)
|
||||
и будет доработан позже.
|
||||
|
||||
|
||||
|
||||
Тестирование
|
||||
------------
|
||||
|
||||
Для тестирования используются Linux network namespaces и простой HTTP-сервер,
|
||||
чтобы убедиться, что туннель работает.
|
||||
|
||||
### Подготовка
|
||||
|
||||
Команда `sudo ./test/prepare` создаст network namespaces и мост между ними.
|
||||
|
||||
### Запуск туннеля и HTTP-сервера
|
||||
|
||||
Каждую из этих команд нужно запустить в отдельном окне терминала
|
||||
и не прерывать.
|
||||
|
||||
* `sudo ./test/tunnel_server`
|
||||
* `sudo ./test/tunnel_client`
|
||||
* `sudo ./test/http_server`
|
||||
|
||||
### Тестирование
|
||||
|
||||
Выполнение команды `sudo ./test/curl` должно вывести на экран сообщение
|
||||
`Hello, World!`. Это означает, что HTTP-запросы передаются по нашему туннелю.
|
||||
|
||||
### Завершение
|
||||
|
||||
Завершите каждый из процессов, висящих в открытых окнах терминала, с помощью
|
||||
сочетания клавиш `Ctrl+C` (иногда может потребоваться несколько нажатий).
|
||||
Затем выполните команду `sudo ./test/cleanup` для удаления namespace'ов.
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"mode": "client",
|
||||
"address": "127.0.0.1",
|
||||
"address": "192.168.1.11",
|
||||
"port": 12345,
|
||||
"iface_name": "tun0",
|
||||
"iface_name": "tun2",
|
||||
"iface_mtu": 1500,
|
||||
"iface_addr": "10.0.0.1",
|
||||
"iface_dstaddr": "10.0.0.2",
|
||||
"iface_addr": "10.0.0.2",
|
||||
"iface_dstaddr": "10.0.0.1",
|
||||
"iface_netmask": "255.255.255.0"
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"mode": "server",
|
||||
"address": "0.0.0.0",
|
||||
"address": "192.168.1.11",
|
||||
"port": 12345,
|
||||
"iface_name": "tun1",
|
||||
"iface_mtu": 1500,
|
||||
"iface_addr": "10.0.0.2",
|
||||
"iface_dstaddr": "10.0.0.1",
|
||||
"iface_addr": "10.0.0.1",
|
||||
"iface_dstaddr": "10.0.0.2",
|
||||
"iface_netmask": "255.255.255.0"
|
||||
}
|
||||
|
|
14
test/cleanup
Executable file
14
test/cleanup
Executable file
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
ROOT="$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" >/dev/null 2>&1 && pwd)"
|
||||
|
||||
. "$ROOT/test/const.sh"
|
||||
|
||||
ip link del "$BRIDGE_IFACE_NAME"
|
||||
ip link del "$SERVER_BR_VETH_IFACE_NAME"
|
||||
ip link del "$CLIENT_BR_VETH_IFACE_NAME"
|
||||
|
||||
ip netns delete "$SERVER_NAMESPACE"
|
||||
ip netns delete "$CLIENT_NAMESPACE"
|
17
test/const.sh
Normal file
17
test/const.sh
Normal file
|
@ -0,0 +1,17 @@
|
|||
SERVER_NAMESPACE='namespace1'
|
||||
CLIENT_NAMESPACE='namespace2'
|
||||
|
||||
SERVER_VETH_IFACE_NAME='veth1'
|
||||
CLIENT_VETH_IFACE_NAME='veth2'
|
||||
|
||||
SERVER_BR_VETH_IFACE_NAME="br-$SERVER_VETH_IFACE_NAME"
|
||||
CLIENT_BR_VETH_IFACE_NAME="br-$CLIENT_VETH_IFACE_NAME"
|
||||
|
||||
BRIDGE_IFACE_NAME='br1'
|
||||
|
||||
BRIDGE_ADDR='192.168.1.10/24'
|
||||
SERVER_ADDR='192.168.1.11/24'
|
||||
CLIENT_ADDR='192.168.1.12/24'
|
||||
|
||||
HTTP_ADDR='10.0.0.1'
|
||||
HTTP_PORT=80
|
9
test/curl
Executable file
9
test/curl
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
ROOT="$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" >/dev/null 2>&1 && pwd)"
|
||||
|
||||
. "$ROOT/test/const.sh"
|
||||
|
||||
ip netns exec "$CLIENT_NAMESPACE" curl "http://$HTTP_ADDR:$HTTP_PORT"
|
10
test/http_server
Executable file
10
test/http_server
Executable file
|
@ -0,0 +1,10 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
ROOT="$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" >/dev/null 2>&1 && pwd)"
|
||||
|
||||
. "$ROOT/test/const.sh"
|
||||
|
||||
ip netns exec "$SERVER_NAMESPACE" socat "TCP-LISTEN:$HTTP_PORT,fork,crlf" \
|
||||
SYSTEM:'echo "HTTP/1.0 200"; echo "Content-Type: text/plain"; echo; echo "Hello, World!"'
|
32
test/prepare
Executable file
32
test/prepare
Executable file
|
@ -0,0 +1,32 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
ROOT="$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" >/dev/null 2>&1 && pwd)"
|
||||
|
||||
. "$ROOT/test/const.sh"
|
||||
|
||||
ip netns add "$SERVER_NAMESPACE"
|
||||
ip netns add "$CLIENT_NAMESPACE"
|
||||
|
||||
ip link add "$SERVER_VETH_IFACE_NAME" type veth peer name "$SERVER_BR_VETH_IFACE_NAME"
|
||||
ip link add "$CLIENT_VETH_IFACE_NAME" type veth peer name "$CLIENT_BR_VETH_IFACE_NAME"
|
||||
|
||||
ip link set "$SERVER_VETH_IFACE_NAME" netns "$SERVER_NAMESPACE"
|
||||
ip link set "$CLIENT_VETH_IFACE_NAME" netns "$CLIENT_NAMESPACE"
|
||||
|
||||
ip netns exec "$SERVER_NAMESPACE" ip addr add "$SERVER_ADDR" dev "$SERVER_VETH_IFACE_NAME"
|
||||
ip netns exec "$CLIENT_NAMESPACE" ip addr add "$CLIENT_ADDR" dev "$CLIENT_VETH_IFACE_NAME"
|
||||
|
||||
ip link add name "$BRIDGE_IFACE_NAME" type bridge
|
||||
|
||||
ip link set "$BRIDGE_IFACE_NAME" up
|
||||
ip link set "$SERVER_BR_VETH_IFACE_NAME" up
|
||||
ip link set "$CLIENT_BR_VETH_IFACE_NAME" up
|
||||
ip netns exec "$SERVER_NAMESPACE" ip link set "$SERVER_VETH_IFACE_NAME" up
|
||||
ip netns exec "$CLIENT_NAMESPACE" ip link set "$CLIENT_VETH_IFACE_NAME" up
|
||||
|
||||
ip link set "$SERVER_BR_VETH_IFACE_NAME" master "$BRIDGE_IFACE_NAME"
|
||||
ip link set "$CLIENT_BR_VETH_IFACE_NAME" master "$BRIDGE_IFACE_NAME"
|
||||
|
||||
ip addr add "$BRIDGE_ADDR" brd + dev "$BRIDGE_IFACE_NAME"
|
9
test/tunnel_client
Executable file
9
test/tunnel_client
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
ROOT="$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" >/dev/null 2>&1 && pwd)"
|
||||
|
||||
. "$ROOT/test/const.sh"
|
||||
|
||||
ip netns exec "$CLIENT_NAMESPACE" "$ROOT/main.py" "$ROOT/config_client.json"
|
9
test/tunnel_server
Executable file
9
test/tunnel_server
Executable file
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
ROOT="$(cd "$(dirname "$(dirname "${BASH_SOURCE[0]}")")" >/dev/null 2>&1 && pwd)"
|
||||
|
||||
. "$ROOT/test/const.sh"
|
||||
|
||||
ip netns exec "$SERVER_NAMESPACE" "$ROOT/main.py" "$ROOT/config_server.json"
|
Reference in a new issue