2020-06-13 04:04:03 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Tahoe-LAFS -- secure, distributed storage grid
|
|
|
|
#
|
|
|
|
# Copyright © 2020 The Tahoe-LAFS Software Foundation
|
|
|
|
#
|
|
|
|
# This file is part of Tahoe-LAFS.
|
|
|
|
#
|
|
|
|
# See the docs/about.rst file for licensing information.
|
|
|
|
|
|
|
|
"""
|
|
|
|
Tests for the allmydata.testing helpers
|
|
|
|
"""
|
|
|
|
|
2020-06-11 20:14:42 +00:00
|
|
|
from twisted.internet.defer import (
|
|
|
|
inlineCallbacks,
|
|
|
|
)
|
|
|
|
|
2020-06-13 04:57:38 +00:00
|
|
|
from allmydata.uri import (
|
|
|
|
from_string,
|
|
|
|
CHKFileURI,
|
|
|
|
)
|
2020-06-11 20:14:42 +00:00
|
|
|
from allmydata.testing.web import (
|
|
|
|
create_tahoe_treq_client,
|
|
|
|
)
|
|
|
|
|
2020-06-13 04:04:12 +00:00
|
|
|
from hypothesis import (
|
|
|
|
given,
|
|
|
|
)
|
|
|
|
from hypothesis.strategies import (
|
|
|
|
binary,
|
|
|
|
)
|
|
|
|
|
|
|
|
from testtools import (
|
|
|
|
TestCase,
|
|
|
|
)
|
|
|
|
from testtools.matchers import (
|
|
|
|
Always,
|
|
|
|
)
|
|
|
|
from testtools.twistedsupport import (
|
|
|
|
succeeded,
|
|
|
|
)
|
|
|
|
|
2020-06-11 20:14:42 +00:00
|
|
|
|
|
|
|
class FakeWebTest(TestCase):
|
|
|
|
"""
|
|
|
|
Test the WebUI verified-fakes infrastucture
|
|
|
|
"""
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(FakeWebTest, self).setUp()
|
|
|
|
self.http_client = create_tahoe_treq_client()
|
|
|
|
|
2020-06-13 04:04:12 +00:00
|
|
|
@given(
|
|
|
|
content=binary(),
|
|
|
|
)
|
|
|
|
def test_create_and_download(self, content):
|
2020-06-11 20:14:42 +00:00
|
|
|
"""
|
2020-06-13 04:04:12 +00:00
|
|
|
Upload some content (via 'PUT /uri') and then download it (via
|
|
|
|
'GET /uri?uri=...')
|
2020-06-11 20:14:42 +00:00
|
|
|
"""
|
|
|
|
|
2020-06-13 04:04:12 +00:00
|
|
|
@inlineCallbacks
|
|
|
|
def do_test():
|
2020-06-13 07:55:14 +00:00
|
|
|
resp = yield self.http_client.put("http://example.com/uri?replace=true", content)
|
2020-06-13 04:08:36 +00:00
|
|
|
self.assertEqual(resp.code, 201)
|
2020-06-11 20:14:42 +00:00
|
|
|
|
2020-06-13 04:57:38 +00:00
|
|
|
cap_raw = yield resp.content()
|
|
|
|
cap = from_string(cap_raw)
|
|
|
|
self.assertIsInstance(cap, CHKFileURI)
|
2020-06-11 20:14:42 +00:00
|
|
|
|
2020-06-13 04:04:12 +00:00
|
|
|
resp = yield self.http_client.get(
|
2020-06-13 04:57:38 +00:00
|
|
|
"http://example.com/uri?uri={}".format(cap.to_string())
|
2020-06-13 04:04:12 +00:00
|
|
|
)
|
|
|
|
self.assertEqual(resp.code, 200)
|
|
|
|
|
|
|
|
round_trip_content = yield resp.content()
|
|
|
|
self.assertEqual(content, round_trip_content)
|
|
|
|
self.assertThat(
|
|
|
|
do_test(),
|
|
|
|
succeeded(Always()),
|
|
|
|
)
|
2020-06-13 07:55:14 +00:00
|
|
|
|
|
|
|
@inlineCallbacks
|
|
|
|
def test_duplicate_upload(self):
|
|
|
|
"""
|
|
|
|
Upload the same content (via 'PUT /uri') twice with no overwrite
|
|
|
|
"""
|
|
|
|
|
|
|
|
content = "fake content\n" * 200
|
|
|
|
|
|
|
|
resp = yield self.http_client.put("http://example.com/uri", content)
|
|
|
|
self.assertEqual(resp.code, 201)
|
|
|
|
|
|
|
|
cap_raw = yield resp.content()
|
|
|
|
cap = from_string(cap_raw)
|
|
|
|
self.assertIsInstance(cap, CHKFileURI)
|
|
|
|
|
|
|
|
# this one fails: same content but no ?replace=true
|
|
|
|
resp = yield self.http_client.put("http://example.com/uri", content)
|
|
|
|
self.assertEqual(resp.code, 409)
|