Module Name: src Committed By: pooka Date: Sun Feb 6 18:44:30 UTC 2011
Modified Files: src/tests/lib: Makefile Added Files: src/tests/lib/librumphijack: Atffile Makefile h_netget.c index.html netstat.expout t_tcpip.sh Log Message: Add a simple test for the purpose of making sure rumphijack works on -current in addition to 5.x. The test serves a simple index.html on a hijacked bozohttpd and checks the file can be retrieved. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/tests/lib/Makefile cvs rdiff -u -r0 -r1.1 src/tests/lib/librumphijack/Atffile \ src/tests/lib/librumphijack/Makefile \ src/tests/lib/librumphijack/h_netget.c \ src/tests/lib/librumphijack/index.html \ src/tests/lib/librumphijack/netstat.expout \ src/tests/lib/librumphijack/t_tcpip.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/lib/Makefile diff -u src/tests/lib/Makefile:1.10 src/tests/lib/Makefile:1.11 --- src/tests/lib/Makefile:1.10 Mon Dec 20 23:47:23 2010 +++ src/tests/lib/Makefile Sun Feb 6 18:44:29 2011 @@ -1,9 +1,9 @@ -# $NetBSD: Makefile,v 1.10 2010/12/20 23:47:23 pgoyette Exp $ +# $NetBSD: Makefile,v 1.11 2011/02/06 18:44:29 pooka Exp $ .include <bsd.own.mk> TESTS_SUBDIRS= csu libc libm libevent libobjc libposix libprop librt \ - libpthread libutil semaphore + libpthread librumphijack libutil semaphore .if ${MKCRYPTO} != "no" TESTS_SUBDIRS+= libdes Added files: Index: src/tests/lib/librumphijack/Atffile diff -u /dev/null src/tests/lib/librumphijack/Atffile:1.1 --- /dev/null Sun Feb 6 18:44:30 2011 +++ src/tests/lib/librumphijack/Atffile Sun Feb 6 18:44:29 2011 @@ -0,0 +1,6 @@ +Content-Type: application/X-atf-atffile; version="1" +X-NetBSD-Id: "$NetBSD: Atffile,v 1.1 2011/02/06 18:44:29 pooka Exp $" + +prop: test-suite = "NetBSD" + +tp-glob: t_* Index: src/tests/lib/librumphijack/Makefile diff -u /dev/null src/tests/lib/librumphijack/Makefile:1.1 --- /dev/null Sun Feb 6 18:44:30 2011 +++ src/tests/lib/librumphijack/Makefile Sun Feb 6 18:44:29 2011 @@ -0,0 +1,16 @@ +# $NetBSD: Makefile,v 1.1 2011/02/06 18:44:29 pooka Exp $ +# + +.include <bsd.own.mk> + +TESTSDIR= ${TESTSBASE}/lib/librumphijack + +TESTS_SH= t_tcpip +TESTS_C= h_netget + +FILES= netstat.expout index.html +FILESDIR= ${TESTSDIR} + +ATFFILE= yes + +.include <bsd.test.mk> Index: src/tests/lib/librumphijack/h_netget.c diff -u /dev/null src/tests/lib/librumphijack/h_netget.c:1.1 --- /dev/null Sun Feb 6 18:44:30 2011 +++ src/tests/lib/librumphijack/h_netget.c Sun Feb 6 18:44:29 2011 @@ -0,0 +1,101 @@ +/* $NetBSD: h_netget.c,v 1.1 2011/02/06 18:44:29 pooka Exp $ */ + +/*- + * Copyright (c) 2011 Antti Kantee. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * simple utility to fetch a webpage. we wouldn't need this + * if we had something like netcat in base + */ + +#include <sys/cdefs.h> +__RCSID("$NetBSD: h_netget.c,v 1.1 2011/02/06 18:44:29 pooka Exp $"); + +#include <sys/types.h> +#include <sys/socket.h> + +#include <arpa/inet.h> + +#include <netinet/in.h> + +#include <err.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#define GETSTR "GET / HTTP/1.0\n\n" + +int +main(int argc, char *argv[]) +{ + char buf[8192]; + struct sockaddr_in sin; + ssize_t n; + int s, fd; + + setprogname(argv[0]); + if (argc != 4) { + fprintf(stderr, "usage: %s address port savefile\n", + getprogname()); + exit(1); + } + + s = socket(PF_INET, SOCK_STREAM, 0); + if (s == -1) + err(1, "socket"); + + memset(&sin, 0, sizeof(sin)); + sin.sin_len = sizeof(sin); + sin.sin_family = AF_INET; + sin.sin_port = htons(atoi(argv[2])); + sin.sin_addr.s_addr = inet_addr(argv[1]); + + fd = open(argv[3], O_CREAT | O_RDWR, 0644); + if (fd == -1) + err(1, "open"); + if (ftruncate(fd, 0) == -1) + err(1, "ftruncate savefile"); + + if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) == -1) + err(1, "connect"); + + if (write(s, GETSTR, strlen(GETSTR)) != strlen(GETSTR)) + err(1, "socket write"); + + for (;;) { + n = read(s, buf, sizeof(buf)); + if (n == 0) + break; + if (n == -1) + err(1, "socket read"); + + if (write(fd, buf, n) != n) + err(1, "write file"); + } + + exit(0); +} Index: src/tests/lib/librumphijack/index.html diff -u /dev/null src/tests/lib/librumphijack/index.html:1.1 --- /dev/null Sun Feb 6 18:44:30 2011 +++ src/tests/lib/librumphijack/index.html Sun Feb 6 18:44:30 2011 @@ -0,0 +1,5 @@ +<html><head> +<title>test page</title> +</head><body> +i am a test, how do you do? +</body></html> Index: src/tests/lib/librumphijack/netstat.expout diff -u /dev/null src/tests/lib/librumphijack/netstat.expout:1.1 --- /dev/null Sun Feb 6 18:44:30 2011 +++ src/tests/lib/librumphijack/netstat.expout Sun Feb 6 18:44:30 2011 @@ -0,0 +1,6 @@ +Active Internet connections (including servers) +Proto Recv-Q Send-Q Local Address Foreign Address State +tcp 0 0 *.http *.* LISTEN +Active Internet6 connections (including servers) +Proto Recv-Q Send-Q Local Address Foreign Address (state) +tcp6 0 0 *.http *.* LISTEN Index: src/tests/lib/librumphijack/t_tcpip.sh diff -u /dev/null src/tests/lib/librumphijack/t_tcpip.sh:1.1 --- /dev/null Sun Feb 6 18:44:30 2011 +++ src/tests/lib/librumphijack/t_tcpip.sh Sun Feb 6 18:44:30 2011 @@ -0,0 +1,70 @@ +# $NetBSD: t_tcpip.sh,v 1.1 2011/02/06 18:44:30 pooka Exp $ +# +# Copyright (c) 2011 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +rumpnetsrv='rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet' +export RUMP_SERVER=unix://csock + +atf_test_case http cleanup +http_head() +{ + atf_set "descr" "Start hijacked httpd and get webpage from it" +} + +http_body() +{ + + atf_check -s exit:0 ${rumpnetsrv} ${RUMP_SERVER} + # make sure clients die after we nuke the server + export RUMPHIJACK_RETRY='die' + + # start bozo in daemon mode + atf_check -s exit:0 -e ignore env LD_PRELOAD=/usr/lib/librumphijack.so \ + /usr/libexec/httpd -b -s $(atf_get_srcdir) + + atf_check -s exit:0 -o file:"$(atf_get_srcdir)/netstat.expout" \ + rump.netstat -a + + # get the webpage + atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \ + $(atf_get_srcdir)/h_netget 127.0.0.1 80 webfile + + # check that we got what we wanted + atf_check -o match:'HTTP/1.0 200 OK' cat webfile + atf_check -o match:'Content-Length: 95' cat webfile + atf_check -o file:"$(atf_get_srcdir)/index.html" \ + sed -n '1,/^$/!p' webfile +} + +http_cleanup() +{ + rump.halt +} + +atf_init_test_cases() +{ + atf_add_test_case http +}