comparison test/test_cgi.py @ 5162:3ee79a2d95d4

rename clean_url method to examine_url. the method doesn't realy clean anything, it throws a ValueError if it finds a problem
author John Rouillard <rouilj@ieee.org>
date Sat, 23 Jul 2016 15:22:06 -0400
parents 12190efa30d4
children 232c74973a56
comparison
equal deleted inserted replaced
5161:12190efa30d4 5162:3ee79a2d95d4
1171 result = self.client.renderContext() 1171 result = self.client.renderContext()
1172 self.assertNotEqual(-1, result.index('<title>User listing - Roundup issue tracker</title>')) 1172 self.assertNotEqual(-1, result.index('<title>User listing - Roundup issue tracker</title>'))
1173 self.assertNotEqual(-1, result.index('ok message')) 1173 self.assertNotEqual(-1, result.index('ok message'))
1174 # print result 1174 # print result
1175 1175
1176 def testclean_url(self): 1176 def testexamine_url(self):
1177 ''' test the clean_url function ''' 1177 ''' test the examine_url function '''
1178
1179 def te(url, exception, raises=ValueError):
1180 with self.assertRaises(raises) as cm:
1181 examine_url(url)
1182 self.assertEqual(cm.exception.message, exception)
1183
1184
1178 action = actions.Action(self.client) 1185 action = actions.Action(self.client)
1179 clean_url = action.clean_url 1186 examine_url = action.examine_url
1180 1187
1181 # Christmas tree url: test of every component that passes 1188 # Christmas tree url: test of every component that passes
1182 self.assertEqual( 1189 self.assertEqual(
1183 clean_url("http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue"), 1190 examine_url("http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue"),
1184 'http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue') 1191 'http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue')
1185 1192
1186 # allow replacing http with https if base is http 1193 # allow replacing http with https if base is http
1187 self.assertEqual( 1194 self.assertEqual(
1188 clean_url("https://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue"), 1195 examine_url("https://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue"),
1189 'https://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue') 1196 'https://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue')
1190 1197
1191 1198
1192 # change base to use https and make sure we don't redirect to http 1199 # change base to use https and make sure we don't redirect to http
1193 saved_base = action.base 1200 saved_base = action.base
1194 action.base = "https://tracker.example/cgi-bin/roundup.cgi/bugs/" 1201 action.base = "https://tracker.example/cgi-bin/roundup.cgi/bugs/"
1195 with self.assertRaises(ValueError) as cm: 1202 te("http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue",
1196 clean_url("http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue") 1203 'Base url https://tracker.example/cgi-bin/roundup.cgi/bugs/ requires https. Redirect url http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue uses http.')
1197 self.assertEqual(cm.exception.message, 'Base url https://tracker.example/cgi-bin/roundup.cgi/bugs/ requires https. Redirect url http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue uses http.')
1198 action.base = saved_base 1204 action.base = saved_base
1199 1205
1200 # url doesn't have to be valid to roundup, just has to be contained 1206 # url doesn't have to be valid to roundup, just has to be contained
1201 # inside of roundup. No zoik class is defined 1207 # inside of roundup. No zoik class is defined
1202 self.assertEqual(clean_url("http://tracker.example/cgi-bin/roundup.cgi/bugs/zoik7;parm=bar?@template=foo&parm=(zot)#issue"), "http://tracker.example/cgi-bin/roundup.cgi/bugs/zoik7;parm=bar?@template=foo&parm=(zot)#issue") 1208 self.assertEqual(examine_url("http://tracker.example/cgi-bin/roundup.cgi/bugs/zoik7;parm=bar?@template=foo&parm=(zot)#issue"), "http://tracker.example/cgi-bin/roundup.cgi/bugs/zoik7;parm=bar?@template=foo&parm=(zot)#issue")
1203 1209
1204 # test with wonky schemes 1210 # test with wonky schemes
1205 with self.assertRaises(ValueError) as cm: 1211 te("email://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue",
1206 clean_url("email://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue"), 1212 'Unrecognized scheme in email://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue')
1207 self.assertEqual(cm.exception.message, 'Unrecognized scheme in email://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue') 1213
1208 1214 te("http%3a//tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue", 'Unrecognized scheme in http%3a//tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue')
1209 with self.assertRaises(ValueError) as cm:
1210 clean_url("http%3a//tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue"),
1211 self.assertEqual(cm.exception.message, 'Unrecognized scheme in http%3a//tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue')
1212 1215
1213 # test different netloc/path prefix 1216 # test different netloc/path prefix
1214 # assert port 1217 # assert port
1215 with self.assertRaises(ValueError) as cm: 1218 te("http://tracker.example:1025/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue",'Net location in http://tracker.example:1025/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue does not match base: tracker.example')
1216 clean_url("http://tracker.example:1025/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue"),
1217 self.assertEqual(cm.exception.message, 'Net location in http://tracker.example:1025/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue does not match base: tracker.example')
1218 1219
1219 #assert user 1220 #assert user
1220 with self.assertRaises(ValueError) as cm: 1221 te("http://user@tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue", 'Net location in http://user@tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue does not match base: tracker.example')
1221 clean_url("http://user@tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue"),
1222 self.assertEqual(cm.exception.message, 'Net location in http://user@tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue does not match base: tracker.example')
1223 1222
1224 #assert user:password 1223 #assert user:password
1225 with self.assertRaises(ValueError) as cm: 1224 te("http://user:pass@tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue", 'Net location in http://user:pass@tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue does not match base: tracker.example')
1226 clean_url("http://user:pass@tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue"),
1227 self.assertEqual(cm.exception.message, 'Net location in http://user:pass@tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue does not match base: tracker.example')
1228 1225
1229 # try localhost http scheme 1226 # try localhost http scheme
1230 with self.assertRaises(ValueError) as cm: 1227 te("http://localhost/cgi-bin/roundup.cgi/bugs/user3", 'Net location in http://localhost/cgi-bin/roundup.cgi/bugs/user3 does not match base: tracker.example')
1231 clean_url("http://localhost/cgi-bin/roundup.cgi/bugs/user3")
1232 self.assertEqual(cm.exception.message, 'Net location in http://localhost/cgi-bin/roundup.cgi/bugs/user3 does not match base: tracker.example')
1233 1228
1234 # try localhost https scheme 1229 # try localhost https scheme
1235 with self.assertRaises(ValueError) as cm: 1230 te("https://localhost/cgi-bin/roundup.cgi/bugs/user3", 'Net location in https://localhost/cgi-bin/roundup.cgi/bugs/user3 does not match base: tracker.example')
1236 clean_url("https://localhost/cgi-bin/roundup.cgi/bugs/user3")
1237 self.assertEqual(cm.exception.message, 'Net location in https://localhost/cgi-bin/roundup.cgi/bugs/user3 does not match base: tracker.example')
1238 1231
1239 # try different host 1232 # try different host
1240 with self.assertRaises(ValueError) as cm: 1233 te("http://bad.guys.are.us/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue", 'Net location in http://bad.guys.are.us/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue does not match base: tracker.example')
1241 clean_url("http://bad.guys.are.us/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue"),
1242 self.assertEqual(cm.exception.message, 'Net location in http://bad.guys.are.us/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#issue does not match base: tracker.example')
1243 1234
1244 # change the base path to .../bug from .../bugs 1235 # change the base path to .../bug from .../bugs
1245 with self.assertRaises(ValueError) as cm: 1236 te("http://tracker.example/cgi-bin/roundup.cgi/bug/user3;parm=bar?@template=foo&parm=(zot)#issue", 'Base path /cgi-bin/roundup.cgi/bugs/ is not a prefix for url http://tracker.example/cgi-bin/roundup.cgi/bug/user3;parm=bar?@template=foo&parm=(zot)#issue')
1246 clean_url("http://tracker.example/cgi-bin/roundup.cgi/bug/user3;parm=bar?@template=foo&parm=(zot)#issue"),
1247 self.assertEqual(cm.exception.message, 'Base path /cgi-bin/roundup.cgi/bugs/ is not a prefix for url http://tracker.example/cgi-bin/roundup.cgi/bug/user3;parm=bar?@template=foo&parm=(zot)#issue')
1248 1237
1249 # change the base path eliminate - in cgi-bin 1238 # change the base path eliminate - in cgi-bin
1250 with self.assertRaises(ValueError) as cm: 1239 te("http://tracker.example/cgibin/roundup.cgi/bug/user3;parm=bar?@template=foo&parm=(zot)#issue",'Base path /cgi-bin/roundup.cgi/bugs/ is not a prefix for url http://tracker.example/cgibin/roundup.cgi/bug/user3;parm=bar?@template=foo&parm=(zot)#issue')
1251 clean_url("http://tracker.example/cgibin/roundup.cgi/bug/user3;parm=bar?@template=foo&parm=(zot)#issue"),
1252 self.assertEqual(cm.exception.message, 'Base path /cgi-bin/roundup.cgi/bugs/ is not a prefix for url http://tracker.example/cgibin/roundup.cgi/bug/user3;parm=bar?@template=foo&parm=(zot)#issue')
1253 1240
1254 1241
1255 # scan for unencoded characters 1242 # scan for unencoded characters
1256 # we skip schema and net location since unencoded character 1243 # we skip schema and net location since unencoded character
1257 # are allowed only by an explicit match to a reference. 1244 # are allowed only by an explicit match to a reference.
1258 # 1245 #
1259 # break components with unescaped character '<' 1246 # break components with unescaped character '<'
1260 # path component 1247 # path component
1261 with self.assertRaises(ValueError) as cm: 1248 te("http://tracker.example/cgi-bin/roundup.cgi/bugs/<user3;parm=bar?@template=foo&parm=(zot)#issue", 'Path component (/cgi-bin/roundup.cgi/bugs/<user3) in http://tracker.example/cgi-bin/roundup.cgi/bugs/<user3;parm=bar?@template=foo&parm=(zot)#issue is not properly escaped')
1262 clean_url("http://tracker.example/cgi-bin/roundup.cgi/bugs/<user3;parm=bar?@template=foo&parm=(zot)#issue"),
1263 self.assertEqual(cm.exception.message, 'Path component (/cgi-bin/roundup.cgi/bugs/<user3) in http://tracker.example/cgi-bin/roundup.cgi/bugs/<user3;parm=bar?@template=foo&parm=(zot)#issue is not properly escaped')
1264 1249
1265 # params component 1250 # params component
1266 with self.assertRaises(ValueError) as cm: 1251 te("http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=b<ar?@template=foo&parm=(zot)#issue", 'Params component (parm=b<ar) in http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=b<ar?@template=foo&parm=(zot)#issue is not properly escaped')
1267 clean_url("http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=b<ar?@template=foo&parm=(zot)#issue"),
1268 self.assertEqual(cm.exception.message, 'Params component (parm=b<ar) in http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=b<ar?@template=foo&parm=(zot)#issue is not properly escaped')
1269 1252
1270 # query component 1253 # query component
1271 with self.assertRaises(ValueError) as cm: 1254 te("http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=<foo>&parm=(zot)#issue", 'Query component (@template=<foo>&parm=(zot)) in http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=<foo>&parm=(zot)#issue is not properly escaped')
1272 clean_url("http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=<foo>&parm=(zot)#issue"),
1273 self.assertEqual(cm.exception.message, 'Query component (@template=<foo>&parm=(zot)) in http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=<foo>&parm=(zot)#issue is not properly escaped')
1274 1255
1275 # fragment component 1256 # fragment component
1276 with self.assertRaises(ValueError) as cm: 1257 te("http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#iss<ue", 'Fragment component (iss<ue) in http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#iss<ue is not properly escaped')
1277 clean_url("http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#iss<ue"),
1278 self.assertEqual(cm.exception.message, 'Fragment component (iss<ue) in http://tracker.example/cgi-bin/roundup.cgi/bugs/user3;parm=bar?@template=foo&parm=(zot)#iss<ue is not properly escaped')
1279 1258
1280 class TemplateTestCase(unittest.TestCase): 1259 class TemplateTestCase(unittest.TestCase):
1281 ''' Test the template resolving code, i.e. what can be given to @template 1260 ''' Test the template resolving code, i.e. what can be given to @template
1282 ''' 1261 '''
1283 def setUp(self): 1262 def setUp(self):

Roundup Issue Tracker: http://roundup-tracker.org/