• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python authentication.DigestAuthentication类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tastypie.authentication.DigestAuthentication的典型用法代码示例。如果您正苦于以下问题:Python DigestAuthentication类的具体用法?Python DigestAuthentication怎么用?Python DigestAuthentication使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_check_active_false

    def test_check_active_false(self):
        auth = DigestAuthentication(require_active=False)
        request = HttpRequest()

        bob_doe = User.objects.get(username='bobdoe')
        create_api_key(User, instance=bob_doe, created=True)
        auth_request = auth.is_authenticated(request)
        request.META['HTTP_AUTHORIZATION'] = python_digest.build_authorization_request(
            username=bob_doe.username,
            method=request.method,
            uri='/',
            nonce_count=1,
            digest_challenge=python_digest.parse_digest_challenge(auth_request['WWW-Authenticate']),
            password=bob_doe.api_key.key
        )
        auth_request = auth.is_authenticated(request)
        self.assertTrue(auth_request, True)
开发者ID:mthornhill,项目名称:django-tastypie,代码行数:17,代码来源:authentication.py


示例2: test_check_active_true

    def test_check_active_true(self):
        auth = DigestAuthentication()
        request = HttpRequest()

        bob_doe = User.objects.get(username='bobdoe')
        create_api_key(User, instance=bob_doe, created=True)
        auth_request = auth.is_authenticated(request)
        request.META['HTTP_AUTHORIZATION'] = python_digest.build_authorization_request(
            bob_doe.username,
            request.method,
            '/', # uri
            1,   # nonce_count
            digest_challenge=auth_request['WWW-Authenticate'],
            password=bob_doe.api_key.key
        )
        auth_request = auth.is_authenticated(request)
        self.assertFalse(auth_request)
开发者ID:10to8,项目名称:django-tastypie,代码行数:17,代码来源:authentication.py


示例3: test_check_active_true

    def test_check_active_true(self):
        auth = DigestAuthentication()
        request = HttpRequest()

        bob_doe = User.objects.get(username="bobdoe")
        create_api_key(User, instance=bob_doe, created=True)
        auth_request = auth.is_authenticated(request)
        request.META["HTTP_AUTHORIZATION"] = python_digest.build_authorization_request(
            username=bob_doe.username,
            method=request.method,
            uri="/",
            nonce_count=1,
            digest_challenge=python_digest.parse_digest_challenge(auth_request["WWW-Authenticate"]),
            password=bob_doe.api_key.key,
        )
        auth_request = auth.is_authenticated(request)
        self.assertFalse(auth_request)
开发者ID:mattbriancon,项目名称:django-tastypie,代码行数:17,代码来源:authentication.py


示例4: test_whitelisting

    def test_whitelisting(self):
        auth = DigestAuthentication(whitelisted_methods=['a_method'])
        request = HttpRequest()

        # Simulate sending the signal.
        john_doe = User.objects.get(username='johndoe')
        create_api_key(User, instance=john_doe, created=True)

        # Calling with a whitelisted method_name without credentials should work
        self.assertEqual(auth.is_authenticated(request, method_name='a_method'), True)
        
        # Calling any other method should require the Api Key
        self.assertEqual(isinstance(auth.is_authenticated(request, method_name='another_method'), HttpUnauthorized), True)

        # Correct digest
        john_doe = User.objects.get(username='johndoe')
        request.META['HTTP_AUTHORIZATION'] = python_digest.build_authorization_request(
            john_doe.username,
            request.method,
            '/', # uri
            1,   # nonce_count
            digest_challenge=auth.is_authenticated(request)['WWW-Authenticate'],
            password=john_doe.api_key.key
        )
        self.assertEqual(auth.is_authenticated(request, method_name="another_method"), True)
        self.assertEqual(auth.is_authenticated(request, method_name="a_method"), True)
开发者ID:YACFirm,项目名称:django-tastypie,代码行数:26,代码来源:authentication.py


示例5: test_is_authenticated

    def test_is_authenticated(self):
        auth = DigestAuthentication()
        request = HttpRequest()

        # Simulate sending the signal.
        john_doe = User.objects.get(username='johndoe')
        create_api_key(User, instance=john_doe, created=True)

        # No HTTP Basic auth details should fail.
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # HttpUnauthorized with auth type and realm
        self.assertEqual(auth_request['WWW-Authenticate'].find('Digest'), 0)
        self.assertEqual(auth_request['WWW-Authenticate'].find(' realm="django-tastypie"') > 0, True)
        self.assertEqual(auth_request['WWW-Authenticate'].find(' opaque=') > 0, True)
        self.assertEqual(auth_request['WWW-Authenticate'].find('nonce=') > 0, True)

        # Wrong basic auth details.
        request.META['HTTP_AUTHORIZATION'] = 'abcdefg'
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # No password.
        request.META['HTTP_AUTHORIZATION'] = base64.b64encode('daniel'.encode('utf-8')).decode('utf-8')
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # Wrong user/password.
        request.META['HTTP_AUTHORIZATION'] = base64.b64encode('daniel:pass'.encode('utf-8')).decode('utf-8')
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # Correct user/password.
        john_doe = User.objects.get(username='johndoe')
        request.META['HTTP_AUTHORIZATION'] = python_digest.build_authorization_request(
            username=john_doe.username,
            method=request.method,
            uri='/',
            nonce_count=1,
            digest_challenge=python_digest.parse_digest_challenge(auth_request['WWW-Authenticate']),
            password=john_doe.api_key.key
        )
        auth_request = auth.is_authenticated(request)
        self.assertEqual(auth_request, True)
开发者ID:mthornhill,项目名称:django-tastypie,代码行数:45,代码来源:authentication.py


示例6: test_is_authenticated

    def test_is_authenticated(self):
        auth = DigestAuthentication()
        request = HttpRequest()

        # Simulate sending the signal.
        john_doe = User.objects.get(username="johndoe")
        create_api_key(User, instance=john_doe, created=True)

        # No HTTP Basic auth details should fail.
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # HttpUnauthorized with auth type and realm
        self.assertEqual(auth_request["WWW-Authenticate"].find("Digest"), 0)
        self.assertEqual(auth_request["WWW-Authenticate"].find(' realm="django-tastypie"') > 0, True)
        self.assertEqual(auth_request["WWW-Authenticate"].find(" opaque=") > 0, True)
        self.assertEqual(auth_request["WWW-Authenticate"].find("nonce=") > 0, True)

        # Wrong basic auth details.
        request.META["HTTP_AUTHORIZATION"] = "abcdefg"
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # No password.
        request.META["HTTP_AUTHORIZATION"] = base64.b64encode("daniel")
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # Wrong user/password.
        request.META["HTTP_AUTHORIZATION"] = base64.b64encode("daniel:pass")
        auth_request = auth.is_authenticated(request)
        self.assertEqual(isinstance(auth_request, HttpUnauthorized), True)

        # Correct user/password.
        john_doe = User.objects.get(username="johndoe")
        request.META["HTTP_AUTHORIZATION"] = python_digest.build_authorization_request(
            john_doe.username,
            request.method,
            "/",  # uri
            1,  # nonce_count
            digest_challenge=auth_request["WWW-Authenticate"],
            password=john_doe.api_key.key,
        )
        auth_request = auth.is_authenticated(request)
        self.assertEqual(auth_request, True)
开发者ID:coffindragger,项目名称:django-tastypie,代码行数:45,代码来源:authentication.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python authentication.MultiAuthentication类代码示例发布时间:2022-05-27
下一篇:
Python authentication.BasicAuthentication类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap