external test script

pull/81/head
Jacob Barthelmeh 2018-07-02 17:07:51 -06:00
parent a631cf5794
commit 73bcd5c95a
3 changed files with 81 additions and 10 deletions

View File

@ -100,6 +100,8 @@ static void ShowUsage(void)
printf(" -p <num> port to connect on, default %d\n", wolfSshPort);
printf(" -u <username> username to authenticate as (REQUIRED)\n");
printf(" -P <password> password for username, prompted if omitted\n");
printf(" -x exit after successful connection without doing\n"
" read/write\n");
}
@ -160,12 +162,13 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
char* host = (char*)wolfSshIp;
const char* username = NULL;
const char* password = NULL;
byte imExit = 0;
int argc = ((func_args*)args)->argc;
char** argv = ((func_args*)args)->argv;
((func_args*)args)->return_code = 0;
while ((ch = mygetopt(argc, argv, "?h:p:u:P:")) != -1) {
while ((ch = mygetopt(argc, argv, "?h:p:u:P:x")) != -1) {
switch (ch) {
case 'h':
host = myoptarg;
@ -187,6 +190,11 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
password = myoptarg;
break;
case 'x':
/* exit after successful connection without read/write */
imExit = 1;
break;
case '?':
ShowUsage();
exit(EXIT_SUCCESS);
@ -235,16 +243,18 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
if (ret != WS_SUCCESS)
err_sys("Couldn't connect SSH stream.");
ret = wolfSSH_stream_send(ssh, (byte*)testString,
(word32)strlen(testString));
if (ret <= 0)
err_sys("Couldn't send test string.");
if (!imExit) {
ret = wolfSSH_stream_send(ssh, (byte*)testString,
(word32)strlen(testString));
if (ret <= 0)
err_sys("Couldn't send test string.");
ret = wolfSSH_stream_read(ssh, (byte*)rxBuf, sizeof(rxBuf) - 1);
if (ret <= 0)
err_sys("Stream read failed.");
rxBuf[ret] = '\0';
printf("Server said: %s\n", rxBuf);
ret = wolfSSH_stream_read(ssh, (byte*)rxBuf, sizeof(rxBuf) - 1);
if (ret <= 0)
err_sys("Stream read failed.");
rxBuf[ret] = '\0';
printf("Server said: %s\n", rxBuf);
}
ret = wolfSSH_shutdown(ssh);
if (ret != WS_SUCCESS)

View File

@ -0,0 +1,59 @@
#!/bin/sh
# external tests
host="test.rebex.net"
user="demo"
password="password"
if test -n "$WOLFSSH_EXTERNAL_TEST"; then
echo "WOLFSSL_EXTERNAH_TEST set, running test..."
else
echo "WOLFSSL_EXTERNAH_TEST NOT set, won't run"
exit 0
fi
do_cleanup() {
echo "in cleanup"
}
do_trap() {
echo "got trap"
do_cleanup
exit -1
}
trap do_trap INT TERM
[ ! -x ./examples/client/client ] && echo -e "\n\nClient doesn't exist" && exit 1
echo "Testing client connection to $host : "
./examples/client/client -u $user -P $password -h $host -p 22 -x
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo -e "failed to connect\n"
do_cleanup
exit 1
fi
echo -e "Success\n"
# not having the sftp client built in is not a failure case
if [ -x ./wolfsftp/client/wolfsftp ]; then
echo "Testing wolfsftp connection to $host : "
echo "exit" | ./wolfsftp/client/wolfsftp -u $user -P $password -h $host -p 22
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo -e "failed to connect\n"
do_cleanup
exit 1
else
echo -e "Success\n"
fi
else
echo -e "\n\nwolfSFTP client doesn't exist"
fi
echo -e "\nALL Tests Passed"
exit 0

View File

@ -8,3 +8,5 @@ if BUILD_SFTP
dist_noinst_SCRIPTS+= scripts/sftp.test
endif
dist_noinst_SCRIPTS+= scripts/external.test