From ab3a9fb31b60dc7be9ca2aa42b88152c7d2b413f Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 16 Feb 2012 12:48:06 -0700 Subject: [PATCH] make set.cgi more portable --- tests/default/cgi/set.cgi | 16 +++++++++++++++- tests/test.py | 8 ++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/default/cgi/set.cgi b/tests/default/cgi/set.cgi index 1ee8b96..c8fe9da 100755 --- a/tests/default/cgi/set.cgi +++ b/tests/default/cgi/set.cgi @@ -2,7 +2,21 @@ echo Content-Type: text/plain echo -set | sort | grep 'GATEWAY\|SERVER\|REQUEST\|SCRIPT\|REMOTE\|HTTP\|AUTH\|CONTENT\|QUERY\|PATH_' +for k in GATEWAY_INTERFACE \ + SERVER_PROTOCOL SERVER_SOFTWARE SERVER_NAME SERVER_PORT \ + REQUEST_METHOD REQUEST_URI \ + SCRIPT_NAME \ + REMOTE_ADDR REMOTE_PORT REMOTE_IDENT \ + HTTP_USER_AGENT HTTP_COOKIE HTTP_REFERER HTTP_ACCEPT_ENCODING \ + AUTH_TYPE \ + CONTENT_TYPE CONTENT_LENGTH \ + QUERY_STRING \ + PATH_INFO PATH_TRANSLATED; do + v=$(eval echo \${$k}) + if [ -n "$v" ]; then + echo "$k:$v" + fi +done if [ -n "$CONTENT_TYPE" ]; then echo -n "Form data: " dd bs=1 count=$CONTENT_LENGTH 2>/dev/null diff --git a/tests/test.py b/tests/test.py index 5018296..5cd196d 100755 --- a/tests/test.py +++ b/tests/test.py @@ -76,17 +76,17 @@ class CGITests(BasicTests): def testSet(self): so, se = self.get('/cgi/set.cgi', 'default') - self.assertEqual(so, b'HTTP/1.0 200 OK\r\nServer: fnord/2.0\r\nPragma: no-cache\r\nConnection: close\r\nContent-Type: text/plain\r\n\nGATEWAY_INTERFACE=CGI/1.1\nREMOTE_ADDR=10.1.2.3\nREMOTE_PORT=5858\nREQUEST_METHOD=GET\nREQUEST_URI=/cgi/set.cgi\nSCRIPT_NAME=/cgi/set.cgi\nSERVER_NAME=default:80\nSERVER_PORT=80\nSERVER_PROTOCOL=HTTP/1.0\nSERVER_SOFTWARE=fnord/2.0\n') + self.assertEqual(so, b'HTTP/1.0 200 OK\r\nServer: fnord/2.0\r\nPragma: no-cache\r\nConnection: close\r\nContent-Type: text/plain\r\n\nGATEWAY_INTERFACE:CGI/1.1\nSERVER_PROTOCOL:HTTP/1.0\nSERVER_SOFTWARE:fnord/2.0\nSERVER_NAME:default:80\nSERVER_PORT:80\nREQUEST_METHOD:GET\nREQUEST_URI:/cgi/set.cgi\nSCRIPT_NAME:/cgi/set.cgi\nREMOTE_ADDR:10.1.2.3\nREMOTE_PORT:5858\n') self.assertEqual(se, b'10.1.2.3 200 248 default:80 (null) (null) /cgi/set.cgi\n') def testSetArgs(self): so, se = self.get('/cgi/set.cgi?a=1&b=2&c=3', 'default') - self.assertEqual(so, b"HTTP/1.0 200 OK\r\nServer: fnord/2.0\r\nPragma: no-cache\r\nConnection: close\r\nContent-Type: text/plain\r\n\nGATEWAY_INTERFACE=CGI/1.1\nQUERY_STRING='a=1&b=2&c=3'\nREMOTE_ADDR=10.1.2.3\nREMOTE_PORT=5858\nREQUEST_METHOD=GET\nREQUEST_URI=/cgi/set.cgi\nSCRIPT_NAME=/cgi/set.cgi\nSERVER_NAME=default:80\nSERVER_PORT=80\nSERVER_PROTOCOL=HTTP/1.0\nSERVER_SOFTWARE=fnord/2.0\n") - self.assertEqual(se, b'10.1.2.3 200 275 default:80 (null) (null) /cgi/set.cgi\n') + self.assertEqual(so, b'HTTP/1.0 200 OK\r\nServer: fnord/2.0\r\nPragma: no-cache\r\nConnection: close\r\nContent-Type: text/plain\r\n\nGATEWAY_INTERFACE:CGI/1.1\nSERVER_PROTOCOL:HTTP/1.0\nSERVER_SOFTWARE:fnord/2.0\nSERVER_NAME:default:80\nSERVER_PORT:80\nREQUEST_METHOD:GET\nREQUEST_URI:/cgi/set.cgi\nSCRIPT_NAME:/cgi/set.cgi\nREMOTE_ADDR:10.1.2.3\nREMOTE_PORT:5858\nQUERY_STRING:a=1&b=2&c=3\n') + self.assertEqual(se, b'10.1.2.3 200 273 default:80 (null) (null) /cgi/set.cgi\n') def testPost(self): so, se = self.post('/cgi/set.cgi', 'default', 'a=1&b=2&c=3') - self.assertEqual(so, b'HTTP/1.0 200 OK\r\nServer: fnord/2.0\r\nPragma: no-cache\r\nConnection: close\r\nContent-Type: text/plain\r\n\nCONTENT_LENGTH=11\nCONTENT_TYPE=application/x-www-form-urlencoded\nGATEWAY_INTERFACE=CGI/1.1\nREMOTE_ADDR=10.1.2.3\nREMOTE_PORT=5858\nREQUEST_METHOD=POST\nREQUEST_URI=/cgi/set.cgi\nSCRIPT_NAME=/cgi/set.cgi\nSERVER_NAME=default:80\nSERVER_PORT=80\nSERVER_PROTOCOL=HTTP/1.0\nSERVER_SOFTWARE=fnord/2.0\nForm data: a=1&b=2&c=3') + self.assertEqual(so, b'HTTP/1.0 200 OK\r\nServer: fnord/2.0\r\nPragma: no-cache\r\nConnection: close\r\nContent-Type: text/plain\r\n\nGATEWAY_INTERFACE:CGI/1.1\nSERVER_PROTOCOL:HTTP/1.0\nSERVER_SOFTWARE:fnord/2.0\nSERVER_NAME:default:80\nSERVER_PORT:80\nREQUEST_METHOD:POST\nREQUEST_URI:/cgi/set.cgi\nSCRIPT_NAME:/cgi/set.cgi\nREMOTE_ADDR:10.1.2.3\nREMOTE_PORT:5858\nCONTENT_TYPE:application/x-www-form-urlencoded\nCONTENT_LENGTH:11\nForm data: a=1&b=2&c=3') unittest.main()