Test Blossom

This commit is contained in:
Mike Dilger 2024-11-17 14:10:59 +13:00
parent beb9635e13
commit 501edee9a4
No known key found for this signature in database
GPG Key ID: 47581A78D4329BA4
9 changed files with 156 additions and 0 deletions

3
test_blossom/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
event.map
lmdb/
downloaded

7
test_blossom/README.md Normal file
View File

@ -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`

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

2
test_blossom/blossom/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

3
test_blossom/clean.rs Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
rm -rf ./event.map ./lmdb/ ./blossom/* ./downloaded

37
test_blossom/config.toml Normal file
View File

@ -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"

26
test_blossom/create_auth.sh Executable file
View File

@ -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"

6
test_blossom/run.rs Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
pushd ..
cargo build --release || exit 1
popd
../target/release/chorus ./config.toml

72
test_blossom/test.sh Executable file
View File

@ -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