mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Use byte literals where appropriate
Reviewed-By: Petr Viktorin <pviktori@redhat.com>
This commit is contained in:
@@ -87,7 +87,7 @@ class update_upload_cacrt(Updater):
|
|||||||
entry.single_value['cACertificate;binary'] = ca_cert
|
entry.single_value['cACertificate;binary'] = ca_cert
|
||||||
ldap.add_entry(entry)
|
ldap.add_entry(entry)
|
||||||
else:
|
else:
|
||||||
if '' in entry['cACertificate;binary']:
|
if b'' in entry['cACertificate;binary']:
|
||||||
entry.single_value['cACertificate;binary'] = ca_cert
|
entry.single_value['cACertificate;binary'] = ca_cert
|
||||||
ldap.update_entry(entry)
|
ldap.update_entry(entry)
|
||||||
|
|
||||||
|
|||||||
@@ -1260,7 +1260,7 @@ class ReplicationManager(object):
|
|||||||
sub = {'suffix': self.suffix, 'fqdn': replica}
|
sub = {'suffix': self.suffix, 'fqdn': replica}
|
||||||
try:
|
try:
|
||||||
entry.raw['aci'].remove(
|
entry.raw['aci'].remove(
|
||||||
'(target = "ldap:///cn=*,cn=ca_renewal,cn=ipa,cn=etc,'
|
b'(target = "ldap:///cn=*,cn=ca_renewal,cn=ipa,cn=etc,'
|
||||||
'%(suffix)s")(version 3.0; acl "Add CA Certificates for '
|
'%(suffix)s")(version 3.0; acl "Add CA Certificates for '
|
||||||
'renewals"; allow(add) userdn = "ldap:///fqdn=%(fqdn)s,'
|
'renewals"; allow(add) userdn = "ldap:///fqdn=%(fqdn)s,'
|
||||||
'cn=computers,cn=accounts,%(suffix)s";)' % sub)
|
'cn=computers,cn=accounts,%(suffix)s";)' % sub)
|
||||||
@@ -1268,7 +1268,7 @@ class ReplicationManager(object):
|
|||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
entry.raw['aci'].remove(
|
entry.raw['aci'].remove(
|
||||||
'(target = "ldap:///cn=*,cn=ca_renewal,cn=ipa,cn=etc,'
|
b'(target = "ldap:///cn=*,cn=ca_renewal,cn=ipa,cn=etc,'
|
||||||
'%(suffix)s")(targetattr = "userCertificate")'
|
'%(suffix)s")(targetattr = "userCertificate")'
|
||||||
'(version 3.0; acl "Modify CA Certificates for renewals"; '
|
'(version 3.0; acl "Modify CA Certificates for renewals"; '
|
||||||
'allow(write) userdn = "ldap:///fqdn=%(fqdn)s,'
|
'allow(write) userdn = "ldap:///fqdn=%(fqdn)s,'
|
||||||
@@ -1277,7 +1277,7 @@ class ReplicationManager(object):
|
|||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
entry.raw['aci'].remove(
|
entry.raw['aci'].remove(
|
||||||
'(target = "ldap:///cn=CAcert,cn=ipa,cn=etc,%(suffix)s")'
|
b'(target = "ldap:///cn=CAcert,cn=ipa,cn=etc,%(suffix)s")'
|
||||||
'(targetattr = cACertificate)(version 3.0; acl "Modify CA '
|
'(targetattr = cACertificate)(version 3.0; acl "Modify CA '
|
||||||
'Certificate"; allow (write) userdn = "ldap:///fqdn='
|
'Certificate"; allow (write) userdn = "ldap:///fqdn='
|
||||||
'%(fqdn)s,cn=computers,cn=accounts,%(suffix)s";)' % sub)
|
'%(fqdn)s,cn=computers,cn=accounts,%(suffix)s";)' % sub)
|
||||||
@@ -1305,7 +1305,7 @@ class ReplicationManager(object):
|
|||||||
sub = {'suffix': self.suffix, 'fqdn': replica}
|
sub = {'suffix': self.suffix, 'fqdn': replica}
|
||||||
try:
|
try:
|
||||||
entry.raw['aci'].remove(
|
entry.raw['aci'].remove(
|
||||||
'(targetfilter = "(objectClass=nsContainer)")'
|
b'(targetfilter = "(objectClass=nsContainer)")'
|
||||||
'(targetattr = "cn || objectClass || ipaConfigString")'
|
'(targetattr = "cn || objectClass || ipaConfigString")'
|
||||||
'(version 3.0; acl "Read IPA Masters"; allow (read, '
|
'(version 3.0; acl "Read IPA Masters"; allow (read, '
|
||||||
'search, compare) userdn = "ldap:///fqdn=%(fqdn)s,'
|
'search, compare) userdn = "ldap:///fqdn=%(fqdn)s,'
|
||||||
@@ -1314,7 +1314,7 @@ class ReplicationManager(object):
|
|||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
entry.raw['aci'].remove(
|
entry.raw['aci'].remove(
|
||||||
'(targetfilter = "(objectClass=nsContainer)")'
|
b'(targetfilter = "(objectClass=nsContainer)")'
|
||||||
'(targetattr = "ipaConfigString")(version 3.0; acl '
|
'(targetattr = "ipaConfigString")(version 3.0; acl '
|
||||||
'"Modify IPA Masters"; allow (write) userdn = '
|
'"Modify IPA Masters"; allow (write) userdn = '
|
||||||
'"ldap:///fqdn=%(fqdn)s,cn=computers,cn=accounts,'
|
'"ldap:///fqdn=%(fqdn)s,cn=computers,cn=accounts,'
|
||||||
@@ -1343,7 +1343,7 @@ class ReplicationManager(object):
|
|||||||
sub = {'suffix': self.suffix, 'fqdn': replica}
|
sub = {'suffix': self.suffix, 'fqdn': replica}
|
||||||
try:
|
try:
|
||||||
entry.raw['aci'].remove(
|
entry.raw['aci'].remove(
|
||||||
'(targetfilter = "(&(objectClass=ipaCertificate)'
|
b'(targetfilter = "(&(objectClass=ipaCertificate)'
|
||||||
'(ipaConfigString=ipaCA))")(targetattr = '
|
'(ipaConfigString=ipaCA))")(targetattr = '
|
||||||
'"ipaCertIssuerSerial || cACertificate")(version 3.0; acl '
|
'"ipaCertIssuerSerial || cACertificate")(version 3.0; acl '
|
||||||
'"Modify CA Certificate Store Entry"; allow (write) '
|
'"Modify CA Certificate Store Entry"; allow (write) '
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ import struct
|
|||||||
|
|
||||||
|
|
||||||
# A string that should have bytes 'x\00' through '\xff':
|
# A string that should have bytes 'x\00' through '\xff':
|
||||||
binary_bytes = ''.join(struct.pack('B', d) for d in range(256))
|
binary_bytes = b''.join(struct.pack('B', d) for d in range(256))
|
||||||
assert '\x00' in binary_bytes and '\xff' in binary_bytes
|
assert b'\x00' in binary_bytes and b'\xff' in binary_bytes
|
||||||
assert type(binary_bytes) is str and len(binary_bytes) == 256
|
assert type(binary_bytes) is str and len(binary_bytes) == 256
|
||||||
|
|
||||||
# A UTF-8 encoded str:
|
# A UTF-8 encoded str:
|
||||||
utf8_bytes = '\xd0\x9f\xd0\xb0\xd0\xb2\xd0\xb5\xd0\xbb'
|
utf8_bytes = b'\xd0\x9f\xd0\xb0\xd0\xb2\xd0\xb5\xd0\xbb'
|
||||||
|
|
||||||
# The same UTF-8 data decoded (a unicode instance):
|
# The same UTF-8 data decoded (a unicode instance):
|
||||||
unicode_str = u'\u041f\u0430\u0432\u0435\u043b'
|
unicode_str = u'\u041f\u0430\u0432\u0435\u043b'
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ from ipalib import _
|
|||||||
if six.PY3:
|
if six.PY3:
|
||||||
unicode = str
|
unicode = str
|
||||||
|
|
||||||
NULLS = (None, '', u'', tuple(), [])
|
NULLS = (None, b'', u'', tuple(), [])
|
||||||
|
|
||||||
class test_DefaultFrom(ClassChecker):
|
class test_DefaultFrom(ClassChecker):
|
||||||
"""
|
"""
|
||||||
@@ -1636,4 +1636,4 @@ class test_DateTime(ClassChecker):
|
|||||||
u'1991-31-12Z',
|
u'1991-31-12Z',
|
||||||
u'1991-12-07T25:30:05Z',
|
u'1991-12-07T25:30:05Z',
|
||||||
):
|
):
|
||||||
raises(ConversionError, o.convert, value)
|
raises(ConversionError, o.convert, value)
|
||||||
|
|||||||
@@ -67,10 +67,10 @@ def test_round_trip():
|
|||||||
assert_equal(dump_n_load(unicode_str), unicode_str)
|
assert_equal(dump_n_load(unicode_str), unicode_str)
|
||||||
assert_equal(dump_n_load(Binary(binary_bytes)).data, binary_bytes)
|
assert_equal(dump_n_load(Binary(binary_bytes)).data, binary_bytes)
|
||||||
assert isinstance(dump_n_load(Binary(binary_bytes)), Binary)
|
assert isinstance(dump_n_load(Binary(binary_bytes)), Binary)
|
||||||
assert type(dump_n_load('hello')) is bytes
|
assert type(dump_n_load(b'hello')) is bytes
|
||||||
assert type(dump_n_load(u'hello')) is bytes
|
assert type(dump_n_load(u'hello')) is bytes
|
||||||
assert_equal(dump_n_load(''), '')
|
assert_equal(dump_n_load(b''), b'')
|
||||||
assert_equal(dump_n_load(u''), '')
|
assert_equal(dump_n_load(u''), b'')
|
||||||
assert dump_n_load(None) is None
|
assert dump_n_load(None) is None
|
||||||
|
|
||||||
# Now we test our wrap and unwrap methods in combination with dumps, loads:
|
# Now we test our wrap and unwrap methods in combination with dumps, loads:
|
||||||
@@ -81,9 +81,9 @@ def test_round_trip():
|
|||||||
assert_equal(round_trip(utf8_bytes), utf8_bytes)
|
assert_equal(round_trip(utf8_bytes), utf8_bytes)
|
||||||
assert_equal(round_trip(unicode_str), unicode_str)
|
assert_equal(round_trip(unicode_str), unicode_str)
|
||||||
assert_equal(round_trip(binary_bytes), binary_bytes)
|
assert_equal(round_trip(binary_bytes), binary_bytes)
|
||||||
assert type(round_trip('hello')) is bytes
|
assert type(round_trip(b'hello')) is bytes
|
||||||
assert type(round_trip(u'hello')) is unicode
|
assert type(round_trip(u'hello')) is unicode
|
||||||
assert_equal(round_trip(''), '')
|
assert_equal(round_trip(b''), b'')
|
||||||
assert_equal(round_trip(u''), u'')
|
assert_equal(round_trip(u''), u'')
|
||||||
assert round_trip(None) is None
|
assert round_trip(None) is None
|
||||||
compound = [utf8_bytes, None, binary_bytes, (None, unicode_str),
|
compound = [utf8_bytes, None, binary_bytes, (None, unicode_str),
|
||||||
@@ -99,13 +99,13 @@ def test_xml_wrap():
|
|||||||
f = rpc.xml_wrap
|
f = rpc.xml_wrap
|
||||||
assert f([], API_VERSION) == tuple()
|
assert f([], API_VERSION) == tuple()
|
||||||
assert f({}, API_VERSION) == dict()
|
assert f({}, API_VERSION) == dict()
|
||||||
b = f('hello', API_VERSION)
|
b = f(b'hello', API_VERSION)
|
||||||
assert isinstance(b, Binary)
|
assert isinstance(b, Binary)
|
||||||
assert b.data == 'hello'
|
assert b.data == b'hello'
|
||||||
u = f(u'hello', API_VERSION)
|
u = f(u'hello', API_VERSION)
|
||||||
assert type(u) is unicode
|
assert type(u) is unicode
|
||||||
assert u == u'hello'
|
assert u == u'hello'
|
||||||
value = f([dict(one=False, two=u'hello'), None, 'hello'], API_VERSION)
|
value = f([dict(one=False, two=u'hello'), None, b'hello'], API_VERSION)
|
||||||
|
|
||||||
|
|
||||||
def test_xml_unwrap():
|
def test_xml_unwrap():
|
||||||
@@ -120,8 +120,8 @@ def test_xml_unwrap():
|
|||||||
assert value == utf8_bytes
|
assert value == utf8_bytes
|
||||||
assert f(utf8_bytes) == unicode_str
|
assert f(utf8_bytes) == unicode_str
|
||||||
assert f(unicode_str) == unicode_str
|
assert f(unicode_str) == unicode_str
|
||||||
value = f([True, Binary('hello'), dict(one=1, two=utf8_bytes, three=None)])
|
value = f([True, Binary(b'hello'), dict(one=1, two=utf8_bytes, three=None)])
|
||||||
assert value == (True, 'hello', dict(one=1, two=unicode_str, three=None))
|
assert value == (True, b'hello', dict(one=1, two=unicode_str, three=None))
|
||||||
assert type(value[1]) is bytes
|
assert type(value[1]) is bytes
|
||||||
assert type(value[2]['two']) is unicode
|
assert type(value[2]['two']) is unicode
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ def test_xml_dumps():
|
|||||||
params = (binary_bytes, utf8_bytes, unicode_str, None)
|
params = (binary_bytes, utf8_bytes, unicode_str, None)
|
||||||
|
|
||||||
# Test serializing an RPC request:
|
# Test serializing an RPC request:
|
||||||
data = f(params, API_VERSION, 'the_method')
|
data = f(params, API_VERSION, b'the_method')
|
||||||
(p, m) = loads(data)
|
(p, m) = loads(data)
|
||||||
assert_equal(m, u'the_method')
|
assert_equal(m, u'the_method')
|
||||||
assert type(p) is tuple
|
assert type(p) is tuple
|
||||||
@@ -165,7 +165,7 @@ def test_xml_loads():
|
|||||||
wrapped = rpc.xml_wrap(params, API_VERSION)
|
wrapped = rpc.xml_wrap(params, API_VERSION)
|
||||||
|
|
||||||
# Test un-serializing an RPC request:
|
# Test un-serializing an RPC request:
|
||||||
data = dumps(wrapped, 'the_method', allow_none=True)
|
data = dumps(wrapped, b'the_method', allow_none=True)
|
||||||
(p, m) = f(data)
|
(p, m) = f(data)
|
||||||
assert_equal(m, u'the_method')
|
assert_equal(m, u'the_method')
|
||||||
assert_equal(p, params)
|
assert_equal(p, params)
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ class test_LDAPEntry(object):
|
|||||||
assert nice == [2, 3, u'5']
|
assert nice == [2, 3, u'5']
|
||||||
assert raw == ['3', '5', '2']
|
assert raw == ['3', '5', '2']
|
||||||
|
|
||||||
raw = ['a', 'b']
|
raw = [b'a', b'b']
|
||||||
e.raw['test'] = raw
|
e.raw['test'] = raw
|
||||||
assert e['test'] is not nice
|
assert e['test'] is not nice
|
||||||
assert e['test'] == [u'a', u'b']
|
assert e['test'] == [u'a', u'b']
|
||||||
@@ -314,7 +314,7 @@ class test_LDAPEntry(object):
|
|||||||
nice = 'not list'
|
nice = 'not list'
|
||||||
e['test'] = nice
|
e['test'] = nice
|
||||||
assert e['test'] is nice
|
assert e['test'] is nice
|
||||||
assert e.raw['test'] == ['not list']
|
assert e.raw['test'] == [b'not list']
|
||||||
|
|
||||||
e.raw['test'].append('second')
|
e.raw['test'].append('second')
|
||||||
assert e['test'] == ['not list', u'second']
|
assert e['test'] == ['not list', u'second']
|
||||||
|
|||||||
@@ -201,13 +201,13 @@ def test_entry_to_dict():
|
|||||||
DN('cn=test'),
|
DN('cn=test'),
|
||||||
textattr=[u'text'],
|
textattr=[u'text'],
|
||||||
dnattr=[DN('cn=test')],
|
dnattr=[DN('cn=test')],
|
||||||
binaryattr=['\xffabcd'],
|
binaryattr=[b'\xffabcd'],
|
||||||
attributelevelrights=rights)
|
attributelevelrights=rights)
|
||||||
the_dict = {
|
the_dict = {
|
||||||
u'dn': u'cn=test',
|
u'dn': u'cn=test',
|
||||||
u'textattr': [u'text'],
|
u'textattr': [u'text'],
|
||||||
u'dnattr': [u'cn=test'],
|
u'dnattr': [u'cn=test'],
|
||||||
u'binaryattr': ['\xffabcd'],
|
u'binaryattr': [b'\xffabcd'],
|
||||||
u'attributelevelrights': rights}
|
u'attributelevelrights': rights}
|
||||||
assert_deepequal(
|
assert_deepequal(
|
||||||
baseldap.entry_to_dict(entry, all=True, raw=True),
|
baseldap.entry_to_dict(entry, all=True, raw=True),
|
||||||
|
|||||||
Reference in New Issue
Block a user