Skip to content

Commit

Permalink
first test-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
superstes committed Oct 7, 2023
1 parent 440989c commit c11d7d6
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 20 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Feel free to contribute to this project!

- [ ] SOCKS5 Proxy

- [ ] Authentication

- [ ] Forwarding

- [x] TCP
Expand Down
2 changes: 2 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ General tests are ran against the 'transparent' mode.

We need a tester- and a proxy-VM.

Why use a dedicated proxy-VM? The most-used implementation of transparent-mode is redirecting routed traffic by using the `prerouting` chain. That's also the way it should be tested. In addition to this - the `proxyproto` mode is also used to connect to a remote server.

* Add 'tester' user on both nodes
* Add service to run proxy-instances on proxy-vm

Expand Down
2 changes: 1 addition & 1 deletion test/setup_client/stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TMP_DIR_REPO="$(cat /tmp/calamary_${VERSION}.run)"
bash "${TMP_DIR_REPO}/calamary/test/postExec.sh" "$VERSION"

# cleanup
if echo "$TMP_DIR_REPO" | grep -q '/tmp/calamary'
if grep -q '/tmp/calamary' <<< "$TMP_DIR_REPO"
then
rm -rf "$TMP_DIR_REPO"
fi
Expand Down
2 changes: 1 addition & 1 deletion test/testGeneral.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set +e

# tests are targeting the 'transparent' mode

source ./base.sh
source ./util/base.sh

PROXY_PORT="${PROXY_PORT:="${PORT_BASE}1"}"

Expand Down
11 changes: 10 additions & 1 deletion test/testHttp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
set -uo pipefail
set +e

source ./base.sh
source ./util/base.sh

PROXY_PORT="${PROXY_PORT:="${PORT_BASE}4"}"

export http_proxy="http://${PROXY_HOST}:${PROXY_PORT}"
export https_proxy="http://${PROXY_HOST}:${PROXY_PORT}"
export HTTP_PROXY="http://${PROXY_HOST}:${PROXY_PORT}"
export HTTPS_PROXY="http://${PROXY_HOST}:${PROXY_PORT}"

testsHttp=()

# log_header 'RUNNING TESTS: HTTP'
Expand All @@ -20,3 +25,7 @@ do
done

unset PROXY_PORT
unset http_proxy
unset https_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
11 changes: 10 additions & 1 deletion test/testHttps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
set -uo pipefail
set +e

source ./base.sh
source ./util/base.sh

PROXY_PORT="${PROXY_PORT:="${PORT_BASE}5"}"

export http_proxy="https://${PROXY_HOST}:${PROXY_PORT}"
export https_proxy="https://${PROXY_HOST}:${PROXY_PORT}"
export HTTP_PROXY="https://${PROXY_HOST}:${PROXY_PORT}"
export HTTPS_PROXY="https://${PROXY_HOST}:${PROXY_PORT}"

testsHttps=()

# log_header 'RUNNING TESTS: HTTPS'
Expand All @@ -20,3 +25,7 @@ do
done

unset PROXY_PORT
unset http_proxy
unset https_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
2 changes: 1 addition & 1 deletion test/testProxyproto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -uo pipefail
set +e

source ./base.sh
source ./util/base.sh

PROXY_PORT="${PROXY_PORT:="${PORT_BASE}3"}"

Expand Down
7 changes: 6 additions & 1 deletion test/testSocks5.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
set -uo pipefail
set +e

source ./base.sh
source ./util/base.sh

PROXY_PORT="${PROXY_PORT:="${PORT_BASE}6"}"

export http_proxy="socks5://${PROXY_HOST}:${PROXY_PORT}"
export https_proxy="socks5://${PROXY_HOST}:${PROXY_PORT}"
export HTTP_PROXY="socks5://${PROXY_HOST}:${PROXY_PORT}"
export HTTPS_PROXY="socks5://${PROXY_HOST}:${PROXY_PORT}"

testsSocks5=()

# log_header 'RUNNING TESTS: SOCKS5'
Expand Down
5 changes: 2 additions & 3 deletions test/testTransparent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
set -uo pipefail
set +e

source ./base.sh
source ./util/base.sh
source ./util/route.sh

PROXY_PORT="${PROXY_PORT:="${PORT_BASE}1"}"

testsTransparent=()
testsTransparent[0]="basic"
testsTransparent[1]="dummyOk"
#testsTransparent[2]="dummyFail"

log_header 'RUNNING TESTS: TRANSPARENT'

Expand Down
2 changes: 1 addition & 1 deletion test/testTransparentTproxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -uo pipefail
set +e

source ./base.sh
source ./util/base.sh

PROXY_PORT="${PROXY_PORT:="${PORT_BASE}2"}"

Expand Down
10 changes: 10 additions & 0 deletions test/transparent/basic.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
#!/bin/bash

target='1.1.1.1'
route_add "$target"
c1=$(curlRc "http://${target}")
c2=$(curlRc "https://${target}")
route_rm "$target"

if [[ "$c1" != "0" ]] || [[ "$c2" != "0" ]]
then
exit 1
fi
5 changes: 0 additions & 5 deletions test/transparent/dummyFail.sh

This file was deleted.

5 changes: 0 additions & 5 deletions test/transparent/dummyOk.sh

This file was deleted.

5 changes: 5 additions & 0 deletions test/base.sh → test/util/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ function runTest {
echo ''
return 0
}

function curlRc {
curl --connect-timeout 3 --fail "$1"
return "$?"
}
53 changes: 53 additions & 0 deletions test/util/route.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/bash

function route_ex {
if [[ "$1" == '4' ]]
then
rts="$(ip route show)"
else
rts="$(ip -6 route show)"
fi
if grep -q "$2" <<< "$rts"
then
return 1
else
return 0
fi
}

function route_add {
net="$1"
rt="route add $net via $PROXY_HOST"

if grep -q ':' <<< "$net" && grep -q ':' <<< "$PROXY_HOST"
then
if ! route_ex '6' "$rt"
then
ip -6 $rt
fi
else
if ! route_ex '4' "$rt"
then
ip $rt
fi
fi
}

function route_rm {
net="$1"
rt="route del $net via $PROXY_HOST"

if grep -q ':' <<< "$net" && grep -q ':' <<< "$PROXY_HOST"
then
if route_ex '6' "$rt"
then
ip -6 $rt
fi
else
if route_ex '4' "$rt"
then
ip $rt
fi
fi
}

0 comments on commit c11d7d6

Please sign in to comment.