def testRemoteStream(self): """ The default clone is the root on localhost which must render to REPR_DIRECTORY """ assert Clone().ping(), "locally running provider instance required" from angel_app.resource.abstractContentManager import REPR_DIRECTORY assert REPR_DIRECTORY == Clone().open().read()
def testAcceptable(self): """ Validating a (reachable) clone against itself should always succeed. """ clone = Clone("missioneternity.org") assert collect.acceptable(clone, clone.publicKeyString(), clone.resourceID())
def testCloneList(self): clone = Clone("missioneternity.org") cl = [cc for cc in collect.cloneList([clone], clone.publicKeyString(), clone.resourceID() )] print cl assert len(cl) > 0
def testCloneList(self): clone = Clone("missioneternity.org") cl = [ cc for cc in collect.cloneList([clone], clone.publicKeyString(), clone.resourceID()) ] print cl assert len(cl) > 0
def testAccessible(self): clone = Clone("missioneternity.org") (cc, acc) = collect.accessible(clone) assert acc assert cc == clone clone2 = Clone("sample.invalid") (cc, acc) = collect.accessible(clone2) assert False == acc assert cc == clone2
def testMount(self): testMountPoint = os.path.sep.join([self.testDirPath, "MISSION ETERNITY"]) setMountPoint(testMountPoint, "http://missioneternity.org:6221/") mounted = Crypto(testMountPoint) remote = Clone("missioneternity.org") print "" print "foo:", mounted.deadProperties().get(ResourceID.qname()) print mounted.resourceID() print remote.resourceID() assert mounted.resourceID() == remote.resourceID()
def testMount(self): testMountPoint = os.path.sep.join( [self.testDirPath, "MISSION ETERNITY"]) setMountPoint(testMountPoint, "http://missioneternity.org:6221/") mounted = Crypto(testMountPoint) remote = Clone("missioneternity.org") print "" print "foo:", mounted.deadProperties().get(ResourceID.qname()) print mounted.resourceID() print remote.resourceID() assert mounted.resourceID() == remote.resourceID()
def testPing(self): import socket oldTimeOut = socket.getdefaulttimeout() from angel_app.resource.remote.clone import Clone cc = Clone("80.219.195.84", 6221) assert False == cc.ping() dd = Clone("localhost") assert True == dd.ping(), "Make sure you have a local provider instance running." assert oldTimeOut == socket.getdefaulttimeout()
def makeClone(self): """ Will create and return a Clone object of the local resource. """ nodename = AngelConfig.get("maintainer", "nodename") providerport = AngelConfig.getint("provider", "listenPort") return Clone(nodename, providerport, self.relativeURL())
def testAllowRemoteResourceRead(self): """ Perform read-only requests on remote resource """ from angel_app.resource.remote.clone import Clone # fake resource, modification of which should be disallowed dd = Clone("localhost", providerport, "/TEST/") assert dd.ping(), "Test resource root unreachable. Make sure you have a provider instance running." assert self.dirResource.exists() methodsAndExpectedResponseCodes = [ ("GET", responsecode.OK), ("PROPFIND", responsecode.MULTI_STATUS), ] for method, expect in methodsAndExpectedResponseCodes: runRequest(dd, method, expect)
def testCollectionRedirect(self): """ path without trailing backslash affords redirect for directories """ from angel_app.resource.remote.clone import Clone dd = Clone("localhost", providerport, "/TEST") methodsAndExpectedResponseCodes = [("GET", responsecode.MOVED_PERMANENTLY)] for method, expect in methodsAndExpectedResponseCodes: runRequest(dd, method, expect)
def testDenyRemoteResourceModification(self): """ Assert (except for PROPPATCH) that all modification requests for the root resource are denied. For this test to run, you need a running instance of the provider. """ from angel_app.resource.remote.clone import Clone # fake resource, modification of which should be disallowed dd = Clone("localhost", providerport, "/TEST/") assert dd.ping(), "Test resource root unreachable." methodsAndExpectedResponseCodes = [ ("MKCOL", responsecode.FORBIDDEN), ("DELETE", responsecode.FORBIDDEN), ("PUT", responsecode.FORBIDDEN), ("MOVE", responsecode.FORBIDDEN), ("COPY", responsecode.FORBIDDEN) ] for method, expect in methodsAndExpectedResponseCodes: runRequest(dd, method, expect)
def testIterateClones(self): clone = Clone("missioneternity.org") cl = collect.iterateClones([clone], clone.publicKeyString(), clone.resourceID() ) if len(cl.good) > 0: ref = cl.good[0] for cc in cl.good[1:]: assert cc.revision() == ref.revision() assert cc.publicKeyString() == clone.publicKeyString() assert cc.resourceID() == clone.resourceID() assert cc.validate() for cc in cl.old: assert cc not in cl.good assert cc not in cl.unreachable assert cc.validate() if len(cl.good) > 0: assert cc.revision() < cl.good[0].revision() for cc in cl.unreachable: assert (not cc.ping()) or (not cc.exists())
def pingBack(clone, request, publicKeyString, resourceID, lresource): """ Determine if the clone as advertised in the PROPPATCH request is reachable. TODO: validate & clean up TODO: avoid pingBack() to self! @return the (potentially modified) clone, if it's reachable, None otherwise """ log.debug("pingBack(%r) called.", clone) clones = eliminateSelfReferences([clone]) # get rid of pingBacks to self! if len(clones) < 1: return None else: clone = clones[0] del clones if not clone.ping() or not clone.exists(): dns_resolved_ips = resolvedns(clone.getHost()) ip_address = str(request.remoteAddr.host) if not ip_address in dns_resolved_ips: # only fallback to IP if nodename does not already resolve to it log.info( "Invalid PROPPATCH request. Can't pingBack() to clone at: %r. Falling back to IP '%s'.", clone, ip_address) # can't connect to the clone as advertised by "nodename", # the "nodename" defaults to something marginally useful, so this might be expected, # default to the request's originating ip address and try again. clone = Clone(ip_address, clone.port, clone.path) # here, we should still expect to be fooled by NATs etc. (clone, access) = collect.accessible(clone) if not access: log.info( "Invalid PROPPATCH request. Can't pingBack() to clone at: %r", clone) return None else: log.info( "Invalid PROPPATCH request. Can't pingBack() to clone at: %r. NOT falling back to IP '%s', because nodename already resolves to it.", clone, ip_address) return None validate = ValidateClone(lresource, publicKeyString, resourceID) if not validate(clone): log.info("Invalid PROPPATCH request. Invalid data for clone at: %r", clone) return None return clone
def testPing(self): import socket oldTimeOut = socket.getdefaulttimeout() from angel_app.resource.remote.clone import Clone cc = Clone("80.219.195.84", 6221) assert False == cc.ping() dd = Clone("localhost") assert True == dd.ping( ), "Make sure you have a local provider instance running." assert oldTimeOut == socket.getdefaulttimeout()
def testIterateClones(self): clone = Clone("missioneternity.org") cl = collect.iterateClones([clone], clone.publicKeyString(), clone.resourceID()) if len(cl.good) > 0: ref = cl.good[0] for cc in cl.good[1:]: assert cc.revision() == ref.revision() assert cc.publicKeyString() == clone.publicKeyString() assert cc.resourceID() == clone.resourceID() assert cc.validate() for cc in cl.old: assert cc not in cl.good assert cc not in cl.unreachable assert cc.validate() if len(cl.good) > 0: assert cc.revision() < cl.good[0].revision() for cc in cl.unreachable: assert (not cc.ping()) or (not cc.exists())
def makeTestClone(self): self.testClone = Clone(host="localhost", port=AngelConfig.getint("presenter", "listenPort"), path="/TEST/")