Skip to content

Commit

Permalink
fixes for test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
superstes committed Oct 7, 2023
1 parent c11d7d6 commit 4a083ab
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 51 deletions.
4 changes: 2 additions & 2 deletions lib/cnf/config.go
Expand Up @@ -30,8 +30,8 @@ type ServiceConfig struct {
type ServiceListener struct {
Mode meta.ListenMode `yaml:"mode" default:"transparent"`
Port uint16 `yaml:"port"`
IP4 []string `yaml:"ip4" default:"[\"127.0.0.1\"]"`
IP6 []string `yaml:"ip6" default:"[\"::1\"]"`
IP4 YamlStringArray `yaml:"ip4" default:"[\"127.0.0.1\"]"`
IP6 YamlStringArray `yaml:"ip6" default:"[\"::1\"]"`
Tcp bool `yaml:"tcp" default:"true"`
Udp bool `yaml:"udp" default:"false"` // not implemented
TProxy bool `yaml:"tproxy" default:"false"`
Expand Down
41 changes: 28 additions & 13 deletions test/config.yml
Expand Up @@ -14,12 +14,20 @@ service:
tproxy: true
- mode: 'proxyproto'
port: PORT_BASE3
ip4: ['0.0.0.0']
ip6: ['::']
- mode: 'http'
port: PORT_BASE4
ip4: ['0.0.0.0']
ip6: ['::']
# - mode: 'https'

Check warning on line 23 in test/config.yml

View workflow job for this annotation

GitHub Actions / build (3.1)

23:5 [comments-indentation] comment not indented like content
# port: PORT_BASE5
# ip4: ['0.0.0.0']
# ip6: ['::']
# - mode: 'socks5'
# port: PORT_BASE6
# ip4: ['0.0.0.0']
# ip6: ['::']

certs:
# caPublic: 'CRT_BASE.ca.crt'
Expand All @@ -39,33 +47,40 @@ service:
retries: 1 # connect-retries

metrics:
enabled: false
enabled: true
port: 9512

vars:
- name: 'net_private'
value: ['192.168.0.0/16', '172.16.0.0/12', '10.0.0.0/8']
- name: 'svc_http'
- name: 'svc_tcp'
value: [80, 443]
- name: 'svc_udp'
value: [53, 123]

rules:
- match:
dest: '192.168.100.0/24'
action: 'drop'

- match:
port: ['!443', '!80']
action: 'drop'
dest: '!$net_private'
port: '$svc_tcp'
protoL3: 'ip4'
protoL4: 'tcp'
action: 'accept'

- match:
src: '$net_private'
dest: '$net_private'
port: '$svc_http'
port: '$svc_tcp'
protoL3: 'ip6'
protoL4: 'tcp'
action: 'accept'

- match:
dest: '!$net_private'
port: [443, 80]
protoL4: 'tcp'
port: '$svc_udp'
protoL3: 'ip4'
protoL4: 'udp'
action: 'accept'

- match:
port: '$svc_udp'
protoL3: 'ip6'
protoL4: 'udp'
action: 'accept'
33 changes: 2 additions & 31 deletions test/main.sh
Expand Up @@ -14,27 +14,7 @@ then
PORT_BASE="3${PORT_BASE:1}"
fi

function log {
echo ''
echo "$1"
echo ''
}

function log_header {
echo "##### $1 #####"
}

function stop_proxy {
log 'STOPPING PROXY'
ssh_cmd "sudo systemctl stop calamary@${VERSION}.service"
}

function cleanup {
log 'CLEANUP'
ssh_cmd "sudo rm -f ${TMP_BASE}*"
rm -f ./*_tmp.*
stop_proxy
}
source ./util/main.sh

cleanup

Expand All @@ -50,9 +30,6 @@ log 'GENERATING CERTS'
openssl req -x509 -newkey rsa:4096 -keyout 'cert_tmp.key' -out 'cert_tmp.crt' -sha256 -days 60 -nodes -subj "$CERT_CN" 2>/dev/null

log 'COPYING FILES TO PROXY-HOST'
function copy_file {
scp -P "$PROXY_SSH_PORT" "$1" "$PROXY_USER"@"$PROXY_HOST":"$2" >/dev/null 2>&1
}

copy_file 'calamary' "$TMP_BASE"
copy_file 'config_tmp.yml' "${TMP_BASE}.yml"
Expand All @@ -63,13 +40,7 @@ ssh_cmd "sudo chown proxy:proxy ${TMP_BASE}*"
log 'STARTING PROXY'
ssh_cmd "sudo systemctl start calamary@${VERSION}.service"

function fail {
log 'TEST-RUN FAILED!'
status='FAILED'
stop_proxy
update_badge
exit 99
}
# todo: iptables/nftables NAT for transparent mode

log 'STARTING TESTS'

Expand Down
4 changes: 2 additions & 2 deletions test/testGeneral.sh
Expand Up @@ -3,11 +3,11 @@
set -uo pipefail
set +e

# tests are targeting the 'transparent' mode

source ./util/base.sh

PORT_BASE="${PORT_BASE:='1000'}"
PROXY_PORT="${PROXY_PORT:="${PORT_BASE}1"}"
# tests are targeting the 'transparent' mode

testsGeneral=()

Expand Down
1 change: 1 addition & 0 deletions test/testHttp.sh
Expand Up @@ -5,6 +5,7 @@ set +e

source ./util/base.sh

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

export http_proxy="http://${PROXY_HOST}:${PROXY_PORT}"
Expand Down
1 change: 1 addition & 0 deletions test/testHttps.sh
Expand Up @@ -5,6 +5,7 @@ set +e

source ./util/base.sh

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

export http_proxy="https://${PROXY_HOST}:${PROXY_PORT}"
Expand Down
1 change: 1 addition & 0 deletions test/testProxyproto.sh
Expand Up @@ -5,6 +5,7 @@ set +e

source ./util/base.sh

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

testsProxyproto=()
Expand Down
1 change: 1 addition & 0 deletions test/testSocks5.sh
Expand Up @@ -5,6 +5,7 @@ set +e

source ./util/base.sh

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

export http_proxy="socks5://${PROXY_HOST}:${PROXY_PORT}"
Expand Down
2 changes: 1 addition & 1 deletion test/testTransparent.sh
Expand Up @@ -4,8 +4,8 @@ set -uo pipefail
set +e

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

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

testsTransparent=()
Expand Down
1 change: 1 addition & 0 deletions test/testTransparentTproxy.sh
Expand Up @@ -5,6 +5,7 @@ set +e

source ./util/base.sh

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

testsTransparentTproxy=()
Expand Down
Binary file added test/tools/EasyRSA-3.1.6.tgz
Binary file not shown.
1 change: 1 addition & 0 deletions test/tools/sources.txt
@@ -0,0 +1 @@
EasyRSA: https://github.com/OpenVPN/easy-rsa/
2 changes: 2 additions & 0 deletions test/util/base.sh
@@ -1,5 +1,7 @@
#!/bin/bash

source ./route.sh

function runTest {
testScript="$1"
echo ''
Expand Down
33 changes: 33 additions & 0 deletions test/util/main.sh
@@ -0,0 +1,33 @@
#!/bin/bash

function log {
echo "$1"
}

function log_header {
echo "##### $1 #####"
}

function stop_proxy {
log 'STOPPING PROXY'
ssh_cmd "sudo systemctl stop calamary@${VERSION}.service"
}

function cleanup {
log 'CLEANUP'
ssh_cmd "sudo rm -f ${TMP_BASE}*"
rm -f ./*_tmp.*
stop_proxy
}

function copy_file {
scp -P "$PROXY_SSH_PORT" "$1" "$PROXY_USER"@"$PROXY_HOST":"$2" >/dev/null 2>&1
}

function fail {
log 'TEST-RUN FAILED!'
status='FAILED'
stop_proxy
update_badge
exit 99
}
6 changes: 4 additions & 2 deletions test/wrapper.sh
Expand Up @@ -5,6 +5,8 @@

set -eo pipefail

echo ''

if [ -z "$1" ]
then
echo ''
Expand All @@ -31,9 +33,7 @@ BADGE_COLORS[FAILED]='#d9644d'
BADGE_COLORS[FAILED-ENVIRONMENT]='#d9644d'

function log {
echo ''
echo "$1"
echo ''
}

function update_badge {
Expand Down Expand Up @@ -80,3 +80,5 @@ WD="$(pwd)"
# start actual testing
log 'STARTING TESTS'
source ./main.sh

echo ''

0 comments on commit 4a083ab

Please sign in to comment.