-
Notifications
You must be signed in to change notification settings - Fork 343
Unbreak unit tests with Twisted 25.5.0
by add parsePOSTFormSubmission
arg to FakeSite
#18577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Twisted's `Site` exposes `_parsePOSTFormSubmission` which is accessed by `Request` during initialisation (since Twisted 25.5.0). Provide the same attribute so that tests remain compatible across Twisted versions.
Otherwise they end up overrunning Twisted’s AMP protocol message size and raising a `TooLong` error.
6f26c31
to
b3ddde3
Compare
@@ -226,8 +226,7 @@ | |||
isLeaf = True | |||
|
|||
def render(self, request: SynapseRequest) -> bytes: | |||
# Type-ignore: mypy thinks request.path is Optional[Any], not bytes. | |||
return request.path # type: ignore[return-value] | |||
return request.path |
Check warning
Code scanning / CodeQL
Reflected server-side cross-site scripting Medium test
user-provided value
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
To fix the issue, we need to escape the request.path
value before returning it in the render
method of the DummyResource
class. This ensures that any potentially malicious input is properly sanitized and cannot execute as part of an HTML response. The html.escape()
function from Python's standard library is suitable for this purpose, as it escapes special characters like <
, >
, and &
.
The changes will be made in the render
method of the DummyResource
class in the OptionsResourceTests
test case. Specifically:
- Import the
html
module to use thehtml.escape()
function. - Modify the
render
method to escaperequest.path
before returning it.
-
Copy modified lines R229-R230
@@ -228,3 +228,4 @@ | ||
def render(self, request: SynapseRequest) -> bytes: | ||
return request.path | ||
from html import escape | ||
return escape(request.path.decode()).encode() | ||
|
Twisted's
Site
exposes_parsePOSTFormSubmission
which is accessed byRequest
during initialisation (since Twisted 25.5.0, https://github.com/twisted/twisted/pull/12413/files#diff-6c8252af78a4a1c3cdfd2474b7349fb479c0e0a308a8336e4ddab729f55df9baR802).Provide the same attribute so that tests remain compatible across Twisted versions.
Fixes #18565.
Pull Request Checklist
EventStore
toEventWorkerStore
.".code blocks
.