From 76ae7c28ea6224b2c919122d5dc71bcc00a0ecaa Mon Sep 17 00:00:00 2001 From: yum Date: Mon, 3 Jul 2023 18:44:43 -0700 Subject: Begin work on proxy server Create a simple server with 3 endpoints: * /create_session: Create a session and return its identifier. * /set_transcript: Update a session's transcript. * /get_transcript: Fetch a session's transcript. Right now the session ID provides authentication *and* authorization. There is no public/private ID so you have to trust whoever you share your ID with. IDs are long and generated by the server, so it should be somewhat secure against low-effort hacking. Other updates: * Drop whisper_requirements.txt - no longer needed. * Vendor curl to make it easier to interact with the server. TODO: * Fuzz test the server. --- BrowserSource/Proxy/integration_test.sh | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 BrowserSource/Proxy/integration_test.sh (limited to 'BrowserSource/Proxy/integration_test.sh') diff --git a/BrowserSource/Proxy/integration_test.sh b/BrowserSource/Proxy/integration_test.sh new file mode 100644 index 0000000..5aabc9e --- /dev/null +++ b/BrowserSource/Proxy/integration_test.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +SERVER_IP="$1" +if [ -z "$SERVER_IP" ]; then + echo "Usage: $0 server_ip" + exit 1 +fi +echo "Testing server at $SERVER_IP" + +SESSION_ID_0=$(curl -s -X GET $SERVER_IP:8080/api/v0/create_session | awk -F':' '{print $2}' | tr -d '}') +echo "Got session id $SESSION_ID_0" +if [ -z "$SESSION_ID_0" ]; then + echo "Expected session ID to be non-empty" + exit 1 +fi + +echo "Initial transcript should be empty" +T0=$(curl -s -X GET -d "$SESSION_ID_0" $SERVER_IP:8080/api/v0/get_transcript) +if [ "$T0" != "" ]; then + echo "Expected initial transcript to be empty, but got $T0" + exit 1 +fi +echo "Pass!" + +echo "Should be able to update transcript once" +T1_EXP="foo bar" +curl -s -X POST -d "$SESSION_ID_0 $T1_EXP" $SERVER_IP:8080/api/v0/set_transcript + +T1=$(curl -s -X GET -d "$SESSION_ID_0" $SERVER_IP:8080/api/v0/get_transcript) +if [ "$T1" != "$T1_EXP" ]; then + echo "Expected transcript to be $T1_EXP, but got $T1" + exit 1 +fi +echo "Pass!" + +echo "Subsequent update should overwrite" +T2_EXP="baz qux" +curl -s -X POST -d "$SESSION_ID_0 $T2_EXP" $SERVER_IP:8080/api/v0/set_transcript + +T2=$(curl -s -X GET -d "$SESSION_ID_0" $SERVER_IP:8080/api/v0/get_transcript) +if [ "$T2" != "$T2_EXP" ]; then + echo "Expected transcript to be $T2_EXP, but got $T2" + exit 1 +fi +echo "Pass!" + -- cgit v1.2.3