|
@@ -3,7 +3,9 @@ import time
|
3
|
3
|
import caldav
|
4
|
4
|
import transaction
|
5
|
5
|
from caldav.lib.error import AuthorizationError
|
6
|
|
-from nose.tools import eq_, ok_
|
|
6
|
+from nose.tools import eq_
|
|
7
|
+from nose.tools import ok_
|
|
8
|
+from nose.tools import raises
|
7
|
9
|
import requests
|
8
|
10
|
from requests.exceptions import ConnectionError
|
9
|
11
|
from sqlalchemy.orm.exc import NoResultFound
|
|
@@ -13,6 +15,7 @@ from tracim.lib.calendar import CalendarManager
|
13
|
15
|
from tracim.lib.workspace import WorkspaceApi
|
14
|
16
|
from tracim.model import DBSession
|
15
|
17
|
from tracim.tests import TestCalendar as BaseTestCalendar
|
|
18
|
+from tracim.tests import not_raises
|
16
|
19
|
from tracim.model.auth import User
|
17
|
20
|
from tracim.model.data import Content
|
18
|
21
|
|
|
@@ -34,6 +37,7 @@ class TestCalendar(BaseTestCalendar):
|
34
|
37
|
except ConnectionError as exc:
|
35
|
38
|
ok_(False, 'Unable to contact radicale on HTTP: {0}'.format(exc))
|
36
|
39
|
|
|
40
|
+ @not_raises(AuthorizationError)
|
37
|
41
|
def test_func__radicale_auth__ok__as_lawrence(self):
|
38
|
42
|
radicale_base_url = CalendarManager.get_base_url()
|
39
|
43
|
client = caldav.DAVClient(
|
|
@@ -41,12 +45,9 @@ class TestCalendar(BaseTestCalendar):
|
41
|
45
|
username='lawrence-not-real-email@fsf.local',
|
42
|
46
|
password='foobarbaz'
|
43
|
47
|
)
|
44
|
|
- try:
|
45
|
|
- client.propfind()
|
46
|
|
- ok_(True, 'No auth error when communicate with radicale server')
|
47
|
|
- except AuthorizationError:
|
48
|
|
- ok_(False, 'AuthorizationError when communicate with radicale')
|
|
48
|
+ client.propfind()
|
49
|
49
|
|
|
50
|
+ @raises(AuthorizationError)
|
50
|
51
|
def test_func__radicale_auth__fail__as_john_doe(self):
|
51
|
52
|
radicale_base_url = CalendarManager.get_base_url()
|
52
|
53
|
client = caldav.DAVClient(
|
|
@@ -54,13 +55,9 @@ class TestCalendar(BaseTestCalendar):
|
54
|
55
|
username='john.doe@foo.local',
|
55
|
56
|
password='nopasswd'
|
56
|
57
|
)
|
57
|
|
- try:
|
58
|
|
- client.propfind()
|
59
|
|
- ok_(False, 'Auth with unknown user should be raise'
|
60
|
|
- ' AuthorizationError !')
|
61
|
|
- except AuthorizationError:
|
62
|
|
- ok_(True, 'AuthorizationError thrown correctly')
|
|
58
|
+ client.propfind()
|
63
|
59
|
|
|
60
|
+ @not_raises(AuthorizationError)
|
64
|
61
|
def test_func__rights_read_user_calendar__ok__as_lawrence(self):
|
65
|
62
|
radicale_base_url = CalendarManager.get_base_url()
|
66
|
63
|
client = caldav.DAVClient(
|
|
@@ -72,17 +69,13 @@ class TestCalendar(BaseTestCalendar):
|
72
|
69
|
User.email == 'lawrence-not-real-email@fsf.local'
|
73
|
70
|
).one()
|
74
|
71
|
user_calendar_url = CalendarManager.get_user_calendar_url(user.user_id)
|
75
|
|
- try:
|
76
|
|
- caldav.Calendar(
|
77
|
|
- parent=client,
|
78
|
|
- client=client,
|
79
|
|
- url=user_calendar_url
|
80
|
|
- ).events()
|
81
|
|
-
|
82
|
|
- ok_(True, 'User can access it\'s own calendar')
|
83
|
|
- except AuthorizationError:
|
84
|
|
- ok_(False, 'User should not access that')
|
|
72
|
+ caldav.Calendar(
|
|
73
|
+ parent=client,
|
|
74
|
+ client=client,
|
|
75
|
+ url=user_calendar_url
|
|
76
|
+ ).events()
|
85
|
77
|
|
|
78
|
+ @raises(AuthorizationError)
|
86
|
79
|
def test_func__rights_read_user_calendar__fail__as_john_doe(self):
|
87
|
80
|
radicale_base_url = CalendarManager.get_base_url()
|
88
|
81
|
client = caldav.DAVClient(
|
|
@@ -94,17 +87,13 @@ class TestCalendar(BaseTestCalendar):
|
94
|
87
|
User.email == 'admin@admin.admin'
|
95
|
88
|
).one()
|
96
|
89
|
user_calendar_url = CalendarManager.get_user_calendar_url(other_user.user_id)
|
97
|
|
- try:
|
98
|
|
- caldav.Calendar(
|
99
|
|
- parent=client,
|
100
|
|
- client=client,
|
101
|
|
- url=user_calendar_url
|
102
|
|
- ).events()
|
103
|
|
-
|
104
|
|
- ok_(False, 'User can\'t acces other user calendar')
|
105
|
|
- except AuthorizationError:
|
106
|
|
- ok_(True, 'User should not acces other user calendar')
|
|
90
|
+ caldav.Calendar(
|
|
91
|
+ parent=client,
|
|
92
|
+ client=client,
|
|
93
|
+ url=user_calendar_url
|
|
94
|
+ ).events()
|
107
|
95
|
|
|
96
|
+ @not_raises(AuthorizationError)
|
108
|
97
|
def test_func__rights_read_workspace_calendar__ok__as_owner(self):
|
109
|
98
|
lawrence = DBSession.query(User).filter(
|
110
|
99
|
User.email == 'lawrence-not-real-email@fsf.local'
|
|
@@ -128,17 +117,13 @@ class TestCalendar(BaseTestCalendar):
|
128
|
117
|
username='lawrence-not-real-email@fsf.local',
|
129
|
118
|
password='foobarbaz'
|
130
|
119
|
)
|
131
|
|
- try:
|
132
|
|
- caldav.Calendar(
|
133
|
|
- parent=client,
|
134
|
|
- client=client,
|
135
|
|
- url=workspace_calendar_url
|
136
|
|
- ).events()
|
137
|
|
-
|
138
|
|
- ok_(True, 'User can acces own workspace calendar')
|
139
|
|
- except AuthorizationError:
|
140
|
|
- ok_(False, 'User should not acces own workspace calendar')
|
|
120
|
+ caldav.Calendar(
|
|
121
|
+ parent=client,
|
|
122
|
+ client=client,
|
|
123
|
+ url=workspace_calendar_url
|
|
124
|
+ ).events()
|
141
|
125
|
|
|
126
|
+ @raises(AuthorizationError)
|
142
|
127
|
def test_func__rights_read_workspace_calendar__fail__as_unauthorized(self):
|
143
|
128
|
lawrence = DBSession.query(User).filter(
|
144
|
129
|
User.email == 'lawrence-not-real-email@fsf.local'
|
|
@@ -162,16 +147,11 @@ class TestCalendar(BaseTestCalendar):
|
162
|
147
|
username='bob@fsf.local',
|
163
|
148
|
password='foobarbaz'
|
164
|
149
|
)
|
165
|
|
- try:
|
166
|
|
- caldav.Calendar(
|
167
|
|
- parent=client,
|
168
|
|
- client=client,
|
169
|
|
- url=workspace_calendar_url
|
170
|
|
- ).events()
|
171
|
|
-
|
172
|
|
- ok_(False, 'User can\'t access unright workspace calendar')
|
173
|
|
- except AuthorizationError:
|
174
|
|
- ok_(True, 'User should not access unright workspace calendar')
|
|
150
|
+ caldav.Calendar(
|
|
151
|
+ parent=client,
|
|
152
|
+ client=client,
|
|
153
|
+ url=workspace_calendar_url
|
|
154
|
+ ).events()
|
175
|
155
|
|
176
|
156
|
def test_func__event_create__ok__nominal_case(self):
|
177
|
157
|
lawrence = DBSession.query(User).filter(
|