Changeset 404:96838d29a13a

Show
Ignore:
Timestamp:
06/04/08 12:16:11 (2 years ago)
Author:
Brian Warner <warner@allmydata.com>
branch:
default
Message:

fix registerReference() with both name= and furlFile= when the file already exists, closes #64

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ChangeLog

    r402 r404  
    112008-06-04  Brian Warner  <warner@allmydata.com> 
     2 
     3        * foolscap/pb.py (Tub.registerReference): fix an exception that 
     4        occurs if you call this with both name= and furlFile= and the 
     5        furlFile already exists. Also prohibit attempts to change the name 
     6        to something other than what is in the furlFile. Thanks to Brian 
     7        Granger for the patch. Closes #64. 
    28 
    39        * foolscap/_version.py (verstr): bump revision to 0.2.7+ while 
  • foolscap/pb.py

    r403 r404  
    1010from foolscap import util 
    1111from foolscap.referenceable import SturdyRef 
    12 from foolscap.tokens import PBError, BananaError, WrongTubIdError 
     12from foolscap.tokens import PBError, BananaError, WrongTubIdError, \ 
     13     WrongNameError 
    1314from foolscap.reconnector import Reconnector 
    1415from foolscap.logging import log as flog 
     
    668669                pass 
    669670        if oldfurl: 
     671            sr = SturdyRef(oldfurl) 
    670672            if name is None: 
    671                 sr = SturdyRef(oldfurl) 
    672673                name = sr.name 
    673674            if self.tubID != sr.tubID: 
    674                 raise WrongTubIdError("I cannot keep using the old FURL (%s)
     675                raise WrongTubIdError("I cannot keep using the old FURL from %s
    675676                                      " because it does not have the same" 
    676677                                      " TubID as I do (%s)" % 
    677                                       (oldfurl, self.tubID)) 
     678                                      (furlFile, self.tubID)) 
     679            if name != sr.name: 
     680                raise WrongNameError("I cannot keep using the old FURL from %s" 
     681                                     " because you called registerReference" 
     682                                     " with a new name (%s)" % 
     683                                     (furlFile, name)) 
    678684        name = self._assignName(ref, name) 
    679685        assert name 
  • foolscap/test/test_registration.py

    r71 r404  
    33from twisted.trial import unittest 
    44 
    5 import weakref, gc 
     5import os, weakref, gc 
    66from foolscap import UnauthenticatedTub 
    77from foolscap.test.common import HelperTarget 
     8from foolscap.tokens import WrongNameError 
    89 
    910class Registration(unittest.TestCase): 
     
    5152        url = tub.registerReference(target) 
    5253 
     54    def test_duplicate(self): 
     55        basedir = "test_registration" 
     56        os.makedirs(basedir) 
     57        ff = os.path.join(basedir, "duplicate.furl") 
     58        t1 = HelperTarget() 
     59        tub = UnauthenticatedTub() 
     60        tub.setLocation("bogus:1234567") 
     61        u1 = tub.registerReference(t1, "name", furlFile=ff) 
     62        u2 = tub.registerReference(t1, "name", furlFile=ff) 
     63        self.failUnlessEqual(u1, u2) 
     64        self.failUnlessRaises(WrongNameError, 
     65                              tub.registerReference, t1, "newname", furlFile=ff) 
     66 
     67 
     68 
  • foolscap/tokens.py

    r261 r404  
    116116class WrongTubIdError(Exception): 
    117117    """getReference(furlFile=) used a FURL with a different TubID""" 
     118class WrongNameError(Exception): 
     119    """getReference(furlFule=) used a FURL with a different name""" 
    118120 
    119121