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]))
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',
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:
"""
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:
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