11import shutil , errno , pytest , json , gzip , mimetypes , os , re
22
3+ from roundup import date as rdate
34from roundup import i18n
45from roundup import password
56from roundup .anypy .strings import b2s
@@ -94,6 +95,11 @@ def setup_class(cls):
9495 # also used for text searching.
9596 result = cls .db .issue .create (title = "foo bar RESULT" )
9697
98+ # add a message to allow retrieval
99+ result = cls .db .msg .create (author = "1" ,
100+ content = "a message foo bar RESULT" ,
101+ date = rdate .Date (),
102+ messageid = "test-msg-id" )
97103 cls .db .commit ()
98104 cls .db .close ()
99105
@@ -191,12 +197,14 @@ def test_start_in_german(self):
191197 self .assertTrue (b'dauerhaft anmelden?' in f .content )
192198
193199 def test_byte_Ranges (self ):
194- """ Roundup only handles one simple two number range.
200+ """ Roundup only handles one simple two number range, or
201+ a single number to start from:
195202 Range: 10-20
203+ Range: 10-
196204
197- The following are not supported.
205+ The following is not supported.
198206 Range: 10-20, 25-30
199- Range: 10-
207+ Range: -10
200208
201209 Also If-Range only supports strong etags not dates or weak etags.
202210
@@ -220,7 +228,27 @@ def test_byte_Ranges(self):
220228 self .assertEqual (f .headers ['content-range' ],
221229 "bytes 0-10/%s" % expected_length )
222230
231+ # get bytes 11-21 unconditionally (0 index really??)
232+ hdrs = {"Range" : "bytes=10-20" }
233+ f = requests .get (self .url_base () + "/@@file/style.css" , headers = hdrs )
234+ self .assertEqual (f .status_code , 206 )
235+ self .assertEqual (f .content , b"ge styles *" )
236+ # compression disabled for length < 100, so we can use 11 here
237+ self .assertEqual (f .headers ['content-length' ], '11' )
238+ self .assertEqual (f .headers ['content-range' ],
239+ "bytes 10-20/%s" % expected_length )
240+
241+ # get all bytest starting from 11
242+ hdrs = {"Range" : "bytes=11-" }
243+ f = requests .get (self .url_base () + "/@@file/style.css" , headers = hdrs )
244+ self .assertEqual (f .status_code , 206 )
245+ self .assertEqual (f .headers ['content-range' ],
246+ "bytes 11-%s/%s" % (int (expected_length ) - 1 ,
247+ expected_length ))
248+ self .assertIn ("SHA:" , f .content ) # detect sha sum at end of file
249+
223250 # conditional request 11 bytes since etag matches 206 code
251+ hdrs = {"Range" : "bytes=0-10" }
224252 hdrs ['If-Range' ] = etag
225253 f = requests .get (self .url_base () + "/@@file/style.css" , headers = hdrs )
226254 self .assertEqual (f .status_code , 206 )
@@ -262,7 +290,98 @@ def test_byte_Ranges(self):
262290 self .assertEqual (f .status_code , 416 )
263291 self .assertEqual (f .headers ['content-range' ],
264292 "bytes */%s" % expected_length )
265-
293+
294+ # invalid range multiple ranges
295+ hdrs ['Range' ] = "bytes=0-10, 20-45"
296+ print (hdrs )
297+ f = requests .get (self .url_base () + "/@@file/style.css" , headers = hdrs )
298+ self .assertEqual (f .status_code , 200 )
299+ self .assertNotIn ('content-range' , f .headers ,
300+ 'content-range should not be present' )
301+ self .assertIn ("SHA:" , f .content ) # detect sha sum at end of file
302+
303+ # invalid range is single number not number followed by -
304+ hdrs ['Range' ] = "bytes=1"
305+ print (hdrs )
306+ f = requests .get (self .url_base () + "/@@file/style.css" , headers = hdrs )
307+ self .assertEqual (f .status_code , 200 )
308+ self .assertNotIn ('content-range' , f .headers ,
309+ 'content-range should not be present' )
310+ self .assertIn ("SHA:" , f .content ) # detect sha sum at end of file
311+
312+ # range is invalid first number not a number
313+ hdrs ['Range' ] = "bytes=boom-99" # bad first value
314+ print (hdrs )
315+ f = requests .get (self .url_base () + "/@@file/style.css" , headers = hdrs )
316+ self .assertEqual (f .status_code , 200 )
317+ self .assertNotIn ('content-range' , f .headers ,
318+ 'content-range should not be present' )
319+ self .assertIn ("SHA:" , f .content ) # detect sha sum at end of file
320+
321+ # range is invalid last number not a number
322+ hdrs ['Range' ] = "bytes=1-boom" # bad last value
323+ print (hdrs )
324+ f = requests .get (self .url_base () + "/@@file/style.css" , headers = hdrs )
325+ self .assertEqual (f .status_code , 200 )
326+ self .assertNotIn ('content-range' , f .headers ,
327+ 'content-range should not be present' )
328+ self .assertIn ("SHA:" , f .content ) # detect sha sum at end of file
329+
330+ # range is invalid first position empty
331+ hdrs ['Range' ] = "bytes=-11" # missing first value
332+ print (hdrs )
333+ f = requests .get (self .url_base () + "/@@file/style.css" , headers = hdrs )
334+ self .assertEqual (f .status_code , 200 )
335+ self .assertNotIn ('content-range' , f .headers ,
336+ 'content-range should not be present' )
337+ self .assertIn ("SHA:" , f .content ) # detect sha sum at end of file
338+
339+ # range is invalid #2 < #1
340+ hdrs ['Range' ] = "bytes=11-1" # inverted range
341+ print (hdrs )
342+ f = requests .get (self .url_base () + "/@@file/style.css" , headers = hdrs )
343+ self .assertEqual (f .status_code , 200 )
344+ self .assertNotIn ('content-range' , f .headers ,
345+ 'content-range should not be present' )
346+ self .assertIn ("SHA:" , f .content ) # detect sha sum at end of file
347+
348+ # range is invalid negative first number
349+ hdrs ['Range' ] = "bytes=-1-11" # negative first number
350+ print (hdrs )
351+ f = requests .get (self .url_base () + "/@@file/style.css" , headers = hdrs )
352+ self .assertEqual (f .status_code , 200 )
353+ self .assertNotIn ('content-range' , f .headers ,
354+ 'content-range should not be present' )
355+ self .assertIn ("SHA:" , f .content ) # detect sha sum at end of file
356+
357+ # range is invalid negative second number
358+ hdrs ['Range' ] = "bytes=1--11" # negative second number
359+ print (hdrs )
360+ f = requests .get (self .url_base () + "/@@file/style.css" , headers = hdrs )
361+ self .assertEqual (f .status_code , 200 )
362+ self .assertNotIn ('content-range' , f .headers ,
363+ 'content-range should not be present' )
364+ self .assertIn ("SHA:" , f .content ) # detect sha sum at end of file
365+
366+ # range is unsupported units
367+ hdrs ['Range' ] = "badunits=1-11"
368+ print (hdrs )
369+ f = requests .get (self .url_base () + "/@@file/style.css" , headers = hdrs )
370+ self .assertEqual (f .status_code , 200 )
371+ self .assertNotIn ('content-range' , f .headers ,
372+ 'content-range should not be present' )
373+ self .assertIn ("SHA:" , f .content ) # detect sha sum at end of file
374+
375+
376+ # valid range, invalid file
377+ hdrs ['Range' ] = "bytes=0-11"
378+ print (hdrs )
379+ f = requests .get (self .url_base () + "/@@file/style_nope.css" ,
380+ headers = hdrs )
381+ self .assertEqual (f .status_code , 404 )
382+ self .assertNotIn ('content-range' , f .headers ,
383+ 'content-range should not be present' )
384+
266385 def test_rest_preflight_collection (self ):
267386 # no auth for rest csrf preflight
268387 f = requests .options (self .url_base () + '/rest/data/user' ,
@@ -562,7 +681,22 @@ def test_ims(self):
562681
563682
564683 def test_load_issue1 (self ):
565- f = requests .get (self .url_base () + '/issue1>' ,
684+ import pdb ; pdb .set_trace ()
685+ for tail in [
686+ '/issue1' , # normal url
687+ '/issue00001' , # leading 0's should be stripped from id
688+ '/issue1>' # surprise this works too, should it??
689+ ]:
690+ f = requests .get (self .url_base () + tail ,
691+ headers = { 'Accept-Encoding' : 'gzip' ,
692+ 'Accept' : '*/*' })
693+
694+ self .assertIn (b'foo bar RESULT' , f .content )
695+ self .assertEqual (f .status_code , 200 )
696+
697+ def test_load_msg1 (self ):
698+ # leading 0's should be stripped from id
699+ f = requests .get (self .url_base () + '/msg0001' ,
566700 headers = { 'Accept-Encoding' : 'gzip' ,
567701 'Accept' : '*/*' })
568702
@@ -1173,6 +1307,12 @@ def setup_class(cls):
11731307
11741308 result = cls .db .issue .create (title = "foo bar RESULT" )
11751309
1310+ # add a message to allow retrieval
1311+ result = cls .db .msg .create (author = "1" ,
1312+ content = "a message foo bar RESULT" ,
1313+ date = rdate .Date (),
1314+ messageid = "test-msg-id" )
1315+
11761316 cls .db .commit ()
11771317 cls .db .close ()
11781318
0 commit comments