2525from ietf .person .models import Person , Email
2626from ietf .utils .test_utils import TestCase , unicontent
2727from ietf .utils .mail import outbox , empty_outbox
28- from ietf .utils .test_data import make_test_data
28+ from ietf .utils .test_data import make_test_data , create_person
2929from ietf .utils .test_utils import login_testing_unauthorized
3030from ietf .group .factories import GroupFactory , RoleFactory , GroupEventFactory
3131from ietf .meeting .factories import SessionFactory
@@ -240,14 +240,27 @@ def test_group_charter(self):
240240 self .assertTrue (milestone .docs .all ()[0 ].name in unicontent (r ))
241241
242242 def test_group_about (self ):
243+
244+ def verify_cannot_edit_group (username ):
245+ self .client .login (username = username , password = username + "+password" )
246+ r = self .client .get (url )
247+ self .assertEqual (r .status_code , 403 )
248+
249+ def verify_can_edit_group (username ):
250+ self .client .login (username = username , password = username + "+password" )
251+ r = self .client .get (url )
252+ self .assertEqual (r .status_code , 200 )
253+
243254 make_test_data ()
244255 group = Group .objects .create (
245256 type_id = "team" ,
246257 acronym = "testteam" ,
247258 name = "Test Team" ,
248259 description = "The test team is testing." ,
249260 state_id = "active" ,
261+ parent = Group .objects .get (acronym = "farfut" ),
250262 )
263+ create_person (group , "chair" , name = "Testteam Chairman" , username = "teamchairman" )
251264
252265 for url in [group .about_url (),
253266 urlreverse ('ietf.group.info.group_about' ,kwargs = dict (acronym = group .acronym )),
@@ -260,6 +273,14 @@ def test_group_about(self):
260273 self .assertTrue (group .acronym in unicontent (r ))
261274 self .assertTrue (group .description in unicontent (r ))
262275
276+ url = urlreverse ('ietf.group.edit.edit' , kwargs = dict (acronym = group .acronym ))
277+
278+ for username in ['plain' ,'iana' ,'iab chair' ,'irtf chair' ,'marschairman' ]:
279+ verify_cannot_edit_group (username )
280+
281+ for username in ['secretary' ,'teamchairman' ,'ad' ]:
282+ verify_can_edit_group (username )
283+
263284 def test_materials (self ):
264285 make_test_data ()
265286 group = Group .objects .create (type_id = "team" , acronym = "testteam" , name = "Test Team" , state_id = "active" )
@@ -1104,5 +1125,44 @@ def test_edit_status_update(self):
11041125 self .assertEqual (response .status_code , 302 )
11051126 self .assertEqual (chair .group .latest_event (type = 'status_update' ).desc ,'This came from a file.' )
11061127
1128+ class GroupParentLoopTests (TestCase ):
11071129
1108-
1130+ def test_group_parent_loop (self ):
1131+ make_test_data ()
1132+ mars = Group .objects .get (acronym = "mars" )
1133+ test1 = Group .objects .create (
1134+ type_id = "team" ,
1135+ acronym = "testteam1" ,
1136+ name = "Test One" ,
1137+ description = "The test team 1 is testing." ,
1138+ state_id = "active" ,
1139+ parent = mars ,
1140+ )
1141+ test2 = Group .objects .create (
1142+ type_id = "team" ,
1143+ acronym = "testteam2" ,
1144+ name = "Test Two" ,
1145+ description = "The test team 2 is testing." ,
1146+ state_id = "active" ,
1147+ parent = test1 ,
1148+ )
1149+ # Change the parent of Mars to make a loop
1150+ mars .parent = test2
1151+
1152+ # In face of the loop in the parent links, the code should not loop forever
1153+ import signal
1154+
1155+ def timeout_handler (signum , frame ):
1156+ raise Exception ("Infinite loop in parent links is not handeled properly." )
1157+
1158+ signal .signal (signal .SIGALRM , timeout_handler )
1159+ signal .alarm (1 ) # One second
1160+ try :
1161+ test2 .is_decendant_of ("ietf" )
1162+ except Exception :
1163+ raise
1164+ finally :
1165+ signal .alarm (0 )
1166+
1167+ # If we get here, then there is not an infinite loop
1168+ return
0 commit comments