diff options
Diffstat (limited to 'test')
43 files changed, 723 insertions, 17 deletions
diff --git a/test/node/404/404.html b/test/node/404/404.html new file mode 100644 index 00000000..6d0c635a --- /dev/null +++ b/test/node/404/404.html @@ -0,0 +1,6 @@ +<html> +<head><title>404 Not Found</title></head> +<body bgcolor="white"> +<center><h1>404 Not Found</h1></center> +</body> +</html> diff --git a/test/node/404/app.js b/test/node/404/app.js new file mode 100755 index 00000000..9600d486 --- /dev/null +++ b/test/node/404/app.js @@ -0,0 +1,8 @@ +#!/usr/bin/env node + +var fs = require('fs'); + +require('unit-http').createServer(function (req, res) { + res.writeHead(404, {}); + res.end(fs.readFileSync('404.html')); +}).listen(7080); diff --git a/test/node/basic/app.js b/test/node/basic/app.js new file mode 100755 index 00000000..bc8d570a --- /dev/null +++ b/test/node/basic/app.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.writeHead(200, {'Content-Length': 12, 'Content-Type': 'text/plain'}); + res.end('Hello World\n'); +}).listen(7080); diff --git a/test/node/double_end/app.js b/test/node/double_end/app.js new file mode 100755 index 00000000..d8280917 --- /dev/null +++ b/test/node/double_end/app.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.end(); + res.end(); +}).listen(7080); diff --git a/test/node/get_header_names/app.js b/test/node/get_header_names/app.js new file mode 100755 index 00000000..4cbccc16 --- /dev/null +++ b/test/node/get_header_names/app.js @@ -0,0 +1,8 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.setHeader('DATE', ['date1', 'date2']); + res.setHeader('X-Header', 'blah'); + res.setHeader('X-Names', res.getHeaderNames()); + res.end(); +}).listen(7080); diff --git a/test/node/get_header_type/app.js b/test/node/get_header_type/app.js new file mode 100755 index 00000000..b606f142 --- /dev/null +++ b/test/node/get_header_type/app.js @@ -0,0 +1,7 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.setHeader('X-Number', 100); + res.setHeader('X-Type', typeof(res.getHeader('X-Number'))); + res.end(); +}).listen(7080); diff --git a/test/node/get_variables/app.js b/test/node/get_variables/app.js new file mode 100755 index 00000000..5c1faf41 --- /dev/null +++ b/test/node/get_variables/app.js @@ -0,0 +1,9 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + let query = require('url').parse(req.url, true).query; + res.setHeader('X-Var-1', query.var1); + res.setHeader('X-Var-2', query.var2); + res.setHeader('X-Var-3', query.var3); + res.end(); +}).listen(7080); diff --git a/test/node/has_header/app.js b/test/node/has_header/app.js new file mode 100755 index 00000000..040f551e --- /dev/null +++ b/test/node/has_header/app.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.setHeader('X-Has-Header', res.hasHeader(req['headers']['X-Header']) + ''); + res.end(); +}).listen(7080); diff --git a/test/node/header_name_case/app.js b/test/node/header_name_case/app.js new file mode 100755 index 00000000..490bd4d5 --- /dev/null +++ b/test/node/header_name_case/app.js @@ -0,0 +1,8 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.setHeader('X-Header', '1'); + res.setHeader('X-header', '2'); + res.setHeader('X-HEADER', '3'); + res.end(); +}).listen(7080); diff --git a/test/node/header_name_valid/app.js b/test/node/header_name_valid/app.js new file mode 100755 index 00000000..425f026f --- /dev/null +++ b/test/node/header_name_valid/app.js @@ -0,0 +1,7 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.writeHead(200, {}); + res.setHeader('@$', 'test'); + res.end(); +}).listen(7080); diff --git a/test/node/header_value_object/app.js b/test/node/header_value_object/app.js new file mode 100755 index 00000000..ff4e2bb0 --- /dev/null +++ b/test/node/header_value_object/app.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.setHeader('X-Header', {}); + res.end(); +}).listen(7080); diff --git a/test/node/mirror/app.js b/test/node/mirror/app.js new file mode 100755 index 00000000..abcb87cb --- /dev/null +++ b/test/node/mirror/app.js @@ -0,0 +1,12 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + let body = ''; + req.on('data', chunk => { + body += chunk.toString(); + }); + req.on('end', () => { + res.writeHead(200, {'Content-Length': Buffer.byteLength(body)}); + res.end(body); + }); +}).listen(7080); diff --git a/test/node/post_variables/app.js b/test/node/post_variables/app.js new file mode 100755 index 00000000..928a38cf --- /dev/null +++ b/test/node/post_variables/app.js @@ -0,0 +1,15 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + let body = ''; + req.on('data', chunk => { + body += chunk.toString(); + }); + req.on('end', () => { + let query = require('querystring').parse(body); + res.setHeader('X-Var-1', query.var1); + res.setHeader('X-Var-2', query.var2); + res.setHeader('X-Var-3', query.var3); + res.end(); + }); +}).listen(7080); diff --git a/test/node/promise_end/app.js b/test/node/promise_end/app.js new file mode 100755 index 00000000..ed22464c --- /dev/null +++ b/test/node/promise_end/app.js @@ -0,0 +1,16 @@ +#!/usr/bin/env node + +var fs = require('fs'); + +require('unit-http').createServer(function (req, res) { + res.write('blah'); + + Promise.resolve().then(() => { + res.end(); + }); + + req.on('data', (data) => { + fs.appendFile('callback', '', function() {}); + }); + +}).listen(7080); diff --git a/test/node/promise_handler/app.js b/test/node/promise_handler/app.js new file mode 100755 index 00000000..54df09d1 --- /dev/null +++ b/test/node/promise_handler/app.js @@ -0,0 +1,18 @@ +#!/usr/bin/env node + +var fs = require('fs'); + +require('unit-http').createServer(function (req, res) { + res.end(); + + if (req.headers['X-Write-Call']) { + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.write('blah'); + } + + Promise.resolve().then(() => { + req.on('data', (data) => { + fs.appendFile(data.toString(), '', function() {}); + }); + }); +}).listen(7080); diff --git a/test/node/remove_header/app.js b/test/node/remove_header/app.js new file mode 100755 index 00000000..578b72a7 --- /dev/null +++ b/test/node/remove_header/app.js @@ -0,0 +1,11 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.setHeader('X-Header', 'test'); + res.setHeader('Was-Header', res.hasHeader('X-Header').toString()); + + res.removeHeader(req['headers']['X-Remove']); + res.setHeader('Has-Header', res.hasHeader('X-Header').toString()); + + res.end(); +}).listen(7080); diff --git a/test/node/set_header_array/app.js b/test/node/set_header_array/app.js new file mode 100755 index 00000000..faac45c7 --- /dev/null +++ b/test/node/set_header_array/app.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.setHeader('Set-Cookie', ['tc=one,two,three', 'tc=four,five,six']); + res.end(); +}).listen(7080); diff --git a/test/node/status_message/app.js b/test/node/status_message/app.js new file mode 100755 index 00000000..4f3b064a --- /dev/null +++ b/test/node/status_message/app.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.writeHead(200, 'blah', {'Content-Type': 'text/plain'}); + res.end(); +}).listen(7080); diff --git a/test/node/update_header/app.js b/test/node/update_header/app.js new file mode 100755 index 00000000..0c5cd237 --- /dev/null +++ b/test/node/update_header/app.js @@ -0,0 +1,7 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.setHeader('X-Header', 'test'); + res.setHeader('X-Header', 'new'); + res.end(); +}).listen(7080); diff --git a/test/node/variables/app.js b/test/node/variables/app.js new file mode 100755 index 00000000..968afba5 --- /dev/null +++ b/test/node/variables/app.js @@ -0,0 +1,20 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + let body = ''; + req.on('data', chunk => { + body += chunk.toString(); + }); + req.on('end', () => { + res.setHeader('Request-Method', req.method); + res.setHeader('Request-Uri', req.url); + res.setHeader('Server-Protocol', req.httpVersion); + res.setHeader('Request-Raw-Headers', req.rawHeaders.join()); + res.setHeader('Content-Length', Buffer.byteLength(body)); + res.setHeader('Content-Type', req.headers['Content-Type']); + res.setHeader('Custom-Header', req.headers['Custom-Header']); + res.setHeader('Http-Host', req.headers['Host']); + res.writeHead(200, {}); + res.end(body); + }); +}).listen(7080); diff --git a/test/node/write_before_write_head/app.js b/test/node/write_before_write_head/app.js new file mode 100755 index 00000000..9fe3a58d --- /dev/null +++ b/test/node/write_before_write_head/app.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.write('blah'); + res.writeHead(200, {'Content-Type': 'text/plain'}); +}).listen(7080); diff --git a/test/node/write_buffer/app.js b/test/node/write_buffer/app.js new file mode 100755 index 00000000..f41de2a1 --- /dev/null +++ b/test/node/write_buffer/app.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.end(new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72])); +}).listen(7080); diff --git a/test/node/write_callback/app.js b/test/node/write_callback/app.js new file mode 100755 index 00000000..3a9e51e8 --- /dev/null +++ b/test/node/write_callback/app.js @@ -0,0 +1,13 @@ +#!/usr/bin/env node + +var fs = require('fs'); + +require('unit-http').createServer(function (req, res) { + res.writeHead(200, {'Content-Type': 'text/plain'}); + var a = 'world'; + res.write('hello', 'utf8', function() { + a = 'blah'; + fs.appendFile('callback', '', function() {}); + }); + res.end(a); +}).listen(7080); diff --git a/test/node/write_multiple/app.js b/test/node/write_multiple/app.js new file mode 100755 index 00000000..3cbb3b86 --- /dev/null +++ b/test/node/write_multiple/app.js @@ -0,0 +1,8 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.writeHead(200, {'Content-Type': 'text/plain', 'Content-Length': 14}); + res.write('write'); + res.write('write2'); + res.end('end'); +}).listen(7080); diff --git a/test/node/write_return/app.js b/test/node/write_return/app.js new file mode 100755 index 00000000..3ae967c6 --- /dev/null +++ b/test/node/write_return/app.js @@ -0,0 +1,6 @@ +#!/usr/bin/env node + +require('unit-http').createServer(function (req, res) { + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.end(res.write('body').toString()); +}).listen(7080); diff --git a/test/php/date_time/index.php b/test/php/date_time/index.php new file mode 100644 index 00000000..4e06fdf9 --- /dev/null +++ b/test/php/date_time/index.php @@ -0,0 +1,4 @@ +<?php +$d = new DateTime('2011-01-01T15:03:01.012345Z'); +echo $d->format('u'); +?> diff --git a/test/php/highlight_file_exec/index.php b/test/php/highlight_file_exec/index.php new file mode 100644 index 00000000..adcd5ed8 --- /dev/null +++ b/test/php/highlight_file_exec/index.php @@ -0,0 +1,4 @@ +<?php +highlight_file('index.php'); +exec('pwd'); +?> diff --git a/test/test_access_log.py b/test/test_access_log.py index 05f5f54a..c8464796 100644 --- a/test/test_access_log.py +++ b/test/test_access_log.py @@ -305,4 +305,4 @@ Connection: close 'reopen 2') if __name__ == '__main__': - unittest.main() + TestUnitAccessLog.main() diff --git a/test/test_configuration.py b/test/test_configuration.py index 6db65bb3..02705afe 100644 --- a/test/test_configuration.py +++ b/test/test_configuration.py @@ -218,4 +218,4 @@ class TestUnitConfiguration(unit.TestUnitControl): }), 'no port') if __name__ == '__main__': - unittest.main() + TestUnitConfiguration.main() diff --git a/test/test_go_application.py b/test/test_go_application.py index 650d1c27..fd80bf5b 100644 --- a/test/test_go_application.py +++ b/test/test_go_application.py @@ -151,4 +151,4 @@ class TestUnitGoApplication(unit.TestUnitApplicationGo): 'arguments empty') if __name__ == '__main__': - unittest.main() + TestUnitGoApplication.main() diff --git a/test/test_http_header.py b/test/test_http_header.py index 1ca0920d..b850831d 100644 --- a/test/test_http_header.py +++ b/test/test_http_header.py @@ -163,4 +163,4 @@ a self.assertEqual(resp['status'], 200, 'transfer encoding chunked') if __name__ == '__main__': - unittest.main() + TestUnitHTTPHeader.main() diff --git a/test/test_node_application.py b/test/test_node_application.py new file mode 100644 index 00000000..5dedb5a3 --- /dev/null +++ b/test/test_node_application.py @@ -0,0 +1,284 @@ +import unittest +import unit + +class TestUnitNodeApplication(unit.TestUnitApplicationNode): + + def setUpClass(): + u = unit.TestUnit().check_modules('node') + + def test_node_application_basic(self): + self.load('basic') + + resp = self.get() + self.assertEqual(resp['headers']['Content-Type'], 'text/plain', + 'basic header') + self.assertEqual(resp['body'], 'Hello World\n', 'basic body') + + def test_node_application_seq(self): + self.load('basic') + + self.assertEqual(self.get()['status'], 200, 'seq') + self.assertEqual(self.get()['status'], 200, 'seq 2') + + def test_node_application_variables(self): + self.load('variables') + + body = 'Test body string.' + + resp = self.post(headers={ + 'Host': 'localhost', + 'Content-Type': 'text/html', + 'Custom-Header': 'blah' + }, body=body) + + self.assertEqual(resp['status'], 200, 'status') + headers = resp['headers'] + header_server = headers.pop('Server') + self.assertRegex(header_server, r'Unit/[\d\.]+', 'server header') + + date = headers.pop('Date') + self.assertEqual(date[-4:], ' GMT', 'date header timezone') + self.assertLess(abs(self.date_to_sec_epoch(date) - self.sec_epoch()), 5, + 'date header') + + raw_headers = headers.pop('Request-Raw-Headers') + self.assertRegex(raw_headers, r'^(?:Host|localhost|Content-Type|' \ + 'text\/html|Custom-Header|blah|Content-Length|17|,)+$', + 'raw headers') + + self.assertDictEqual(headers, { + 'Content-Length': str(len(body)), + 'Content-Type': 'text/html', + 'Request-Method': 'POST', + 'Request-Uri': '/', + 'Http-Host': 'localhost', + 'Server-Protocol': 'HTTP/1.1', + 'Custom-Header': 'blah' + }, 'headers') + self.assertEqual(resp['body'], body, 'body') + + def test_node_application_get_variables(self): + self.load('get_variables') + + resp = self.get(url='/?var1=val1&var2=&var3') + self.assertEqual(resp['headers']['X-Var-1'], 'val1', 'GET variables') + self.assertEqual(resp['headers']['X-Var-2'], '', 'GET variables 2') + self.assertEqual(resp['headers']['X-Var-3'], '', 'GET variables 3') + + def test_node_application_post_variables(self): + self.load('post_variables') + + resp = self.post(headers={ + 'Content-Type': 'application/x-www-form-urlencoded', + 'Host': 'localhost', + 'Connection': 'close' + }, body='var1=val1&var2=&var3') + + self.assertEqual(resp['headers']['X-Var-1'], 'val1', 'POST variables') + self.assertEqual(resp['headers']['X-Var-2'], '', 'POST variables 2') + self.assertEqual(resp['headers']['X-Var-3'], '', 'POST variables 3') + + def test_node_application_404(self): + self.load('404') + + resp = self.get() + + self.assertEqual(resp['status'], 404, '404 status') + self.assertRegex(resp['body'], r'<title>404 Not Found</title>', + '404 body') + + def test_node_keepalive_body(self): + self.load('mirror') + + (resp, sock) = self.post(headers={ + 'Connection': 'keep-alive', + 'Content-Type': 'text/html', + 'Host': 'localhost' + }, start=True, body='0123456789' * 500) + + self.assertEqual(resp['body'], '0123456789' * 500, 'keep-alive 1') + + resp = self.post(headers={ + 'Connection': 'close', + 'Content-Type': 'text/html', + 'Host': 'localhost' + }, sock=sock, body='0123456789') + + self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') + + def test_node_application_write_buffer(self): + self.load('write_buffer') + + self.assertEqual(self.get()['body'], '6\r\nbuffer\r\n0\r\n\r\n', + 'write buffer') + + @unittest.expectedFailure + def test_node_application_write_callback(self): + self.load('write_callback') + + self.assertEqual(self.get()['body'], + '5\r\nhello\r\n5\r\nworld\r\n0\r\n\r\n', 'write callback order') + self.assertTrue(self.waitforfiles(self.testdir + '/node/callback'), + 'write callback') + + def test_node_application_write_before_writeHead(self): + self.skip_alerts.append(r'process \d+ exited on signal') + self.load('write_before_write_head') + + self.get() + + def test_node_application_double_end(self): + self.load('double_end') + + self.assertEqual(self.get()['status'], 200, 'double end') + self.assertEqual(self.get()['status'], 200, 'double end 2') + + def test_node_application_write_return(self): + self.load('write_return') + + self.assertEqual(self.get()['body'], + '4\r\nbody\r\n4\r\ntrue\r\n0\r\n\r\n', 'write return') + + def test_node_application_remove_header(self): + self.load('remove_header') + + resp = self.get(headers={ + 'Host': 'localhost', + 'X-Remove': 'X-Header' + }) + self.assertEqual(resp['headers']['Was-Header'], 'true', 'was header') + self.assertEqual(resp['headers']['Has-Header'], 'false', 'has header') + self.assertFalse('X-Header' in resp['headers'], 'remove header') + + def test_node_application_remove_header_nonexisting(self): + self.load('remove_header') + + self.assertEqual(self.get(headers={ + 'Host': 'localhost', + 'X-Remove': 'blah' + })['headers']['Has-Header'], 'true', 'remove header nonexisting') + + def test_node_application_update_header(self): + self.load('update_header') + + self.assertEqual(self.get()['headers']['X-Header'], 'new', + 'update header') + + def test_node_application_set_header_array(self): + self.load('set_header_array') + + self.assertListEqual(self.get()['headers']['Set-Cookie'], + ['tc=one,two,three', 'tc=four,five,six'], 'set header array') + + @unittest.expectedFailure + def test_node_application_status_message(self): + self.load('status_message') + + self.assertRegex(self.get(raw_resp=True), r'200 blah', 'status message') + + def test_node_application_get_header_type(self): + self.load('get_header_type') + + self.assertEqual(self.get()['headers']['X-Type'], 'number', + 'get header type') + + @unittest.expectedFailure + def test_node_application_header_name_case(self): + self.load('header_name_case') + + headers = self.get()['headers'] + + self.assertEqual(headers['X-HEADER'], '3', 'header value') + self.assertNotIn('X-Header', headers, 'insensitive') + self.assertNotIn('X-header', headers, 'insensitive 2') + + def test_node_application_promise_handler(self): + self.load('promise_handler') + + self.assertEqual(self.post(headers={ + 'Host': 'localhost', + 'Content-Type': 'text/html' + }, body='callback')['status'], 200, 'promise handler request') + self.assertTrue(self.waitforfiles(self.testdir + '/node/callback'), + 'promise handler') + + @unittest.expectedFailure + def test_node_application_promise_handler_write_after_end(self): + self.skip_alerts.append(r'process \d+ exited on signal') + self.load('promise_handler') + + self.assertEqual(self.post(headers={ + 'Host': 'localhost', + 'Content-Type': 'text/html', + 'X-Write-Call': '1' + }, body='callback')['status'], 200, + 'promise handler request write after end') + + def test_node_application_promise_end(self): + self.load('promise_end') + + self.assertEqual(self.post(headers={ + 'Host': 'localhost', + 'Content-Type': 'text/html' + }, body='end')['status'], 200, 'promise end request') + self.assertTrue(self.waitforfiles(self.testdir + '/node/callback'), + 'promise end') + + def test_node_application_promise_multiple_calls(self): + self.load('promise_handler') + + self.post(headers={ + 'Host': 'localhost', + 'Content-Type': 'text/html' + }, body='callback1') + + self.assertTrue(self.waitforfiles(self.testdir + '/node/callback1'), + 'promise first call') + + self.post(headers={ + 'Host': 'localhost', + 'Content-Type': 'text/html' + }, body='callback2') + + self.assertTrue(self.waitforfiles(self.testdir + '/node/callback2'), + 'promise second call') + + @unittest.expectedFailure + def test_node_application_header_name_valid(self): + self.load('header_name_valid') + + self.assertNotIn('status', self.get(), 'header name valid') + + @unittest.expectedFailure + def test_node_application_header_value_object(self): + self.load('header_value_object') + + self.assertIn('X-Header', self.get()['headers'], 'header value object') + + @unittest.expectedFailure + def test_node_application_get_header_names(self): + self.load('get_header_names') + + self.assertListEqual(self.get()['headers']['X-Names'], + ['date', 'x-header'], 'get header names') + + def test_node_application_has_header(self): + self.load('has_header') + + self.assertEqual(self.get(headers={ + 'Host': 'localhost', + 'X-Header': 'length' + })['headers']['X-Has-Header'], 'false', 'has header length') + + self.assertEqual(self.get(headers={ + 'Host': 'localhost', + 'X-Header': 'Date' + })['headers']['X-Has-Header'], 'false', 'has header date') + + def test_node_application_write_multiple(self): + self.load('write_multiple') + + self.assertEqual(self.get()['body'], 'writewrite2end', 'write multiple') + +if __name__ == '__main__': + TestUnitNodeApplication.main() diff --git a/test/test_perl_application.py b/test/test_perl_application.py index 09e3d576..c9cb3f0c 100644 --- a/test/test_perl_application.py +++ b/test/test_perl_application.py @@ -167,4 +167,4 @@ class TestUnitPerlApplication(unit.TestUnitApplicationPerl): self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') if __name__ == '__main__': - unittest.main() + TestUnitPerlApplication.main() diff --git a/test/test_php_application.py b/test/test_php_application.py index 0dbc743d..e0058d9a 100644 --- a/test/test_php_application.py +++ b/test/test_php_application.py @@ -1,11 +1,16 @@ import unittest import unit +import re class TestUnitPHPApplication(unit.TestUnitApplicationPHP): def setUpClass(): unit.TestUnit().check_modules('php') + def search_disabled(self, name): + p = re.compile(name + '\(\) has been disabled') + return self.search_in_log(p) + def test_php_application_variables(self): self.load('variables') @@ -204,5 +209,110 @@ class TestUnitPHPApplication(unit.TestUnitApplicationPHP): self.assertEqual(self.get()['headers']['X-Precision'], '5', 'ini value repeat') + def test_php_application_disable_functions_exec(self): + self.load('highlight_file_exec') + + self.conf({"admin": { "disable_functions": "exec" }}, + 'applications/highlight_file_exec/options') + + self.get() + + self.assertIsNotNone(self.search_disabled('exec'), + 'disable_functions exec') + self.assertIsNone(self.search_disabled('highlight_file'), + 'disable_functions highlight_file') + + def test_php_application_disable_functions_highlight_file(self): + self.load('highlight_file_exec') + + self.conf({"admin": { "disable_functions": "highlight_file" }}, + 'applications/highlight_file_exec/options') + + self.get() + + self.assertIsNone(self.search_disabled('exec'), + 'disable_functions exec') + self.assertIsNotNone(self.search_disabled('highlight_file'), + 'disable_functions highlight_file') + + def test_php_application_disable_functions_comma(self): + self.load('highlight_file_exec') + + self.conf({"admin": { "disable_functions": "exec,highlight_file" }}, + 'applications/highlight_file_exec/options') + + self.get() + + self.assertIsNotNone(self.search_disabled('exec'), + 'disable_functions exec') + self.assertIsNotNone(self.search_disabled('highlight_file'), + 'disable_functions highlight_file') + + def test_php_application_disable_functions_space(self): + self.load('highlight_file_exec') + + self.conf({"admin": { "disable_functions": "exec highlight_file" }}, + 'applications/highlight_file_exec/options') + + self.get() + + self.assertIsNotNone(self.search_disabled('exec'), + 'disable_functions exec') + self.assertIsNotNone(self.search_disabled('highlight_file'), + 'disable_functions highlight_file') + + def test_php_application_disable_functions_user(self): + self.load('highlight_file_exec') + + self.conf({"user": { "disable_functions": "exec" }}, + 'applications/highlight_file_exec/options') + + self.get() + + self.assertIsNotNone(self.search_disabled('exec'), + 'disable_functions exec') + self.assertIsNone(self.search_disabled('highlight_file'), + 'disable_functions highlight_file') + + def test_php_application_disable_functions_nonexistent(self): + self.load('highlight_file_exec') + + self.conf({"admin": { "disable_functions": "blah" }}, + 'applications/highlight_file_exec/options') + + self.get() + + self.assertIsNone(self.search_disabled('exec'), + 'disable_functions exec') + self.assertIsNone(self.search_disabled('highlight_file'), + 'disable_functions highlight_file') + + def test_php_application_disable_classes(self): + self.load('date_time') + + self.get() + + self.assertIsNone(self.search_disabled('DateTime'), + 'disable_classes before') + + self.conf({"admin": { "disable_classes": "DateTime" }}, + 'applications/date_time/options') + + self.get() + + self.assertIsNotNone(self.search_disabled('DateTime'), + 'disable_classes') + + def test_php_application_disable_classes_user(self): + self.load('date_time') + + self.conf({"user": { "disable_classes": "DateTime" }}, + 'applications/date_time/options') + + self.get() + + self.assertIsNotNone(self.search_disabled('DateTime'), + 'disable_classes user') + if __name__ == '__main__': - unittest.main() + TestUnitPHPApplication.main() diff --git a/test/test_php_basic.py b/test/test_php_basic.py index 9e0ce822..1ea46c91 100644 --- a/test/test_php_basic.py +++ b/test/test_php_basic.py @@ -139,4 +139,4 @@ class TestUnitPHPBasic(unit.TestUnitControl): 'delete app again') if __name__ == '__main__': - unittest.main() + TestUnitPHPBasic.main() diff --git a/test/test_python_application.py b/test/test_python_application.py index e71b6432..667047bc 100644 --- a/test/test_python_application.py +++ b/test/test_python_application.py @@ -349,4 +349,4 @@ Connection: close self.assertEqual(self.get()['body'], '0123456789', 'write') if __name__ == '__main__': - unittest.main() + TestUnitPythonApplication.main() diff --git a/test/test_python_basic.py b/test/test_python_basic.py index 4cb194f6..b5179dea 100644 --- a/test/test_python_basic.py +++ b/test/test_python_basic.py @@ -149,4 +149,4 @@ class TestUnitPythonBasic(unit.TestUnitControl): 'delete app again') if __name__ == '__main__': - unittest.main() + TestUnitPythonBasic.main() diff --git a/test/test_python_environment.py b/test/test_python_environment.py index 907ad57c..71e4d5b7 100644 --- a/test/test_python_environment.py +++ b/test/test_python_environment.py @@ -125,4 +125,4 @@ class TestUnitPythonEnvironment(unit.TestUnitApplicationPython): })['body'], pwd_default, 'restore default') if __name__ == '__main__': - unittest.main() + TestUnitPythonEnvironment.main() diff --git a/test/test_python_procman.py b/test/test_python_procman.py index 297484eb..65268d49 100644 --- a/test/test_python_procman.py +++ b/test/test_python_procman.py @@ -245,4 +245,4 @@ class TestUnitPythonProcman(unit.TestUnitApplicationPython): self.assertEqual(len(self.pids_for_process()), 0, 'stop all') if __name__ == '__main__': - unittest.main() + TestUnitPythonProcman.main() diff --git a/test/test_ruby_application.py b/test/test_ruby_application.py index 77040127..57ab88cd 100644 --- a/test/test_ruby_application.py +++ b/test/test_ruby_application.py @@ -284,4 +284,4 @@ class TestUnitRubyApplication(unit.TestUnitApplicationRuby): self.assertEqual(resp['body'], '0123456789', 'keep-alive 2') if __name__ == '__main__': - unittest.main() + TestUnitRubyApplication.main() diff --git a/test/test_settings.py b/test/test_settings.py index 816dcb5e..b4ac33dc 100644 --- a/test/test_settings.py +++ b/test/test_settings.py @@ -170,4 +170,4 @@ Content-Length: %d 'settings'), 'settings negative value') if __name__ == '__main__': - unittest.main() + TestUnitSettings.main() diff --git a/test/test_tls.py b/test/test_tls.py index aaf939ec..fa5c9754 100644 --- a/test/test_tls.py +++ b/test/test_tls.py @@ -417,4 +417,4 @@ Connection: close self.assertEqual(resp['body'], '0123456789', 'application respawn body') if __name__ == '__main__': - unittest.main() + TestUnitTLS.main() diff --git a/test/unit.py b/test/unit.py index a5f96968..e88ed684 100644 --- a/test/unit.py +++ b/test/unit.py @@ -7,6 +7,7 @@ import time import shutil import socket import select +import argparse import platform import tempfile import unittest @@ -19,6 +20,31 @@ class TestUnit(unittest.TestCase): architecture = platform.architecture()[0] maxDiff = None + detailed = False + save_log = False + + def __init__(self, methodName='runTest'): + super().__init__(methodName) + + if re.match(r'.*\/run\.py$', sys.argv[0]): + args, rest = TestUnit._parse_args() + + TestUnit._set_args(args) + + @classmethod + def main(cls): + args, rest = TestUnit._parse_args() + + for i, arg in enumerate(rest): + if arg[:5] == 'test_': + rest[i] = cls.__name__ + '.' + arg + + sys.argv = sys.argv[:1] + rest + + TestUnit._set_args(args) + + unittest.main() + def setUp(self): self._run() @@ -49,7 +75,7 @@ class TestUnit(unittest.TestCase): # remove unit.log - if '--leave' not in sys.argv and success: + if not TestUnit.save_log and success: shutil.rmtree(self.testdir) else: @@ -91,6 +117,12 @@ class TestUnit(unittest.TestCase): except: m = None + elif module == 'node': + if os.path.isdir(self.pardir + '/node/node_modules'): + m = module + else: + m = None + elif module == 'openssl': try: subprocess.check_output(['which', 'openssl']) @@ -227,6 +259,22 @@ class TestUnit(unittest.TestCase): return ret + @staticmethod + def _parse_args(): + parser = argparse.ArgumentParser(add_help=False) + + parser.add_argument('-d', '--detailed', dest='detailed', + action='store_true', help='Detailed output for tests') + parser.add_argument('-l', '--log', dest='save_log', + action='store_true', help='Save unit.log after the test execution') + + return parser.parse_known_args() + + @staticmethod + def _set_args(args): + TestUnit.detailed = args.detailed + TestUnit.save_log = args.save_log + def _print_path_to_log(self): print('Path to unit.log:\n' + self.testdir + '/unit.log') @@ -296,7 +344,7 @@ class TestUnitHTTP(TestUnit): sock.sendall(req) - if '--verbose' in sys.argv: + if TestUnit.detailed: print('>>>', req, sep='\n') resp = '' @@ -305,7 +353,7 @@ class TestUnitHTTP(TestUnit): enc = 'utf-8' if 'encoding' not in kwargs else kwargs['encoding'] resp = self.recvall(sock).decode(enc) - if '--verbose' in sys.argv: + if TestUnit.detailed: print('<<<', resp.encode('utf-8'), sep='\n') if 'raw_resp' not in kwargs: @@ -516,6 +564,35 @@ class TestUnitApplicationGo(TestUnitApplicationProto): } }) +class TestUnitApplicationNode(TestUnitApplicationProto): + def load(self, script, name='app.js'): + + # copy application + + shutil.copytree(self.current_dir + '/node/' + script, + self.testdir + '/node') + + # link modules + + os.symlink(self.pardir + '/node/node_modules', + self.testdir + '/node/node_modules') + + self.conf({ + "listeners": { + "*:7080": { + "application": script + } + }, + "applications": { + script: { + "type": "external", + "processes": { "spare": 0 }, + "working_directory": self.testdir + '/node', + "executable": name + } + } + }) + class TestUnitApplicationPerl(TestUnitApplicationProto): def load(self, script, name='psgi.pl'): self.conf({ |