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


Python http.parse_dict_header函数代码示例

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


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

示例1: test_digest_auth_login_valid

    def test_digest_auth_login_valid(self):
        response = self.client.get("/digest")
        self.assertTrue(response.status_code == 401)
        header = response.headers.get("WWW-Authenticate")
        auth_type, auth_info = header.split(None, 1)
        d = parse_dict_header(auth_info)

        a1 = "john:" + d["realm"] + ":bye"
        ha1 = md5(a1).hexdigest()
        a2 = "GET:/digest"
        ha2 = md5(a2).hexdigest()
        a3 = ha1 + ":" + d["nonce"] + ":" + ha2
        auth_response = md5(a3).hexdigest()

        response = self.client.get(
            "/digest",
            headers={
                "Authorization": 'Digest username="john",realm="'
                + d["realm"]
                + '",nonce="'
                + d["nonce"]
                + '",uri="/digest",response="'
                + auth_response
                + '",opaque="'
                + d["opaque"]
                + '"'
            },
        )
        self.assertTrue(response.data == b"digest_auth:john")
开发者ID:ntrifunovic,项目名称:Flask-HTTPAuth,代码行数:29,代码来源:test_httpauth.py

示例2: _test_digest_response_for_auth_request

    def _test_digest_response_for_auth_request(self, header, username, password, qop, uri, body, nc=1, nonce=None):
        auth_type, auth_info = header.split(None, 1)
        self.assertEqual(auth_type, 'Digest')

        d = parse_dict_header(auth_info)

        nonce = nonce or d['nonce']
        realm = d['realm']
        opaque = d['opaque']
        if qop :
            self.assertIn(qop, [x.strip() for x in d['qop'].split(',')], 'Challenge should contains expected qop')
        algorithm = d['algorithm']

        cnonce, nc = (_hash(os.urandom(10), "MD5"), '{:08}'.format(nc)) if qop in ('auth', 'auth-int') else (None, None)

        auth_header = _make_digest_auth_header(
            username, password, 'GET', uri, nonce, realm, opaque, algorithm, qop, cnonce, nc, body)

        # make second request
        return self.app.get(
            uri,
            environ_base={
                # httpbin's digest auth implementation uses the remote addr to
                # build the nonce
                'REMOTE_ADDR': '127.0.0.1',
            },
            headers={
                'Authorization': auth_header,
            },
            data=body
        ), nonce
开发者ID:wermington,项目名称:httpbin,代码行数:31,代码来源:test_httpbin.py

示例3: test_digest_auth_login_invalid2

    def test_digest_auth_login_invalid2(self):
        response = self.client.get('/digest')
        self.assertEqual(response.status_code, 401)
        header = response.headers.get('WWW-Authenticate')
        auth_type, auth_info = header.split(None, 1)
        d = parse_dict_header(auth_info)

        a1 = 'david:' + 'Authentication Required' + ':bye'
        ha1 = md5(a1).hexdigest()
        a2 = 'GET:/digest'
        ha2 = md5(a2).hexdigest()
        a3 = ha1 + ':' + d['nonce'] + ':' + ha2
        auth_response = md5(a3).hexdigest()

        response = self.client.get(
            '/digest', headers={
                'Authorization': 'Digest username="david",realm="{0}",'
                                 'nonce="{1}",uri="/digest",response="{2}",'
                                 'opaque="{3}"'.format(d['realm'],
                                                       d['nonce'],
                                                       auth_response,
                                                       d['opaque'])})
        self.assertEqual(response.status_code, 401)
        self.assertTrue('WWW-Authenticate' in response.headers)
        self.assertTrue(re.match(r'^Digest realm="Authentication Required",'
                                 r'nonce="[0-9a-f]+",opaque="[0-9a-f]+"$',
                                 response.headers['WWW-Authenticate']))
开发者ID:mozedz,项目名称:Flask-HTTPAuth,代码行数:27,代码来源:test_httpauth.py

示例4: test_digest_custom_nonce_checker

    def test_digest_custom_nonce_checker(self):
        @self.digest_auth.generate_nonce
        def noncemaker():
            return 'not a good nonce'

        @self.digest_auth.generate_opaque
        def opaquemaker():
            return 'some opaque'

        verify_nonce_called = []

        @self.digest_auth.verify_nonce
        def verify_nonce(provided_nonce):
            verify_nonce_called.append(provided_nonce)
            return True

        verify_opaque_called = []

        @self.digest_auth.verify_opaque
        def verify_opaque(provided_opaque):
            verify_opaque_called.append(provided_opaque)
            return True

        response = self.client.get('/digest')
        self.assertEqual(response.status_code, 401)
        header = response.headers.get('WWW-Authenticate')
        auth_type, auth_info = header.split(None, 1)
        d = parse_dict_header(auth_info)

        self.assertEqual(d['nonce'], 'not a good nonce')
        self.assertEqual(d['opaque'], 'some opaque')

        a1 = 'john:' + d['realm'] + ':bye'
        ha1 = md5(a1).hexdigest()
        a2 = 'GET:/digest'
        ha2 = md5(a2).hexdigest()
        a3 = ha1 + ':' + d['nonce'] + ':' + ha2
        auth_response = md5(a3).hexdigest()

        response = self.client.get(
            '/digest', headers={
                'Authorization': 'Digest username="john",realm="{0}",'
                                 'nonce="{1}",uri="/digest",response="{2}",'
                                 'opaque="{3}"'.format(d['realm'],
                                                       d['nonce'],
                                                       auth_response,
                                                       d['opaque'])})
        self.assertEqual(response.data, b'digest_auth:john')
        self.assertEqual(verify_nonce_called, ['not a good nonce'],
                         "Should have verified the nonce.")
        self.assertEqual(verify_opaque_called, ['some opaque'],
                         "Should have verified the opaque.")
开发者ID:pstiasny,项目名称:Flask-HTTPAuth,代码行数:52,代码来源:test_httpauth.py

示例5: enc_cookie

def enc_cookie(val, type='req'):
  val = http.parse_dict_header(val)
  _v = ''
  for k,v in val.items():
    _v += '_' # simulate flags
    _v += enc_uvarint(len(k))
    _v += k
    value = attempt_decode(v)
    if not value is None:
      _v += enc_uvarint(len(value))
      _v += value
    else:
      _v += enc_uvarint(0)
  return _v
开发者ID:hruellan,项目名称:compression-test,代码行数:14,代码来源:bohe.py

示例6: encode

 def encode(self, val):
   val = http.parse_dict_header(val)
   _v = ''
   for k,v in val.items():
     _v += '_' # simulate flags
     _v += self.enc_uvarint(len(k))
     _v += k
     value = self.attempt_decode(v)
     if not value is None:
       _v += self.enc_uvarint(len(value))
       _v += value
     else:
       _v += self.enc_uvarint(0)
   return _v
开发者ID:hruellan,项目名称:compression-test,代码行数:14,代码来源:bohe.py

示例7: test_digest_auth

    def test_digest_auth(self):
        # make first request
        unauthorized_response = self.app.get(
            "/digest-auth/auth/user/passwd",
            environ_base={
                # digest auth uses the remote addr to build the nonce
                "REMOTE_ADDR": "127.0.0.1"
            },
        )
        # make sure it returns a 401
        self.assertEqual(unauthorized_response.status_code, 401)
        header = unauthorized_response.headers.get("WWW-Authenticate")
        auth_type, auth_info = header.split(None, 1)

        # Begin crappy digest-auth implementation
        d = parse_dict_header(auth_info)
        a1 = b"user:" + d["realm"].encode("utf-8") + b":passwd"
        ha1 = md5(a1).hexdigest().encode("utf-8")
        a2 = b"GET:/digest-auth/auth/user/passwd"
        ha2 = md5(a2).hexdigest().encode("utf-8")
        a3 = ha1 + b":" + d["nonce"].encode("utf-8") + b":" + ha2
        auth_response = md5(a3).hexdigest()
        auth_header = (
            'Digest username="user",realm="'
            + d["realm"]
            + '",nonce="'
            + d["nonce"]
            + '",uri="/digest-auth/auth/user/passwd",response="'
            + auth_response
            + '",opaque="'
            + d["opaque"]
            + '"'
        )

        # make second request
        authorized_response = self.app.get(
            "/digest-auth/auth/user/passwd",
            environ_base={
                # httpbin's digest auth implementation uses the remote addr to
                # build the nonce
                "REMOTE_ADDR": "127.0.0.1"
            },
            headers={"Authorization": auth_header},
        )

        # done!
        self.assertEqual(authorized_response.status_code, 200)
开发者ID:4honor,项目名称:httpbin,代码行数:47,代码来源:test_httpbin.py

示例8: test_digest_auth

    def test_digest_auth(self):
        # make first request
        unauthorized_response = self.app.get(
            '/digest-auth/auth/user/passwd',
            environ_base={
                # digest auth uses the remote addr to build the nonce
                'REMOTE_ADDR': '127.0.0.1',
            }
        )
        # make sure it returns a 401
        self.assertEqual(unauthorized_response.status_code, 401)
        header = unauthorized_response.headers.get('WWW-Authenticate')
        auth_type, auth_info = header.split(None, 1)

        # Begin crappy digest-auth implementation
        d = parse_dict_header(auth_info)
        a1 = b'user:' + d['realm'].encode('utf-8') + b':passwd'
        ha1 = md5(a1).hexdigest().encode('utf-8')
        a2 = b'GET:/digest-auth/auth/user/passwd'
        ha2 = md5(a2).hexdigest().encode('utf-8')
        a3 = ha1 + b':' + d['nonce'].encode('utf-8') + b':' + ha2
        auth_response = md5(a3).hexdigest()
        auth_header = 'Digest username="user",realm="' + \
            d['realm'] + \
            '",nonce="' + \
            d['nonce'] + \
            '",uri="/digest-auth/auth/user/passwd",response="' + \
            auth_response + \
            '",opaque="' + \
            d['opaque'] + '"'

        # make second request
        authorized_response = self.app.get(
            '/digest-auth/auth/user/passwd',
            environ_base={
                # httpbin's digest auth implementation uses the remote addr to
                # build the nonce
                'REMOTE_ADDR': '127.0.0.1',
            },
            headers={
                'Authorization': auth_header,
            }
        )

        # done!
        self.assertEqual(authorized_response.status_code, 200)
开发者ID:amywhays,项目名称:httpbin,代码行数:46,代码来源:test_httpbin.py

示例9: test_digest_auth_login_valid

    def test_digest_auth_login_valid(self):
        response = self.client.get('/digest')
        self.assertTrue(response.status_code == 401)
        header = response.headers.get('WWW-Authenticate')
        auth_type, auth_info = header.split(None, 1)
        d = parse_dict_header(auth_info)

        a1 = 'john:' + d['realm'] + ':bye'
        ha1 = md5(a1).hexdigest()
        a2 = 'GET:/digest'
        ha2 = md5(a2).hexdigest()
        a3 = ha1 + ':' + d['nonce'] + ':' + ha2
        auth_response = md5(a3).hexdigest()

        response = self.client.get('/digest',
            headers = { 'Authorization': 'Digest username="john",realm="' + d['realm'] + '",nonce="' + d['nonce'] + '",uri="/digest",response="' + auth_response + '",opaque="' + d['opaque'] + '"' })
        self.assertTrue(response.data == b'digest_auth:john')
开发者ID:cnupdog,项目名称:Flask-HTTPAuth,代码行数:17,代码来源:test_httpauth.py

示例10: _test_digest_auth

    def _test_digest_auth(self, username, password, qop=None, algorithm=None, body=None):
        uri = '/digest-auth/{0}/{1}/{2}'.format(qop or 'wrong-qop', username, password)
        if algorithm:
            uri += '/' + algorithm

        unauthorized_response = self.app.get(
            uri,
            environ_base={
                # digest auth uses the remote addr to build the nonce
                'REMOTE_ADDR': '127.0.0.1',
            }
        )
        # make sure it returns a 401
        self.assertEqual(unauthorized_response.status_code, 401)
        header = unauthorized_response.headers.get('WWW-Authenticate')
        auth_type, auth_info = header.split(None, 1)
        self.assertEqual(auth_type, 'Digest')

        d = parse_dict_header(auth_info)

        nonce = d['nonce']
        realm = d['realm']
        opaque = d['opaque']
        cnonce, nc = (_hash(os.urandom(10), "MD5"), '00000001') if qop in ('auth', 'auth-int') else (None, None)

        auth_header = _make_digest_auth_header(
            username, password, 'GET', uri, nonce, realm, opaque, algorithm, qop, cnonce, nc, body)

        # make second request
        authorized_response = self.app.get(
            uri,
            environ_base={
                # httpbin's digest auth implementation uses the remote addr to
                # build the nonce
                'REMOTE_ADDR': '127.0.0.1',
            },
            headers={
                'Authorization': auth_header,
            },
            data=body
        )

        # done!
        self.assertEqual(authorized_response.status_code, 200)
开发者ID:msabramo,项目名称:httpbin,代码行数:44,代码来源:test_httpbin.py

示例11: test_digest_auth_login_bad_realm

    def test_digest_auth_login_bad_realm(self):
        response = self.client.get('/digest')
        self.assertTrue(response.status_code == 401)
        header = response.headers.get("WWW-Authenticate")
        auth_type, auth_info = header.split(None, 1)
        d = parse_dict_header(auth_info)

        a1 = "john:" + 'Wrong Realm' + ":bye" 
        ha1 = md5(a1).hexdigest()
        a2 = "GET:/digest"
        ha2 = md5(a2).hexdigest()
        a3 = ha1 + ":" + d['nonce'] + ":" + ha2
        auth_response = md5(a3).hexdigest()

        response = self.client.get('/digest', 
            headers = { "Authorization": 'Digest username="john",realm="' + d['realm'] + '",nonce="' + d['nonce'] + '",uri="/digest",response="' + auth_response + '",opaque="' + d['opaque'] + '"' })
        self.assertTrue(response.status_code == 401)
        self.assertTrue("WWW-Authenticate" in response.headers)
        self.assertTrue(re.match(r'^Digest realm="Authentication Required",nonce="[0-9a-f]+",opaque="[0-9a-f]+"$', response.headers["WWW-Authenticate"]))
开发者ID:ruscruzel,项目名称:Flask-HTTPAuth,代码行数:19,代码来源:test_httpauth.py

示例12: test_digest_ha1_pw_auth_login_valid

    def test_digest_ha1_pw_auth_login_valid(self):
        response = self.client.get('/digest_ha1_pw')
        self.assertTrue(response.status_code == 401)
        header = response.headers.get('WWW-Authenticate')
        auth_type, auth_info = header.split(None, 1)
        d = parse_dict_header(auth_info)

        a1 = 'john:' + d['realm'] + ':bye'
        ha1 = md5(a1).hexdigest()
        a2 = 'GET:/digest_ha1_pw'
        ha2 = md5(a2).hexdigest()
        a3 = ha1 + ':' + d['nonce'] + ':' + ha2
        auth_response = md5(a3).hexdigest()

        response = self.client.get(
            '/digest', headers={
                'Authorization': 'Digest username="john",realm="{0}",'
                                 'nonce="{1}",uri="/digest_ha1_pw",response="{2}",'
                                 'opaque="{3}"'.format(d['realm'],
                                                       d['nonce'],
                                                       auth_response,
                                                       d['opaque'])})
        self.assertEqual(response.data, b'digest_auth:john')
开发者ID:mozedz,项目名称:Flask-HTTPAuth,代码行数:23,代码来源:test_httpauth.py

示例13: enc_p3p

def enc_p3p(val, type='req'):
  val = http.parse_dict_header(val)
  _v = ''
  # policy refs
  if 'policyref' in val:
    _v += enc_uvarint(len(val['policyref']))
    _v += val['policyref']
  else:
    _v += enc_uvarint(0)
  cp = ''
  if 'CP' in val:
    tokens = val['CP'].split(' ')
    for token in tokens:
      # check for the fake P3P profiles like google produces... will ignore those nil values for now
      if not token[:3] in p3p_table:
        cp = '' 
        break
      q = (p3p_table.index(token[:3])+1) << 2
      if len(token) == 4:
        q |= ['a','i','o'].index(token[-1])
      cp += struct.pack('!B',q)
  if len(cp) > 0:
    _v += cp
  return _v
开发者ID:hruellan,项目名称:compression-test,代码行数:24,代码来源:bohe.py

示例14: test_dict_header

 def test_dict_header(self):
     d = http.parse_dict_header('foo="bar baz", blah=42')
     assert d == {'foo': 'bar baz', 'blah': '42'}
开发者ID:TomCorwine,项目名称:werkzeug,代码行数:3,代码来源:test_http.py

示例15: test_dict_header

 def test_dict_header(self):
     d = http.parse_dict_header('foo="bar baz", blah=42')
     self.assert_equal(d, {"foo": "bar baz", "blah": "42"})
开发者ID:homeworkprod,项目名称:werkzeug,代码行数:3,代码来源:http.py


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