|  | @@ -1,11 +1,13 @@
 | 
	
		
			
			| 1 | 1 |  import time
 | 
	
		
			
			| 2 | 2 |  
 | 
	
		
			
			| 3 | 3 |  import caldav
 | 
	
		
			
			|  | 4 | +import transaction
 | 
	
		
			
			| 4 | 5 |  from caldav.lib.error import AuthorizationError
 | 
	
		
			
			| 5 | 6 |  from nose.tools import eq_, ok_
 | 
	
		
			
			| 6 | 7 |  import requests
 | 
	
		
			
			| 7 | 8 |  from requests.exceptions import ConnectionError
 | 
	
		
			
			| 8 | 9 |  
 | 
	
		
			
			|  | 10 | +from tracim.lib.workspace import WorkspaceApi
 | 
	
		
			
			| 9 | 11 |  from tracim.model import DBSession
 | 
	
		
			
			| 10 | 12 |  from tracim.tests import TestCalendar as BaseTestCalendar
 | 
	
		
			
			| 11 | 13 |  from tracim.model.auth import User
 | 
	
	
		
			
			|  | @@ -53,7 +55,7 @@ class TestCalendar(BaseTestCalendar):
 | 
	
		
			
			| 53 | 55 |          except AuthorizationError:
 | 
	
		
			
			| 54 | 56 |              ok_(True, 'AuthorizationError thrown correctly')
 | 
	
		
			
			| 55 | 57 |  
 | 
	
		
			
			| 56 |  | -    def test_func__radicale_rights_read_user_calendar__ok__as_lawrence(self):
 | 
	
		
			
			|  | 58 | +    def test_func__rights_read_user_calendar__ok__as_lawrence(self):
 | 
	
		
			
			| 57 | 59 |          radicale_base_url = self._get_base_url()
 | 
	
		
			
			| 58 | 60 |          client = caldav.DAVClient(
 | 
	
		
			
			| 59 | 61 |              radicale_base_url,
 | 
	
	
		
			
			|  | @@ -75,7 +77,7 @@ class TestCalendar(BaseTestCalendar):
 | 
	
		
			
			| 75 | 77 |          except AuthorizationError:
 | 
	
		
			
			| 76 | 78 |              ok_(False, 'User should not access that')
 | 
	
		
			
			| 77 | 79 |  
 | 
	
		
			
			| 78 |  | -    def test_func__radicale_rights_read_user_calendar__fail__as_john_doe(self):
 | 
	
		
			
			|  | 80 | +    def test_func__rights_read_user_calendar__fail__as_john_doe(self):
 | 
	
		
			
			| 79 | 81 |          radicale_base_url = self._get_base_url()
 | 
	
		
			
			| 80 | 82 |          client = caldav.DAVClient(
 | 
	
		
			
			| 81 | 83 |              radicale_base_url,
 | 
	
	
		
			
			|  | @@ -96,3 +98,71 @@ class TestCalendar(BaseTestCalendar):
 | 
	
		
			
			| 96 | 98 |              ok_(False, 'User can\'t acces other user calendar')
 | 
	
		
			
			| 97 | 99 |          except AuthorizationError:
 | 
	
		
			
			| 98 | 100 |              ok_(True, 'User should not acces other user calendar')
 | 
	
		
			
			|  | 101 | +
 | 
	
		
			
			|  | 102 | +    def test_func__rights_read_workspace_calendar__ok__as_owner(self):
 | 
	
		
			
			|  | 103 | +        lawrence = DBSession.query(User).filter(
 | 
	
		
			
			|  | 104 | +            User.email == 'lawrence-not-real-email@fsf.local'
 | 
	
		
			
			|  | 105 | +        ).one()
 | 
	
		
			
			|  | 106 | +        workspace = WorkspaceApi(lawrence).create_workspace(
 | 
	
		
			
			|  | 107 | +            'workspace_1',
 | 
	
		
			
			|  | 108 | +            save_now=False
 | 
	
		
			
			|  | 109 | +        )
 | 
	
		
			
			|  | 110 | +        workspace.calendar_enabled = True
 | 
	
		
			
			|  | 111 | +        DBSession.flush()
 | 
	
		
			
			|  | 112 | +
 | 
	
		
			
			|  | 113 | +        workspace_calendar_url = self._get_workspace_calendar_url(
 | 
	
		
			
			|  | 114 | +            workspace.workspace_id
 | 
	
		
			
			|  | 115 | +        )
 | 
	
		
			
			|  | 116 | +
 | 
	
		
			
			|  | 117 | +        transaction.commit()
 | 
	
		
			
			|  | 118 | +
 | 
	
		
			
			|  | 119 | +        radicale_base_url = self._get_base_url()
 | 
	
		
			
			|  | 120 | +        client = caldav.DAVClient(
 | 
	
		
			
			|  | 121 | +            radicale_base_url,
 | 
	
		
			
			|  | 122 | +            username='lawrence-not-real-email@fsf.local',
 | 
	
		
			
			|  | 123 | +            password='foobarbaz'
 | 
	
		
			
			|  | 124 | +        )
 | 
	
		
			
			|  | 125 | +        try:
 | 
	
		
			
			|  | 126 | +            caldav.Calendar(
 | 
	
		
			
			|  | 127 | +                parent=client,
 | 
	
		
			
			|  | 128 | +                client=client,
 | 
	
		
			
			|  | 129 | +                url=workspace_calendar_url
 | 
	
		
			
			|  | 130 | +            ).events()
 | 
	
		
			
			|  | 131 | +
 | 
	
		
			
			|  | 132 | +            ok_(True, 'User can acces own workspace calendar')
 | 
	
		
			
			|  | 133 | +        except AuthorizationError:
 | 
	
		
			
			|  | 134 | +            ok_(False, 'User should not acces own workspace calendar')
 | 
	
		
			
			|  | 135 | +
 | 
	
		
			
			|  | 136 | +    def test_func__rights_read_workspace_calendar__fail__as_unauthorized(self):
 | 
	
		
			
			|  | 137 | +        lawrence = DBSession.query(User).filter(
 | 
	
		
			
			|  | 138 | +            User.email == 'lawrence-not-real-email@fsf.local'
 | 
	
		
			
			|  | 139 | +        ).one()
 | 
	
		
			
			|  | 140 | +        workspace = WorkspaceApi(lawrence).create_workspace(
 | 
	
		
			
			|  | 141 | +            'workspace_1',
 | 
	
		
			
			|  | 142 | +            save_now=False
 | 
	
		
			
			|  | 143 | +        )
 | 
	
		
			
			|  | 144 | +        workspace.calendar_enabled = True
 | 
	
		
			
			|  | 145 | +        DBSession.flush()
 | 
	
		
			
			|  | 146 | +
 | 
	
		
			
			|  | 147 | +        workspace_calendar_url = self._get_workspace_calendar_url(
 | 
	
		
			
			|  | 148 | +            workspace.workspace_id
 | 
	
		
			
			|  | 149 | +        )
 | 
	
		
			
			|  | 150 | +
 | 
	
		
			
			|  | 151 | +        transaction.commit()
 | 
	
		
			
			|  | 152 | +
 | 
	
		
			
			|  | 153 | +        radicale_base_url = self._get_base_url()
 | 
	
		
			
			|  | 154 | +        client = caldav.DAVClient(
 | 
	
		
			
			|  | 155 | +            radicale_base_url,
 | 
	
		
			
			|  | 156 | +            username='bob@fsf.local',
 | 
	
		
			
			|  | 157 | +            password='foobarbaz'
 | 
	
		
			
			|  | 158 | +        )
 | 
	
		
			
			|  | 159 | +        try:
 | 
	
		
			
			|  | 160 | +            caldav.Calendar(
 | 
	
		
			
			|  | 161 | +                parent=client,
 | 
	
		
			
			|  | 162 | +                client=client,
 | 
	
		
			
			|  | 163 | +                url=workspace_calendar_url
 | 
	
		
			
			|  | 164 | +            ).events()
 | 
	
		
			
			|  | 165 | +
 | 
	
		
			
			|  | 166 | +            ok_(False, 'User can\'t access unright workspace calendar')
 | 
	
		
			
			|  | 167 | +        except AuthorizationError:
 | 
	
		
			
			|  | 168 | +            ok_(True, 'User should not access unright workspace calendar')
 |