diff --git a/test_blossom/.gitignore b/test_blossom/.gitignore new file mode 100644 index 0000000..20080a8 --- /dev/null +++ b/test_blossom/.gitignore @@ -0,0 +1,3 @@ +event.map +lmdb/ +downloaded diff --git a/test_blossom/README.md b/test_blossom/README.md new file mode 100644 index 0000000..dbdd73d --- /dev/null +++ b/test_blossom/README.md @@ -0,0 +1,7 @@ +# Testing Blossom functionality of Chorus + +In one shell run `run.sh` to run a local chorus. + +Then in another shell run `test.sh` to run tests against that running instance. + +When done, break out of the server and run `clean.sh` diff --git a/test_blossom/avatar-placeholder.webp b/test_blossom/avatar-placeholder.webp new file mode 100644 index 0000000..e8f5973 Binary files /dev/null and b/test_blossom/avatar-placeholder.webp differ diff --git a/test_blossom/blossom/.gitignore b/test_blossom/blossom/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/test_blossom/blossom/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/test_blossom/clean.rs b/test_blossom/clean.rs new file mode 100755 index 0000000..80a123d --- /dev/null +++ b/test_blossom/clean.rs @@ -0,0 +1,3 @@ +#!/bin/bash + +rm -rf ./event.map ./lmdb/ ./blossom/* ./downloaded diff --git a/test_blossom/config.toml b/test_blossom/config.toml new file mode 100644 index 0000000..c6b2f8f --- /dev/null +++ b/test_blossom/config.toml @@ -0,0 +1,37 @@ +# See contrib/chorus.toml for a documented config file + +data_directory = "." +ip_address = "127.0.0.1" +port = 8089 +hostname = "localhost" +chorus_is_behind_a_proxy = false +use_tls = false +certchain_pem_path = "tls/fullchain.pem" +key_pem_path = "tls/privkey.pem" +name = "Chorus Sample" +description = "A sample run of the Chorus relay" +# icon_url = +open_relay = false +user_hex_keys = [ + "12bb541d03bfc3cab0f4a8e4db28947f60faae6fca4e315eb27f809c6eff9a0b" +] +moderator_hex_keys = [ + "12bb541d03bfc3cab0f4a8e4db28947f60faae6fca4e315eb27f809c6eff9a0b" +] +verify_events = true +allow_scraping = false +allow_scrape_if_limited_to = 100 +allow_scrape_if_max_seconds = 7200 +max_subscriptions = 128 +serve_ephemeral = true +serve_relay_lists = true +server_log_level = "Info" +library_log_level = "Info" +client_log_level = "Warn" +enable_ip_blocking = true +minimum_ban_seconds = 1 +timeout_seconds = 60 +max_connections_per_ip = 5 +throttling_bytes_per_second = 131072 +throttling_burst = 4194304 +blossom_directory = "./blossom" \ No newline at end of file diff --git a/test_blossom/create_auth.sh b/test_blossom/create_auth.sh new file mode 100755 index 0000000..a536e1b --- /dev/null +++ b/test_blossom/create_auth.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +PUBKEY=12bb541d03bfc3cab0f4a8e4db28947f60faae6fca4e315eb27f809c6eff9a0b +PRIVKEY=b4a98d96270b6cd30c80e4fd594461d2b22d8dbcfbcd1f7b11bf0ef2b028a56b +AUTH_EXPIRATION=1900000000 + +VERB=$1 +HASH=$2 + +if [ x$VERB = x ] ; then + echo "USAGE: create_auth.sh VERB HASH" + exit 1 +fi + +if [ x$HASH = x ] ; then + echo "USAGE: create_auth.sh VERB HASH" + exit 1 +fi + +PRE_EVENT='{"pubkey": "'$PUBKEY'", "kind": 24242, "created_at": 0, "tags": [["expiration","'$AUTH_EXPIRATION'"], ["t","'$VERB'"], ["x","'$HASH'"]], "content":""}' + +EVENT=$(echo "$PRE_EVENT" | nak event --sec $PRIVKEY) + +EVENT_BASE64=$(echo $EVENT | base64 -w 0) + +echo "Authorization: Nostr $EVENT_BASE64" diff --git a/test_blossom/run.rs b/test_blossom/run.rs new file mode 100755 index 0000000..ecfbf4b --- /dev/null +++ b/test_blossom/run.rs @@ -0,0 +1,6 @@ +#!/bin/bash + +pushd .. +cargo build --release || exit 1 +popd +../target/release/chorus ./config.toml diff --git a/test_blossom/test.sh b/test_blossom/test.sh new file mode 100755 index 0000000..7ef675b --- /dev/null +++ b/test_blossom/test.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +if ! command -v curl 2>&1 >/dev/null +then + echo "curl command is required." + exit 1 +fi + +if ! command -v jq 2>&1 >/dev/null +then + echo "jq command is required." + exit 1 +fi + +if ! command -v nak 2>&1 >/dev/null +then + echo "nak command is required. https://github.com/fiatjaf/nak" + exit 1 +fi + +# UPLOAD TEST ------------ + +FILE="./avatar-placeholder.webp" +HASH=$(sha256sum $FILE | awk '{print $1}') + +# Generate nostr auth +AUTH=$(./create_auth.sh upload $HASH) + +# Upload +DESCRIPTOR=$(curl -s --data-binary @"$FILE" -X PUT --header "$AUTH" http://127.0.0.1:8089/upload) +if [ $? -ne 0 ] ; then + echo "FAILED: Curl (uploading) exited with a non-zero status" + exit 1 +fi +echo "PASS: FILE UPLOADED" + +# Extract the sha256 and compare it +DHASH=$(echo "$DESCRIPTOR" | jq -r .sha256) +if [ $? -ne 0 ] ; then + echo "FAILED: jq failed extracting sha256 from descriptor" + exit 1 +fi +if [ "$HASH" != "$DHASH" ] ; then + echo "returned descriptor 'sha256' does not match the hash" +fi +echo "PASS: DESCRIPTOR HASH MATCHES" + +# Extract the URL for download +URL=$(echo "$DESCRIPTOR" | jq -r .url) +if [ $? -ne 0 ] ; then + echo "FAILED: jq failed extracting url from descriptor" + exit 1 +fi + +# DOWNLOAD TEST ----------- + +curl -s "$URL" > downloaded +if [ $? -ne 0 ] ; then + echo "FAILED: Curl (downloading) exited with a non-zero status" + exit 1 +fi +echo "PASS: FILE DOWNLOADED" + +# Compare the files +if cmp -s "$FILE" downloaded; then + echo "PASS: THE DOWNLOADED FILE MATCHES THE UPLOADED FILE" +else + echo "FAIL: THE DOWNLOADED FILE DOES NOT MATCH THE UPLOADED FILE" +fi + +echo "end." +exit 0