#!/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 <&1 </dev/null || true log_success "Passed: $auth_mode" ) if [ $# -eq 0 ]; then set -- no-authentication password-in-url password-prompt unencrypted-key encrypted-key fi for auth_mode in "$@"; do run_authentication_test "$auth_mode" done log_success "All tests passed!"