12
12
from globaleaks .tests import helpers
13
13
14
14
15
+ class TestAuthTypeHandler (helpers .TestHandlerWithPopulatedDB ):
16
+ _handler = auth .AuthTypeHandler
17
+
18
+ # since all logins for roles admin, receiver and custodian happen
19
+ # in the same way, the following tests are performed on the recipient user.
20
+
21
+ @inlineCallbacks
22
+ def test_whistleblower_request (self ):
23
+ handler = self .request ({
24
+ 'username' : '' ,
25
+ })
26
+
27
+ response = yield handler .post ()
28
+ self .assertTrue ('type' in response )
29
+ self .assertEqual (response ['type' ], 'key' )
30
+ self .assertTrue ('salt' in response )
31
+ self .assertEqual (response ['salt' ], helpers .VALID_SALT1 )
32
+
33
+ @inlineCallbacks
34
+ def test_receiver1_request (self ):
35
+ handler = self .request ({
36
+ 'username' : 'receiver1' ,
37
+ })
38
+
39
+ response = yield handler .post ()
40
+ self .assertTrue ('type' in response )
41
+ self .assertEqual (response ['type' ], 'key' )
42
+ self .assertTrue ('salt' in response )
43
+ self .assertEqual (response ['salt' ], helpers .VALID_SALT1 )
44
+
45
+ @inlineCallbacks
46
+ def test_receiver2_request (self ):
47
+ handler = self .request ({
48
+ 'username' : 'receiver2' ,
49
+ })
50
+
51
+ response = yield handler .post ()
52
+ self .assertTrue ('type' in response )
53
+ self .assertEqual (response ['type' ], 'password' )
54
+
55
+
15
56
class TestAuthentication (helpers .TestHandlerWithPopulatedDB ):
16
57
_handler = auth .AuthenticationHandler
17
58
@@ -23,7 +64,7 @@ def test_successful_login(self):
23
64
handler = self .request ({
24
65
'tid' : 1 ,
25
66
'username' : 'admin' ,
26
- 'password' : helpers .VALID_PASSWORD1 ,
67
+ 'password' : helpers .VALID_KEY1 ,
27
68
'authcode' : '' ,
28
69
})
29
70
response = yield handler .post ()
@@ -34,7 +75,7 @@ def test_successful_multitenant_login_switch(self):
34
75
handler = self .request ({
35
76
'tid' : 1 ,
36
77
'username' : 'admin' ,
37
- 'password' : helpers .VALID_PASSWORD1 ,
78
+ 'password' : helpers .VALID_KEY1 ,
38
79
'authcode' : ''
39
80
})
40
81
@@ -52,7 +93,7 @@ def test_accept_login_in_https(self):
52
93
handler = self .request ({
53
94
'tid' : 1 ,
54
95
'username' : 'admin' ,
55
- 'password' : helpers .VALID_PASSWORD1 ,
96
+ 'password' : helpers .VALID_KEY1 ,
56
97
'authcode' : ''
57
98
})
58
99
State .tenants [1 ].cache ['https_admin' ] = True
@@ -64,7 +105,7 @@ def test_deny_login_in_https(self):
64
105
handler = self .request ({
65
106
'tid' : 1 ,
66
107
'username' : 'admin' ,
67
- 'password' : helpers .VALID_PASSWORD1 ,
108
+ 'password' : helpers .VALID_KEY1 ,
68
109
'authcode' : ''
69
110
})
70
111
State .tenants [1 ].cache ['https_admin' ] = False
@@ -101,7 +142,7 @@ def test_single_session_per_user(self):
101
142
handler = self .request ({
102
143
'tid' : 1 ,
103
144
'username' : 'admin' ,
104
- 'password' : helpers .VALID_PASSWORD1 ,
145
+ 'password' : helpers .VALID_KEY1 ,
105
146
'authcode' : '' ,
106
147
})
107
148
@@ -110,7 +151,7 @@ def test_single_session_per_user(self):
110
151
handler = self .request ({
111
152
'tid' : 1 ,
112
153
'username' : 'admin' ,
113
- 'password' : helpers .VALID_PASSWORD1 ,
154
+ 'password' : helpers .VALID_KEY1 ,
114
155
'authcode' : '' ,
115
156
})
116
157
@@ -124,7 +165,7 @@ def test_session_is_revoked(self):
124
165
auth_handler = self .request ({
125
166
'tid' : 1 ,
126
167
'username' : 'receiver1' ,
127
- 'password' : helpers .VALID_PASSWORD1 ,
168
+ 'password' : helpers .VALID_KEY1 ,
128
169
'authcode' : '' ,
129
170
})
130
171
@@ -140,7 +181,7 @@ def test_session_is_revoked(self):
140
181
auth_handler = self .request ({
141
182
'tid' : 1 ,
142
183
'username' : 'receiver1' ,
143
- 'password' : helpers .VALID_PASSWORD1 ,
184
+ 'password' : helpers .VALID_KEY1 ,
144
185
'authcode' : '' ,
145
186
})
146
187
@@ -166,7 +207,7 @@ def test_login_reject_on_ip_filtering(self):
166
207
handler = self .request ({
167
208
'tid' : 1 ,
168
209
'username' : 'admin' ,
169
- 'password' : helpers .VALID_PASSWORD1 ,
210
+ 'password' : helpers .VALID_KEY1 ,
170
211
'authcode' : ''
171
212
}, client_addr = b'192.168.1.1' )
172
213
yield self .assertFailure (handler .post (), errors .AccessLocationInvalid )
@@ -179,7 +220,7 @@ def test_login_success_on_ip_filtering(self):
179
220
handler = self .request ({
180
221
'tid' : 1 ,
181
222
'username' : 'admin' ,
182
- 'password' : helpers .VALID_PASSWORD1 ,
223
+ 'password' : helpers .VALID_KEY1 ,
183
224
'authcode' : ''
184
225
}, client_addr = b'192.168.2.1' )
185
226
response = yield handler .post ()
@@ -192,15 +233,15 @@ class TestReceiptAuth(helpers.TestHandlerWithPopulatedDB):
192
233
@inlineCallbacks
193
234
def test_invalid_whistleblower_login (self ):
194
235
handler = self .request ({
195
- 'receipt' : 'INVALIDRECEIPT' ,
236
+ 'receipt' : 'INVALIDRECEIPT'
196
237
})
197
238
yield self .assertFailure (handler .post (), errors .InvalidAuthentication )
198
239
199
240
@inlineCallbacks
200
241
def test_successful_whistleblower_login (self ):
201
242
yield self .perform_full_submission_actions ()
202
243
handler = self .request ({
203
- 'receipt' : self .lastReceipt ,
244
+ 'receipt' : self .lastReceipt
204
245
})
205
246
handler .request .client_using_tor = True
206
247
response = yield handler .post ()
@@ -257,7 +298,7 @@ def test_single_session_per_whistleblower(self):
257
298
valid_session = Sessions .get (second_id )
258
299
self .assertTrue (valid_session is not None )
259
300
260
- self .assertEqual (valid_session .user_role , 'whistleblower' )
301
+ self .assertEqual (valid_session .role , 'whistleblower' )
261
302
262
303
wbtip_handler = self .request (headers = {'x-session' : second_id },
263
304
handler_cls = WBTipInstance )
@@ -276,7 +317,7 @@ def test_successful_admin_session_setup_renewal_and_logout(self):
276
317
handler = self .request ({
277
318
'tid' : 1 ,
278
319
'username' : 'admin' ,
279
- 'password' : helpers .VALID_PASSWORD1 ,
320
+ 'password' : helpers .VALID_KEY1 ,
280
321
'authcode' : ''
281
322
})
282
323
0 commit comments