From a14cee5cce616a5490f64f1aa71ba9106c3e3270 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Thu, 9 Apr 2020 15:09:58 -0400 Subject: [PATCH 1/4] Remove nevow from allmydata.web.root.IncidentReporter This change calls for an explanation: - `RenderMixin` doesn't seem to be adding anything here, so it is gone. - The web browser was unhappy without a charset in the response (Firefox 74 was anyway), so `content-type` header also gets a `charset=UTF-8`. - Returning a Unicode string made nevow appserver unhappy, so it is just a `str`. The precise error message was: exceptions.TypeError: ('Could not adapt', u'An incident report has been saved to logs/incidents/ in the node directory.', ) Fixes: ticket:3294 --- newsfragments/3294.minor | 0 src/allmydata/web/root.py | 13 +++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 newsfragments/3294.minor diff --git a/newsfragments/3294.minor b/newsfragments/3294.minor new file mode 100644 index 000000000..e69de29bb diff --git a/src/allmydata/web/root.py b/src/allmydata/web/root.py index 8726cb00f..95c80994e 100644 --- a/src/allmydata/web/root.py +++ b/src/allmydata/web/root.py @@ -28,7 +28,7 @@ from allmydata.web.common import ( WebError, get_arg, MultiFormatPage, - RenderMixin, + MultiFormatResource, get_format, get_mutable_type, render_time_delta, @@ -169,14 +169,15 @@ class FileHandler(rend.Page): raise WebError("/file must be followed by a file-cap and a name", http.NOT_FOUND) -class IncidentReporter(RenderMixin, rend.Page): - def render_POST(self, ctx): - req = IRequest(ctx) +class IncidentReporter(MultiFormatResource): + """Handler for /report_incident POST request""" + + def render(self, req): log.msg(format="User reports incident through web page: %(details)s", details=get_arg(req, "details", ""), level=log.WEIRD, umid="LkD9Pw") - req.setHeader("content-type", "text/plain") - return "An incident report has been saved to logs/incidents/ in the node directory." + req.setHeader("content-type", "text/plain; charset=UTF-8") + return b"An incident report has been saved to logs/incidents/ in the node directory." SPACE = u"\u00A0"*2 From 497a832ad920e47ef71608a953ba950430719ce5 Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Thu, 9 Apr 2020 15:54:33 -0400 Subject: [PATCH 2/4] Use Twisted < 20.0.0 Twisted 20.3.0 has dropped Python 2.7 support, so we need to stick to the prior release as long as we use Python 2.7. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index caa37f16e..17ae09295 100644 --- a/setup.py +++ b/setup.py @@ -98,7 +98,7 @@ install_requires = [ # `pip install tahoe-lafs[sftp]` would not install requirements # specified by Twisted[conch]. Since this would be the *whole point* of # an sftp extra in Tahoe-LAFS, there is no point in having one. - "Twisted[tls,conch] >= 18.4.0", + "Twisted[tls,conch] >= 18.4.0, < 20.0.0", # We need Nevow >= 0.11.1 which can be installed using pip. "Nevow >= 0.11.1", From 15131a9f71da04c448b9fc707556a77ce18f836d Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Tue, 14 Apr 2020 16:10:20 -0400 Subject: [PATCH 3/4] Handle just POST requests in IncidentReporter --- src/allmydata/web/root.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/allmydata/web/root.py b/src/allmydata/web/root.py index 95c80994e..06d02efbc 100644 --- a/src/allmydata/web/root.py +++ b/src/allmydata/web/root.py @@ -173,6 +173,9 @@ class IncidentReporter(MultiFormatResource): """Handler for /report_incident POST request""" def render(self, req): + if req.method != "POST": + raise WebError("/report_incident can only be used with POST") + log.msg(format="User reports incident through web page: %(details)s", details=get_arg(req, "details", ""), level=log.WEIRD, umid="LkD9Pw") From 73938ad446bff329864fd82f03e7d3b5ebf503ff Mon Sep 17 00:00:00 2001 From: Sajith Sasidharan Date: Thu, 16 Apr 2020 13:30:08 -0400 Subject: [PATCH 4/4] Drop upper bound on Twisted version CI broke build because CI was broke; the new Twisted release wasn't the problem. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 17ae09295..caa37f16e 100644 --- a/setup.py +++ b/setup.py @@ -98,7 +98,7 @@ install_requires = [ # `pip install tahoe-lafs[sftp]` would not install requirements # specified by Twisted[conch]. Since this would be the *whole point* of # an sftp extra in Tahoe-LAFS, there is no point in having one. - "Twisted[tls,conch] >= 18.4.0, < 20.0.0", + "Twisted[tls,conch] >= 18.4.0", # We need Nevow >= 0.11.1 which can be installed using pip. "Nevow >= 0.11.1",