Skip to content

Commit

Permalink
do unquote to set basic auth headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
keijack committed Nov 7, 2022
1 parent 9d48b62 commit 065da80
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion py_eureka_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
SOFTWARE.
"""

version = "0.11.4"
version = "0.11.5"

"""
Status of instances
Expand Down
7 changes: 4 additions & 3 deletions py_eureka_client/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
import re
import base64
import gzip
from typing import Union

import urllib.request
import urllib.error

from typing import Union
from urllib.parse import unquote


class HTTPError(urllib.error.HTTPError):
pass
Expand Down Expand Up @@ -64,7 +65,7 @@ def parse_url(url):
addr = url
if m.group(2) is not None:
addr = addr.replace(m.group(2), "")
ori_auth = f"{m.group(3)}:{m.group(4)}".encode()
ori_auth = f"{unquote(m.group(3))}:{unquote(m.group(4))}".encode()
auth_str = base64.standard_b64encode(ori_auth).decode()
else:
auth_str = None
Expand Down
41 changes: 41 additions & 0 deletions tests/py_eureka_client/test_http_basic_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-

"""
Copyright (c) 2018 Keijack Wu
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

import unittest
import asyncio

import py_eureka_client.logger as logger
from py_eureka_client.http_client import HttpClient, HttpRequest, HttpResponse

logger.set_level("DEBUG")


class TestEurekaServer(unittest.TestCase):

def test_load_page(self):
req = HttpRequest("http://keijack:qwe%40rty%[email protected]:8080/a.txt")
client = HttpClient()
res: HttpResponse = asyncio.run(client.urlopen(req))
print(res.body_text)
assert res.body_text == 'hello!'

0 comments on commit 065da80

Please sign in to comment.