Skip to content

Commit

Permalink
fix[integration tests]: Improve container SSH connection validation a…
Browse files Browse the repository at this point in the history
…nd allowed ssh settings
  • Loading branch information
sidey79 committed Dec 30, 2024
1 parent 7f5a41a commit 9c4ad43
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
32 changes: 20 additions & 12 deletions scripts/test-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

cd "$(readlink -f "$(dirname "$BASH_SOURCE")")"/..

IMAGE="${1:-$( docker images | grep '^fhem/*' | grep -v "<none>" | awk '{print $3}' | uniq )}"
IMAGE="${1:-$( docker images | grep 'alexa' | grep -v "<none>" | awk '{print $3}' | uniq )}"

echo -e "\n\n"
docker images
Expand All @@ -15,14 +15,14 @@ RETURNCODE=0

for ID in $IMAGE; do
echo "Booting up container for variant $ID ..."
CONTAINER=$( docker run -d -ti --health-interval=60s --health-timeout=10s --health-start-period=150s --health-retries=5 $ID )
CONTAINER=$( docker run -d -ti --health-interval=60s --health-timeout=10s --health-start-period=150s --health-retries=5 "$ID" )
docker container ls | grep 'fhem/.*'

echo -ne "Waiting for container ..."
sleep 3
bootstate="created"
until [ $bootstate != "created" ]; do
bootstate=$( docker inspect --format="{{json .State}}" $CONTAINER 2>/dev/null | jq -r .Status )
until [ "$bootstate" != "created" ]; do
bootstate=$( docker inspect --format="{{json .State}}" "$CONTAINER" 2>/dev/null | jq -r .Status )
echo -n " ."
sleep 3
done
Expand All @@ -37,13 +37,21 @@ for ID in $IMAGE; do
if [ -z "$status" ]; then
echo -ne "\nWaiting for health status report ..."
healthstate="starting"
until [ $healthstate != "starting" ]; do
healthstate=$( docker inspect --format="{{json .State}}" $CONTAINER 2>/dev/null | jq -r .Health.Status )
until [ "$healthstate" != "starting" ]; do
healthstate=$( docker inspect --format="{{json .State}}" "$CONTAINER" 2>/dev/null | jq -r .Health.Status )
echo -n " ."
sleep 3
done
if [ -n "$healthstate" ] && [ "$healthstate" == "healthy" ]; then
status="OK"

# Check SSH connection
if ! output=$(docker container exec --user 6062 "${CONTAINER}" ssh -F .ssh/config -p 58824 fhem-va.fhem.de status 2>&1); then
echo "$output"
status="ssh-error"
else
status="OK"
fi

elif [ -n "$healthstate" ] && [ "$healthstate" != "null" ]; then
status=$healthstate
else
Expand All @@ -53,15 +61,15 @@ for ID in $IMAGE; do
fi

if [ "$status" != "OK" ]; then
echo -e "\nImage $ID did come up with unexpected state "$status". Integration test FAILED!\n\n"
docker logs $CONTAINER
docker container rm $CONTAINER --force --volumes 2>&1>/dev/null
docker rmi $ID >/dev/null
echo -e "\nImage $ID did come up with unexpected state $status. Integration test FAILED!\n\n"
docker logs "$CONTAINER"
docker container rm "$CONTAINER" --force --volumes 2>&1>/dev/null
docker rmi "$ID" >/dev/null
echo "$ID $status" >> ./failed_variants
(( RETURNCODE++ ))
else
echo -e "\nImage $ID integration test PASSED.\n\n"
docker container rm $CONTAINER --force --volumes 2>&1>/dev/null
docker container rm "$CONTAINER" --force --volumes 2>&1>/dev/null
fi
done

Expand Down
19 changes: 10 additions & 9 deletions src/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ generate_ssh_keys() {
if [ ! -s ${ALEXAFHEM_DIR}/.ssh/id_rsa ]; then
echo -e " - Generating SSH RSA client certificate for user 'alexa-fhem' ..."
rm -f ${ALEXAFHEM_DIR}/.ssh/id_rsa*
ssh-keygen -t rsa -b 4096 -f ${ALEXAFHEM_DIR}/.ssh/id_rsa -q -N "" -o -a 100
ssh-keygen -t rsa-sha2-512 -b 4096 -f ${ALEXAFHEM_DIR}/.ssh/id_rsa -q -N "" -o -a 100
sed -i "s/root@.*/alexa-fhem@alexa-fhem-docker/" ${ALEXAFHEM_DIR}/.ssh/id_rsa.pub
fi
chmod 600 ${ALEXAFHEM_DIR}/.ssh/id_rsa
Expand All @@ -55,14 +55,15 @@ generate_ssh_keys() {

harden_ssh_client() {
if [ ! -f ${ALEXAFHEM_DIR}/.ssh/config ]; then
echo "IdentityFile ~/.ssh/id_ed25519
IdentityFile ~/.ssh/id_rsa
Ciphers [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr
HostKeyAlgorithms ssh-ed25519,ssh-rsa
KexAlgorithms curve25519-sha256,[email protected],diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256
MACs [email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,[email protected]
" > "${ALEXAFHEM_DIR}"/.ssh/config
printf "%s\n" \
"IdentityFile ~/.ssh/id_ed25519" \
"IdentityFile ~/.ssh/id_rsa" \
"PubkeyAcceptedKeyTypes +ssh-rsa" \
"HostKeyAlgorithms +ssh-rsa" \
"Ciphers [email protected],[email protected],aes256-ctr,aes192-ctr,[email protected],aes128-ctr" \
"MACs hmac-sha2-256,hmac-sha2-512,[email protected],[email protected],[email protected]" \
"KexAlgorithms [email protected],curve25519-sha256,[email protected],gss-curve25519-sha256-,diffie-hellman-group16-sha512,gss-group16-sha512-,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha256" \
"Ciphers aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]" > "${ALEXAFHEM_DIR}"/.ssh/config
fi
}

Expand Down

0 comments on commit 9c4ad43

Please sign in to comment.