From 866e4442b529e14290db98e3f353caa92c96cc73 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Thu, 21 May 2020 13:11:23 +0200 Subject: Removed old, 10 years unused test files They do not build anymore and I believe most of their functionality is already covered by new testst. Signed-off-by: Jakub Jelen Reviewed-by: Andreas Schneider --- tests/authentication.c | 74 ----------------- tests/connection.c | 31 ------- tests/sftp_stress/main.c | 174 ---------------------------------------- tests/test_exec.c | 62 -------------- tests/test_pcap.c | 50 ------------ tests/test_ssh_bind_accept_fd.c | 147 --------------------------------- tests/test_tunnel.c | 76 ------------------ tests/tests.h | 8 -- 8 files changed, 622 deletions(-) delete mode 100644 tests/authentication.c delete mode 100644 tests/connection.c delete mode 100644 tests/sftp_stress/main.c delete mode 100644 tests/test_exec.c delete mode 100644 tests/test_pcap.c delete mode 100644 tests/test_ssh_bind_accept_fd.c delete mode 100644 tests/test_tunnel.c delete mode 100644 tests/tests.h diff --git a/tests/authentication.c b/tests/authentication.c deleted file mode 100644 index 248b646f..00000000 --- a/tests/authentication.c +++ /dev/null @@ -1,74 +0,0 @@ -/* -This file is distributed in public domain. You can do whatever you want -with its content. -*/ - - -#include -#include -#include -#include - -#include - -#include "tests.h" -static int auth_kbdint(SSH_SESSION *session){ - int err=ssh_userauth_kbdint(session,NULL,NULL); - char *name,*instruction,*prompt,*ptr; - char buffer[128]; - int i,n; - char echo; - while (err==SSH_AUTH_INFO){ - name=ssh_userauth_kbdint_getname(session); - instruction=ssh_userauth_kbdint_getinstruction(session); - n=ssh_userauth_kbdint_getnprompts(session); - if(strlen(name)>0) - printf("%s\n",name); - if(strlen(instruction)>0) - printf("%s\n",instruction); - for(i=0;i -#include -#include "tests.h" -SSH_OPTIONS *set_opts(int argc, char **argv){ - SSH_OPTIONS *options=ssh_options_new(); - char *host=NULL; - if(ssh_options_getopt(options,&argc, argv)){ - fprintf(stderr,"error parsing command line :%s\n",ssh_get_error(options)); - return NULL; - } - int i; - while((i=getopt(argc,argv,""))!=-1){ - switch(i){ - default: - fprintf(stderr,"unknown option %c\n",optopt); - } - } - if(optind < argc) - host=argv[optind++]; - if(host==NULL){ - fprintf(stderr,"must provide an host name\n"); - return NULL; - } - ssh_options_set_host(options,host); - return options; -} diff --git a/tests/sftp_stress/main.c b/tests/sftp_stress/main.c deleted file mode 100644 index ac3f8bb4..00000000 --- a/tests/sftp_stress/main.c +++ /dev/null @@ -1,174 +0,0 @@ -/* - * main.c - * - * Created on: 22 juin 2009 - * Author: aris - */ -#include -#include -#include -#include -#include -#include -#include -#include -#define TEST_READ 1 -#define TEST_WRITE 2 -#define NTHREADS 3 -#define FILESIZE 100000 -unsigned char samplefile[FILESIZE]; -volatile int stop=0; - -const char* hosts[]={"localhost","barebone"}; -void signal_stop(){ - stop=1; - printf("Stopping...\n"); -} - -SSH_SESSION *connect_host(const char *hostname); -int sftp_test(SSH_SESSION *session, int test); - -int docycle(const char *host, int test){ - SSH_SESSION *session=connect_host(host); - int ret=SSH_ERROR; - if(!session){ - printf("connect failed\n"); - } else { - printf("Connected\n"); - ret=sftp_test(session,test); - if(ret != SSH_OK){ - printf("Error in sftp\n"); - } - ssh_disconnect(session); - } - return ret; -} - -int thread(){ - while(docycle(hosts[rand()%2],TEST_WRITE) == SSH_OK) - if(stop) - break; - return 0; -} - -int main(int argc, char **argv){ - int i; - pthread_t threads[NTHREADS]; - ssh_init(); - srand(time(NULL)); - for(i=0;i -#include -#include -#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_session_is_known_server(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 = ssh_channel_new(session); - ssh_channel_open_session(channel); - printf("Execute 'ls' on the channel\n"); - error = ssh_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 (ssh_channel_read(channel, buf, sizeof(buf), 0)) { - printf("%s", buf); - } - printf("\n"); - printf("---------------------end------------------------\n"); - ssh_channel_send_eof(channel); - fprintf(stderr, "Exit status: %d\n", ssh_channel_get_exit_status(channel)); - - printf("\nChannel test finished\n"); - ssh_channel_close(channel); - ssh_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; -} diff --git a/tests/test_pcap.c b/tests/test_pcap.c deleted file mode 100644 index 01aa714a..00000000 --- a/tests/test_pcap.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of the SSH Library - * - * Copyright (c) 2009 by Aris Adamantiadis - * - * The SSH Library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation; either version 2.1 of the License, or (at your - * option) any later version. - * - * The SSH Library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with the SSH Library; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - * MA 02111-1307, USA. - */ - -/* Simple test for the pcap functions */ - -#include -#include -#include - -#include -#include -#include - -int main(int argc, char **argv){ - ssh_pcap_file pcap; - ssh_pcap_context ctx; - ssh_buffer buffer=ssh_buffer_new(); - char *str="Hello, this is a test string to test the capabilities of the" - "pcap file writer."; - printf("Simple pcap tester\n"); - pcap=ssh_pcap_file_new(); - if(ssh_pcap_file_open(pcap,"test.cap") != SSH_OK){ - printf("error happened\n"); - return EXIT_FAILURE; - } - buffer_add_data(buffer,str,strlen(str)); - ctx=ssh_pcap_context_new(NULL); - ssh_pcap_context_set_file(ctx,pcap); - ssh_pcap_context_write(ctx,SSH_PCAP_DIR_OUT,str,strlen(str),strlen(str)); - - return EXIT_SUCCESS; -} diff --git a/tests/test_ssh_bind_accept_fd.c b/tests/test_ssh_bind_accept_fd.c deleted file mode 100644 index 5aa8211a..00000000 --- a/tests/test_ssh_bind_accept_fd.c +++ /dev/null @@ -1,147 +0,0 @@ -/* Test the ability to use ssh_bind_accept_fd. - * - * Expected behavior: Prints "SUCCESS!" - * - * Faulty behavior observed before change: Connection timeout - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct options { - const char *server_keyfile; -} options; - -const char HOST[] = "127.0.0.1"; -const int PORT = 3333; - -int get_connection() { - int rc, server_socket, client_conn = -1; - struct sockaddr_in server_socket_addr; - struct sockaddr_storage client_conn_addr; - socklen_t client_conn_addr_size = sizeof(client_conn_addr); - - server_socket = socket(PF_INET, SOCK_STREAM, 0); - if (server_socket < 0) { - goto out; - } - - server_socket_addr.sin_family = AF_INET; - server_socket_addr.sin_port = htons(PORT); - if (inet_pton(AF_INET, HOST, &server_socket_addr.sin_addr) != 1) { - goto out; - } - - rc = bind(server_socket, (struct sockaddr *)&server_socket_addr, - sizeof(server_socket_addr)); - if (rc < 0) { - goto out; - } - - if (listen(server_socket, 0) < 0) { - goto out; - } - - client_conn = accept(server_socket, - (struct sockaddr *)&client_conn_addr, - &client_conn_addr_size); - - out: - return client_conn; -} - -void ssh_server() { - ssh_bind bind; - ssh_session session; - - int client_conn = get_connection(); - if (client_conn < 0) { - err(1, "get_connection"); - } - - bind = ssh_bind_new(); - if (!bind) { - errx(1, "ssh_bind_new"); - } - -#ifdef HAVE_DSA - /*TODO mbedtls this is probably required */ - if (ssh_bind_options_set(bind, SSH_BIND_OPTIONS_DSAKEY, - options.server_keyfile) != SSH_OK) { - errx(1, "ssh_bind_options_set(SSH_BIND_OPTIONS_DSAKEY"); - } -#else - if (ssh_bind_options_set(bind, SSH_BIND_OPTIONS_RSAKEY, - options.server_keyfile) != SSH_OK) { - errx(1, "ssh_bind_options_set(SSH_BIND_OPTIONS_RSAKEY"); - } -#endif - - session = ssh_new(); - if (!session) { - errx(1, "ssh_new"); - } - - if (ssh_bind_accept_fd(bind, session, client_conn) != SSH_OK) { - errx(1, "ssh_bind_accept: %s", ssh_get_error(bind)); - } - - if (ssh_handle_key_exchange(session) != SSH_OK) { - errx(1, "ssh_handle_key_exchange: %s", ssh_get_error(session)); - } - - printf("SUCCESS!\n"); -} - -void ssh_client() { - ssh_session session; - - session = ssh_new(); - if (!session) { - errx(1, "ssh_new"); - } - - if (ssh_options_set(session, SSH_OPTIONS_HOST, HOST) < 0) { - errx(1, "ssh_options_set(SSH_OPTIONS_HOST)"); - } - if (ssh_options_set(session, SSH_OPTIONS_PORT, &PORT) < 0) { - errx(1, "ssh_options_set(SSH_OPTIONS_PORT)"); - } - - if (ssh_connect(session) != SSH_OK) { - errx(1, "ssh_connect: %s", ssh_get_error(session)); - } -} - -int main(int argc, const char *argv[]) { - if (argc != 2) { - printf("Usage: %s \n", argv[0]); - exit(1); - } - - options.server_keyfile = argv[1]; - - pid_t pid = fork(); - if (pid < 0) { - errx(1, "fork"); - } - if (pid == 0) { - /* Allow the server to get set up */ - sleep(3); - - ssh_client(); - } else { - ssh_server(); - } - - return 0; -} diff --git a/tests/test_tunnel.c b/tests/test_tunnel.c deleted file mode 100644 index 952c73e1..00000000 --- a/tests/test_tunnel.c +++ /dev/null @@ -1,76 +0,0 @@ -/* -This file is distributed in public domain. You can do whatever you want -with its content. -*/ -#include -#include -#include -#include "tests.h" -#define ECHO_PORT 7 -void do_connect(SSH_SESSION *session){ - 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_session_is_known_server(session); - // we don't care what happens here - 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=ssh_channel_new(session); - error=ssh_channel_open_forward(channel,"localhost",ECHO_PORT,"localhost",42); - if(error!=SSH_OK){ - fprintf(stderr,"Error when opening forward:%s\n",ssh_get_error(session)); - return; - } - printf("Forward opened\n"); - int i=0; - char string[20]; - char buffer[20]; - for(i=0;i<2000;++i){ - sprintf(string,"%d\n",i); - ssh_channel_write(channel,string,strlen(string)); - do { - error=ssh_channel_poll(channel,0); - //if(error < strlen(string)) - //usleep(10); - } while(error < strlen(string) && error >= 0); - if(error>0){ - error=ssh_channel_read_nonblocking(channel,buffer,strlen(string),0); - if(error>=0){ - if(memcmp(buffer,string,strlen(string))!=0){ - fprintf(stderr,"Problem with answer: wanted %s got %s\n",string,buffer); - } else { - printf("."); - fflush(stdout); - } - } - - } - if(error==-1){ - fprintf(stderr,"Channel reading error : %s\n",ssh_get_error(session)); - break; - } - } - printf("\nChannel test finished\n"); - ssh_channel_close(channel); - ssh_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; -} diff --git a/tests/tests.h b/tests/tests.h deleted file mode 100644 index dd001f1f..00000000 --- a/tests/tests.h +++ /dev/null @@ -1,8 +0,0 @@ -/* -This file is distributed in public domain. You can do whatever you want -with its content. -*/ -#include -int authenticate (SSH_SESSION *session); -SSH_OPTIONS *set_opts(int argc, char **argv); - -- cgit v1.2.3