helper_furl = f.read()
f.close()
self.helper_furl = helper_furl
- f = open(os.path.join(basedirs[3],"helper.furl"), "w")
- f.write(helper_furl)
- f.close()
+ if self.numclients >= 4:
+ f = open(os.path.join(basedirs[3],"helper.furl"), "w")
+ f.write(helper_furl)
+ f.close()
# this starts the rest of the clients
for i in range(1, self.numclients):
l = self.clients[0].getServiceNamed("webish").listener
port = l._port.getHost().port
self.webish_url = "http://localhost:%d/" % port
- # and the helper-using webport
- l = self.clients[3].getServiceNamed("webish").listener
- port = l._port.getHost().port
- self.helper_webish_url = "http://localhost:%d/" % port
+ if self.numclients >=4:
+ # and the helper-using webport
+ l = self.clients[3].getServiceNamed("webish").listener
+ port = l._port.getHost().port
+ self.helper_webish_url = "http://localhost:%d/" % port
d.addCallback(_connected)
return d
--- /dev/null
+import os
+
+from twisted.trial import unittest
+from twisted.internet import defer, reactor
+from twisted.python import log
+from twisted.web import client, http
+
+from allmydata.test.common import SystemTestMixin
+
+
+class TestCase(SystemTestMixin, unittest.TestCase):
+
+ def setAmbientUploadAuthority(self,ambientUploadAuthority):
+ self.ambientUploadAuthority = ambientUploadAuthority
+
+ def _test_ambient_upload_authority(self):
+ self.webip = "127.0.0.1"
+ self.webport = 3456
+ self.basedir = self.mktemp()
+
+ # set up an introducer and a node
+ d = self.set_up_nodes(1)
+ d.addCallback(self._test_ambient_upload_authority2)
+ d.addErrback(self.fail)
+ return d
+
+ def _set_up_nodes_extra_config(self):
+ # we need to remove the 'webport' old-style config file
+ # or else the node won't start
+ os.remove(os.path.join(self.getdir("client0"), "webport"))
+ f = open(os.path.join(self.getdir("client0"), "tahoe.cfg"), "wt")
+ f.write("\n")
+ f.write("[node]\n")
+ f.write("web.ambient_upload_authority = %s\n" % ("false","true")[self.ambientUploadAuthority])
+ f.write("web.port = tcp:%d:interface=%s\n" % (self.webport, self.webip))
+ f.write("\n")
+ f.write("[client]\n")
+ f.write("introducer.furl = %s\n" % self.introducer_furl)
+ f.write("\n")
+ f.write("[storage]\n")
+ f.write("enabled = true\n")
+ f.write("\n")
+ f.close()
+
+
+ def _test_ambient_upload_authority2(self, ignored=None):
+ content_type = 'multipart/form-data; boundary=----------ThIs_Is_tHe_bouNdaRY_$'
+ body = '------------ThIs_Is_tHe_bouNdaRY_$\r\nContent-Disposition: form-data; name="t"\r\n\r\nupload\r\n------------ThIs_Is_tHe_bouNdaRY_$\r\nContent-Disposition: form-data; name="file"; filename="file1.txt"\r\nContent-Type: application/octet-stream\r\n\r\nsome test text\r\n------------ThIs_Is_tHe_bouNdaRY_$--\r\n'
+ headers = {'Content-Type': content_type,
+ 'Content-Length': len(body)}
+
+ deferreds = []
+ expected = (http.BAD_REQUEST, http.OK)[self.ambientUploadAuthority]
+
+ # try to upload using the local web client
+ def tryRequest(pathetc, method, postdata=None, headers=None):
+ url = "http://%s:%d/%s" % (self.webip, self.webport, pathetc)
+ f = client.HTTPClientFactory(url,method, postdata, headers)
+ f.deferred.addCallback(self._cbCheckResponse,[f,expected])
+ f.deferred.addErrback(self._cbCheckResponse,[f,expected])
+ deferreds.append(f.deferred)
+ reactor.connectTCP(self.webip, self.webport, f)
+
+ tryRequest("uri","PUT","non contents\r\n")
+ tryRequest("uri?t=mkdir","PUT")
+ tryRequest("uri?t=mkdir","POST")
+ tryRequest("uri?t=upload","POST",body,headers)
+
+ # give us one deferred that will fire iff all of the above succeed
+ dlist = defer.DeferredList(deferreds,fireOnOneCallback=False,
+ fireOnOneErrback=True)
+ dlist.addErrback(self.fail)
+
+ return dlist
+
+ def _cbCheckResponse(self, ignored, cmp):
+ r = cmp[0]
+ expected = cmp[1]
+ self.failUnless(int(r.status) == expected)
+
+
+class TestAmbientUploadAuthorityEnabled(TestCase):
+ def setUp(self):
+ TestCase.setUp(self)
+ self.setAmbientUploadAuthority(True)
+
+ def test_ambient_upload_authority_enabled(self):
+ return self._test_ambient_upload_authority()
+
+class TestAmbientUploadAuthorityDisabled(TestCase):
+ def setUp(self):
+ TestCase.setUp(self)
+ self.setAmbientUploadAuthority(False)
+
+ def test_ambient_upload_authority_disabled(self):
+ return self._test_ambient_upload_authority()
+
class URIHandler(RenderMixin, rend.Page):
# I live at /uri . There are several operations defined on /uri itself,
# mostly involved with creation of unlinked files and directories.
+
+ def setAmbientUploadAuthority(self, ambientUploadAuthority):
+ self.ambientUploadAuthority = ambientUploadAuthority
def render_GET(self, ctx):
req = IRequest(ctx)
return there
def render_PUT(self, ctx):
+ if not self.ambientUploadAuthority:
+ raise WebError("/uri handling of PUT not enabled on this node")
+
req = IRequest(ctx)
# either "PUT /uri" to create an unlinked file, or
# "PUT /uri?t=mkdir" to create an unlinked directory
raise WebError(errmsg, http.BAD_REQUEST)
def render_POST(self, ctx):
+ if not self.ambientUploadAuthority:
+ raise WebError("/uri handling of POST not enabled on this node")
+
# "POST /uri?t=upload&file=newfile" to upload an
# unlinked file or "POST /uri?t=mkdir" to create a
# new directory
rend.Page.__init__(self, original)
self.child_operations = operations.OphandleTable()
+ def setAmbientUploadAuthority(self, ambientUploadAuthority):
+ self.child_uri.setAmbientUploadAuthority(ambientUploadAuthority)
+
child_uri = URIHandler()
child_cap = URIHandler()
child_file = FileHandler()