Merge remote-tracking branch 'origin/topic/struck/BIT-1277'

* origin/topic/struck/BIT-1277:
  [ADD] Added the feature to return 0 content to the python http test server and added functionality for post requests
  [ADD] added baseline for the new active-http test and added a test to check for the content-length 0 fix.
  [ADD] added baseline for the new exec test and added a test to check for the empty files fix.
  [FIX] exec should write an empty string when file is empty instead of the filename
  [FIX] Add files to result table even if the files are empty

BIT-1277 #merged
This commit is contained in:
Robin Sommer 2014-10-24 11:40:51 -07:00
commit 4216a5eb1c
9 changed files with 76 additions and 14 deletions

View file

@ -1,4 +1,9 @@
2.3-254 | 2014-10-24 11:40:51 -0700
* Fix active-http.bro to deal reliably with empty server responses,
which will now be passed back as empty files. (Christian Struck)
2.3-248 | 2014-10-23 14:20:59 -0700
* Change order in which a plugin's scripts are loaded at startup.

View file

@ -1 +1 @@
2.3-248
2.3-254

View file

@ -65,12 +65,14 @@ function request2curl(r: Request, bodyfile: string, headersfile: string): string
cmd = fmt("%s -m %.0f", cmd, r$max_time);
if ( r?$client_data )
cmd = fmt("%s -d -", cmd);
cmd = fmt("%s -d @-", cmd);
if ( r?$addl_curl_args )
cmd = fmt("%s %s", cmd, r$addl_curl_args);
cmd = fmt("%s \"%s\"", cmd, str_shell_escape(r$url));
# Make sure file will exist even if curl did not write one.
cmd = fmt("%s && touch %s", cmd, str_shell_escape(bodyfile));
return cmd;
}

View file

@ -106,6 +106,15 @@ event Input::end_of_data(name: string, source:string)
local track_file = parts[2];
# If the file is empty, still add it to the result$files table. This is needed
# because it is expected that the file was read even if it was empty.
local result = results[name];
if ( ! result?$files )
result$files = table();
if ( track_file !in result$files )
result$files[track_file] = vector();
Input::remove(name);
if ( name !in pending_files )

View file

@ -1,4 +1,9 @@
[code=200, msg=OK^M, body=It works!, headers={
test1, [code=200, msg=OK^M, body=It works!, headers={
[Server] = 1.0,
[Content-type] = text/plain,
[Date] = July 22, 2013
}]
test2, [code=200, msg=OK^M, body=, headers={
[Server] = 1.0,
[Content-type] = text/plain,
[Date] = July 22, 2013

View file

@ -1,6 +1,10 @@
test2, [exit_code=1, signal_exit=F, stdout=[here's something on stdout, some more stdout, last stdout], stderr=[and some stderr, more stderr, last stderr], files=<uninitialized>]
test1, [exit_code=0, signal_exit=F, stdout=[done, exit, stop], stderr=<uninitialized>, files={
[out1] = [insert text here, and here],
[out2] = [insert more text here, and there]
}]
test2, [exit_code=1, signal_exit=F, stdout=[here's something on stdout, some more stdout, last stdout], stderr=[and some stderr, more stderr, last stderr], files=<uninitialized>]
test4, [exit_code=0, signal_exit=F, stdout=[hibye], stderr=<uninitialized>, files=<uninitialized>]
test5, [exit_code=0, signal_exit=F, stdout=<uninitialized>, stderr=<uninitialized>, files={
[out4] = [test],
[out3] = []
}]

View file

@ -1,7 +1,7 @@
# @TEST-REQUIRES: which python
# @TEST-REQUIRES: which curl
#
# @TEST-EXEC: btest-bg-run httpd python $SCRIPTS/httpd.py --max 1 --addr=127.0.0.1
# @TEST-EXEC: btest-bg-run httpd python $SCRIPTS/httpd.py --max 2 --addr=127.0.0.1
# @TEST-EXEC: sleep 3
# @TEST-EXEC: btest-bg-run bro bro -b %INPUT
# @TEST-EXEC: btest-bg-wait 15
@ -11,18 +11,32 @@
@load base/frameworks/communication # let network-time run. otherwise there are no heartbeats...
redef exit_only_after_terminate = T;
event bro_init()
{
local req = ActiveHTTP::Request($url="127.0.0.1:32123");
global c: count = 0;
when ( local resp = ActiveHTTP::request(req) )
function check_exit_condition()
{
print resp;
c += 1;
if ( c == 2 )
terminate();
}
function test_request(label: string, req: ActiveHTTP::Request)
{
when ( local response = ActiveHTTP::request(req) )
{
print label, response;
check_exit_condition();
}
timeout 1min
{
print "HTTP request timeout";
terminate();
check_exit_condition();
}
}
event bro_init()
{
test_request("test1", [$url="127.0.0.1:32123"]);
test_request("test2", [$url="127.0.0.1:32123/empty", $method="POST"]);
}

View file

@ -14,7 +14,7 @@ function check_exit_condition()
{
c += 1;
if ( c == 3 )
if ( c == 4 )
terminate();
}
@ -35,6 +35,8 @@ event bro_init()
# Not sure of a portable way to test signals yet.
#test_cmd("test3", [$cmd="bash ../suicide.sh"]);
test_cmd("test4", [$cmd="bash ../stdin.sh", $stdin="hibye"]);
test_cmd("test5", [$cmd="bash ../empty_file.sh",
$read_files=set("out3", "out4")]);
}
@TEST-END-FILE
@ -73,3 +75,9 @@ echo "nope"
read -r line
echo "$line"
@TEST-END-FILE
@TEST-START-FILE empty_file.sh
#! /usr/bin/env bash
touch out3
echo "test" > out4
@TEST-END-FILE

View file

@ -2,12 +2,27 @@
import BaseHTTPServer
class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
if "/empty" in self.path:
self.wfile.write("")
else:
self.wfile.write("It works!")
def do_POST(self):
self.send_response(200)
self.send_header("Content-type", "text/plain")
self.end_headers()
if "/empty" in self.path:
self.wfile.write("")
else:
self.wfile.write("It works!")
def version_string(self):