From a0772385f1b4086aacdc6d84a3daea4b2ef26f30 Mon Sep 17 00:00:00 2001
From: chengyechun <chengyechun1@huawei.com>
Date: Thu, 5 Jan 2023 23:43:22 +0800
Subject: [PATCH] skip tests for '%C' if there is no openssl on local path

---
 regress/percent.sh                            | 24 +++++++++++----
 ...t-if-there-is-no-openssl-on-local-pa.patch | 30 +++++++++++++++++++
 2 files changed, 48 insertions(+), 6 deletions(-)
 create mode 100644 skip-percent-test-if-there-is-no-openssl-on-local-pa.patch

diff --git a/regress/percent.sh b/regress/percent.sh
index 7ed4184..9c112eb 100644
--- a/regress/percent.sh
+++ b/regress/percent.sh
@@ -13,6 +13,10 @@ USERID=`id -u`
 HOST=`hostname | cut -f1 -d.`
 HOSTNAME=`hostname`
 
+# Check if there is openssl in local PATH
+NOOPENSSL=0
+for i in $PATH;do [ -x "$i/openssl" ] && NOOPENSSL=1; done
+
 # Localcommand is evaluated after connection because %T is not available
 # until then.  Because of this we use a different method of exercising it,
 # and we can't override the remote user otherwise authentication will fail.
@@ -77,11 +81,14 @@ for i in matchexec localcommand remotecommand controlpath identityagent \
 	if [ "$i" = "$localcommand" ]; then
 		trial $i '%T' NONE
 	fi
-	# Matches implementation in readconf.c:ssh_connection_hash()
-	HASH=`printf "${HOSTNAME}127.0.0.1${PORT}$REMUSER" |
-	    $OPENSSL_BIN sha1 | cut -f2 -d' '`
+    # skip tests for '%C' since no openssl in local PATH
+	if [ $NOOPENSSL -eq 1 ]; then
+	    # Matches implementation in readconf.c:ssh_connection_hash()	
+        HASH=`printf "${HOSTNAME}127.0.0.1${PORT}$REMUSER" |
+            $OPENSSL_BIN sha1 | cut -f2 -d' '`
+	fi
 	trial $i '%%' '%'
-	trial $i '%C' $HASH
+	if [ $NOOPENSSL -eq 1 ]; then trial $i '%C' $HASH; fi
 	trial $i '%i' $USERID
 	trial $i '%h' 127.0.0.1
 	trial $i '%L' $HOST
@@ -95,8 +102,13 @@ for i in matchexec localcommand remotecommand controlpath identityagent \
 	# containing %d for UserKnownHostsFile
 	if [ "$i" != "userknownhostsfile" ]; then
 		trial $i '%d' $HOME
-		trial $i '%%/%C/%i/%h/%d/%L/%l/%n/%p/%r/%u' \
-		    "%/$HASH/$USERID/127.0.0.1/$HOME/$HOST/$HOSTNAME/somehost/$PORT/$REMUSER/$USER"
+        if [ $NOOPENSSL -eq 0 ]; then
+            trial $i '%%/%i/%h/%d/%L/%l/%n/%p/%r/%u' \
+                "%/$USERID/127.0.0.1/$HOME/$HOST/$HOSTNAME/somehost/$PORT/$REMUSER/$USER"
+        else
+		    trial $i '%%/%C/%i/%h/%d/%L/%l/%n/%p/%r/%u' \
+		        "%/$HASH/$USERID/127.0.0.1/$HOME/$HOST/$HOSTNAME/somehost/$PORT/$REMUSER/$USER"
+        fi
 	fi
 done
 
diff --git a/skip-percent-test-if-there-is-no-openssl-on-local-pa.patch b/skip-percent-test-if-there-is-no-openssl-on-local-pa.patch
new file mode 100644
index 0000000..c7af5d9
--- /dev/null
+++ b/skip-percent-test-if-there-is-no-openssl-on-local-pa.patch
@@ -0,0 +1,30 @@
+From 1da9e48b41ab6eca157d4fa3b74490510d9006ae Mon Sep 17 00:00:00 2001
+From: chengyechun <chengyechun1@huawei.com>
+Date: Thu, 5 Jan 2023 23:43:22 +0800
+Subject: [PATCH] skip percent test if there is no openssl on local path as
+ scp3 did
+
+---
+ regress/percent.sh | 6 ++++++
+ 1 file changed, 6 insertions(+)
+
+diff --git a/regress/percent.sh b/regress/percent.sh
+index 7ed4184..08afbc8 100644
+--- a/regress/percent.sh
++++ b/regress/percent.sh
+@@ -8,6 +8,12 @@ if [ -x "/usr/xpg4/bin/id" ]; then
+ 	export PATH
+ fi
+ 
++NOOPENSSL=0
++for i in $PATH;do [ -x "$i/openssl" ] && $OPENSSL=1; done
++if [ $? -eq 0 ]; then
++	skip "No openssl on local path."
++fi
++
+ USER=`id -u -n`
+ USERID=`id -u`
+ HOST=`hostname | cut -f1 -d.`
+-- 
+2.23.0
+
-- 
2.23.0

