summaryrefslogtreecommitdiffstats
path: root/src/bin/shell
diff options
context:
space:
mode:
authorFrancis Dupont <fdupont@isc.org>2020-07-11 18:42:06 +0200
committerFrancis Dupont <fdupont@isc.org>2020-09-12 10:49:43 +0200
commit74d89a019e54db3885b13b44851912c4e030b36e (patch)
tree959d5065b4335977c899a2f69aa6b52a32cc80b2 /src/bin/shell
parent[#1304] Checkpoint: updated shell + http basic_auth (diff)
downloadkea-74d89a019e54db3885b13b44851912c4e030b36e.tar.xz
kea-74d89a019e54db3885b13b44851912c4e030b36e.zip
[#1304] Fixed unicode handling
Diffstat (limited to 'src/bin/shell')
-rw-r--r--src/bin/shell/kea-shell.in13
-rw-r--r--src/bin/shell/tests/shell_unittest.py.in24
2 files changed, 30 insertions, 7 deletions
diff --git a/src/bin/shell/kea-shell.in b/src/bin/shell/kea-shell.in
index d4fa02f101..32125655c2 100644
--- a/src/bin/shell/kea-shell.in
+++ b/src/bin/shell/kea-shell.in
@@ -30,9 +30,12 @@ from kea_conn import CARequest # CAResponse
if sys.version_info[0] == 2:
# This is Python 2.x
import kea_connector2 as kea_connector
+ def auth8(s):
+ return unicode(s, 'utf-8')
elif sys.version_info[0] == 3:
# This is Python 3.x
import kea_connector3 as kea_connector
+ auth8 = str
else:
# This is... have no idea what it is.
raise SystemExit("Unknown python version:" + str(sys.version_info[0]))
@@ -70,9 +73,9 @@ def shell_body():
parser.add_argument('--service', nargs="?", action="append",
help='target spcified service. If not specified,'
'control agent will receive command.')
- parser.add_argument('--auth-user', type=str, default='',
+ parser.add_argument('--auth-user', type=auth8, default='',
help='Basic HTTP authentication user')
- parser.add_argument('--auth-password', type=str, default='',
+ parser.add_argument('--auth-password', type=auth8, default='',
help='Basic HTTP authentication password')
parser.add_argument('command', type=str, nargs="?",
default='list-commands',
@@ -94,9 +97,9 @@ def shell_body():
params.http_port = cmd_args.port
params.path += cmd_args.path
if cmd_args.auth_user is not '':
- user = cmd_args.auth_user.encode('latin1')
- password = cmd_args.auth_password.encode('latin1')
- secret = b':'.join((user, password))
+ user = cmd_args.auth_user
+ password = cmd_args.auth_password
+ secret = b':'.join((user.encode('utf-8'), password.encode('utf-8')))
if sys.version_info[0] == 3:
params.auth = b64encode(secret).strip().decode('ascii')
else:
diff --git a/src/bin/shell/tests/shell_unittest.py.in b/src/bin/shell/tests/shell_unittest.py.in
index 74c320749f..b65b65c727 100644
--- a/src/bin/shell/tests/shell_unittest.py.in
+++ b/src/bin/shell/tests/shell_unittest.py.in
@@ -147,8 +147,8 @@ class CARequestUnitTest(unittest.TestCase):
"""
user = 'foo'
password = 'bar'
- buser = user.encode('latin1')
- bpassword = password.encode('latin1')
+ buser = user.encode('utf-8')
+ bpassword = password.encode('utf-8')
secret = b':'.join((buser, bpassword))
self.assertEqual(b'foo:bar', secret)
if sys.version_info[0] == 3:
@@ -157,6 +157,26 @@ class CARequestUnitTest(unittest.TestCase):
auth = b64encode(secret).strip().encode('ascii')
self.assertEqual('Zm9vOmJhcg==', auth)
+ def test_auth_unicode(self):
+ """
+ This test check if the basic HTTP authentication uses UTF-8 encoding.
+ """
+ if sys.version_info[0] == 3:
+ user = 'libert\xe9'
+ password = '\xe9galit\xe9'
+ else:
+ user = u'libert\xe9'
+ password = u'\xe9galit\xe9'
+ buser = user.encode('utf-8')
+ bpassword = password.encode('utf-8')
+ secret = b':'.join((buser, bpassword))
+ self.assertEqual(b'libert\xc3\xa9:\xc3\xa9galit\xc3\xa9', secret)
+ if sys.version_info[0] == 3:
+ auth = b64encode(secret).strip().decode('ascii')
+ else:
+ auth = b64encode(secret).strip().encode('ascii')
+ self.assertEqual('bGliZXJ0w6k6w6lnYWxpdMOp', auth)
+
def test_header_auth(self):
"""
This test checks if the basic HTTP authentication header is