当前位置: 首页>>代码示例>>Python>>正文


Python MozLdapBackend.authenticate方法代码示例

本文整理汇总了Python中lib.auth.backends.MozLdapBackend.authenticate方法的典型用法代码示例。如果您正苦于以下问题:Python MozLdapBackend.authenticate方法的具体用法?Python MozLdapBackend.authenticate怎么用?Python MozLdapBackend.authenticate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lib.auth.backends.MozLdapBackend的用法示例。


在下文中一共展示了MozLdapBackend.authenticate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_authenticate_without_ldap

# 需要导入模块: from lib.auth.backends import MozLdapBackend [as 别名]
# 或者: from lib.auth.backends.MozLdapBackend import authenticate [as 别名]
    def test_authenticate_without_ldap(self):
        assert not User.objects.all().exists()
        user = User.objects.create(username="foo", email="[email protected]")
        user.set_password("secret")
        user.save()

        backend = MozLdapBackend()
        eq_(backend.authenticate("[email protected]", "secret"), user)
        eq_(backend.authenticate("foo", "secret"), user)
        eq_(backend.authenticate("foo", "JUNK"), None)
开发者ID:peterbe,项目名称:elmo,代码行数:12,代码来源:tests.py

示例2: test_lost_group_privileges

# 需要导入模块: from lib.auth.backends import MozLdapBackend [as 别名]
# 或者: from lib.auth.backends.MozLdapBackend import authenticate [as 别名]
    def test_lost_group_privileges(self):
        # test a user that is part of the `Localizers` group one day but not
        # the other

        assert not User.objects.all().exists()
        ldap.open = Mock('ldap.open')
        ldap.open.mock_returns = Mock('ldap_connection')
        ldap.set_option = Mock(return_value=None)

        groups = [
          ('cn=scm_l10n,ou=groups,dc=mozilla',
           {'cn': ['scm_l10n']}),
          ('cn=buildteam,ou=groups,dc=mozilla',
           {'cn': ['buildteam']})
        ]
        ldap.initialize = Mock(return_value=MockLDAP({
          'dc=mozilla': self.fake_user,
          'ou=groups,dc=mozilla': groups
        }))
        backend = MozLdapBackend()

        user = backend.authenticate('foo', 'secret')
        assert user == User.objects.get()
        ok_(user.groups.filter(name='Localizers').exists())
        ok_(user.groups.filter(name='build').exists())

        new_groups = [
          ('cn=buildteam,ou=groups,dc=mozilla',
           {'cn': ['buildteam']})
        ]
        ldap.initialize = Mock(return_value=MockLDAP({
          'dc=mozilla': self.fake_user,
          'ou=groups,dc=mozilla': new_groups
        }))

        user = backend.authenticate('foo', 'secret')
        assert user == User.objects.get()
        ok_(not user.groups.filter(name='Localizers').exists())
        ok_(user.groups.filter(name='build').exists())

        # Now reverse it
        new_new_groups = [
          ('cn=scm_l10n,ou=groups,dc=mozilla',
           {'cn': ['scm_l10n']})
        ]
        ldap.initialize = Mock(return_value=MockLDAP({
          'dc=mozilla': self.fake_user,
          'ou=groups,dc=mozilla': new_new_groups
        }))

        user = backend.authenticate('foo', 'secret')
        assert user == User.objects.get()
        ok_(user.groups.filter(name='Localizers').exists())
        ok_(not user.groups.filter(name='build').exists())
开发者ID:Archaeopteryx,项目名称:elmo,代码行数:56,代码来源:tests.py

示例3: test_authenticate_without_ldap

# 需要导入模块: from lib.auth.backends import MozLdapBackend [as 别名]
# 或者: from lib.auth.backends.MozLdapBackend import authenticate [as 别名]
    def test_authenticate_without_ldap(self):
        assert not User.objects.all().exists()
        user = User.objects.create(username='foo', email='[email protected]')
        user.set_password('secret')
        user.save()

        backend = MozLdapBackend()
        eq_(backend.authenticate('[email protected]', 'secret'),
                         user)
        eq_(backend.authenticate('foo', 'secret'), user)
        eq_(backend.authenticate('foo', 'JUNK'), None)
开发者ID:lauraxt,项目名称:elmo,代码行数:13,代码来源:tests.py

示例4: test_authenticate_with_non_ascii_password

# 需要导入模块: from lib.auth.backends import MozLdapBackend [as 别名]
# 或者: from lib.auth.backends.MozLdapBackend import authenticate [as 别名]
    def test_authenticate_with_non_ascii_password(self):
        assert not User.objects.all().exists()
        ldap.open = Mock('ldap.open')
        ldap.open.mock_returns = Mock('ldap_connection')
        ldap.set_option = Mock(return_value=None)

        email = '[email protected]'
        fake_user = [
          ('mail=%s,...' % email,
           {'cn': ['Peter Bengtsson'],
            'givenName': ['Peter'],
            'mail': [email],
            'sn': ['Bengtsson'],
            'uid': ['pbengtsson']
            })
        ]

        ldap.initialize = Mock(return_value=MockLDAP({
          'dc=mozilla': fake_user,
          'ou=groups,dc=mozilla': self.fake_group
        }))
        backend = MozLdapBackend()

        user = backend.authenticate(email, 's\xc4cret')
        self.assertTrue(user)
        self.assertTrue(User.objects.get(email=email))
开发者ID:Pike,项目名称:elmo,代码行数:28,代码来源:tests.py

示例5: test_authenticate_with_ldap_new_user_with_long_email

# 需要导入模块: from lib.auth.backends import MozLdapBackend [as 别名]
# 或者: from lib.auth.backends.MozLdapBackend import authenticate [as 别名]
    def test_authenticate_with_ldap_new_user_with_long_email(self):
        assert not User.objects.all().exists()
        ldap.open = Mock("ldap.open")
        ldap.open.mock_returns = Mock("ldap_connection")
        ldap.set_option = Mock(return_value=None)

        long_email = "[email protected]"
        fake_user = [
            (
                "mail=%s,..." % long_email,
                {
                    "cn": ["Peter Bengtsson"],
                    "givenName": ["Pet\xc3\xa3r"],  # utf-8 encoded
                    "mail": [long_email],
                    "sn": ["Bengtss\xc2\xa2n"],
                    "uid": ["pbengtsson"],
                },
            )
        ]

        ldap.initialize = Mock(
            return_value=MockLDAP({"dc=mozilla": fake_user, "ou=groups,dc=mozilla": self.fake_group})
        )
        backend = MozLdapBackend()

        user = backend.authenticate(long_email, "secret")
        ok_(user)
        ok_(User.objects.get(email=long_email))
        ok_(len(User.objects.get(email=long_email).username) <= 30)
        user = User.objects.get(first_name=u"Pet\xe3r")
        eq_(user.last_name, u"Bengtss\xa2n")
        ok_(not user.has_usable_password())
        ok_(not user.check_password("secret"))
开发者ID:peterbe,项目名称:elmo,代码行数:35,代码来源:tests.py

示例6: test_authenticate_with_ldap_new_user_with_long_email

# 需要导入模块: from lib.auth.backends import MozLdapBackend [as 别名]
# 或者: from lib.auth.backends.MozLdapBackend import authenticate [as 别名]
    def test_authenticate_with_ldap_new_user_with_long_email(self):
        assert not User.objects.all().exists()
        ldap.open = Mock('ldap.open')
        ldap.open.mock_returns = Mock('ldap_connection')
        ldap.set_option = Mock(return_value=None)

        long_email = '[email protected]'
        fake_user = [
          ('mail=%s,...' % long_email,
           {'cn': ['Peter Bengtsson'],
            'givenName': ['Pet\xc3\xa3r'], # utf-8 encoded
            'mail': [long_email],
            'sn': ['Bengtss\xc2\xa2n'],
            'uid': ['pbengtsson']
            })
        ]

        ldap.initialize = Mock(return_value=MockLDAP({
          'dc=mozilla': fake_user,
          'ou=groups,dc=mozilla': self.fake_group
        }))
        backend = MozLdapBackend()

        user = backend.authenticate(long_email, 'secret')
        ok_(user)
        ok_(User.objects.get(email=long_email))
        ok_(len(User.objects.get(email=long_email).username) <= 30)
        user = User.objects.get(first_name=u'Pet\xe3r')
        eq_(user.last_name, u'Bengtss\xa2n')
        ok_(not user.has_usable_password())
        ok_(not user.check_password('secret'))
开发者ID:lauraxt,项目名称:elmo,代码行数:33,代码来源:tests.py

示例7: test_authenticate_with_ldap_existing_user

# 需要导入模块: from lib.auth.backends import MozLdapBackend [as 别名]
# 或者: from lib.auth.backends.MozLdapBackend import authenticate [as 别名]
    def test_authenticate_with_ldap_existing_user(self):
        assert not User.objects.all().exists()
        user = User.objects.create(
          username='foo',
          first_name=u'P\xe4ter',
          last_name=u'B\xa3ngtsson',
        )
        user.set_unusable_password()
        user.save()

        ldap.open = Mock('ldap.open')
        ldap.open.mock_returns = Mock('ldap_connection')
        ldap.set_option = Mock(return_value=None)

        ldap.initialize = Mock(return_value=MockLDAP({
          'dc=mozilla': self.fake_user,
          'ou=groups,dc=mozilla': self.fake_group
        }))
        backend = MozLdapBackend()

        user = backend.authenticate('foo', 'secret')
        ok_(user)
        _first_name = self.fake_user[0][1]['givenName'][0]
        eq_(user.first_name, unicode(_first_name, 'utf-8'))
        _last_name = self.fake_user[0][1]['sn'][0]
        eq_(user.last_name, unicode(_last_name, 'utf-8'))
        eq_(user.email, self.fake_user[0][1]['mail'][0])

        user_saved = User.objects.get(username='foo')
        eq_(user_saved.first_name, user.first_name)
        eq_(user_saved.last_name, user.last_name)
开发者ID:lauraxt,项目名称:elmo,代码行数:33,代码来源:tests.py

示例8: test_authenticate_with_ldap_existing_user

# 需要导入模块: from lib.auth.backends import MozLdapBackend [as 别名]
# 或者: from lib.auth.backends.MozLdapBackend import authenticate [as 别名]
    def test_authenticate_with_ldap_existing_user(self):
        assert not User.objects.all().exists()
        user = User.objects.create(
          username='foo',
          email='[email protected]',
          first_name='P\xe4ter',
          last_name='B\xa3ngtsson',
        )
        assert user.groups.all().count() == 0
        user.set_unusable_password()
        user.save()

        ldap.open = Mock('ldap.open')
        ldap.open.mock_returns = Mock('ldap_connection')
        ldap.set_option = Mock(return_value=None)

        ldap.initialize = Mock(return_value=MockLDAP({
          'dc=mozilla': self.fake_user,
          'ou=groups,dc=mozilla': self.fake_group
        }))
        backend = MozLdapBackend()

        user = backend.authenticate('[email protected]', 'secret')
        self.assertTrue(user)
        _first_name = self.fake_user[0][1]['givenName'][0]
        self.assertEqual(user.first_name, _first_name.decode('utf-8'))
        _last_name = self.fake_user[0][1]['sn'][0]
        self.assertEqual(user.last_name, _last_name.decode('utf-8'))
        self.assertEqual(user.email, self.fake_user[0][1]['mail'][0])

        user_saved = User.objects.get(email='[email protected]')
        self.assertEqual(user_saved.first_name, user.first_name)
        self.assertEqual(user_saved.last_name, user.last_name)

        self.assertTrue(user_saved.groups.filter(name='Localizers').exists())
开发者ID:Pike,项目名称:elmo,代码行数:37,代码来源:tests.py

示例9: test_authenticate_with_ldap_existing_user

# 需要导入模块: from lib.auth.backends import MozLdapBackend [as 别名]
# 或者: from lib.auth.backends.MozLdapBackend import authenticate [as 别名]
    def test_authenticate_with_ldap_existing_user(self):
        assert not User.objects.all().exists()
        user = User.objects.create(username="foo", first_name=u"P\xe4ter", last_name=u"B\xa3ngtsson")
        assert user.groups.all().count() == 0
        user.set_unusable_password()
        user.save()

        ldap.open = Mock("ldap.open")
        ldap.open.mock_returns = Mock("ldap_connection")
        ldap.set_option = Mock(return_value=None)

        ldap.initialize = Mock(
            return_value=MockLDAP({"dc=mozilla": self.fake_user, "ou=groups,dc=mozilla": self.fake_group})
        )
        backend = MozLdapBackend()

        user = backend.authenticate("foo", "secret")
        ok_(user)
        _first_name = self.fake_user[0][1]["givenName"][0]
        eq_(user.first_name, unicode(_first_name, "utf-8"))
        _last_name = self.fake_user[0][1]["sn"][0]
        eq_(user.last_name, unicode(_last_name, "utf-8"))
        eq_(user.email, self.fake_user[0][1]["mail"][0])

        user_saved = User.objects.get(username="foo")
        eq_(user_saved.first_name, user.first_name)
        eq_(user_saved.last_name, user.last_name)

        ok_(user_saved.groups.filter(name="Localizers").exists())
开发者ID:peterbe,项目名称:elmo,代码行数:31,代码来源:tests.py

示例10: test_authenticate_with_ldap_wrong_password

# 需要导入模块: from lib.auth.backends import MozLdapBackend [as 别名]
# 或者: from lib.auth.backends.MozLdapBackend import authenticate [as 别名]
 def test_authenticate_with_ldap_wrong_password(self):
     ldap.initialize = Mock(
         return_value=MockLDAP(
             {"dc=mozilla": self.fake_user, "ou=groups,dc=mozilla": self.fake_group},
             credentials={self.fake_user[0][0]: "rightsecret"},
         )
     )
     backend = MozLdapBackend()
     user = backend.authenticate("foo", "secret")
     eq_(user, None)
开发者ID:peterbe,项目名称:elmo,代码行数:12,代码来源:tests.py

示例11: test_authentication_ldap_username_not_recognized

# 需要导入模块: from lib.auth.backends import MozLdapBackend [as 别名]
# 或者: from lib.auth.backends.MozLdapBackend import authenticate [as 别名]
 def test_authentication_ldap_username_not_recognized(self):
     ldap.initialize = Mock(return_value=MockLDAP({
       'dc=mozilla': None,
       'ou=groups,dc=mozilla': self.fake_group
     }, credentials={
       self.fake_user[0][0]: 'secret'
     }))
     backend = MozLdapBackend()
     user = backend.authenticate('foo', 'secret')
     ok_(not user)
开发者ID:lauraxt,项目名称:elmo,代码行数:12,代码来源:tests.py

示例12: test_authenticate_with_ldap_wrong_username

# 需要导入模块: from lib.auth.backends import MozLdapBackend [as 别名]
# 或者: from lib.auth.backends.MozLdapBackend import authenticate [as 别名]
 def test_authenticate_with_ldap_wrong_username(self):
     ldap.initialize = Mock(return_value=MockLDAP({
       'dc=mozilla': self.fake_user,
       'ou=groups,dc=mozilla': self.fake_group
     }, credentials={
       'some-other-uid': 'secret'
     }))
     backend = MozLdapBackend()
     user = backend.authenticate('foo', 'secret')
     eq_(user, None)
开发者ID:lauraxt,项目名称:elmo,代码行数:12,代码来源:tests.py

示例13: test_authenticate_with_ldap_wrong_password

# 需要导入模块: from lib.auth.backends import MozLdapBackend [as 别名]
# 或者: from lib.auth.backends.MozLdapBackend import authenticate [as 别名]
 def test_authenticate_with_ldap_wrong_password(self):
     ldap.initialize = Mock(return_value=MockLDAP({
       'dc=mozilla': self.fake_user,
       'ou=groups,dc=mozilla': self.fake_group
     }, credentials={
       self.fake_user[0][0]: 'rightsecret'
     }))
     backend = MozLdapBackend()
     user = backend.authenticate('foo', 'secret')
     eq_(user, None)
开发者ID:lauraxt,项目名称:elmo,代码行数:12,代码来源:tests.py

示例14: test_authenticate_with_ldap_wrong_username

# 需要导入模块: from lib.auth.backends import MozLdapBackend [as 别名]
# 或者: from lib.auth.backends.MozLdapBackend import authenticate [as 别名]
 def test_authenticate_with_ldap_wrong_username(self):
     ldap.initialize = Mock(
         return_value=MockLDAP(
             {"dc=mozilla": self.fake_user, "ou=groups,dc=mozilla": self.fake_group},
             credentials={"some-other-uid": "secret"},
         )
     )
     backend = MozLdapBackend()
     user = backend.authenticate("foo", "secret")
     eq_(user, None)
开发者ID:peterbe,项目名称:elmo,代码行数:12,代码来源:tests.py

示例15: test_authentication_ldap_username_not_recognized

# 需要导入模块: from lib.auth.backends import MozLdapBackend [as 别名]
# 或者: from lib.auth.backends.MozLdapBackend import authenticate [as 别名]
 def test_authentication_ldap_username_not_recognized(self):
     ldap.initialize = Mock(
         return_value=MockLDAP(
             {"dc=mozilla": None, "ou=groups,dc=mozilla": self.fake_group},
             credentials={self.fake_user[0][0]: "secret"},
         )
     )
     backend = MozLdapBackend()
     user = backend.authenticate("foo", "secret")
     ok_(not user)
开发者ID:peterbe,项目名称:elmo,代码行数:12,代码来源:tests.py


注:本文中的lib.auth.backends.MozLdapBackend.authenticate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。