Something went wrong. Try again.
Manage a distributed indexed dataset of files and metadata, using a Dolt database to track who has copies of what.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164#!/bin/bash
# Usage: interactive_tests.sh [no-authentication | unencrypted-key]## Each argument selects how the test SFTP server authenticates clients. With no# argument, every configuration is tested in turn.
set -e
cd "$(dirname "$0")"source ../assert.sh
# Runs the full end-to-end test for one authentication configuration. The body is# a subshell so its `cd`s don't leak into the next configuration.run_authentication_test() ( local auth_mode=$1
sftp_url="sftp://127.0.0.1:2222/" client_key_answer="" password="" password_initial_prompt_answer=$'n\n' password_subsequent_prompt_answer=""
# Credentials that the server must reject. Empty means the configuration has no # authentication to reject. rejected_sftp_url="$sftp_url" rejected_client_key_answer="" rejected_password_initial_prompt_answer=$'n\n' case "$auth_mode" in no-authentication) server_auth_args=(--no-authentication) rejected_sftp_url="" ;; password-in-url) server_auth_args=(--password password) sftp_url="sftp://user:password@127.0.0.1:2222/" password_initial_prompt_answer="" rejected_sftp_url="sftp://user:wrong-password@127.0.0.1:2222/" rejected_password_initial_prompt_answer="" ;; password-prompt) server_auth_args=(--password password) password_initial_prompt_answer=$'y\npassword\n' password_subsequent_prompt_answer=$'password\n' rejected_password_initial_prompt_answer=$'y\nwrong-password\n' ;; unencrypted-key) server_auth_args=(--authorized-keys ../id_ed25519.pub) client_key_answer="../id_ed25519" rejected_client_key_answer="../unauthorized_id_ed25519" ;; encrypted-key) server_auth_args=(--authorized-keys ../id_ed25519.pub --server-key-passphrase password) client_key_answer="../id_ed25519" password="password" password_initial_prompt_answer=$'y\npassword\n' password_subsequent_prompt_answer=$'password\n' rejected_client_key_answer="../unauthorized_id_ed25519" rejected_password_initial_prompt_answer=$'y\npassword\n' ;; *) echo "Unknown authentication configuration: $auth_mode" return 1 ;; esac
log_header "Testing authentication configuration: $auth_mode"
temp_dir=$(mktemp -d) cd $temp_dir
ssh-keygen -t ed25519 -f ./id_ed25519 -N "$password" -q ssh-keygen -t ed25519 -f ./unauthorized_id_ed25519 -N "$password" -q
mkdir upstream mkdir downstream mkdir rejected cd upstream
# Initialize the dolt-annex repository interactively with a local database and filestore dolt-annex <<EOFCreate New Local Database
Local OnlyFirefoxExitEOF
# Launch the dolt-annex interactive prompt and immediately exit, asserting the setup has already been completed successfully dolt-annex <<EOFExitEOF
dolt-annex server "${server_auth_args[@]}" --host 127.0.0.1 --port 2222 --server-key ../id_ed25519 & server_pid=$! cd dolt dolt sql-server & sql_pid=$!
sleep 1
# A client that presents a wrong password or an unauthorized key must be rejected if [ -n "$rejected_sftp_url" ]; then ( cd ../../rejected
rejected_status=0 rejected_output=$(dolt-annex 2>&1 <<EOFConnect to Remote Databasemysql://root@127.0.0.1/doltnRemote Only${rejected_sftp_url}${rejected_client_key_answer}${rejected_password_initial_prompt_answer}ExitEOF ) || rejected_status=$?
assert_not_eq 0 "$rejected_status" "$auth_mode: rejected client exited successfully" assert_contain "$rejected_output" "Permission denied" "$auth_mode: rejected client did not fail with an authentication error" ) log_success "Rejected unauthorized client: $auth_mode" fi
cd ../../downstream
dolt-annex <<EOFConnect to Remote Databasemysql://root@127.0.0.1/doltnRemote Only${sftp_url}${client_key_answer}${password_initial_prompt_answer}Firefox${password_subsequent_prompt_answer}ExitEOF
dolt-annex <<EOF${password_subsequent_prompt_answer}ExitEOF
dolt-annex <<EOF${password_subsequent_prompt_answer}Gallery-dl Downloadhttps://e621.net/posts/6780547
ExitEOF
kill $server_pid $sql_pid wait $server_pid $sql_pid 2>/dev/null || true
log_success "Passed: $auth_mode")
if [ $# -eq 0 ]; then set -- no-authentication password-in-url password-prompt unencrypted-key encrypted-keyfi
for auth_mode in "$@"; do run_authentication_test "$auth_mode"done
log_success "All tests passed!"