@@ -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"""
0 commit comments