Imported Upstream version 4.6.2
This commit is contained in:
0
ipatests/test_ipaserver/test_install/__init__.py
Normal file
0
ipatests/test_ipaserver/test_install/__init__.py
Normal file
63
ipatests/test_ipaserver/test_install/test_adtrustinstance.py
Executable file
63
ipatests/test_ipaserver/test_install/test_adtrustinstance.py
Executable file
@@ -0,0 +1,63 @@
|
||||
# Authors:
|
||||
# Sumit Bose <sbose@redhat.com>
|
||||
#
|
||||
# Copyright (C) 2011 Red Hat
|
||||
# see file 'COPYING' for use and warranty information
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
Test `adtrustinstance`
|
||||
"""
|
||||
import pytest
|
||||
import six
|
||||
|
||||
from ipaserver.install import adtrustinstance
|
||||
|
||||
if six.PY3:
|
||||
unicode = str
|
||||
|
||||
|
||||
@pytest.mark.tier0
|
||||
class test_adtrustinstance(object):
|
||||
"""
|
||||
Test `adtrustinstance`.
|
||||
"""
|
||||
|
||||
def test_make_netbios_name(self):
|
||||
s = adtrustinstance.make_netbios_name("ABCDEF")
|
||||
assert s == 'ABCDEF' and isinstance(s, str)
|
||||
s = adtrustinstance.make_netbios_name(U"ABCDEF")
|
||||
assert s == 'ABCDEF' and isinstance(s, unicode)
|
||||
s = adtrustinstance.make_netbios_name("abcdef")
|
||||
assert s == 'ABCDEF'
|
||||
s = adtrustinstance.make_netbios_name("abc.def")
|
||||
assert s == 'ABC'
|
||||
s = adtrustinstance.make_netbios_name("abcdefghijklmnopqr.def")
|
||||
assert s == 'ABCDEFGHIJKLMNO'
|
||||
s = adtrustinstance.make_netbios_name("A!$%B&/()C=?+*D")
|
||||
assert s == 'ABCD'
|
||||
s = adtrustinstance.make_netbios_name("!$%&/()=?+*")
|
||||
assert not s
|
||||
|
||||
def test_check_netbios_name(self):
|
||||
assert adtrustinstance.check_netbios_name("ABCDEF")
|
||||
assert not adtrustinstance.check_netbios_name("abcdef")
|
||||
assert adtrustinstance.check_netbios_name("ABCDE12345ABCDE")
|
||||
assert not adtrustinstance.check_netbios_name("ABCDE12345ABCDE1")
|
||||
assert not adtrustinstance.check_netbios_name("")
|
||||
|
||||
assert adtrustinstance.check_netbios_name(U"ABCDEF")
|
||||
assert not adtrustinstance.check_netbios_name(U"abcdef")
|
||||
assert adtrustinstance.check_netbios_name(U"ABCDE12345ABCDE")
|
||||
assert not adtrustinstance.check_netbios_name(U"ABCDE12345ABCDE1")
|
||||
125
ipatests/test_ipaserver/test_install/test_cainstance.py
Normal file
125
ipatests/test_ipaserver/test_install/test_cainstance.py
Normal file
@@ -0,0 +1,125 @@
|
||||
#
|
||||
# Copyright (C) 2017 FreeIPA Contributors see COPYING for license
|
||||
#
|
||||
|
||||
from binascii import hexlify
|
||||
import pickle
|
||||
# pylint: disable=import-error
|
||||
from six.moves.configparser import RawConfigParser
|
||||
# pylint: enable=import-error
|
||||
from six import StringIO
|
||||
import pytest
|
||||
from ipaserver.install import cainstance
|
||||
|
||||
pytestmark = pytest.mark.tier0
|
||||
|
||||
|
||||
class test_ExternalCAProfile(object):
|
||||
def test_MSCSTemplateV1_good(self):
|
||||
o = cainstance.MSCSTemplateV1("MySubCA")
|
||||
assert hexlify(o.get_ext_data()) == b'1e0e004d007900530075006200430041'
|
||||
|
||||
def test_MSCSTemplateV1_bad(self):
|
||||
with pytest.raises(ValueError):
|
||||
cainstance.MSCSTemplateV1("MySubCA:1")
|
||||
|
||||
def test_MSCSTemplateV1_pickle_roundtrip(self):
|
||||
o = cainstance.MSCSTemplateV1("MySubCA")
|
||||
s = pickle.dumps(o)
|
||||
assert o.get_ext_data() == pickle.loads(s).get_ext_data()
|
||||
|
||||
def test_MSCSTemplateV2_too_few_parts(self):
|
||||
with pytest.raises(ValueError):
|
||||
cainstance.MSCSTemplateV2("1.2.3.4")
|
||||
|
||||
def test_MSCSTemplateV2_too_many_parts(self):
|
||||
with pytest.raises(ValueError):
|
||||
cainstance.MSCSTemplateV2("1.2.3.4:100:200:300")
|
||||
|
||||
def test_MSCSTemplateV2_bad_oid(self):
|
||||
with pytest.raises(ValueError):
|
||||
cainstance.MSCSTemplateV2("not_an_oid:1")
|
||||
|
||||
def test_MSCSTemplateV2_non_numeric_major_version(self):
|
||||
with pytest.raises(ValueError):
|
||||
cainstance.MSCSTemplateV2("1.2.3.4:major:200")
|
||||
|
||||
def test_MSCSTemplateV2_non_numeric_minor_version(self):
|
||||
with pytest.raises(ValueError):
|
||||
cainstance.MSCSTemplateV2("1.2.3.4:100:minor")
|
||||
|
||||
def test_MSCSTemplateV2_major_version_lt_zero(self):
|
||||
with pytest.raises(ValueError):
|
||||
cainstance.MSCSTemplateV2("1.2.3.4:-1:200")
|
||||
|
||||
def test_MSCSTemplateV2_minor_version_lt_zero(self):
|
||||
with pytest.raises(ValueError):
|
||||
cainstance.MSCSTemplateV2("1.2.3.4:100:-1")
|
||||
|
||||
def test_MSCSTemplateV2_major_version_gt_max(self):
|
||||
with pytest.raises(ValueError):
|
||||
cainstance.MSCSTemplateV2("1.2.3.4:4294967296:200")
|
||||
|
||||
def test_MSCSTemplateV2_minor_version_gt_max(self):
|
||||
with pytest.raises(ValueError):
|
||||
cainstance.MSCSTemplateV2("1.2.3.4:100:4294967296")
|
||||
|
||||
def test_MSCSTemplateV2_good_major(self):
|
||||
o = cainstance.MSCSTemplateV2("1.2.3.4:4294967295")
|
||||
assert hexlify(o.get_ext_data()) == b'300c06032a0304020500ffffffff'
|
||||
|
||||
def test_MSCSTemplateV2_good_major_minor(self):
|
||||
o = cainstance.MSCSTemplateV2("1.2.3.4:4294967295:0")
|
||||
assert hexlify(o.get_ext_data()) \
|
||||
== b'300f06032a0304020500ffffffff020100'
|
||||
|
||||
def test_MSCSTemplateV2_pickle_roundtrip(self):
|
||||
o = cainstance.MSCSTemplateV2("1.2.3.4:4294967295:0")
|
||||
s = pickle.dumps(o)
|
||||
assert o.get_ext_data() == pickle.loads(s).get_ext_data()
|
||||
|
||||
def test_ExternalCAProfile_dispatch(self):
|
||||
"""
|
||||
Test that constructing ExternalCAProfile actually returns an
|
||||
instance of the appropriate subclass.
|
||||
"""
|
||||
assert isinstance(
|
||||
cainstance.ExternalCAProfile("MySubCA"),
|
||||
cainstance.MSCSTemplateV1)
|
||||
assert isinstance(
|
||||
cainstance.ExternalCAProfile("1.2.3.4:100"),
|
||||
cainstance.MSCSTemplateV2)
|
||||
|
||||
def test_write_pkispawn_config_file_MSCSTemplateV1(self):
|
||||
template = cainstance.MSCSTemplateV1(u"SubCA")
|
||||
expected = (
|
||||
'[CA]\n'
|
||||
'pki_req_ext_oid = 1.3.6.1.4.1.311.20.2\n'
|
||||
'pki_req_ext_data = 1e0a00530075006200430041\n\n'
|
||||
)
|
||||
self._test_write_pkispawn_config_file(template, expected)
|
||||
|
||||
def test_write_pkispawn_config_file_MSCSTemplateV2(self):
|
||||
template = cainstance.MSCSTemplateV2(u"1.2.3.4:4294967295")
|
||||
expected = (
|
||||
'[CA]\n'
|
||||
'pki_req_ext_oid = 1.3.6.1.4.1.311.21.7\n'
|
||||
'pki_req_ext_data = 300c06032a0304020500ffffffff\n\n'
|
||||
)
|
||||
self._test_write_pkispawn_config_file(template, expected)
|
||||
|
||||
def _test_write_pkispawn_config_file(self, template, expected):
|
||||
"""
|
||||
Test that the values we read from an ExternalCAProfile
|
||||
object can be used to produce a reasonable-looking pkispawn
|
||||
configuration.
|
||||
"""
|
||||
config = RawConfigParser()
|
||||
config.optionxform = str
|
||||
config.add_section("CA")
|
||||
config.set("CA", "pki_req_ext_oid", template.ext_oid)
|
||||
config.set("CA", "pki_req_ext_data",
|
||||
hexlify(template.get_ext_data()).decode('ascii'))
|
||||
out = StringIO()
|
||||
config.write(out)
|
||||
assert out.getvalue() == expected
|
||||
38
ipatests/test_ipaserver/test_install/test_service.py
Normal file
38
ipatests/test_ipaserver/test_install/test_service.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# Authors:
|
||||
# Petr Viktorin <pviktori@redhat.com>
|
||||
#
|
||||
# Copyright (C) 2014 Red Hat
|
||||
# see file 'COPYING' for use and warranty information
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
"""
|
||||
Tests for the `ipaserver.service` module.
|
||||
"""
|
||||
|
||||
from ipaserver.install import service
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.tier0
|
||||
def test_format_seconds():
|
||||
assert service.format_seconds(0) == '0 seconds'
|
||||
assert service.format_seconds(1) == '1 second'
|
||||
assert service.format_seconds(2) == '2 seconds'
|
||||
assert service.format_seconds(11) == '11 seconds'
|
||||
assert service.format_seconds(60) == '1 minute'
|
||||
assert service.format_seconds(61) == '1 minute 1 second'
|
||||
assert service.format_seconds(62) == '1 minute 2 seconds'
|
||||
assert service.format_seconds(120) == '2 minutes'
|
||||
assert service.format_seconds(125) == '2 minutes 5 seconds'
|
||||
Reference in New Issue
Block a user