def test_add_directory_entry(self): """ Adding a capability to a mutable directory """ content = b"content " * 200 http_client = create_tahoe_treq_client() tahoe_client = create_tahoe_client( DecodedURL.from_text(u"http://example.com/"), http_client, ) # first create a mutable directory mut_cap = yield tahoe_client.create_mutable_directory() # create an immutable and link it into the directory file_cap = yield tahoe_client.create_immutable(content) yield tahoe_client.add_entry_to_mutable_directory( mut_cap, u"foo", file_cap) # prove we can access the expected file via a GET uri = DecodedURL.from_text(u"http://example.com/uri/") uri = uri.child(mut_cap.danger_real_capability_string(), u"foo") resp = http_client.get(uri.to_uri().to_text()) self.assertThat(resp, succeeded(MatchesStructure(code=Equals(200), ))) self.assertThat( resp.result.content(), succeeded(Equals(content)), )
def setUp(self): super(TestTahoeMonitor, self).setUp() self.root = create_fake_tahoe_root() self.http_client = create_tahoe_treq_client(self.root) self.tahoe_client = create_tahoe_client( DecodedURL.from_text(u"http://example.com"), self.http_client, ) self.node = self.useFixture(NodeDirectory(FilePath(self.mktemp()))) # when the "service" is run it wants to check shares-happy from Tahoe with self.node.tahoe_cfg.open("w") as f: f.write(b"[client]\nshares.happy = 1\n") self.basedir = FilePath(self.mktemp()) self.config = create_global_configuration( self.basedir, u"tcp:0", self.node.path, u"tcp:localhost:0", ) self.reactor = MemoryReactorClock() self.service = MagicFolderService( self.reactor, self.config, WebSocketStatusService(self.reactor, self.config), self.tahoe_client, )
def setUp(self): super(TestAdd, self).setUp() self.root = create_fake_tahoe_root() self.http_client = create_tahoe_treq_client(self.root) self.tahoe_client = create_tahoe_client( DecodedURL.from_text(u"http://example.com"), self.http_client, ) self.magic_dir = FilePath(self.mktemp()) self.magic_dir.makedirs() self.node = self.useFixture(NodeDirectory(FilePath(self.mktemp()))) self.basedir = FilePath(self.mktemp()) self.config = create_global_configuration( self.basedir, u"tcp:5555", self.node.path, u"tcp:localhost:5555", ) clock = Clock() self.service = MagicFolderService( clock, self.config, WebSocketStatusService(clock, self.config), self.tahoe_client, )
def test_duplicate_upload(self, content): """ Upload the same content (via 'PUT /uri') twice """ http_client = create_tahoe_treq_client() @inlineCallbacks def do_test(): resp = yield http_client.put("http://example.com/uri", content) self.assertEqual(resp.code, 201) cap_raw = yield resp.content() self.assertThat( cap_raw, AfterPreprocessing( from_string, IsInstance(CHKFileURI) ) ) resp = yield http_client.put("http://example.com/uri", content) self.assertThat(resp.code, Equals(200)) self.assertThat( do_test(), succeeded(Always()), )
def test_create_and_download(self, content): """ Upload some content (via 'PUT /uri') and then download it (via 'GET /uri?uri=...') """ http_client = create_tahoe_treq_client() @inlineCallbacks def do_test(): resp = yield http_client.put("http://example.com/uri", content) self.assertThat(resp.code, Equals(201)) cap_raw = yield resp.content() cap = from_string(cap_raw) self.assertThat(cap, IsInstance(CHKFileURI)) resp = yield http_client.get( "http://example.com/uri?uri={}".format(cap.to_string())) self.assertThat(resp.code, Equals(200)) round_trip_content = yield resp.content() # using the form "/uri/<cap>" is also valid resp = yield http_client.get("http://example.com/uri/{}".format( cap.to_string())) self.assertEqual(resp.code, 200) round_trip_content = yield resp.content() self.assertEqual(content, round_trip_content) self.assertThat( do_test(), succeeded(Always()), )
def setup_example(self): self.root = create_fake_tahoe_root() self.http_client = create_tahoe_treq_client(self.root) self.tahoe_client = create_tahoe_client( DecodedURL.from_text(u"http://example.com"), self.http_client, ) self.alice = create_local_author(u"alice") self.stash_dir = FilePath(mktemp()) self.stash_dir.makedirs() # 'trial' will delete this when done
def test_download_no_arg(self): """ Error if we GET from "/uri" with no ?uri= query-arg """ http_client = create_tahoe_treq_client() uri = DecodedURL.from_text(u"http://example.com/uri/") resp = http_client.get(uri.to_uri().to_text()) self.assertThat(resp, succeeded(MatchesStructure(code=Equals(400))))
def test_download_missing(self): """ If a capability is requested for which the stored cyphertext cannot be located, **GET /uri?uri=CAP** returns a GONE response code. """ http_client = create_tahoe_treq_client() cap_gen = capability_generator("URI:CHK:") uri = DecodedURL.from_text(u"http://example.com/uri?uri={}".format( next(cap_gen))) resp = http_client.get(uri.to_uri().to_text()) self.assertThat(resp, succeeded(MatchesStructure(code=Equals(GONE), )))