def setUp(self): try: os.mkdir(self.testDirPath) except: pass self.dirResource = Crypto(self.testDirPath) self.dirResource._registerWithParent() self.dirResource._updateMetadata()
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 reSign(path = ""): """ Request new signing of resource. Path is a relative path with respect to repository root. """ rr = Crypto(absPath(path)) if not rr.validate(): rr._signContent() rr.seal() assert rr.validate()
class ProppatchTest(unittest.TestCase): testDirPath = os.path.sep.join([repositoryPath, "TEST"]) def setUp(self): try: os.mkdir(self.testDirPath) except: pass self.dirResource = Crypto(self.testDirPath) self.dirResource._registerWithParent() self.dirResource._updateMetadata() def tearDown(self): self.dirResource.remove() def testProppatchRequestGenerateParse(self): """ Make a PROPPATCH request body, then parse it back in and compare to the input. """ body = clone.makeCloneBody(self.dirResource) xml = davxml.WebDAVDocument.fromString(body) cloneElement = proppatch.validateBodyXML(xml) cc = clone.cloneFromElement(cloneElement) assert cc.path == self.dirResource.relativePath()
def showDialog(self, title, source, mountpoint): """ @return: a (source, mountpoint) pair, unless the dialog was cancelled, in which case we return None """ def validate(source, mountpoint): """ @return: an error message, if validation failed, None otherwise """ # validate the source url from angel_app.uri import parse try: parse(source) # valid uri except Exception, e: # couldn't parse, so fail return "Not a valid angel-app URI: " + source + """ Example valid URI: http://missioneternity.org:6221/""" # validate the destination path try: from angel_app.resource.local.basic import Basic repositoryPath = wx.GetApp( ).config.container['common']['repository'] destination = Basic(repositoryPath + os.sep + mountpoint) if not destination.fp.exists() or not destination.isCollection( ): from angel_app.resource.local.internal.resource import Crypto try: newResource = Crypto(repositoryPath + os.sep + mountpoint) os.mkdir(repositoryPath + os.sep + mountpoint) newResource.seal() except Exception, e: log.warn("Error creating mount point '%s'" % mountpoint, exc_info=e) return "Error creating the mount point '%s'!" % mountpoint else: return None else:
def showDialog(self, title, source, mountpoint): """ @return: a (source, mountpoint) pair, unless the dialog was cancelled, in which case we return None """ def validate(source, mountpoint): """ @return: an error message, if validation failed, None otherwise """ # validate the source url from angel_app.uri import parse try: parse(source) # valid uri except Exception, e: # couldn't parse, so fail return "Not a valid angel-app URI: " + source + """ Example valid URI: http://missioneternity.org:6221/""" # validate the destination path try: from angel_app.resource.local.basic import Basic repositoryPath = wx.GetApp().config.container['common']['repository'] destination = Basic(repositoryPath + os.sep + mountpoint) if not destination.fp.exists() or not destination.isCollection(): from angel_app.resource.local.internal.resource import Crypto try: newResource = Crypto(repositoryPath + os.sep + mountpoint) os.mkdir(repositoryPath + os.sep + mountpoint) newResource.seal() except Exception, e: log.warn("Error creating mount point '%s'" % mountpoint, exc_info = e) return "Error creating the mount point '%s'!" % mountpoint else: return None else:
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()
class LocalResourceTest(resourceTest.ResourceTest): """ Super-class of local resource tests. Doesn't provide any test cases itself. """ testDirPath = os.path.sep.join([repositoryPath, "TEST"]) testFilePath = os.path.sep.join([testDirPath, "file.txt"]) testText = "lorem ipsum" def makeTestDirectory(self): os.mkdir(self.testDirPath) self.testDirectory = Crypto(self.testDirPath) self.testDirectory._registerWithParent() self.testDirectory._updateMetadata() def makeTestFile(self): open(self.testFilePath, 'w').write(self.testText) self.testFile = Crypto(self.testFilePath) self.testFile._registerWithParent() self.testFile._updateMetadata() def makeTestClone(self): self.testClone = Clone(host="localhost", port=AngelConfig.getint("presenter", "listenPort"), path="/TEST/") def setUp(self): self.makeTestDirectory() self.makeTestFile() self.makeTestClone() def tearDown(self): Crypto(self.testDirPath).remove() def testInterfaceCompliance(self): pass
def dance(options): from angel_app.log import getLogger from angel_app.config import config AngelConfig = config.getConfig() port = AngelConfig.getint("presenter", "listenPort") interface = AngelConfig.get("presenter", "listenInterface") repository = AngelConfig.get("common", "repository") from angel_app.resource.local.internal.resource import Crypto Crypto.rootDirectory = repository root = Crypto(repository) from twisted.web2 import server from twisted.web2 import channel from twisted.internet import reactor site = server.Site(root) reactor.listenTCP(port, channel.HTTPFactory(site), 50, interface) getLogger().info('Listening on IP %s port %d and serving content from %s', interface, port, repository) getLogger().growl("User", "ETERNITY FILE SYSTEM", "Available on port %s." % port) reactor.run() getLogger().info("Quit")
def setUp(self): os.mkdir(self.testDirPath) cc = Crypto(self.testDirPath) cc._registerWithParent() cc._updateMetadata() self.testResource = cc
class ForbiddenTest(unittest.TestCase): """ I make sure that all destructive method calls are forbidden on the external interface. """ testDirPath = os.path.sep.join([repositoryPath, "TEST"]) def setUp(self): try: os.mkdir(self.testDirPath) except: pass self.dirResource = Crypto(self.testDirPath) self.dirResource._registerWithParent() self.dirResource._updateMetadata() def tearDown(self): self.dirResource.remove() 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 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 testProppatch(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. """ # fake resource, modification of which should be disallowed dd = clone.Clone("localhost", providerport, "/TEST/") assert dd.ping(), "Test resource root unreachable. Make sure you have a running provider instance." method = "PROPPATCH" response = dd.remote.performRequest(method) assert (response.status == responsecode.BAD_REQUEST), \ "Request with empty body must fail with 400 BAD_REQUEST. Received: " + `response.status` body = makePushBody(self.dirResource) response = dd.remote.performRequest(method, body = body) assert (response.status == responsecode.FORBIDDEN), \ "Request with extensive property update must fail with 403 FORBIDDEN. Received: " + `response.status` body = clone.makeCloneBody(self.dirResource) response = dd.remote.performRequest(method, body = body) # TODO: we might want to add a detailed analysis of the MULTI_STATUS response here. assert (response.status == responsecode.MULTI_STATUS), \ "Request with well-formed property update must succeed with MULTI_STATUS response. Received: " + `response.status`
def tearDown(self): Crypto(self.testDirPath)._deRegisterWithParent() shutil.rmtree(self.testDirPath, ignore_errors=True)
def makeTestDirectory(self): os.mkdir(self.testDirPath) self.testDirectory = Crypto(self.testDirPath) self.testDirectory._registerWithParent() self.testDirectory._updateMetadata()
def setMountPoint(mountPoint, URLToMount): """ @param path is the resource that we want to use as a mount point @param pointsTo is the URL of the resource that we want to mount """ log.info("attempting to mount: %s at %s", URLToMount, mountPoint) pp = absPath(mountPoint) from angel_app.resource.remote import clone cc = clone.cloneFromURI(URLToMount) if not (cc.ping() and cc.exists()): # don't fail, just mount at next startup log.warn("Can not connect to %s. Can not initialize mount point.", URLToMount) return # --- the local mount point can be initialized --- log.info("mount point and clone OK, proceeding to mount.") # create the mount point, if necessary if not os.path.exists(pp): os.mkdir(pp) else: assert Basic(pp).isCollection(), "Mount point must be a directory." rr = Crypto(pp) from angel_app import elements # initialize all required properties -- rubbish is ok for many of them, # as long as we clearly state that ${URLToMount} is the original: dp = rr.deadProperties() dp.set(elements.PublicKeyString.fromString( cc.publicKeyString())) dp.set(elements.MetaDataSignature.fromString( cc.metaDataSignature())) dp.set(elements.ContentSignature.fromString( rr._computeContentHexDigest() )) rid = cc.resourceID() lid = elements.ResourceID.fromString(rid) dp.set(lid) rr._registerWithParent() # add the clone from angel_app.resource.remote.clone import clonesToElement # here, we store a list of already known clones + the remote mount ! # this makes sure that it works both for the first virgin mount as well as later dp.set(clonesToElement(rr.clones() + [cc])) from angel_app.maintainer.client import inspectResource try: inspectResource(rr) except KeyboardInterrupt: raise except Exception, e: log.warn("Resource inspection failed for mount point: %s", pp, exc_info = e)
def makeTestFile(self): open(self.testFilePath, 'w').write(self.testText) self.testFile = Crypto(self.testFilePath) self.testFile._registerWithParent() self.testFile._updateMetadata()
def tearDown(self): Crypto(self.testDirPath).remove()
def setMountPoint(mountPoint, URLToMount): """ @param path is the resource that we want to use as a mount point @param pointsTo is the URL of the resource that we want to mount """ log.info("attempting to mount: %s at %s", URLToMount, mountPoint) pp = absPath(mountPoint) from angel_app.resource.remote import clone cc = clone.cloneFromURI(URLToMount) if not (cc.ping() and cc.exists()): # don't fail, just mount at next startup log.warn("Can not connect to %s. Can not initialize mount point.", URLToMount) return # --- the local mount point can be initialized --- log.info("mount point and clone OK, proceeding to mount.") # create the mount point, if necessary if not os.path.exists(pp): os.mkdir(pp) else: assert Basic(pp).isCollection(), "Mount point must be a directory." rr = Crypto(pp) from angel_app import elements # initialize all required properties -- rubbish is ok for many of them, # as long as we clearly state that ${URLToMount} is the original: dp = rr.deadProperties() dp.set(elements.PublicKeyString.fromString(cc.publicKeyString())) dp.set(elements.MetaDataSignature.fromString(cc.metaDataSignature())) dp.set(elements.ContentSignature.fromString(rr._computeContentHexDigest())) rid = cc.resourceID() lid = elements.ResourceID.fromString(rid) dp.set(lid) rr._registerWithParent() # add the clone from angel_app.resource.remote.clone import clonesToElement # here, we store a list of already known clones + the remote mount ! # this makes sure that it works both for the first virgin mount as well as later dp.set(clonesToElement(rr.clones() + [cc])) from angel_app.maintainer.client import inspectResource try: inspectResource(rr) except KeyboardInterrupt: raise except Exception, e: log.warn("Resource inspection failed for mount point: %s", pp, exc_info=e)