@@ -29,6 +29,30 @@ def testFlagPost(self):
2929 self .assertEqual (c .flags .filter (flag = CommentFlag .SUGGEST_REMOVAL ).count (), 1 )
3030 return c
3131
32+ def testFlagPostNext (self ):
33+ """
34+ POST the flag view, explicitly providing a next url.
35+ """
36+ comments = self .createSomeComments ()
37+ pk = comments [0 ].pk
38+ self .client .login (username = "normaluser" , password = "normaluser" )
39+ response = self .client .post ("/flag/%d/" % pk , {'next' : "/go/here/" })
40+ self .assertEqual (response ["Location" ],
41+ "http://testserver/go/here/?c=1" )
42+
43+ def testFlagPostUnsafeNext (self ):
44+ """
45+ POSTing to the flag view with an unsafe next url will ignore the
46+ provided url when redirecting.
47+ """
48+ comments = self .createSomeComments ()
49+ pk = comments [0 ].pk
50+ self .client .login (username = "normaluser" , password = "normaluser" )
51+ response = self .client .post ("/flag/%d/" % pk ,
52+ {'next' : "http://elsewhere/bad" })
53+ self .assertEqual (response ["Location" ],
54+ "http://testserver/flagged/?c=%d" % pk )
55+
3256 def testFlagPostTwice (self ):
3357 """Users don't get to flag comments more than once."""
3458 c = self .testFlagPost ()
@@ -48,7 +72,7 @@ def testFlagAnon(self):
4872 def testFlaggedView (self ):
4973 comments = self .createSomeComments ()
5074 pk = comments [0 ].pk
51- response = self .client .get ("/flagged/" , data = {"c" :pk })
75+ response = self .client .get ("/flagged/" , data = {"c" : pk })
5276 self .assertTemplateUsed (response , "comments/flagged.html" )
5377
5478 def testFlagSignals (self ):
@@ -100,6 +124,33 @@ def testDeletePost(self):
100124 self .assertTrue (c .is_removed )
101125 self .assertEqual (c .flags .filter (flag = CommentFlag .MODERATOR_DELETION , user__username = "normaluser" ).count (), 1 )
102126
127+ def testDeletePostNext (self ):
128+ """
129+ POSTing the delete view will redirect to an explicitly provided a next
130+ url.
131+ """
132+ comments = self .createSomeComments ()
133+ pk = comments [0 ].pk
134+ makeModerator ("normaluser" )
135+ self .client .login (username = "normaluser" , password = "normaluser" )
136+ response = self .client .post ("/delete/%d/" % pk , {'next' : "/go/here/" })
137+ self .assertEqual (response ["Location" ],
138+ "http://testserver/go/here/?c=1" )
139+
140+ def testDeletePostUnsafeNext (self ):
141+ """
142+ POSTing to the delete view with an unsafe next url will ignore the
143+ provided url when redirecting.
144+ """
145+ comments = self .createSomeComments ()
146+ pk = comments [0 ].pk
147+ makeModerator ("normaluser" )
148+ self .client .login (username = "normaluser" , password = "normaluser" )
149+ response = self .client .post ("/delete/%d/" % pk ,
150+ {'next' : "http://elsewhere/bad" })
151+ self .assertEqual (response ["Location" ],
152+ "http://testserver/deleted/?c=%d" % pk )
153+
103154 def testDeleteSignals (self ):
104155 def receive (sender , ** kwargs ):
105156 received_signals .append (kwargs .get ('signal' ))
@@ -115,13 +166,13 @@ def receive(sender, **kwargs):
115166 def testDeletedView (self ):
116167 comments = self .createSomeComments ()
117168 pk = comments [0 ].pk
118- response = self .client .get ("/deleted/" , data = {"c" :pk })
169+ response = self .client .get ("/deleted/" , data = {"c" : pk })
119170 self .assertTemplateUsed (response , "comments/deleted.html" )
120171
121172class ApproveViewTests (CommentTestCase ):
122173
123174 def testApprovePermissions (self ):
124- """The delete view should only be accessible to 'moderators'"""
175+ """The approve view should only be accessible to 'moderators'"""
125176 comments = self .createSomeComments ()
126177 pk = comments [0 ].pk
127178 self .client .login (username = "normaluser" , password = "normaluser" )
@@ -133,7 +184,7 @@ def testApprovePermissions(self):
133184 self .assertEqual (response .status_code , 200 )
134185
135186 def testApprovePost (self ):
136- """POSTing the delete view should mark the comment as removed"""
187+ """POSTing the approve view should mark the comment as removed"""
137188 c1 , c2 , c3 , c4 = self .createSomeComments ()
138189 c1 .is_public = False ; c1 .save ()
139190
@@ -145,6 +196,36 @@ def testApprovePost(self):
145196 self .assertTrue (c .is_public )
146197 self .assertEqual (c .flags .filter (flag = CommentFlag .MODERATOR_APPROVAL , user__username = "normaluser" ).count (), 1 )
147198
199+ def testApprovePostNext (self ):
200+ """
201+ POSTing the approve view will redirect to an explicitly provided a next
202+ url.
203+ """
204+ c1 , c2 , c3 , c4 = self .createSomeComments ()
205+ c1 .is_public = False ; c1 .save ()
206+
207+ makeModerator ("normaluser" )
208+ self .client .login (username = "normaluser" , password = "normaluser" )
209+ response = self .client .post ("/approve/%d/" % c1 .pk ,
210+ {'next' : "/go/here/" })
211+ self .assertEqual (response ["Location" ],
212+ "http://testserver/go/here/?c=1" )
213+
214+ def testApprovePostUnsafeNext (self ):
215+ """
216+ POSTing to the approve view with an unsafe next url will ignore the
217+ provided url when redirecting.
218+ """
219+ c1 , c2 , c3 , c4 = self .createSomeComments ()
220+ c1 .is_public = False ; c1 .save ()
221+
222+ makeModerator ("normaluser" )
223+ self .client .login (username = "normaluser" , password = "normaluser" )
224+ response = self .client .post ("/approve/%d/" % c1 .pk ,
225+ {'next' : "http://elsewhere/bad" })
226+ self .assertEqual (response ["Location" ],
227+ "http://testserver/approved/?c=%d" % c1 .pk )
228+
148229 def testApproveSignals (self ):
149230 def receive (sender , ** kwargs ):
150231 received_signals .append (kwargs .get ('signal' ))
0 commit comments