Debian Codegraph @

python/tests/proton_tests/sasl.py

raw
1 #
2 # Licensed to the Apache Software Foundation (ASF) under one
3 # or more contributor license agreements. See the NOTICE file
4 # distributed with this work for additional information
5 # regarding copyright ownership. The ASF licenses this file
6 # to you under the Apache License, Version 2.0 (the
7 # "License"); you may not use this file except in compliance
8 # with the License. You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing,
13 # software distributed under the License is distributed on an
14 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 # KIND, either express or implied. See the License for the
16 # specific language governing permissions and limitations
17 # under the License.
18 #
19
20 from __future__ import absolute_import
21
22 import os
23
24 from proton import *
25
26 from . import common
27 from . import engine
28 from .common import pump, Skipped
29
30
31 def _sslCertpath(file):
32 """ Return the full path to the certificate, keyfile, etc.
33 """
34 if os.name == "nt":
35 if file.find("private-key") != -1:
36 # The private key is not in a separate store
37 return None
38 # Substitute pkcs#12 equivalent for the CA/key store
39 if file.endswith(".pem"):
40 file = file[:-4] + ".p12"
41 return os.path.join(os.path.dirname(__file__),
42 "ssl_db/%s" % file)
43
44
45 def _testSaslMech(self, mech, clientUser='user@proton', authUser='user@proton',
46 authzid=None, encrypted=False, authenticated=True):
47 self.s1.allowed_mechs(mech)
48 self.c1.open()
49 self.c2.open()
50
51 pump(self.t1, self.t2, 1024)
52
53 if encrypted is not None:
54 assert self.t2.encrypted == encrypted, encrypted
55 assert self.t1.encrypted == encrypted, encrypted
56
57 if authzid is None:
58 authzid = authUser
59
60 assert self.t2.authenticated == authenticated, authenticated
61 assert self.t1.authenticated == authenticated, authenticated
62 if authenticated:
63 # Server
64 assert self.t2.user == authUser
65 assert self.s2.user == authUser
66 assert self.s2.authorization == authzid, self.s2.authorization
67 assert self.s2.mech == mech.strip()
68 assert self.s2.outcome == SASL.OK, self.s2.outcome
69 assert self.c2.state & Endpoint.LOCAL_ACTIVE and self.c2.state & Endpoint.REMOTE_ACTIVE,\
70 "local_active=%s, remote_active=%s" % (
71 self.c1.state & Endpoint.LOCAL_ACTIVE, self.c1.state & Endpoint.REMOTE_ACTIVE)
72 # Client
73 assert self.t1.user == clientUser
74 assert self.s1.user == clientUser
75 assert self.s1.mech == mech.strip()
76 assert self.s1.outcome == SASL.OK, self.s1.outcome
77 assert self.c1.state & Endpoint.LOCAL_ACTIVE and self.c1.state & Endpoint.REMOTE_ACTIVE,\
78 "local_active=%s, remote_active=%s" % (
79 self.c1.state & Endpoint.LOCAL_ACTIVE, self.c1.state & Endpoint.REMOTE_ACTIVE)
80 else:
81 # Server
82 assert self.t2.user is None
83 assert self.s2.user is None
84 assert self.s2.authorization is None, self.s2.authorization
85 assert self.s2.outcome != SASL.OK, self.s2.outcome
86 # Client
87 assert self.t1.user == clientUser
88 assert self.s1.user == clientUser
89 assert self.s1.outcome != SASL.OK, self.s1.outcome
90
91
92 class Test(common.Test):
93 pass
94
95
96 def consumeAllOuput(t):
97 stops = 0
98 while stops < 1:
99 out = t.peek(1024)
100 l = len(out) if out else 0
101 t.pop(l)
102 if l <= 0:
103 stops += 1
104
105
106 class SaslTest(Test):
107
108 def setUp(self):
109 self.t1 = Transport()
110 self.s1 = SASL(self.t1)
111 self.t2 = Transport(Transport.SERVER)
112 self.t2.max_frame_size = 65536
113 self.s2 = SASL(self.t2)
114
115 def pump(self):
116 pump(self.t1, self.t2, 1024)
117
118 # We have to generate the client frames manually because proton does not
119 # generate pipelined SASL and AMQP frames together
120 def testIllegalProtocolLayering(self):
121 # Server
122 self.s2.allowed_mechs('ANONYMOUS')
123
124 c2 = Connection()
125 self.t2.bind(c2)
126
127 assert self.s2.outcome is None
128
129 # Push client bytes into server
130 self.t2.push(
131 # SASL
132 b'AMQP\x03\x01\x00\x00'
133 # @sasl-init(65) [mechanism=:ANONYMOUS, initial-response=b"anonymous@fuschia"]
134 b'\x00\x00\x002\x02\x01\x00\x00\x00SA\xd0\x00\x00\x00"\x00\x00\x00\x02\xa3\x09ANONYMOUS\xa0\x11anonymous@fuschia'
135 # SASL (again illegally)
136 b'AMQP\x03\x01\x00\x00'
137 # @sasl-init(65) [mechanism=:ANONYMOUS, initial-response=b"anonymous@fuschia"]
138 b'\x00\x00\x002\x02\x01\x00\x00\x00SA\xd0\x00\x00\x00"\x00\x00\x00\x02\xa3\x09ANONYMOUS\xa0\x11anonymous@fuschia'
139 # AMQP
140 b'AMQP\x00\x01\x00\x00'
141 # @open(16) [container-id="", channel-max=1234]
142 b'\x00\x00\x00!\x02\x00\x00\x00\x00S\x10\xd0\x00\x00\x00\x11\x00\x00\x00\x0a\xa1\x00@@`\x04\xd2@@@@@@'
143 )
144
145 consumeAllOuput(self.t2)
146
147 assert self.t2.condition
148 assert self.t2.closed
149 assert not c2.state & Endpoint.REMOTE_ACTIVE
150
151 def testPipelinedClient(self):
152 # Server
153 self.s2.allowed_mechs('ANONYMOUS')
154
155 c2 = Connection()
156 self.t2.bind(c2)
157
158 assert self.s2.outcome is None
159
160 # Push client bytes into server
161 self.t2.push(
162 # SASL
163 b'AMQP\x03\x01\x00\x00'
164 # @sasl-init(65) [mechanism=:ANONYMOUS, initial-response=b"anonymous@fuschia"]
165 b'\x00\x00\x002\x02\x01\x00\x00\x00SA\xd0\x00\x00\x00"\x00\x00\x00\x02\xa3\x09ANONYMOUS\xa0\x11anonymous@fuschia'
166 # AMQP
167 b'AMQP\x00\x01\x00\x00'
168 # @open(16) [container-id="", channel-max=1234]
169 b'\x00\x00\x00!\x02\x00\x00\x00\x00S\x10\xd0\x00\x00\x00\x11\x00\x00\x00\x0a\xa1\x00@@`\x04\xd2@@@@@@'
170 )
171
172 consumeAllOuput(self.t2)
173
174 assert not self.t2.condition
175 assert self.s2.outcome == SASL.OK
176 assert c2.state & Endpoint.REMOTE_ACTIVE
177
178 def testPipelinedServer(self):
179 # Client
180 self.s1.allowed_mechs('ANONYMOUS')
181
182 c1 = Connection()
183 self.t1.bind(c1)
184
185 assert self.s1.outcome is None
186
187 # Push server bytes into client
188 # Commented out lines in this test are where the client input processing doesn't
189 # run after output processing even though there is input waiting
190 self.t1.push(
191 # SASL
192 b'AMQP\x03\x01\x00\x00'
193 # @sasl-mechanisms(64) [sasl-server-mechanisms=@PN_SYMBOL[:ANONYMOUS]]
194 b'\x00\x00\x00\x1c\x02\x01\x00\x00\x00S@\xc0\x0f\x01\xe0\x0c\x01\xa3\tANONYMOUS'
195 # @sasl-outcome(68) [code=0]
196 b'\x00\x00\x00\x10\x02\x01\x00\x00\x00SD\xc0\x03\x01P\x00'
197 # AMQP
198 b'AMQP\x00\x01\x00\x00'
199 # @open(16) [container-id="", channel-max=1234]
200 b'\x00\x00\x00!\x02\x00\x00\x00\x00S\x10\xd0\x00\x00\x00\x11\x00\x00\x00\x0a\xa1\x00@@`\x04\xd2@@@@@@'
201 )
202
203 consumeAllOuput(self.t1)
204
205 assert self.s1.outcome == SASL.OK
206 assert c1.state & Endpoint.REMOTE_ACTIVE
207
208 def testPipelined2(self):
209 out1 = self.t1.peek(1024)
210 self.t1.pop(len(out1))
211 self.t2.push(out1)
212
213 self.s2.allowed_mechs('ANONYMOUS')
214 c2 = Connection()
215 c2.open()
216 self.t2.bind(c2)
217
218 out2 = self.t2.peek(1024)
219 self.t2.pop(len(out2))
220 self.t1.push(out2)
221
222 out1 = self.t1.peek(1024)
223 assert len(out1) > 0
224
225 def testFracturedSASL(self):
226 """ PROTON-235
227 """
228 assert self.s1.outcome is None
229
230 # self.t1.trace(Transport.TRACE_FRM)
231
232 out = self.t1.peek(1024)
233 self.t1.pop(len(out))
234 self.t1.push(b"AMQP\x03\x01\x00\x00")
235 out = self.t1.peek(1024)
236 self.t1.pop(len(out))
237 self.t1.push(b"\x00\x00\x00")
238 out = self.t1.peek(1024)
239 self.t1.pop(len(out))
240
241 self.t1.push(b"6\x02\x01\x00\x00\x00S@\xc0\x29\x01\xe0\x26\x04\xa3\x05PLAIN\x0aDIGEST-MD5\x09ANONYMOUS\x08CRAM-MD5")
242 out = self.t1.peek(1024)
243 self.t1.pop(len(out))
244 self.t1.push(b"\x00\x00\x00\x10\x02\x01\x00\x00\x00SD\xc0\x03\x01P\x00")
245 out = self.t1.peek(1024)
246 self.t1.pop(len(out))
247 while out:
248 out = self.t1.peek(1024)
249 self.t1.pop(len(out))
250
251 assert self.s1.outcome == SASL.OK, self.s1.outcome
252
253 def test_singleton(self):
254 """Verify that only a single instance of SASL can exist per Transport"""
255 transport = Transport()
256 attr = object()
257 sasl1 = SASL(transport)
258 sasl1.my_attribute = attr
259 sasl2 = transport.sasl()
260 sasl3 = SASL(transport)
261 assert sasl1 == sasl2
262 assert sasl1 == sasl3
263 assert sasl1.my_attribute == attr
264 assert sasl2.my_attribute == attr
265 assert sasl3.my_attribute == attr
266 transport = Transport()
267 sasl1 = transport.sasl()
268 sasl1.my_attribute = attr
269 sasl2 = SASL(transport)
270 assert sasl1 == sasl2
271 assert sasl1.my_attribute == attr
272 assert sasl2.my_attribute == attr
273
274 def testSaslSkipped(self):
275 """Verify that the server (with SASL) correctly handles a client without SASL"""
276 self.t1 = Transport()
277 self.t2.require_auth(False)
278 self.pump()
279 assert self.s2.outcome is None
280 assert self.t2.condition is None
281 assert self.t2.authenticated == False
282 assert self.s1.outcome is None
283 assert self.t1.condition is None
284 assert self.t1.authenticated == False
285
286 def testSaslSkippedFail(self):
287 """Verify that the server (with SASL) correctly handles a client without SASL"""
288 self.t1 = Transport()
289 self.t2.require_auth(True)
290 self.pump()
291 assert self.s2.outcome is None
292 assert self.t2.condition is not None
293 assert self.s1.outcome is None
294 assert self.t1.condition is not None
295
296 def testMechNotFound(self):
297 self.c1 = Connection()
298 self.c1.open()
299 self.t1.bind(self.c1)
300 self.s1.allowed_mechs('IMPOSSIBLE')
301
302 self.pump()
303
304 assert self.t2.authenticated == False
305 assert self.t1.authenticated == False
306 assert self.s1.outcome != SASL.OK
307 assert self.s2.outcome != SASL.OK
308
309
310 class SASLMechTest(Test):
311 def setUp(self):
312 self.t1 = Transport()
313 self.s1 = SASL(self.t1)
314 self.t2 = Transport(Transport.SERVER)
315 self.s2 = SASL(self.t2)
316
317 self.c1 = Connection()
318 self.c1.user = 'user@proton'
319 self.c1.password = 'password'
320 self.c1.hostname = 'localhost'
321
322 self.c2 = Connection()
323
324 def testANON(self):
325 self.t1.bind(self.c1)
326 self.t2.bind(self.c2)
327 _testSaslMech(self, 'ANONYMOUS', authUser='anonymous')
328
329 def testCRAMMD5(self):
330 common.ensureCanTestExtendedSASL()
331
332 self.t1.bind(self.c1)
333 self.t2.bind(self.c2)
334 _testSaslMech(self, 'CRAM-MD5')
335
336 def testDIGESTMD5(self):
337 common.ensureCanTestExtendedSASL()
338
339 self.t1.bind(self.c1)
340 self.t2.bind(self.c2)
341 _testSaslMech(self, 'DIGEST-MD5')
342
343 # PLAIN shouldn't work without encryption without special setting
344 def testPLAINfail(self):
345 common.ensureCanTestExtendedSASL()
346
347 self.t1.bind(self.c1)
348 self.t2.bind(self.c2)
349 _testSaslMech(self, 'PLAIN', authenticated=False)
350
351 # Client won't accept PLAIN even if offered by server without special setting
352 def testPLAINClientFail(self):
353 common.ensureCanTestExtendedSASL()
354
355 self.s2.allow_insecure_mechs = True
356 self.t1.bind(self.c1)
357 self.t2.bind(self.c2)
358 _testSaslMech(self, 'PLAIN', authenticated=False)
359
360 # PLAIN will only work if both ends are specially set up
361 def testPLAIN(self):
362 common.ensureCanTestExtendedSASL()
363
364 self.s1.allow_insecure_mechs = True
365 self.s2.allow_insecure_mechs = True
366 self.t1.bind(self.c1)
367 self.t2.bind(self.c2)
368 _testSaslMech(self, 'PLAIN')
369
370 # SCRAM not supported before Cyrus SASL 2.1.26
371 # so not universal and hence need a test for support
372 # to keep it in tests.
373 # def testSCRAMSHA1(self):
374 # common.ensureCanTestExtendedSASL()
375 #
376 # self.t1.bind(self.c1)
377 # self.t2.bind(self.c2)
378 # _testSaslMech(self, 'SCRAM-SHA-1')
379
380
381 def _sslConnection(domain, transport, connection):
382 transport.bind(connection)
383 ssl = SSL(transport, domain, None)
384 return connection
385
386
387 class SSLSASLTest(Test):
388 def setUp(self):
389 if not common.isSSLPresent():
390 raise Skipped("No SSL libraries found.")
391
392 self.server_domain = SSLDomain(SSLDomain.MODE_SERVER)
393 self.client_domain = SSLDomain(SSLDomain.MODE_CLIENT)
394
395 self.t1 = Transport()
396 self.s1 = SASL(self.t1)
397 self.t2 = Transport(Transport.SERVER)
398 self.s2 = SASL(self.t2)
399
400 self.c1 = Connection()
401 self.c2 = Connection()
402
403 def testSSLPlainSimple(self):
404 if not SASL.extended():
405 raise Skipped("Simple SASL server does not support PLAIN")
406 common.ensureCanTestExtendedSASL()
407
408 clientUser = 'user@proton'
409 mech = 'PLAIN'
410
411 self.c1.user = clientUser
412 self.c1.password = 'password'
413 self.c1.hostname = 'localhost'
414
415 self.client_domain.set_peer_authentication(SSLDomain.ANONYMOUS_PEER)
416
417 ssl1 = _sslConnection(self.client_domain, self.t1, self.c1)
418 ssl2 = _sslConnection(self.server_domain, self.t2, self.c2)
419
420 _testSaslMech(self, mech, encrypted=True)
421
422 def testSSLPlainAuthzid(self):
423 if not SASL.extended():
424 raise Skipped("Simple SASL server does not support PLAIN")
425 common.ensureCanTestExtendedSASL()
426
427 clientUser = 'user@proton'
428 authzid = 'user2'
429 mech = 'PLAIN'
430
431 self.c1.user = clientUser
432 self.c1.authorization = authzid
433 self.c1.password = 'password'
434 self.c1.hostname = 'localhost'
435
436 self.client_domain.set_peer_authentication(SSLDomain.ANONYMOUS_PEER)
437
438 ssl1 = _sslConnection(self.client_domain, self.t1, self.c1)
439 ssl2 = _sslConnection(self.server_domain, self.t2, self.c2)
440
441 _testSaslMech(self, mech, authzid=authzid, encrypted=True)
442
443 def testSSLPlainSimpleFail(self):
444 if not SASL.extended():
445 raise Skipped("Simple SASL server does not support PLAIN")
446 common.ensureCanTestExtendedSASL()
447
448 clientUser = 'usr@proton'
449 mech = 'PLAIN'
450
451 self.c1.user = clientUser
452 self.c1.password = 'password'
453 self.c1.hostname = 'localhost'
454
455 self.client_domain.set_peer_authentication(SSLDomain.ANONYMOUS_PEER)
456
457 ssl1 = _sslConnection(self.client_domain, self.t1, self.c1)
458 ssl2 = _sslConnection(self.server_domain, self.t2, self.c2)
459
460 _testSaslMech(self, mech, clientUser='usr@proton', encrypted=True, authenticated=False)
461
462 def testSSLExternalSimple(self):
463 if os.name == "nt":
464 extUser = 'O=Client, CN=127.0.0.1'
465 else:
466 extUser = 'O=Client,CN=127.0.0.1'
467 mech = 'EXTERNAL'
468
469 self.server_domain.set_credentials(_sslCertpath("server-certificate.pem"),
470 _sslCertpath("server-private-key.pem"),
471 "server-password")
472 self.server_domain.set_trusted_ca_db(_sslCertpath("ca-certificate.pem"))
473 self.server_domain.set_peer_authentication(SSLDomain.VERIFY_PEER,
474 _sslCertpath("ca-certificate.pem"))
475 self.client_domain.set_credentials(_sslCertpath("client-certificate.pem"),
476 _sslCertpath("client-private-key.pem"),
477 "client-password")
478 self.client_domain.set_trusted_ca_db(_sslCertpath("ca-certificate.pem"))
479 self.client_domain.set_peer_authentication(SSLDomain.VERIFY_PEER)
480
481 ssl1 = _sslConnection(self.client_domain, self.t1, self.c1)
482 ssl2 = _sslConnection(self.server_domain, self.t2, self.c2)
483
484 _testSaslMech(self, mech, clientUser=None, authUser=extUser, encrypted=True)
485
486 def testSSLExternalAuthzid(self):
487 if os.name == "nt":
488 extUser = 'O=Client, CN=127.0.0.1'
489 else:
490 extUser = 'O=Client,CN=127.0.0.1'
491 mech = 'EXTERNAL'
492 authzid = 'user_foo'
493
494 self.c1.authorization = authzid
495
496 self.server_domain.set_credentials(_sslCertpath("server-certificate.pem"),
497 _sslCertpath("server-private-key.pem"),
498 "server-password")
499 self.server_domain.set_trusted_ca_db(_sslCertpath("ca-certificate.pem"))
500 self.server_domain.set_peer_authentication(SSLDomain.VERIFY_PEER,
501 _sslCertpath("ca-certificate.pem"))
502 self.client_domain.set_credentials(_sslCertpath("client-certificate.pem"),
503 _sslCertpath("client-private-key.pem"),
504 "client-password")
505 self.client_domain.set_trusted_ca_db(_sslCertpath("ca-certificate.pem"))
506 self.client_domain.set_peer_authentication(SSLDomain.VERIFY_PEER)
507
508 ssl1 = _sslConnection(self.client_domain, self.t1, self.c1)
509 ssl2 = _sslConnection(self.server_domain, self.t2, self.c2)
510
511 _testSaslMech(self, mech, clientUser=None, authUser=extUser, authzid=authzid, encrypted=True)
512
513 def testSSLExternalSimpleFail(self):
514 mech = 'EXTERNAL'
515
516 self.server_domain.set_credentials(_sslCertpath("server-certificate.pem"),
517 _sslCertpath("server-private-key.pem"),
518 "server-password")
519 self.server_domain.set_trusted_ca_db(_sslCertpath("ca-certificate.pem"))
520 self.server_domain.set_peer_authentication(SSLDomain.VERIFY_PEER,
521 _sslCertpath("ca-certificate.pem"))
522 self.client_domain.set_trusted_ca_db(_sslCertpath("ca-certificate.pem"))
523 self.client_domain.set_peer_authentication(SSLDomain.VERIFY_PEER)
524
525 ssl1 = _sslConnection(self.client_domain, self.t1, self.c1)
526 ssl2 = _sslConnection(self.server_domain, self.t2, self.c2)
527
528 _testSaslMech(self, mech, clientUser=None, authUser=None, encrypted=None, authenticated=False)
529
530
531 class SASLEventTest(engine.CollectorTest):
532 def setUp(self):
533 engine.CollectorTest.setUp(self)
534 self.t1 = Transport()
535 self.s1 = SASL(self.t1)
536 self.t2 = Transport(Transport.SERVER)
537 self.s2 = SASL(self.t2)
538
539 self.c1 = Connection()
540 self.c1.user = 'user@proton'
541 self.c1.password = 'password'
542 self.c1.hostname = 'localhost'
543
544 self.c2 = Connection()
545
546 self.collector = Collector()
547
548 def testNormalAuthenticationClient(self):
549 common.ensureCanTestExtendedSASL()
550 self.c1.collect(self.collector)
551 self.t1.bind(self.c1)
552 self.t2.bind(self.c2)
553 _testSaslMech(self, 'DIGEST-MD5')
554 self.expect(Event.CONNECTION_INIT, Event.CONNECTION_BOUND,
555 Event.CONNECTION_LOCAL_OPEN, Event.TRANSPORT,
556 Event.CONNECTION_REMOTE_OPEN)
557
558 def testNormalAuthenticationServer(self):
559 common.ensureCanTestExtendedSASL()
560 self.c2.collect(self.collector)
561 self.t1.bind(self.c1)
562 self.t2.bind(self.c2)
563 _testSaslMech(self, 'DIGEST-MD5')
564 self.expect(Event.CONNECTION_INIT, Event.CONNECTION_BOUND,
565 Event.CONNECTION_LOCAL_OPEN, Event.TRANSPORT,
566 Event.CONNECTION_REMOTE_OPEN)
567
568 def testFailedAuthenticationClient(self):
569 common.ensureCanTestExtendedSASL()
570 clientUser = "usr@proton"
571 self.c1.user = clientUser
572 self.c1.collect(self.collector)
573 self.t1.bind(self.c1)
574 self.t2.bind(self.c2)
575 _testSaslMech(self, 'DIGEST-MD5', clientUser=clientUser, authenticated=False)
576 self.expect(Event.CONNECTION_INIT, Event.CONNECTION_BOUND,
577 Event.CONNECTION_LOCAL_OPEN, Event.TRANSPORT,
578 Event.TRANSPORT_ERROR,
579 Event.TRANSPORT_TAIL_CLOSED,
580 Event.TRANSPORT_HEAD_CLOSED, Event.TRANSPORT_CLOSED)
581
582 def testFailedAuthenticationServer(self):
583 common.ensureCanTestExtendedSASL()
584 clientUser = "usr@proton"
585 self.c1.user = clientUser
586 self.c2.collect(self.collector)
587 self.t1.bind(self.c1)
588 self.t2.bind(self.c2)
589 _testSaslMech(self, 'DIGEST-MD5', clientUser=clientUser, authenticated=False)
590 self.expect(Event.CONNECTION_INIT, Event.CONNECTION_BOUND,
591 Event.CONNECTION_LOCAL_OPEN, Event.TRANSPORT,
592 Event.TRANSPORT_ERROR,
593 Event.TRANSPORT_TAIL_CLOSED,
594 Event.TRANSPORT_HEAD_CLOSED, Event.TRANSPORT_CLOSED)
595
596 def testNoMechClient(self):
597 common.ensureCanTestExtendedSASL()
598 self.c1.collect(self.collector)
599 self.s2.allowed_mechs('IMPOSSIBLE')
600 self.t1.bind(self.c1)
601 self.t2.bind(self.c2)
602 _testSaslMech(self, 'DIGEST-MD5', authenticated=False)
603 self.expect(Event.CONNECTION_INIT, Event.CONNECTION_BOUND,
604 Event.CONNECTION_LOCAL_OPEN, Event.TRANSPORT,
605 Event.TRANSPORT_ERROR,
606 Event.TRANSPORT_TAIL_CLOSED, Event.TRANSPORT_HEAD_CLOSED, Event.TRANSPORT_CLOSED)
607
608 def testNoMechServer(self):
609 common.ensureCanTestExtendedSASL()
610 self.c2.collect(self.collector)
611 self.s2.allowed_mechs('IMPOSSIBLE')
612 self.t1.bind(self.c1)
613 self.t2.bind(self.c2)
614 _testSaslMech(self, 'DIGEST-MD5', authenticated=False)
615 self.expect(Event.CONNECTION_INIT, Event.CONNECTION_BOUND,
616 Event.CONNECTION_LOCAL_OPEN, Event.TRANSPORT,
617 Event.TRANSPORT_TAIL_CLOSED,
618 Event.TRANSPORT_ERROR, Event.TRANSPORT_HEAD_CLOSED, Event.TRANSPORT_CLOSED)
619
620 def testDisallowedMechClient(self):
621 self.c1.collect(self.collector)
622 self.t1.bind(self.c1)
623 self.t2.bind(self.c2)
624 _testSaslMech(self, 'IMPOSSIBLE', authenticated=False)
625 self.expect(Event.CONNECTION_INIT, Event.CONNECTION_BOUND,
626 Event.CONNECTION_LOCAL_OPEN, Event.TRANSPORT,
627 Event.TRANSPORT_ERROR,
628 Event.TRANSPORT_TAIL_CLOSED, Event.TRANSPORT_HEAD_CLOSED, Event.TRANSPORT_CLOSED)
629
630 def testDisallowedMechServer(self):
631 self.c2.collect(self.collector)
632 self.t1.bind(self.c1)
633 self.t2.bind(self.c2)
634 _testSaslMech(self, 'IMPOSSIBLE', authenticated=False)
635 self.expect(Event.CONNECTION_INIT, Event.CONNECTION_BOUND,
636 Event.CONNECTION_LOCAL_OPEN, Event.TRANSPORT,
637 Event.TRANSPORT_TAIL_CLOSED,
638 Event.TRANSPORT_ERROR, Event.TRANSPORT_HEAD_CLOSED, Event.TRANSPORT_CLOSED)
639
640 def testDisallowedPlainClient(self):
641 self.c1.collect(self.collector)
642 self.t1.bind(self.c1)
643 self.t2.bind(self.c2)
644 _testSaslMech(self, 'PLAIN', authenticated=False)
645 self.expect(Event.CONNECTION_INIT, Event.CONNECTION_BOUND,
646 Event.CONNECTION_LOCAL_OPEN, Event.TRANSPORT,
647 Event.TRANSPORT_ERROR,
648 Event.TRANSPORT_TAIL_CLOSED, Event.TRANSPORT_HEAD_CLOSED, Event.TRANSPORT_CLOSED)
649
650 def testDisallowedPlainServer(self):
651 self.c2.collect(self.collector)
652 self.t1.bind(self.c1)
653 self.t2.bind(self.c2)
654 _testSaslMech(self, 'PLAIN', authenticated=False)
655 self.expect(Event.CONNECTION_INIT, Event.CONNECTION_BOUND,
656 Event.CONNECTION_LOCAL_OPEN, Event.TRANSPORT,
657 Event.TRANSPORT_TAIL_CLOSED,
658 Event.TRANSPORT_ERROR, Event.TRANSPORT_HEAD_CLOSED, Event.TRANSPORT_CLOSED)