[nagiosplug] Add testcase for HTTP chunked encoding

"Thomas Guyot-Sionnest" <[email protected]> Fri, 9 Sep 2011 05:34:36 +0000
Newsgroups gmane.network.nagios.plugins.cvs
Message-ID <[email protected]>
 Module: nagiosplug
 Branch: pu_dermoth_http
 Commit: 0845fb8c2c67accca544e19384ebde2b705e10b9
 Author: Thomas Guyot-Sionnest <[email protected]>
   Date: Thu Sep  8 03:10:08 2011 -0400
    URL: http://nagiosplug.git.sf.net/git/gitweb.cgi?p=nagiosplug/nagiosplug;a=commit;h=0845fb8

Add testcase for HTTP chunked encoding

Runs only if HTTP_CHUNKED (env) is set, fails obviously

---

 plugins/tests/check_http.t |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/plugins/tests/check_http.t b/plugins/tests/check_http.t
index 03d42fd..5092218 100755
--- a/plugins/tests/check_http.t
+++ b/plugins/tests/check_http.t
@@ -18,7 +18,7 @@ use Test::More;
 use NPTest;
 use FindBin qw($Bin);
 
-my $common_tests = 66;
+my $common_tests = 68;
 my $ssl_only_tests = 6;
 # Check that all dependent modules are available
 eval {
@@ -55,6 +55,18 @@ my $port_https_expired = $port_http + 2;
 # This array keeps sockets around for implementing timeouts
 my @persist;
 
+# Helper for returning chunked responses
+our $ckn = 0;
+sub chunked_resp {
+	$ckn++;
+	return "foo" if ($ckn < 2);
+	return "bar" if ($ckn < 3);
+	return "baz" if ($ckn < 4);
+	return "\n"  if ($ckn < 5);
+	$ckn = 0     if ($ckn < 6);
+	return undef;
+}
+
 # Start up all servers
 my @pids;
 my $pid = fork();
@@ -128,6 +140,8 @@ sub run_server {
 				$c->send_crlf;
 				sleep 1;
 				$c->send_response("slow");
+			} elsif ($r->method eq "GET" and $r->url->path eq "/chunked") {
+				$c->send_response(HTTP::Response->new(200, 'OK', undef, \&chunked_resp));
 			} elsif ($r->url->path eq "/method") {
 				if ($r->method eq "DELETE") {
 					$c->send_error(HTTP::Status->RC_METHOD_NOT_ALLOWED);
@@ -353,6 +367,14 @@ sub run_common_tests {
 	is( $result->return_code, 0, $cmd);
 	like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
 
+	SKIP: {
+		skip "FIXME: Chunked-encoding isn't supported yet", 2 unless ($ENV{HTTP_CHUNKED});
+		$cmd = "$command -u /chunked -s foobarbaz";
+		$result = NPTest->testCmd( $cmd );
+		is( $result->return_code, 0, $cmd);
+		like( $result->output, '/^HTTP OK: HTTP/1.1 200 OK - \d+ bytes in [\d\.]+ second/', "Output correct: ".$result->output );
+	}
+
   # These tests may block
 	print "ALRM\n";
 


------------------------------------------------------------------------------
Why Cloud-Based Security and Archiving Make Sense
Osterman Research conducted this study that outlines how and why cloud
computing security and archiving is rapidly being adopted across the IT 
space for its ease of implementation, lower cost, and increased 
reliability. Learn more. http://www.accelacomm.com/jaw/sfnl/114/51425301/