Changeset 1332 for TI05-delivery
- Timestamp:
- 27/07/06 11:43:56 (13 years ago)
- Location:
- TI05-delivery/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI05-delivery/trunk/src/python_ext/bbftpd.c
r1259 r1332 15 15 #include "util.h" 16 16 #include <structures.h> 17 #include <bbftpd_log.h> 17 18 18 19 extern char **environ; … … 200 201 */ 201 202 203 /* log message to bbftpd logger */ 204 static PyObject *pybbftpd_log(PyObject *self, PyObject *args) { 205 int priority; 206 char *message; 207 208 if (!PyArg_ParseTuple(args, "is", &priority, &message)) { 209 return NULL; 210 } 211 212 bbftpd_log(priority, message); 213 214 Py_RETURN_NONE; 215 } 216 202 217 /* send(string) */ 203 static PyObject * bbftpd_send(PyObject *self, PyObject *args) {218 static PyObject *pybbftpd_send(PyObject *self, PyObject *args) { 204 219 char *buffer, logmessage[1024]; 205 220 int len; … … 223 238 224 239 /* recv(length) -> string */ 225 static PyObject * bbftpd_recv(PyObject *self, PyObject *args) {240 static PyObject *pybbftpd_recv(PyObject *self, PyObject *args) { 226 241 char *buffer, logmessage[1024]; 227 242 int len; … … 253 268 * Main entry point for the python module. 254 269 */ 255 static PyObject * bbftpd_run(PyObject *self, PyObject *args) {270 static PyObject *pybbftpd_run(PyObject *self, PyObject *args) { 256 271 int argc, i; 257 272 char **argv, **arg_p; … … 315 330 static PyMethodDef BbftpdMethods[] = { 316 331 { 317 "run", bbftpd_run, METH_VARARGS,332 "run", pybbftpd_run, METH_VARARGS, 318 333 "Execute the bbftpd server.\n" 319 334 "\n" … … 325 340 }, 326 341 { 327 "send", bbftpd_send, METH_VARARGS,342 "send", pybbftpd_send, METH_VARARGS, 328 343 "Send an authentication message to the client.\n" 329 344 "\n" … … 334 349 }, 335 350 { 336 "recv", bbftpd_recv, METH_VARARGS,351 "recv", pybbftpd_recv, METH_VARARGS, 337 352 "Receive an authentication message from the client.\n" 338 353 "\n" … … 342 357 "@return: A string containing the message\n" 343 358 "@raise IOError: if bbftpd_private_recv() call fails\n" 359 }, 360 { 361 "log", pybbftpd_log, METH_VARARGS, 362 "Send a message to the bbftpd logger.\n" 363 "\n" 364 "@param priority: as syslog priority\n" 365 "@param message: A string containing the message to send\n" 344 366 }, 345 367 {NULL, NULL, 0, NULL} -
TI05-delivery/trunk/test/test_embedded.py
r1289 r1332 37 37 38 38 msg = self.recv() 39 s yslog.syslog(syslog.LOG_DEBUG,'AuthContext received Auth message: %s' % msg)39 self.logMessage('AuthContext received Auth message: %s' % msg) 40 40 41 41 self.send(NDG_HANDSHAKE) 42 42 43 43 privatestr = self.recv() 44 s yslog.syslog(syslog.LOG_DEBUG,"AuthContext received privatestr: %s" % privatestr)44 self.logMessage("AuthContext received privatestr: %s" % privatestr) 45 45 46 46 return self.makeAuthzHandler(msg, "TestCaseUser") … … 48 48 def makeAuthzHandler(self, msg, user): 49 49 return TestAuthzHandler(msg, "TestCaseUser") 50 51 def logMessage(self, msg): 52 server.bbftpd.log(syslog.LOG_DEBUG, msg) 50 53 51 54 class TestAuthzHandler(server.LiberalAuthzHandler): … … 71 74 72 75 def authzControl(self, msgcode, transferopt, path): 73 s yslog.syslog(syslog.LOG_DEBUG, 'TestPermAuthzHandler.authzControl: msgcode = %s' % hex(msgcode))76 server.bbftpd.log(syslog.LOG_DEBUG, 'TestPermAuthzHandler.authzControl: msgcode = %s' % hex(msgcode)) 74 77 return self.authzPath(path) 75 78 … … 83 86 mode = stat.S_IMODE(os.stat(path)[stat.ST_MODE]) 84 87 if (mode & 0004): 85 s yslog.syslog(syslog.LOG_DEBUG, 'TestPermAuthzHandler OK')88 server.bbftpd.log(syslog.LOG_DEBUG, 'TestPermAuthzHandler OK') 86 89 return True 87 90 else: 88 s yslog.syslog(syslog.LOG_DEBUG, 'TestPermAuthzHandler FAIL')91 server.bbftpd.log(syslog.LOG_DEBUG, 'TestPermAuthzHandler FAIL') 89 92 raise server.AuthorisationFailure, "TestPermAuthzHandler: no read perms" 90 93 … … 96 99 def setUp(self): 97 100 # We want to mark the beginning of this test case in syslog 98 syslog.openlog('test_embedded.py', 0, syslog.LOG_LOCAL0) 99 syslog.syslog(syslog.LOG_DEBUG, 'Starting TestCase') 100 101 #syslog.openlog('test_embedded.py', 0, syslog.LOG_LOCAL0) 102 #syslog.syslog(syslog.LOG_DEBUG, 'Starting TestCase') 103 104 self._clearLog() 101 105 self._startServer() 102 106 103 107 def tearDown(self): 104 108 self._stopServer() 105 syslog.syslog(syslog.LOG_DEBUG, 'Ended TestCase')106 syslog.closelog()109 #syslog.syslog(syslog.LOG_DEBUG, 'Ended TestCase') 110 #syslog.closelog() 107 111 108 112 #---------------------------------------------------------------------------------- … … 117 121 os.kill(self.pid, signal.SIGTERM) 118 122 os.waitpid(self.pid, 0) 119 syslog.syslog(syslog.LOG_DEBUG, 'Stopping server')123 #syslog.syslog(syslog.LOG_DEBUG, 'Stopping server') 120 124 121 125 … … 137 141 fh = os.popen('sh -c "%s %s %s -u %s -r 1 -e \'%s\' localhost" 2>&1 ' % (BBFTP, f, p, user, cmd)) 138 142 return fh 143 144 def _clearLog(self, logfile="./bbftpd.log"): 145 os.remove(logfile) 146 147 def _readLog(self, logfile="./bbftpd.log"): 148 return open(logfile).read() 149 139 150 140 151 def _readSyslog(self, logfile="/var/log/bbftpd/bbftpd.log"): … … 191 202 192 203 def testStartup(self): 193 lines = self._read Syslog()204 lines = self._readLog() 194 205 # Give syslog time to flush it's logs. 195 206 time.sleep(1) … … 208 219 r' f .*/foo', r' f .*/bar', r' f .*/baz'], output) 209 220 210 lines = self._read Syslog()221 lines = self._readLog() 211 222 self.assertLines(['.*Getting new bbftp connexion.*', 212 223 r'.*Authz: MSG_LIST_V2 .*/test/data/\*.*', … … 223 234 self.assertLines(['Received Auth handshake: NDG-Delivery-server %s' % VERSION], output) 224 235 225 lines = self._read Syslog()236 lines = self._readLog() 226 237 227 238 self.assertLines(['.*AuthContext received Auth message: NDG-Delivery-client %s' % VERSION], lines) … … 234 245 output = fh.read() 235 246 236 lines = self._read Syslog()247 lines = self._readLog() 237 248 self.assertLines(['.*AuthContext received privatestr: testPrivateStr'], lines) 238 249 … … 254 265 255 266 # Check syslog 256 lines = self._read Syslog()267 lines = self._readLog() 257 268 self.assertLines(['.*Authz: RETR .*/foo', '.*GET TestCaseUser .*/foo.*'], lines) 258 269 … … 277 288 278 289 # Check syslog 279 lines = self._read Syslog()290 lines = self._readLog() 280 291 self.assertLines(['.*Authz: STORE .*/new_bar', '.*PUT TestCaseUser .*/new_bar.*'], lines) 281 292 … … 292 303 output = fh.read() 293 304 294 lines = self._read Syslog()305 lines = self._readLog() 295 306 296 307 self.assertLines(['.*Error while private authentication.*'], output) … … 315 326 output = fh.read() 316 327 317 lines = self._read Syslog()328 lines = self._readLog() 318 329 319 330 … … 329 340 output = fh.read() 330 341 331 lines = self._read Syslog()332 333 self.assertLines([' BBFTP-ERROR.* ndg_authz_control: AuthorisationFailure.* no read perms',342 lines = self._readLog() 343 344 self.assertLines(['.* ndg_authz_control: AuthorisationFailure.* no read perms', 334 345 'stat /.*/bar FAILED'], output) 335 346 self.assertLines(['.*Authz: MSG_STAT .*/bar', '.* TestPermAuthzHandler FAIL', … … 351 362 r'stat .*'], output) 352 363 353 lines = self._read Syslog()364 lines = self._readLog() 354 365 self.assertLines(['.*Getting new bbftp connexion.*', 355 366 r'.*Authz: MSG_LIST_V2 .*/test/data/\*.*',
Note: See TracChangeset
for help on using the changeset viewer.