From 01103c50055abef3640cef57d820567931bb3518 Mon Sep 17 00:00:00 2001 From: Tiago Natel Date: Tue, 26 Nov 2019 15:58:25 +0000 Subject: Tests: parsing of "Transfer-Encoding: chunked" responses. --- test/test_python_application.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'test/test_python_application.py') diff --git a/test/test_python_application.py b/test/test_python_application.py index ae8f01ca..5e1ba65a 100644 --- a/test/test_python_application.py +++ b/test/test_python_application.py @@ -540,7 +540,7 @@ Connection: close } ) self.assertEqual(resp['status'], 200, 'status') - self.assertEqual(resp['body'][-5:], '0\r\n\r\n', 'body') + self.assertEqual(resp['body'], 'XXXXXXX', 'body') # Exception before start_response(). @@ -607,12 +607,11 @@ Connection: close 'X-Skip': '2', 'X-Chunked': '1', 'Connection': 'close', - } + }, + raw_resp=True ) - if 'body' in resp: - self.assertNotEqual( - resp['body'][-5:], '0\r\n\r\n', 'incomplete body' - ) + if resp: + self.assertNotEqual(resp[-5:], '0\r\n\r\n', 'incomplete body') self.assertEqual( len(self.findall(r'Traceback')), 4, 'traceback count 4' ) @@ -646,12 +645,11 @@ Connection: close 'X-Skip': '3', 'X-Chunked': '1', 'Connection': 'close', - } + }, + raw_resp=True ) - if 'body' in resp: - self.assertNotEqual( - resp['body'][-5:], '0\r\n\r\n', 'incomplete body 2' - ) + if resp: + self.assertNotEqual(resp[-5:], '0\r\n\r\n', 'incomplete body 2') self.assertEqual( len(self.findall(r'Traceback')), 6, 'traceback count 6' ) -- cgit From c6a11260e8ad5fa64cb025f72aab343aea9f1d63 Mon Sep 17 00:00:00 2001 From: Tiago Natel Date: Mon, 11 Nov 2019 14:36:22 +0000 Subject: Tests: added tests for setting user and group. --- test/test_python_application.py | 77 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'test/test_python_application.py') diff --git a/test/test_python_application.py b/test/test_python_application.py index 5e1ba65a..818816d0 100644 --- a/test/test_python_application.py +++ b/test/test_python_application.py @@ -1,4 +1,7 @@ import re +import os +import grp +import pwd import time import unittest from unit.applications.lang.python import TestApplicationPython @@ -676,5 +679,79 @@ Connection: close len(self.findall(r'Traceback')), 8, 'traceback count 8' ) + def test_python_user_group(self): + if not self.is_su: + print("requires root") + raise unittest.SkipTest() + + nobody_uid = pwd.getpwnam('nobody').pw_uid + + group = 'nobody' + + try: + group_id = grp.getgrnam(group).gr_gid + except: + group = 'nogroup' + group_id = grp.getgrnam(group).gr_gid + + self.load('user_group') + + obj = self.getjson()['body'] + self.assertEqual(obj['UID'], nobody_uid, 'nobody uid') + self.assertEqual(obj['GID'], group_id, 'nobody gid') + + self.load('user_group', user='nobody') + + obj = self.getjson()['body'] + self.assertEqual(obj['UID'], nobody_uid, 'nobody uid user=nobody') + self.assertEqual(obj['GID'], group_id, 'nobody gid user=nobody') + + self.load('user_group', user='nobody', group=group) + + obj = self.getjson()['body'] + self.assertEqual( + obj['UID'], nobody_uid, 'nobody uid user=nobody group=%s' % group + ) + + self.assertEqual( + obj['GID'], group_id, 'nobody gid user=nobody group=%s' % group + ) + + self.load('user_group', group=group) + + obj = self.getjson()['body'] + self.assertEqual( + obj['UID'], nobody_uid, 'nobody uid group=%s' % group + ) + + self.assertEqual(obj['GID'], group_id, 'nobody gid group=%s' % group) + + self.load('user_group', user='root') + + obj = self.getjson()['body'] + self.assertEqual(obj['UID'], 0, 'root uid user=root') + self.assertEqual(obj['GID'], 0, 'root gid user=root') + + group = 'root' + + try: + grp.getgrnam(group) + group = True + except: + group = False + + if group: + self.load('user_group', user='root', group='root') + + obj = self.getjson()['body'] + self.assertEqual(obj['UID'], 0, 'root uid user=root group=root') + self.assertEqual(obj['GID'], 0, 'root gid user=root group=root') + + self.load('user_group', group='root') + + obj = self.getjson()['body'] + self.assertEqual(obj['UID'], nobody_uid, 'root uid group=root') + self.assertEqual(obj['GID'], 0, 'root gid group=root') + if __name__ == '__main__': TestPythonApplication.main() -- cgit