|
30 | 30 | from pymongo.auth import HAVE_KERBEROS, _build_credentials_tuple
|
31 | 31 | from pymongo.errors import OperationFailure
|
32 | 32 | from pymongo.read_preferences import ReadPreference
|
33 |
| -from pymongo.saslprep import saslprep, HAVE_STRINGPREP |
| 33 | +from pymongo.saslprep import HAVE_STRINGPREP |
34 | 34 | from test import client_context, SkipTest, unittest, Version
|
35 | 35 | from test.utils import (delay,
|
36 | 36 | ignore_deprecations,
|
@@ -460,29 +460,64 @@ def test_scram(self):
|
460 | 460 | 'not-a-user', 'pwd')
|
461 | 461 |
|
462 | 462 | if HAVE_STRINGPREP:
|
| 463 | + # Test the use of SASLprep on passwords. For example, |
| 464 | + # saslprep(u'\u2136') becomes u'IV' and saslprep(u'I\u00ADX') |
| 465 | + # becomes u'IX'. SASLprep is only supported when the standard |
| 466 | + # library provides stringprep. |
463 | 467 | client_context.create_user(
|
464 | 468 | 'testscram',
|
465 |
| - saslprep(u'\u2168'), |
466 | 469 | u'\u2168',
|
| 470 | + u'\u2163', |
467 | 471 | roles=['dbOwner'],
|
468 | 472 | mechanisms=['SCRAM-SHA-256'])
|
469 | 473 |
|
| 474 | + client_context.create_user( |
| 475 | + 'testscram', |
| 476 | + u'IX', |
| 477 | + u'IX', |
| 478 | + roles=['dbOwner'], |
| 479 | + mechanisms=['SCRAM-SHA-256']) |
| 480 | + |
| 481 | + self.assertTrue( |
| 482 | + client.testscram.authenticate(u'\u2168', u'\u2163')) |
| 483 | + client.testscram.command('dbstats') |
| 484 | + client.testscram.logout() |
| 485 | + self.assertTrue( |
| 486 | + client.testscram.authenticate( |
| 487 | + u'\u2168', u'\u2163', mechanism='SCRAM-SHA-256')) |
| 488 | + client.testscram.command('dbstats') |
| 489 | + client.testscram.logout() |
| 490 | + self.assertTrue( |
| 491 | + client.testscram.authenticate(u'\u2168', u'IV')) |
| 492 | + client.testscram.command('dbstats') |
| 493 | + client.testscram.logout() |
| 494 | + |
470 | 495 | self.assertTrue(
|
471 |
| - client.testscram.authenticate(u'\u2168', u'\u2168')) |
| 496 | + client.testscram.authenticate(u'IX', u'I\u00ADX')) |
472 | 497 | client.testscram.command('dbstats')
|
473 | 498 | client.testscram.logout()
|
474 | 499 | self.assertTrue(
|
475 | 500 | client.testscram.authenticate(
|
476 |
| - u'\u2168', u'\u2168', mechanism='SCRAM-SHA-256')) |
| 501 | + u'IX', u'I\u00ADX', mechanism='SCRAM-SHA-256')) |
| 502 | + client.testscram.command('dbstats') |
| 503 | + client.testscram.logout() |
| 504 | + self.assertTrue( |
| 505 | + client.testscram.authenticate(u'IX', u'IX')) |
477 | 506 | client.testscram.command('dbstats')
|
478 | 507 | client.testscram.logout()
|
479 |
| - self.assertRaises( |
480 |
| - OperationFailure, |
481 |
| - client.testscram.authenticate, |
482 |
| - u'\u2168', u'\u2168', mechanism='SCRAM-SHA-1') |
483 | 508 |
|
484 | 509 | client = rs_or_single_client_noauth(
|
485 |
| - u'mongodb://\u2168:\u2168@%s:%d/testscram' % (host, port)) |
| 510 | + u'mongodb://\u2168:\u2163@%s:%d/testscram' % (host, port)) |
| 511 | + client.testscram.command('dbstats') |
| 512 | + client = rs_or_single_client_noauth( |
| 513 | + u'mongodb://\u2168:IV@%s:%d/testscram' % (host, port)) |
| 514 | + client.testscram.command('dbstats') |
| 515 | + |
| 516 | + client = rs_or_single_client_noauth( |
| 517 | + u'mongodb://IX:I\u00ADX@%s:%d/testscram' % (host, port)) |
| 518 | + client.testscram.command('dbstats') |
| 519 | + client = rs_or_single_client_noauth( |
| 520 | + u'mongodb://IX:IX@%s:%d/testscram' % (host, port)) |
486 | 521 | client.testscram.command('dbstats')
|
487 | 522 |
|
488 | 523 | self.listener.results.clear()
|
|
0 commit comments