Changeset 1539 for TI05-delivery


Ignore:
Timestamp:
28/09/06 15:08:01 (13 years ago)
Author:
spascoe
Message:

Some bug fixes to auth/authz API.

test_embedded.py now passes (except for the usual testStartup problem).

Location:
TI05-delivery/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • TI05-delivery/trunk/lib/python/ndg/delivery/auth.py

    r1538 r1539  
    1212@author Stephen Pascoe 
    1313""" 
     14 
     15class AuthenticationFailure(Exception): 
     16    """Signals authentication failed. 
     17    """ 
     18    pass 
     19 
     20class AuthorisationFailure(Exception): 
     21    """Signals authorisation failed. 
     22    """ 
     23    pass 
    1424 
    1525 
  • TI05-delivery/trunk/lib/python/ndg/delivery/auth_plugin.py

    r1538 r1539  
    1414 
    1515 
    16 NDG_HANDSHAKE = 'NDG-Delivery-client demo' 
     16NDG_HANDSHAKE = 'NDG-Delivery demo' 
    1717logger = logging.getLogger('ndg.delivery.server') 
    1818     
     
    5858        if path[-2:] == '/*': 
    5959            path = path[:-2] 
    60         mode = stat.S_IMODE(os.stat(path)[stat.ST_MODE]) 
    61         if (mode & 0004): 
     60        if os.access(path, os.R_OK): 
    6261            logger.debug('AuthzHandler OK') 
    6362            return True 
  • TI05-delivery/trunk/lib/python/ndg/delivery/server/pybbftp.py

    r1538 r1539  
    8282 
    8383 
    84 class AuthenticationFailure(Exception): 
    85     """Signals authentication failed. 
    86     """ 
    87     pass 
    88  
    89 class AuthorisationFailure(Exception): 
    90     """Signals authorisation failed. 
    91     """ 
    92     pass 
    9384 
    9485class ServerConnector(object): 
  • TI05-delivery/trunk/src/bbftp-client-3.2.0/includes/bbftp_private_user.h

    r1077 r1539  
    4444 
    4545// Define this in the makefile 
    46 // #define NDG_DELIVERY_VERSION "v0.0.1" 
    47 #define NDG_STR(s) #s 
    48 #define NDG_XSTR(s) NDG_STR(s) 
    49 #define NDG_HANDSHAKE ("NDG-Delivery-client " NDG_XSTR(NDG_DELIVERY_VERSION)) 
     46#define NDG_HANDSHAKE "NDG-Delivery demo" 
    5047 
    5148#define NDG_MESSAGE_LEN 256 
  • TI05-delivery/trunk/src/bbftp-server-3.2.0/includes/ndg.h

    r1448 r1539  
    2020#define NDG_MESSAGE_LEN 256 
    2121 
    22 #define NDG_STR(s) #s 
    23 #define NDG_XSTR(s) NDG_STR(s) 
    24 #define NDG_HANDSHAKE ("NDG-Delivery-server " NDG_XSTR(NDG_DELIVERY_VERSION)) 
     22#define NDG_HANDSHAKE "NDG-Delivery demo" 
    2523 
    2624 
  • TI05-delivery/trunk/test/runclient.py

    r1441 r1539  
    99from glob import glob 
    1010 
    11 #HOME = os.path.abspath(os.getenv('NDG_DELIVERY_HOME', os.curdir)) 
    12 HOME = os.path.abspath(os.path.dirname(__file__)+'/..') 
    13 VERSION = open('%s/VERSION' % HOME).read() 
    14 NDG_MESSAGE_LEN = 256 
    1511 
    16 NDG_HANDSHAKE = "NDG-Delivery-client %s" % VERSION 
    17  
    18  
    19  
     12from ndg.delivery.auth_plugin import AuthClientHandler 
    2013import ndg.delivery.client.pybbftp as DC 
    21  
    22 class AuthClientHandler(DC.AuthClientHandler): 
    23     def __init__(self, privatestr="none"): 
    24         self.privatestr = privatestr 
    25  
    26     def authenticate(self): 
    27         self.send(NDG_HANDSHAKE) 
    28         resp = self.recv() 
    29  
    30         print "Received Auth handshake: %s" % resp 
    31  
    32         self.send(self.privatestr) 
    33  
    34         return True 
    3514 
    3615 
     
    5736    args = args[:i] + args[i+2:] 
    5837 
    59 ach = AuthClientHandler(privatestr) 
     38ach = AuthClientHandler(DC.ClientConnector(), privatestr) 
    6039 
    6140print "** runclient.py: connecting with args %s" % args 
  • TI05-delivery/trunk/test/test_embedded.py

    r1453 r1539  
    1111from glob import glob 
    1212import re, tempfile, getopt, logging 
     13import traceback 
    1314 
    1415HOME = os.path.abspath(os.getenv('NDG_DELIVERY_HOME', os.curdir)) 
    1516BBFTP = glob('%s/src/bbftp-client*/bbftpc/bbftp' % HOME)[0] 
    1617DATADIR = '%s/test/data' % HOME 
    17 VERSION = open('%s/VERSION' % HOME).read() 
    18 NDG_MESSAGE_LEN = 256 
    19  
    20 NDG_HANDSHAKE = "NDG-Delivery-server %s" % VERSION 
    21  
    22  
    23 import ndg.delivery.server.pybbftp as server 
    24 import traceback 
     18 
     19 
     20import ndg.delivery.server.pybbftp as DS 
     21from ndg.delivery.auth_plugin import AuthHandler, AuthzHandler 
     22import ndg.delivery.auth as auth 
    2523 
    2624def flushLogging(): 
     
    3129 
    3230resetLogging() 
    33 server.bbftpd.after_fork_hook = resetLogging 
    34 server.bbftpd.before_fork_hook = flushLogging 
    35  
    36  
    37  
    38 class TestAuthHandler(server.AuthHandler): 
    39      
     31DS.bbftpd.after_fork_hook = resetLogging 
     32DS.bbftpd.before_fork_hook = flushLogging 
     33 
     34TestAuthHandler = AuthHandler 
     35 
     36class TestFailAuthHandler(AuthHandler): 
    4037    def authenticate(self): 
    41  
    42         msg = self.recv() 
    43         self.log(server.LOG_DEBUG, 'AuthContext received Auth message: %s' % msg) 
    44                  
    45         self.send(NDG_HANDSHAKE) 
    46  
    47         privatestr = self.recv() 
    48         self.log(server.LOG_DEBUG, "AuthContext received privatestr: %s" % privatestr) 
    49          
    50         return self.makeAuthzHandler(msg, "TestCaseUser") 
    51  
     38        raise auth.AuthenticationFailure, "TestFailAuthHandler" 
     39 
     40 
     41class TestPermAuthHandler(AuthHandler): 
    5242    def makeAuthzHandler(self, msg, user): 
    53         return TestAuthzHandler(msg, "TestCaseUser") 
    54  
    55  
    56 class TestAuthzHandler(server.LiberalAuthzHandler): 
    57     def __init__(self, version, username): 
    58         super(TestAuthzHandler, self).__init__(username) 
    59         self.version = version 
    60  
    61  
    62  
    63  
    64 class TestFailAuthHandler(server.AuthHandler): 
    65     def authorise(self): 
    66         raise server.AuthenticationFailure, "TestFailAuthHandler" 
    67  
    68  
    69 class TestPermAuthHandler(TestAuthHandler): 
    70     def makeAuthzHandler(self, msg, user): 
    71         return TestPermAuthzHandler(msg, "TestCaseUser") 
    72  
    73 class TestPermAuthzHandler(TestAuthzHandler): 
     43        return TestPermAuthzHandler(self.server, msg, "TestCaseUser") 
     44 
     45class TestPermAuthzHandler(AuthzHandler): 
    7446    """Check's the path's other read permission and authorises accordingly. 
    7547    """ 
    7648 
    7749    def authzControl(self, msgcode, transferopt, path): 
    78         self.log(server.LOG_DEBUG, 'TestPermAuthzHandler.authzControl: msgcode = %s' % hex(msgcode)) 
     50        self.server.log(DS.LOG_DEBUG, 'TestPermAuthzHandler.authzControl: msgcode = %s' % hex(msgcode)) 
    7951        return self.authzPath(path) 
    8052 
     
    8860        mode = stat.S_IMODE(os.stat(path)[stat.ST_MODE]) 
    8961        if (mode & 0004): 
    90             self.log(server.LOG_DEBUG, 'TestPermAuthzHandler OK') 
     62            self.server.log(DS.LOG_DEBUG, 'TestPermAuthzHandler OK') 
    9163            return True 
    9264        else: 
    93             self.log(server.LOG_DEBUG, 'TestPermAuthzHandler FAIL') 
    94             raise server.AuthorisationFailure, "TestPermAuthzHandler: no read perms" 
     65            self.server.log(DS.LOG_DEBUG, 'TestPermAuthzHandler FAIL') 
     66            raise auth.AuthorisationFailure, "TestPermAuthzHandler: no read perms" 
    9567 
    9668 
    9769class BaseFixture(unittest.TestCase): 
    9870 
    99     authContext = TestAuthHandler() 
     71    authContext = TestAuthHandler(DS.ServerConnector()) 
    10072 
    10173    def setUp(self): 
     
    11183    def _startServer(self): 
    11284        # Start the server and store it's PID 
    113         self.pid = server.start(self.authContext, ['-l', 'DEBUG']) 
     85        self.pid = DS.start(self.authContext, ['-l', 'DEBUG']) 
    11486 
    11587    def _stopServer(self): 
     
    205177        print >>open('./bbftpc.log', 'w'), output 
    206178 
    207         self.assertLines(['Received Auth handshake: NDG-Delivery-server %s' % VERSION], output) 
    208  
    209         lines = self._readLog() 
    210  
    211         self.assertLines(['.*AuthContext received Auth message: NDG-Delivery-client %s' % VERSION], lines) 
     179        self.assertLines(['Received Auth handshake: NDG-Delivery demo'], output) 
     180 
     181        lines = self._readLog() 
     182 
     183        self.assertLines(['.*received Auth message: NDG-Delivery demo'], lines) 
    212184 
    213185    def testPrivateStr(self): 
     
    263235 
    264236class AuthFail(BaseFixture): 
    265     authContext = TestFailAuthHandler() 
     237    authContext = TestFailAuthHandler(DS.ServerConnector()) 
    266238 
    267239    def test(self): 
     
    278250 
    279251class Authz(BaseFixture): 
    280     authContext = TestPermAuthHandler() 
     252    authContext = TestPermAuthHandler(DS.ServerConnector()) 
    281253 
    282254    def setUp(self): 
     
    298270        self.assertLines(['Connection and authentication correct', 'stat /.*/foo OK'], output) 
    299271        self.assertLines(['.*Authz: MSG_STAT .*/foo', '.*TestPermAuthzHandler OK', 
    300                           '.*TestPermAuthzHandler.*msgcode = %s.*' % hex(server.MSG.STAT)], lines) 
     272                          '.*TestPermAuthzHandler.*msgcode = %s.*' % hex(DS.MSG.STAT)], lines) 
    301273 
    302274    def testFail(self): 
Note: See TracChangeset for help on using the changeset viewer.