1818from roundup .cgi .templating import HTMLProperty , _HTMLItem , anti_csrf_nonce
1919from roundup .cgi .form_parser import FormParser
2020from roundup import init , instance , password , hyperdb , date
21- from roundup .anypy .strings import StringIO , u2s
21+ from roundup .anypy .strings import StringIO , u2s , b2s
2222
2323# For testing very simple rendering
2424from roundup .cgi .engine_zopetal import RoundupPageTemplate
@@ -1031,6 +1031,7 @@ def hasPermission(s, p, classname=None, d=None, e=None, **kw):
10311031 #raise ValueError
10321032
10331033 def testRestCsrfProtection (self ):
1034+ import json
10341035 # set the password for admin so we can log in.
10351036 passwd = password .Password ('admin' )
10361037 self .db .user .set ('1' , password = passwd )
@@ -1044,7 +1045,7 @@ def wh(s):
10441045 form .list = [
10451046 cgi .MiniFieldStorage ('title' , 'A new issue' ),
10461047 cgi .MiniFieldStorage ('status' , '1' ),
1047- cgi .MiniFieldStorage ('pretty' , 'false' ),
1048+ cgi .MiniFieldStorage ('@ pretty' , 'false' ),
10481049 cgi .MiniFieldStorage ('@apiver' , '1' ),
10491050 ]
10501051 cl = client .Client (self .instance , None ,
@@ -1069,7 +1070,7 @@ def wh(s):
10691070 # Should return explanation because content type is text/plain
10701071 # and not text/xml
10711072 cl .handle_rest ()
1072- self .assertEqual (out [0 ], "<class 'roundup.exceptions.UsageError'>: Required Header Missing\n " )
1073+ self .assertEqual (b2s ( out [0 ]) , "<class 'roundup.exceptions.UsageError'>: Required Header Missing\n " )
10731074 del (out [0 ])
10741075
10751076 cl = client .Client (self .instance , None ,
@@ -1094,7 +1095,10 @@ def wh(s):
10941095
10951096 # Should work as all required headers are present.
10961097 cl .handle_rest ()
1097- self .assertEqual (out [0 ], '{"data": {"link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1", "id": "1"}}\n ' )
1098+ answer = '{"data": {"link": "http://tracker.example/cgi-bin/roundup.cgi/bugs/rest/data/issue/1", "id": "1"}}\n '
1099+ response = json .loads (b2s (out [0 ]))
1100+ expected = json .loads (answer )
1101+ self .assertEqual (response ,expected )
10981102 del (out [0 ])
10991103
11001104 def testXmlrpcCsrfProtection (self ):
0 commit comments