diff --git a/basice2e/client-session-tests.sh b/basice2e/client-session-tests.sh new file mode 100755 index 0000000000000000000000000000000000000000..8e5d2be0e18dcc006190e810d47d60f80157033e --- /dev/null +++ b/basice2e/client-session-tests.sh @@ -0,0 +1,108 @@ +# Client Session Tests: this script will run the "old" `client` binary to init session files and setup the environment +# for the "new" `client-release` binary to run tests on the old session files. + +set -e +#set -o xtrace + +# --- Define variables to use for the test & local network --- + +DEBUGLEVEL=${DEBUGLEVEL-1} +CLIENTOPTS="--password hello --ndf results/ndf.json --sendDelay 100 --waitTimeout 360 --unsafe-channel-creation -v $DEBUGLEVEL" +SERVERLOGS=results/servers +GATEWAYLOGS=results/gateways +UDBOUT=results/udb-console.txt + +# --- Setup a local network --- + +rm -rf client*.log blob* rick*.bin ben*.bin +rm -rf results.bak results +mkdir results + +mkdir -p $SERVERLOGS +mkdir -p $GATEWAYLOGS + +# Start the network +source network.sh + +echo "DOWNLOADING TLS Cert..." +CMD="openssl s_client -showcerts -connect $(tr -d '[:space:]' < results/startgwserver.txt)" +echo $CMD +eval $CMD < /dev/null 2>&1 > "results/startgwcert.bin" +CMD="cat results/startgwcert.bin | openssl x509 -outform PEM" +echo $CMD +eval $CMD > "results/startgwcert.pem" +head "results/startgwcert.pem" + +echo "DOWNLOADING NDF..." +CLIENTCMD="../bin/client getndf --gwhost $(tr -d '[:space:]' < results/startgwserver.txt) --cert results/startgwcert.pem" +eval $CLIENTCMD >> results/ndf.json 2>&1 & +PIDVAL=$! +echo "$CLIENTCMD -- $PIDVAL" +wait $PIDVAL + +# ------------------------------------------------------------------------------ +# TESTS BEGIN BELOW +# ------------------------------------------------------------------------------ + +# --- Pre-canned messaging to self --- +timeout 240s ../bin/client --password hello --ndf results/ndf.json --sendDelay 100 --waitTimeout 360 --unsafe-channel-creation -v 1 -l client9-master.log --sendCount 2 --receiveCount 2 -s blob9/blob9 --sendid 9 --destid 9 -m "Hi 9->9, with E2E Encryption" +timeout 240s ../bin/client-release --force-legacy --password hello --ndf results/ndf.json --sendDelay 100 --waitTimeout 360 --unsafe-channel-creation -v 1 -l client9-release.log --sendCount 2 --receiveCount 2 -s blob9/blob9 --sendid 9 --destid 9 -m "Hi 9->9, with E2E Encryption" + +# --- Messaging to another use, E2E --- + +# Init storage and request an E2E channel with each other +echo "SENDING E2E MESSAGES TO NEW USERS..." +CLIENTCMD="timeout 360s ../bin/client $CLIENTOPTS -l client42-master-init.log -s blob42 --writeContact rick42-contact.bin --unsafe -m \"Hello from Rick42 to myself, without E2E Encryption\"" +eval $CLIENTCMD || true & +PIDVAL=$! +echo "$CLIENTCMD -- $PIDVAL" +wait $PIDVAL +CLIENTCMD="timeout 360s ../bin/client $CLIENTOPTS -l client43-master-init.log -s blob43 --writeContact ben43-contact.bin --destfile rick42-contact.bin --send-auth-request --sendCount 0 --receiveCount 0" +eval $CLIENTCMD || true & +PIDVAL2=$! +echo "$CLIENTCMD -- $PIDVAL" + +echo "Waiting for contact files to be created..." +while [ ! -s ben43-contact.bin ]; do + sleep 1 +done + +# Get the user's IDs +TMPID=$(cat client42-master-init.log | grep -a "User\:" | awk -F' ' '{print $5}') +RICKID=${TMPID} +echo "RICK ID: $RICKID" +TMPID=$(cat client43-master-init.log | grep -a "User\:" | awk -F' ' '{print $5}') +BENID=${TMPID} +echo "BEN ID: $BENID" + +# Confirm channel with each other +CLIENTCMD="timeout 360s ../bin/client $CLIENTOPTS -l client42-master-confirm.log -s blob42 --destfile ben43-contact.bin --sendCount 0 --receiveCount 0" +eval $CLIENTCMD || true & +PIDVAL=$! +echo "$CLIENTCMD -- $PIDVAL" +wait $PIDVAL +wait $PIDVAL2 + +# Send 5 messages to each other +CLIENTCMD="timeout 360s ../bin/client $CLIENTOPTS -l client42-master-send.log -s blob42 --destid b64:$BENID --sendCount 5 --receiveCount 5 -m \"Hello from Rick42, with E2E Encryption\"" +eval $CLIENTCMD || true & +PIDVAL=$! +echo "$CLIENTCMD -- $PIDVAL" +CLIENTCMD="timeout 360s ../bin/client $CLIENTOPTS -l client43-master-send.log -s blob43 --destid b64:$RICKID --sendCount 5 --receiveCount 5 -m \"Hello from Ben43, with E2E Encryption\"" +eval $CLIENTCMD || true & +PIDVAL2=$! +echo "$CLIENTCMD -- $PIDVAL" +wait $PIDVAL +wait $PIDVAL2 + +# Send 5 messages to each other with new client +CLIENTCMD="timeout 360s ../bin/client-release $CLIENTOPTS -l client42-release-send.log -s blob42 --force-legacy --destid b64:$BENID --sendCount 5 --receiveCount 5 -m \"Hello from Rick42, with E2E Encryption\"" +eval $CLIENTCMD || true & +PIDVAL=$! +echo "$CLIENTCMD -- $PIDVAL" +CLIENTCMD="timeout 360s ../bin/client-release $CLIENTOPTS -l client43-release-send.log -s blob43 --force-legacy --destid b64:$RICKID --sendCount 5 --receiveCount 5 -m \"Hello from Ben43, with E2E Encryption\"" +eval $CLIENTCMD || true & +PIDVAL2=$! +echo "$CLIENTCMD -- $PIDVAL" +wait $PIDVAL +wait $PIDVAL2 diff --git a/basice2e/network.sh b/basice2e/network.sh new file mode 100755 index 0000000000000000000000000000000000000000..fa821fba884d86308475a246f3f4154b1226f11e --- /dev/null +++ b/basice2e/network.sh @@ -0,0 +1,109 @@ +# This script is used to start a basic 5 node network for running clients on. It is meant to be `source`'d into a script +# which will run clients on the network, such as `client-session-tests.sh` or the main `run.sh`. +# +# You **must** source it, because otherwise the `trap finish EXIT` instruction will cause the network to stop when +# network.sh returns to your script or shell. Sourcing it will "import" the commands into your script instead, causing +# the trap instruction to stop the network when your script/shell exits. + +echo "STARTING SERVERS..." + +# Copy udbContact into place when running locally. +cp udbContact.bin results/udbContact.bin + +PERMCMD="../bin/permissioning --logLevel $DEBUGLEVEL -c permissioning.yaml " +$PERMCMD > results/permissioning-console.txt 2>&1 & +PIDVAL=$! +echo "$PERMCMD -- $PIDVAL" + + +# Run Client Registrar +CLIENT_REG_CMD="../bin/client-registrar \ +-l 2 -c client-registrar.yaml" +$CLIENT_REG_CMD > results/client-registrat-console.txt 2>&1 & +PIDVAL=$! +echo "$CLIENT_REG_CMD -- $PIDVAL" + +for SERVERID in $(seq 5 -1 1) +do + IDX=$(($SERVERID - 1)) + SERVERCMD="../bin/server --logLevel $DEBUGLEVEL --config server-$SERVERID.yaml" + if [ $SERVERID -eq 5 ] && [ -n "$NSYSENABLED" ] + then + SERVERCMD="nsys profile --session-new=gputest --trace=cuda -o server-$SERVERID $SERVERCMD" + fi + $SERVERCMD > $SERVERLOGS/server-$SERVERID-console.txt 2>&1 & + PIDVAL=$! + echo "$SERVERCMD -- $PIDVAL" +done + +# Start gateways +for GWID in $(seq 5 -1 1) +do + IDX=$(($GWID - 1)) + GATEWAYCMD="../bin/gateway --logLevel $DEBUGLEVEL --config gateway-$GWID.yaml" + $GATEWAYCMD > $GATEWAYLOGS/gateway-$GWID-console.txt 2>&1 & + PIDVAL=$! + echo "$GATEWAYCMD -- $PIDVAL" +done + +jobs -p > results/serverpids + +finish() { + echo "STOPPING SERVERS AND GATEWAYS..." + if [ -n "$NSYSENABLED" ] + then + nsys stop --session=gputest + fi + # NOTE: jobs -p doesn't work in a signal handler + for job in $(cat results/serverpids) + do + echo "KILLING $job" + kill $job || true + done + + sleep 5 + + for job in $(cat results/serverpids) + do + echo "KILL -9 $job" + kill -9 $job || true + done + #tail $SERVERLOGS/* + #tail $CLIENTCLEAN/* + #diff -aruN clients.goldoutput $CLIENTCLEAN +} + +trap finish EXIT +trap finish INT + +# Sleeps can die in a fire on the sun, we wait for the servers to start running +# rounds +rm rid.txt || true +touch rid.txt +cnt=0 +echo -n "Waiting for a round to run" +while [ ! -s rid.txt ] && [ $cnt -lt 120 ]; do + sleep 1 + grep -a "RID 1 ReceiveFinishRealtime END" results/servers/server-* > rid.txt || true + cnt=$(($cnt + 1)) + echo -n "." +done + +# Start a user discovery bot server +echo "STARTING UDB..." +UDBCMD="../bin/udb --logLevel $DEBUGLEVEL --skipVerification --protoUserPath udbProto.json --config udb.yaml -l 1" +$UDBCMD >> $UDBOUT 2>&1 & +PIDVAL=$! +echo $PIDVAL >> results/serverpids +echo "$UDBCMD -- $PIDVAL" +rm rid.txt || true +while [ ! -s rid.txt ] && [ $cnt -lt 30 ]; do + sleep 1 + grep -a "Sending Poll message" results/udb-console.txt > rid.txt || true + cnt=$(($cnt + 1)) + echo -n "." +done + +echo "localhost:8440" > results/startgwserver.txt + +echo "DONE LETS DO STUFF" \ No newline at end of file diff --git a/basice2e/run.sh b/basice2e/run.sh index f3c5ad664d83429e374872a92b1d7fc56d00dd65..73b04e78a2247d0891b853ed379bdc798126d9ca 100755 --- a/basice2e/run.sh +++ b/basice2e/run.sh @@ -64,108 +64,7 @@ echo "NETWORK: $NETWORKENTRYPOINT" if [ "$NETWORKENTRYPOINT" == "localhost:8440" ] then - echo "STARTING SERVERS..." - - # Copy udbContact into place when running locally. - cp udbContact.bin results/udbContact.bin - - PERMCMD="../bin/permissioning --logLevel $DEBUGLEVEL -c permissioning.yaml " - $PERMCMD > results/permissioning-console.txt 2>&1 & - PIDVAL=$! - echo "$PERMCMD -- $PIDVAL" - - - # Run Client Registrar - CLIENT_REG_CMD="../bin/client-registrar \ - -l 2 -c client-registrar.yaml" - $CLIENT_REG_CMD > results/client-registrat-console.txt 2>&1 & - PIDVAL=$! - echo "$CLIENT_REG_CMD -- $PIDVAL" - - for SERVERID in $(seq 5 -1 1) - do - IDX=$(($SERVERID - 1)) - SERVERCMD="../bin/server --logLevel $DEBUGLEVEL --config server-$SERVERID.yaml" - if [ $SERVERID -eq 5 ] && [ -n "$NSYSENABLED" ] - then - SERVERCMD="nsys profile --session-new=gputest --trace=cuda -o server-$SERVERID $SERVERCMD" - fi - $SERVERCMD > $SERVERLOGS/server-$SERVERID-console.txt 2>&1 & - PIDVAL=$! - echo "$SERVERCMD -- $PIDVAL" - done - - # Start gateways - for GWID in $(seq 5 -1 1) - do - IDX=$(($GWID - 1)) - GATEWAYCMD="../bin/gateway --logLevel $DEBUGLEVEL --config gateway-$GWID.yaml" - $GATEWAYCMD > $GATEWAYLOGS/gateway-$GWID-console.txt 2>&1 & - PIDVAL=$! - echo "$GATEWAYCMD -- $PIDVAL" - done - - jobs -p > results/serverpids - - finish() { - echo "STOPPING SERVERS AND GATEWAYS..." - if [ -n "$NSYSENABLED" ] - then - nsys stop --session=gputest - fi - # NOTE: jobs -p doesn't work in a signal handler - for job in $(cat results/serverpids) - do - echo "KILLING $job" - kill $job || true - done - - sleep 5 - - for job in $(cat results/serverpids) - do - echo "KILL -9 $job" - kill -9 $job || true - done - #tail $SERVERLOGS/* - #tail $CLIENTCLEAN/* - #diff -aruN clients.goldoutput $CLIENTCLEAN - } - - trap finish EXIT - trap finish INT - - # Sleeps can die in a fire on the sun, we wait for the servers to start running - # rounds - rm rid.txt || true - touch rid.txt - cnt=0 - echo -n "Waiting for a round to run" - while [ ! -s rid.txt ] && [ $cnt -lt 120 ]; do - sleep 1 - grep -a "RID 1 ReceiveFinishRealtime END" results/servers/server-* > rid.txt || true - cnt=$(($cnt + 1)) - echo -n "." - done - - # Start a user discovery bot server - echo "STARTING UDB..." - UDBCMD="../bin/udb --logLevel $DEBUGLEVEL --skipVerification --protoUserPath udbProto.json --config udb.yaml -l 1" - $UDBCMD >> $UDBOUT 2>&1 & - PIDVAL=$! - echo $PIDVAL >> results/serverpids - echo "$UDBCMD -- $PIDVAL" - rm rid.txt || true - while [ ! -s rid.txt ] && [ $cnt -lt 30 ]; do - sleep 1 - grep -a "Sending Poll message" results/udb-console.txt > rid.txt || true - cnt=$(($cnt + 1)) - echo -n "." - done - - echo "localhost:8440" > results/startgwserver.txt - - echo "DONE LETS DO STUFF" + source network.sh else echo "Connecting to network defined at $NETWORKENTRYPOINT"