Skip to content

Commit 300f717

Browse files
fix: avoid needlessly blocking import of session minutes (ietf-tools#3761)
Fixes ietf-tools#3558
1 parent fb41207 commit 300f717

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

ietf/meeting/tests_views.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6109,17 +6109,47 @@ def test_refuses_identical_import(self):
61096109
kwargs={'num': self.meeting.number, 'session_id': self.session.pk})
61106110

61116111
self.client.login(username='secretary', password='secretary+password')
6112-
r = self.client.post(url, {'markdown_text': 'original markdown text'}) # create a rev
6113-
self.assertEqual(r.status_code, 302)
61146112
with requests_mock.Mocker() as mock:
61156113
mock.get(f'https://notes.ietf.org/{self.session.notes_id()}/download', text='original markdown text')
61166114
mock.get(f'https://notes.ietf.org/{self.session.notes_id()}/info',
61176115
text=json.dumps({"title": "title", "updatetime": "2021-12-02T11:22:33z"}))
6116+
# Create a revision. Run the original text through the preprocessing done when importing
6117+
# from the notes site.
6118+
r = self.client.get(url) # let GET do its preprocessing
6119+
q = PyQuery(r.content)
6120+
r = self.client.post(url, {'markdown_text': q('input[name="markdown_text"]').attr['value']})
6121+
self.assertEqual(r.status_code, 302)
6122+
61186123
r = self.client.get(url) # try to import the same text
61196124
self.assertContains(r, "This document is identical", status_code=200)
61206125
q = PyQuery(r.content)
61216126
self.assertEqual(len(q('button:disabled[type="submit"]')), 1)
6122-
self.assertEqual(len(q('button:not(:disabled)[type="submit"]')), 0)
6127+
self.assertEqual(len(q('button:enabled[type="submit"]')), 0)
6128+
6129+
def test_allows_import_on_existing_bad_unicode(self):
6130+
"""Should not be able to import text identical to the current revision"""
6131+
url = urlreverse('ietf.meeting.views.import_session_minutes',
6132+
kwargs={'num': self.meeting.number, 'session_id': self.session.pk})
6133+
6134+
self.client.login(username='secretary', password='secretary+password')
6135+
r = self.client.post(url, {'markdown_text': 'replaced below'}) # create a rev
6136+
with open(
6137+
self.session.sessionpresentation_set.filter(document__type="minutes").first().document.get_file_name(),
6138+
'wb'
6139+
) as f:
6140+
# Replace existing content with an invalid Unicode byte string. The particular invalid
6141+
# values here are accented characters in the MacRoman charset (see ticket #3756).
6142+
f.write(b'invalid \x8e unicode \x99\n')
6143+
self.assertEqual(r.status_code, 302)
6144+
with requests_mock.Mocker() as mock:
6145+
mock.get(f'https://notes.ietf.org/{self.session.notes_id()}/download', text='original markdown text')
6146+
mock.get(f'https://notes.ietf.org/{self.session.notes_id()}/info',
6147+
text=json.dumps({"title": "title", "updatetime": "2021-12-02T11:22:33z"}))
6148+
r = self.client.get(url) # try to import the same text
6149+
self.assertNotContains(r, "This document is identical", status_code=200)
6150+
q = PyQuery(r.content)
6151+
self.assertEqual(len(q('button:enabled[type="submit"]')), 1)
6152+
self.assertEqual(len(q('button:disabled[type="submit"]')), 0)
61236153

61246154
def test_handles_missing_previous_revision_file(self):
61256155
"""Should still allow import if the file for the previous revision is missing"""

ietf/meeting/views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4169,11 +4169,11 @@ def import_session_minutes(request, session_id, num):
41694169
if current_minutes:
41704170
try:
41714171
with open(current_minutes.get_file_name()) as f:
4172-
if import_contents == Note.preprocess_source(f.read()):
4172+
if import_contents == f.read():
41734173
contents_changed = False
41744174
messages.warning(request, 'This document is identical to the current revision, no need to import.')
4175-
except FileNotFoundError:
4176-
pass # allow import if the file is missing
4175+
except Exception:
4176+
pass # Do not let a failure here prevent minutes from being updated.
41774177

41784178
return render(
41794179
request,

0 commit comments

Comments
 (0)