Changeset 10029 for main/waeup.kofa/trunk
- Timestamp:
- 15 Mar 2013, 07:39:09 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/browser
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py
r10027 r10029 73 73 from waeup.kofa.students.export import EXPORTER_NAMES as STUDENT_EXPORTERS 74 74 75 FORBIDDEN_CHARACTERS = (160,) 76 75 77 grok.context(IKofaObject) 76 78 grok.templatedir('templates') … … 1043 1045 logger = self.context.logger 1044 1046 1045 # XXX: temporary solution to prevent users from 1046 # uploading non-ascii files. 1047 #for element in filecontent: 1048 # try: 1049 # if ord(element) > 128: 1050 # self.flash(_( 1051 # "Only ASCII files are allowed. " 1052 # "Your file contains non-ASCII characters.")) 1053 # logger.info('%s - non-ascii file uploaded: %s' % 1054 # (ob_class, target)) 1055 # return 1056 # except TypeError: 1057 # self.flash(_( 1058 # "Only ASCII files are allowed. " 1059 # "Your file contains non-ASCII characters.")) 1060 # logger.info('%s - non-ascii file uploaded: %s' % 1061 # (ob_class, target)) 1062 # return 1047 # Forbid certain characters in import files. 1048 for element in filecontent: 1049 try: 1050 if ord(element) in FORBIDDEN_CHARACTERS: 1051 self.flash(_( 1052 "Your file contains forbidden characters. " 1053 "Please replace.")) 1054 logger.info('%s - invalid file uploaded: %s' % 1055 (ob_class, target)) 1056 return 1057 except TypeError: 1058 self.flash(_( 1059 "Your file contains forbidden characters. " 1060 "Please replace.")) 1061 logger.info('%s - invalid file uploaded: %s' % 1062 (ob_class, target)) 1063 return 1063 1064 1064 1065 open(target, 'wb').write(filecontent) -
main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_browser.py
r9843 r10029 36 36 37 37 SAMPLE_FILE = os.path.join(os.path.dirname(__file__), 'test_file.csv') 38 FORBIDDEN_FILE = os.path.join(os.path.dirname(__file__), 'forbidden_file.csv') 38 39 39 40 class UniversitySetup(FunctionalTestCase): … … 144 145 return 145 146 147 def test_forbidden_file_upload(self): 148 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 149 self.browser.open(self.datacenter_path) 150 self.assertEqual(self.browser.headers['Status'], '200 Ok') 151 self.assertEqual(self.browser.url, self.datacenter_path) 152 self.browser.getLink("Upload data").click() 153 file = open(FORBIDDEN_FILE) 154 ctrl = self.browser.getControl(name='uploadfile:file') 155 file_ctrl = ctrl.mech_control 156 file_ctrl.add_file(file, filename='my_corrupted_file.csv') 157 self.browser.getControl('Upload').click() 158 self.assertTrue( 159 'Your file contains forbidden characters. Please replace.' 160 in self.browser.contents) 161 logfile = os.path.join( 162 self.app['datacenter'].storage, 'logs', 'datacenter.log') 163 logcontent = open(logfile).read() 164 self.assertTrue('zope.mgr - browser.pages.DatacenterUploadPage - ' 165 'invalid file uploaded:' in logcontent) 166 return 146 167 147 168 class DataCenterUIExportTests(UniversitySetup, FunctionalAsyncTestCase):
Note: See TracChangeset for help on using the changeset viewer.