Ignore:
Timestamp:
08/06/06 12:51:22 (14 years ago)
Author:
spascoe
Message:

There are various changes here.

The server now calls python for authorisation. This is untested, although the test suite passes. More flesh on delivery.server and it's now used in the
test suite. The server now logs python exceptions to syslog from within C code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/trunk/test/test_embedded.py

    r1133 r1141  
    2222 
    2323sys.path.append(BUILDDIR) 
    24 import delivery.bbftpd as bbftpd 
    25          
    26 class AuthzContext: 
    27     def __init__(self, version_msg, user): 
    28         self.version = version_msg 
    29         self.username = user 
    30  
    31 class AuthContext: 
    32     def __call__(self): 
    33         # Read the auth version message 
    34         msg = bbftpd.recv() 
    35         # Trim to first '\0' 
    36         x = msg.find('\0') 
    37         if x: 
    38             msg = msg[:x] 
     24 
     25import delivery.server as server 
     26 
     27 
     28class TestAuthHandler(server.BasicClientAuthHandler): 
     29    def authorise(self): 
     30        msg = self.recvCStr() 
    3931 
    4032        syslog.syslog(syslog.LOG_DEBUG, 'AuthContext received Auth message: %s' % msg) 
    4133 
    42         # Send the response 
    43         msg = NDG_HANDSHAKE + '\0' * (NDG_MESSAGE_LEN - len(NDG_HANDSHAKE)) 
    44         bbftpd.send(msg) 
    45  
    46         # Get privatestr 
    47         privatestr = bbftpd.recv() 
    48         # Trim to first '\0' 
    49         x = privatestr.find('\0') 
    50         if x: 
    51             privatestr = privatestr[:x] 
     34        self.send(NDG_HANDSHAKE) 
     35 
     36        privatestr = self.recvCStr() 
    5237        syslog.syslog(syslog.LOG_DEBUG, "AuthContext received privatestr: %s" % privatestr) 
    5338 
    54         return AuthzContext(msg, "TestCaseUser") 
    55  
    56  
    57 class FailingAuthContext(AuthContext): 
    58     def __call__(self): 
    59         az = super(FailingAuthContext).authorise() 
     39        return TestAuthzHandler(msg, "TestCaseUser") 
     40 
     41class TestAuthzHandler(server.LiberalAuthzHandler): 
     42    def __init__(self, version, username): 
     43        super(TestAuthzHandler, self).__init__(username) 
     44        self.version = version 
     45 
     46 
     47class TestFailAuthHandler(server.AuthHandler): 
     48    def authorise(self): 
    6049        return None 
    61  
    62  
    63  
    6450 
    6551class BaseFixture(unittest.TestCase): 
     
    8167    def _startServer(self, authContext=None): 
    8268        if not authContext: 
    83             authContext = AuthContext() 
     69            authContext = TestAuthHandler() 
    8470        # Start the server and store it's PID 
    85         self.pid = bbftpd.run(authContext, ['-l', 'DEBUG']) 
     71        self.pid = server.start(authContext, ['-l', 'DEBUG']) 
    8672 
    8773    def _stopServer(self): 
     
    217203        # Check the client output 
    218204        output = fh.read() 
     205 
    219206        self.assertLines(['get.*nogzip'], output) 
    220207 
     
    258245        syslog.syslog(syslog.LOG_DEBUG, 'Starting EmbeddedServerTestCase') 
    259246 
    260         self._startServer(authContext=FailingAuthContext()) 
     247        self._startServer(authContext=TestFailAuthHandler()) 
    261248 
    262249    def test(self): 
Note: See TracChangeset for help on using the changeset viewer.