aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/Makefile7
-rw-r--r--tests/authentication.c2
-rw-r--r--tests/test_exec.c62
3 files changed, 68 insertions, 3 deletions
diff --git a/tests/Makefile b/tests/Makefile
index bebfe5b6..8483856e 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,9 +1,12 @@
-all: test_tunnel
+all: test_tunnel test_exec
CFLAGS=-I../include/ -g -Wall
-LDFLAGS=-lssh -L../libssh/.libs
+LDFLAGS=-lssh -L../build/libssh/
test_tunnel: test_tunnel.o authentication.o connection.o
gcc -o $@ $^ $(LDFLAGS)
+test_exec: test_exec.o authentication.o connection.o
+ gcc -o $@ $^ $(LDFLAGS)
+
clean:
rm -f *.o test_tunnel
diff --git a/tests/authentication.c b/tests/authentication.c
index 00abd052..248b646f 100644
--- a/tests/authentication.c
+++ b/tests/authentication.c
@@ -47,7 +47,7 @@ static int auth_kbdint(SSH_SESSION *session){
}
int authenticate (SSH_SESSION *session){
- int auth=ssh_userauth_autopubkey(session);
+ int auth=ssh_userauth_autopubkey(session, NULL);
char *password;
if(auth==SSH_AUTH_ERROR){
fprintf(stderr,"Authenticating with pubkey: %s\n",ssh_get_error(session));
diff --git a/tests/test_exec.c b/tests/test_exec.c
new file mode 100644
index 00000000..1b2081d0
--- /dev/null
+++ b/tests/test_exec.c
@@ -0,0 +1,62 @@
+/*
+This file is distributed in public domain. You can do whatever you want
+with its content.
+*/
+#include <libssh/libssh.h>
+#include <stdio.h>
+#include <string.h>
+#include "tests.h"
+
+void do_connect(SSH_SESSION *session) {
+ char buf[4096] = {0};
+ CHANNEL *channel;
+
+ int error = ssh_connect(session);
+ if (error != SSH_OK) {
+ fprintf(stderr,"Error at connection: %s\n", ssh_get_error(session));
+ return;
+ }
+ printf("Connected\n");
+
+ ssh_is_server_known(session);
+
+ error = authenticate(session);
+ if(error != SSH_AUTH_SUCCESS) {
+ fprintf(stderr,"Error at authentication: %s\n", ssh_get_error(session));
+ return;
+ }
+ printf("Authenticated\n");
+ channel = channel_new(session);
+ channel_open_session(channel);
+ printf("Execute 'ls' on the channel\n");
+ error = channel_request_exec(channel, "ls");
+ if(error != SSH_OK){
+ fprintf(stderr, "Error executing command: %s\n", ssh_get_error(session));
+ return;
+ }
+ printf("--------------------output----------------------\n");
+ while (channel_read(channel, buf, sizeof(buf), 0)) {
+ printf("%s", buf);
+ }
+ printf("\n");
+ printf("---------------------end------------------------\n");
+ channel_send_eof(channel);
+ fprintf(stderr, "Exit status: %d\n", channel_get_exit_status(channel));
+
+ printf("\nChannel test finished\n");
+ channel_close(channel);
+ channel_free(channel);
+}
+
+int main(int argc, char **argv){
+ SSH_OPTIONS *options=set_opts(argc, argv);
+ SSH_SESSION *session=ssh_new();
+ if(options==NULL){
+ return 1;
+ }
+ ssh_set_options(session,options);
+ do_connect(session);
+ ssh_disconnect(session);
+ ssh_finalize();
+ return 0;
+}