From f278315081b24b59bf73e9613e552e3519200a71 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 28 May 2012 04:39:18 +0000 Subject: Improve error reporting with a reason code. Improve debug and audit logging. Fix test scripts to cleanup state from previous builds and correctly report test errors. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1343138 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/http/Makefile.am | 2 +- sca-cpp/trunk/modules/http/http-test | 1 + sca-cpp/trunk/modules/http/http.hpp | 30 +++++++-------- sca-cpp/trunk/modules/http/httpd-test | 1 + sca-cpp/trunk/modules/http/httpd.hpp | 10 +++-- sca-cpp/trunk/modules/http/mod-security-audit-conf | 44 ++++++++++++++++++++++ sca-cpp/trunk/modules/http/mod-security-conf | 21 ++--------- sca-cpp/trunk/modules/http/proxy-test | 1 + 8 files changed, 73 insertions(+), 37 deletions(-) create mode 100755 sca-cpp/trunk/modules/http/mod-security-audit-conf (limited to 'sca-cpp/trunk/modules/http') diff --git a/sca-cpp/trunk/modules/http/Makefile.am b/sca-cpp/trunk/modules/http/Makefile.am index 161279a73f..4fd7cc0818 100644 --- a/sca-cpp/trunk/modules/http/Makefile.am +++ b/sca-cpp/trunk/modules/http/Makefile.am @@ -76,7 +76,7 @@ if WANT_MODSECURITY modsecurity.prefix: $(top_builddir)/config.status echo ${MODSECURITY_PREFIX} >modsecurity.prefix -dist_modsecurity_SCRIPTS = mod-security-conf +dist_modsecurity_SCRIPTS = mod-security-conf mod-security-audit-conf modsecurity_DATA = modsecurity.prefix modsecuritydir = $(prefix)/modules/http diff --git a/sca-cpp/trunk/modules/http/http-test b/sca-cpp/trunk/modules/http/http-test index 73cfe700a6..956b13a516 100755 --- a/sca-cpp/trunk/modules/http/http-test +++ b/sca-cpp/trunk/modules/http/http-test @@ -18,6 +18,7 @@ # under the License. # Setup +rm -rf tmp ./httpd-conf tmp localhost 8090 htdocs ./httpd-event-conf tmp ./httpd-start tmp diff --git a/sca-cpp/trunk/modules/http/http.hpp b/sca-cpp/trunk/modules/http/http.hpp index eb7a8d506f..e8c88f8a83 100644 --- a/sca-cpp/trunk/modules/http/http.hpp +++ b/sca-cpp/trunk/modules/http/http.hpp @@ -371,7 +371,7 @@ template const failable > apply(const list >& h // Setup the CURL session const failable fch = setup(url, cs); if (!hasContent(fch)) - return mkfailure>(reason(fch)); + return mkfailure>(fch); CURL* ch = content(fch); // Set the request headers @@ -440,19 +440,19 @@ const failable evalExpr(const value& expr, const string& url, const CURLS js::JSContext cx; const failable > jsreq = json::jsonRequest(1, car(expr), cdr(expr), cx); if (!hasContent(jsreq)) - return mkfailure(reason(jsreq)); + return mkfailure(jsreq); // POST it to the URL const list h = mklist("Content-Type: application/json-rpc"); const failable > > res = apply >(mklist >(h, content(jsreq)), rcons, list(), url, "POST", cs); if (!hasContent(res)) - return mkfailure(reason(res)); + return mkfailure(res); // Parse and return JSON-RPC result const failable rval = json::jsonResultValue(cadr >(content(res)), cx); debug(rval, "http::evalExpr::result"); if (!hasContent(rval)) - return mkfailure(reason(rval)); + return mkfailure(rval); return content(rval); } @@ -513,7 +513,7 @@ const failable getcontent(const string& url, const CURLSession& cs) { // Get the contents of the resource at the given URL const failable > > res = get>(rcons, list(), url, cs); if (!hasContent(res)) - return mkfailure(reason(res)); + return mkfailure(res); const list ls(reverse(cadr(content(res)))); // Return the content as a list of values @@ -597,7 +597,7 @@ const failable get(const string& url, const CURLSession& cs) { // Get the contents of the resource at the given URL const failable > > res = get >(rcons, list(), url, cs); if (!hasContent(res)) - return mkfailure(reason(res)); + return mkfailure(res); // Parse the returned content return responseValue(content(res)); @@ -608,7 +608,7 @@ const failable get(const string& url, const CURLSession& cs) { */ const failable > > writeRequest(const failable >& ls, const string& ct) { if (!hasContent(ls)) - return mkfailure > >(reason(ls)); + return mkfailure > >(ls); const list > req = mklist >(mklist(string("Content-Type: ") + ct), content(ls)); debug(req, "http::writeRequest::req"); return req; @@ -695,13 +695,13 @@ const failable post(const value& val, const string& url, const CURLSessio // Convert value to a content request const failable > > req = contentRequest(val, url); if (!hasContent(req)) - return mkfailure(reason(req)); + return mkfailure(req); debug(content(req), "http::post::input"); // POST it to the URL const failable > > res = apply>(content(req), rcons, list(), url, "POST", cs); if (!hasContent(res)) - return mkfailure(reason(res)); + return mkfailure(res); // Return the new entry id from the HTTP location header, if any const string loc = location(car(content(res))); @@ -724,13 +724,13 @@ const failable put(const value& val, const string& url, const CURLSession // Convert value to a content request const failable > > req = contentRequest(val, url); if (!hasContent(req)) - return mkfailure(reason(req)); + return mkfailure(req); debug(content(req), "http::put::input"); // PUT it to the URL const failable > > res = apply >(content(req), rcons, list(), url, "PUT", cs); if (!hasContent(res)) - return mkfailure(reason(res)); + return mkfailure(res); debug(true, "http::put::result"); return value(true); @@ -745,13 +745,13 @@ const failable patch(const value& val, const string& url, const CURLSessi // Convert value to a content request const failable > > req = contentRequest(val, url); if (!hasContent(req)) - return mkfailure(reason(req)); + return mkfailure(req); debug(content(req), "http::patch::input"); // PATCH it to the URL const failable > > res = apply >(content(req), rcons, list(), url, "PATCH", cs); if (!hasContent(res)) - return mkfailure(reason(res)); + return mkfailure(res); debug(true, "http::patch::result"); return value(true); @@ -766,7 +766,7 @@ const failable del(const string& url, const CURLSession& cs) { const list > req = mklist(list(), list()); const failable > > res = apply >(req, rcons, list(), url, "DELETE", cs); if (!hasContent(res)) - return mkfailure(reason(res)); + return mkfailure(res); debug(true, "http::delete::result"); return value(true); @@ -805,7 +805,7 @@ const failable connect(const string& url, CURLSession& cs) { // Setup the CURL session const failable fch = setup(url, cs); if (!hasContent(fch)) - return mkfailure(reason(fch)); + return mkfailure(fch); CURL* ch = content(fch); // Connect diff --git a/sca-cpp/trunk/modules/http/httpd-test b/sca-cpp/trunk/modules/http/httpd-test index 2b151d0e12..ab6ab5ad41 100755 --- a/sca-cpp/trunk/modules/http/httpd-test +++ b/sca-cpp/trunk/modules/http/httpd-test @@ -22,6 +22,7 @@ here=`echo "import os; print os.path.realpath('$0')" | python`; here=`dirname $h curl_prefix=`cat $here/../http/curl.prefix` # Setup +rm -rf tmp ./httpd-conf tmp localhost 8090 htdocs ./httpd-event-conf tmp ./httpd-start tmp diff --git a/sca-cpp/trunk/modules/http/httpd.hpp b/sca-cpp/trunk/modules/http/httpd.hpp index 718ed6e52b..7147e8839c 100644 --- a/sca-cpp/trunk/modules/http/httpd.hpp +++ b/sca-cpp/trunk/modules/http/httpd.hpp @@ -402,7 +402,7 @@ const list read(request_rec* r) { */ const failable writeResult(const failable >& ls, const string& ct, request_rec* r) { if (!hasContent(ls)) - return mkfailure(reason(ls)); + return mkfailure(ls); ostringstream os; write(content(ls), os); const string ob(str(os)); @@ -437,8 +437,10 @@ const failable writeResult(const failable >& ls, const string& */ const int reportStatus(const failable& rc) { debug(rc, "httpd::reportStatus::rc"); - if (!hasContent(rc)) - return HTTP_INTERNAL_SERVER_ERROR; + if (!hasContent(rc)) { + const int r = rcode(rc); + return r == -1 ? HTTP_INTERNAL_SERVER_ERROR : r; + } return content(rc); } @@ -725,7 +727,7 @@ const bool debugRequest(request_rec* r, const string& msg) { return true; } -#define debug_httpdRequest(r, msg) if (debug_islogging()) httpd::debugRequest(r, msg) +#define debug_httpdRequest(r, msg) do { if (debug_islogging()) httpd::debugRequest(r, msg); } while(0) #else diff --git a/sca-cpp/trunk/modules/http/mod-security-audit-conf b/sca-cpp/trunk/modules/http/mod-security-audit-conf new file mode 100755 index 0000000000..5914bd1df4 --- /dev/null +++ b/sca-cpp/trunk/modules/http/mod-security-audit-conf @@ -0,0 +1,44 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Generate a minimal mod-security audit configuration. +here=`echo "import os; print os.path.realpath('$0')" | python`; here=`dirname $here` +mkdir -p $1 +root=`echo "import os; print os.path.realpath('$1')" | python` + +mkdir -p $root/tmp + +cat >>$root/conf/mod-security.conf <$root/conf/mod-security-audit-log.conf <$root/conf/mod-security-log.conf <