Skip to content

Commit

Permalink
Format the way black likes it.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccacremona committed Jul 30, 2024
1 parent f873dbc commit d962c45
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions web/main/test/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,35 +370,31 @@ def test_annotated_export_invalid_clamped(annotations_factory):


def test_disallowed_images_stripped(rf, text_block_factory, resource_factory):
request = rf.get('/spoof-export-request')
request = rf.get("/spoof-export-request")

disallowed_srcs = [
'/etc/hosts',
'../../images/foo',
'http://example.com'
]
disallowed_srcs = ["/etc/hosts", "../../images/foo", "http://example.com"]

allowed_srcs = [
f"http://{request.get_host()}/foo",
f"https://{request.get_host()}/foo",
]

text = ''
text = ""
for src in itertools.chain(disallowed_srcs, allowed_srcs):
text = text + f'<img src="{src}">'

text_block = text_block_factory(content=text)
resource = resource_factory(resource=text_block, resource_type='TextBlock')
resource = resource_factory(resource=text_block, resource_type="TextBlock")

# Establish that all images are present in the unaltered HTML
unaltered_html = resource.export(False, None, file_type='html')
unaltered_html = resource.export(False, None, file_type="html")
for src in itertools.chain(disallowed_srcs, allowed_srcs):
assert src in unaltered_html

# Provide a spoofed `request` object which is a required argument for proper export of rich text
# https://github.com/harvard-lil/h2o/blob/dd67276720fe3a7af7e110da958448399a92399f/web/main/utils.py#L282
# Then, establish that only allowed image sources are present.
html = resource.export(False, None, file_type='html', export_options={"request": request})
html = resource.export(False, None, file_type="html", export_options={"request": request})
for src in disallowed_srcs:
assert src not in html
for src in allowed_srcs:
Expand Down

0 comments on commit d962c45

Please sign in to comment.