@@ -27,6 +27,30 @@ def testFlagPost(self):
2727 self .assertEqual (c .flags .filter (flag = CommentFlag .SUGGEST_REMOVAL ).count (), 1 )
2828 return c
2929
30+ def testFlagPostNext (self ):
31+ """
32+ POST the flag view, explicitly providing a next url.
33+ """
34+ comments = self .createSomeComments ()
35+ pk = comments [0 ].pk
36+ self .client .login (username = "normaluser" , password = "normaluser" )
37+ response = self .client .post ("/flag/%d/" % pk , {'next' : "/go/here/" })
38+ self .assertEqual (response ["Location" ],
39+ "http://testserver/go/here/?c=1" )
40+
41+ def testFlagPostUnsafeNext (self ):
42+ """
43+ POSTing to the flag view with an unsafe next url will ignore the
44+ provided url when redirecting.
45+ """
46+ comments = self .createSomeComments ()
47+ pk = comments [0 ].pk
48+ self .client .login (username = "normaluser" , password = "normaluser" )
49+ response = self .client .post ("/flag/%d/" % pk ,
50+ {'next' : "http://elsewhere/bad" })
51+ self .assertEqual (response ["Location" ],
52+ "http://testserver/flagged/?c=%d" % pk )
53+
3054 def testFlagPostTwice (self ):
3155 """Users don't get to flag comments more than once."""
3256 c = self .testFlagPost ()
@@ -46,7 +70,7 @@ def testFlagAnon(self):
4670 def testFlaggedView (self ):
4771 comments = self .createSomeComments ()
4872 pk = comments [0 ].pk
49- response = self .client .get ("/flagged/" , data = {"c" :pk })
73+ response = self .client .get ("/flagged/" , data = {"c" : pk })
5074 self .assertTemplateUsed (response , "comments/flagged.html" )
5175
5276 def testFlagSignals (self ):
@@ -98,6 +122,33 @@ def testDeletePost(self):
98122 self .assertTrue (c .is_removed )
99123 self .assertEqual (c .flags .filter (flag = CommentFlag .MODERATOR_DELETION , user__username = "normaluser" ).count (), 1 )
100124
125+ def testDeletePostNext (self ):
126+ """
127+ POSTing the delete view will redirect to an explicitly provided a next
128+ url.
129+ """
130+ comments = self .createSomeComments ()
131+ pk = comments [0 ].pk
132+ makeModerator ("normaluser" )
133+ self .client .login (username = "normaluser" , password = "normaluser" )
134+ response = self .client .post ("/delete/%d/" % pk , {'next' : "/go/here/" })
135+ self .assertEqual (response ["Location" ],
136+ "http://testserver/go/here/?c=1" )
137+
138+ def testDeletePostUnsafeNext (self ):
139+ """
140+ POSTing to the delete view with an unsafe next url will ignore the
141+ provided url when redirecting.
142+ """
143+ comments = self .createSomeComments ()
144+ pk = comments [0 ].pk
145+ makeModerator ("normaluser" )
146+ self .client .login (username = "normaluser" , password = "normaluser" )
147+ response = self .client .post ("/delete/%d/" % pk ,
148+ {'next' : "http://elsewhere/bad" })
149+ self .assertEqual (response ["Location" ],
150+ "http://testserver/deleted/?c=%d" % pk )
151+
101152 def testDeleteSignals (self ):
102153 def receive (sender , ** kwargs ):
103154 received_signals .append (kwargs .get ('signal' ))
@@ -113,13 +164,13 @@ def receive(sender, **kwargs):
113164 def testDeletedView (self ):
114165 comments = self .createSomeComments ()
115166 pk = comments [0 ].pk
116- response = self .client .get ("/deleted/" , data = {"c" :pk })
167+ response = self .client .get ("/deleted/" , data = {"c" : pk })
117168 self .assertTemplateUsed (response , "comments/deleted.html" )
118169
119170class ApproveViewTests (CommentTestCase ):
120171
121172 def testApprovePermissions (self ):
122- """The delete view should only be accessible to 'moderators'"""
173+ """The approve view should only be accessible to 'moderators'"""
123174 comments = self .createSomeComments ()
124175 pk = comments [0 ].pk
125176 self .client .login (username = "normaluser" , password = "normaluser" )
@@ -131,7 +182,7 @@ def testApprovePermissions(self):
131182 self .assertEqual (response .status_code , 200 )
132183
133184 def testApprovePost (self ):
134- """POSTing the delete view should mark the comment as removed"""
185+ """POSTing the approve view should mark the comment as removed"""
135186 c1 , c2 , c3 , c4 = self .createSomeComments ()
136187 c1 .is_public = False ; c1 .save ()
137188
@@ -143,6 +194,36 @@ def testApprovePost(self):
143194 self .assertTrue (c .is_public )
144195 self .assertEqual (c .flags .filter (flag = CommentFlag .MODERATOR_APPROVAL , user__username = "normaluser" ).count (), 1 )
145196
197+ def testApprovePostNext (self ):
198+ """
199+ POSTing the approve view will redirect to an explicitly provided a next
200+ url.
201+ """
202+ c1 , c2 , c3 , c4 = self .createSomeComments ()
203+ c1 .is_public = False ; c1 .save ()
204+
205+ makeModerator ("normaluser" )
206+ self .client .login (username = "normaluser" , password = "normaluser" )
207+ response = self .client .post ("/approve/%d/" % c1 .pk ,
208+ {'next' : "/go/here/" })
209+ self .assertEqual (response ["Location" ],
210+ "http://testserver/go/here/?c=1" )
211+
212+ def testApprovePostUnsafeNext (self ):
213+ """
214+ POSTing to the approve view with an unsafe next url will ignore the
215+ provided url when redirecting.
216+ """
217+ c1 , c2 , c3 , c4 = self .createSomeComments ()
218+ c1 .is_public = False ; c1 .save ()
219+
220+ makeModerator ("normaluser" )
221+ self .client .login (username = "normaluser" , password = "normaluser" )
222+ response = self .client .post ("/approve/%d/" % c1 .pk ,
223+ {'next' : "http://elsewhere/bad" })
224+ self .assertEqual (response ["Location" ],
225+ "http://testserver/approved/?c=%d" % c1 .pk )
226+
146227 def testApproveSignals (self ):
147228 def receive (sender , ** kwargs ):
148229 received_signals .append (kwargs .get ('signal' ))
0 commit comments