summaryrefslogtreecommitdiffstats
path: root/ipatests
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2014-06-30 18:27:31 -0400
committerMartin Kosek <mkosek@redhat.com>2014-07-01 09:19:51 +0200
commit54e4891fef1efc7af5f1d1485cadfc7ae2e98ad2 (patch)
treef2c2dbea38b598b286ea35cd1bc7b76cbc21ad3d /ipatests
parentdfbd7170e901bc597462191c219c0e2b45c09afa (diff)
downloadfreeipa-54e4891fef1efc7af5f1d1485cadfc7ae2e98ad2.tar.gz
freeipa-54e4891fef1efc7af5f1d1485cadfc7ae2e98ad2.tar.xz
freeipa-54e4891fef1efc7af5f1d1485cadfc7ae2e98ad2.zip
Remove IPA Foreman Smart Proxy
The code has been moved to its own, separate repository at git://git.fedorahosted.org/git/freeipa-foreman-smartproxy.git Reviewed-By: Martin Kosek <mkosek@redhat.com>
Diffstat (limited to 'ipatests')
-rw-r--r--ipatests/test_smartproxy/resttest.py170
-rw-r--r--ipatests/test_smartproxy/test_features.py35
-rw-r--r--ipatests/test_smartproxy/test_host.py145
-rw-r--r--ipatests/test_smartproxy/test_hostgroup.py97
4 files changed, 0 insertions, 447 deletions
diff --git a/ipatests/test_smartproxy/resttest.py b/ipatests/test_smartproxy/resttest.py
deleted file mode 100644
index dc355471f..000000000
--- a/ipatests/test_smartproxy/resttest.py
+++ /dev/null
@@ -1,170 +0,0 @@
-# Authors:
-# Rob Crittenden <rcritten@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/>.
-
-"""
-Base class for all REST tests
-"""
-
-import requests
-import json
-import nose
-from ipatests.util import assert_deepequal, Fuzzy
-from ipatests.test_xmlrpc.xmlrpc_test import fuzzy_uuid, fuzzy_password
-
-FQDN = 'localhost'
-PORT = 8090
-
-EXPECTED = """Expected %r to raise %s.
- options = %r
- output = %r"""
-
-UNEXPECTED = """Expected %r to raise %s, but caught different.
- options = %r
- %s: %s"""
-
-try:
- response = requests.get(
- 'http://%s:%d/ipa/smartproxy/host/host.example.com' % (FQDN, PORT),
- data={})
- server_available = True
-except requests.ConnectionError:
- server_available = False
-
-
-class REST_test(object):
- """
- Base class for all REST tests
-
- A Declarative test suite is controlled by the ``tests`` and
- ``cleanup`` class variables.
-
- The ``tests`` is a list of dictionaries with the following keys:
-
- ``desc``
- A name/description of the test
- ``command``
- A (command, args, kwargs) triple specifying the command to run
- ``expected``
- Can be either an ``errors.PublicError`` instance, in which case
- the command must fail with the given error; or the
- expected result.
- The result is checked with ``tests.util.assert_deepequal``.
- ``extra_check`` (optional)
- A checking function that is called with the response. It must
- return true for the test to pass.
-
- The ``cleanup`` is a list of (command, args, kwargs)
- triples. These are commands get run both before and after tests,
- and must not fail.
- """
-
- cleanup = tuple()
- tests = tuple()
-
- @classmethod
- def setUpClass(cls):
- if not server_available:
- raise nose.SkipTest('%r: Server not available' %
- cls.__module__)
-
- def cleanup_generate(self, stage):
- for (i, request) in enumerate(self.cleanup):
- func = lambda: self.run_cleanup(request)
- func.description = '%s %s-cleanup[%d]: %r' % (
- self.__class__.__name__, stage, i, request
- )
- yield (func,)
-
- def make_request(self, method, uri, data=None):
- request = method('http://%s:%d%s' % (FQDN, PORT, uri), data=data)
- return request
-
- def run_cleanup(self, request):
- (uri, data) = request
- try:
- result = self.make_request(requests.delete, uri, data)
- assert request.status_code in [401, 201, 200]
- except Exception:
- pass
-
- def test_generator(self):
- """
- Iterate through tests.
-
- nose reports each one as a separate test.
- """
-
- # Iterate through pre-cleanup:
- for tup in self.cleanup_generate('pre'):
- yield tup
-
- # Iterate through the tests:
- name = self.__class__.__name__
- for (i, test) in enumerate(self.tests):
- nice = '%s[%d]: %s: %s' % (
- name, i, test['request'][0], test.get('desc', '')
- )
- func = lambda: self.check(nice, **test)
- func.description = nice
- yield (func,)
-
- # Iterate through post-cleanup:
- for tup in self.cleanup_generate('post'):
- yield tup
-
- def check(self, nice, desc, request, method, expected_status, expected):
- (uri, data) = request
- if isinstance(expected, Exception):
- self.check_exception(nice, method, uri, data, expected)
- else:
- self.check_result(nice,
- method,
- uri,
- data,
- expected_status,
- expected)
-
- def check_exception(self, nice, method, uri, data, expected):
- klass = expected.__class__
- name = klass.__name__
- try:
- output = self.make_request(method, uri, data)
- except StandardError, e:
- pass
- else:
- raise AssertionError(
- EXPECTED % (uri, name, method, data, output)
- )
- if not isinstance(e, klass):
- raise AssertionError(
- UNEXPECTED % (uri, name, method, data, e.__class__.__name__, e)
- )
-
- def check_result(self, nice, method, uri, data, expected_status, expected):
- request = self.make_request(method, uri, data)
- assert expected_status == request.status_code
-
- if request.status_code in [200, 201]:
- try:
- data = json.loads(request.text)
- except ValueError, e:
- raise AssertionError(
- 'Could not parse JSON: %s' % e
- )
- assert_deepequal(expected, data, nice)
diff --git a/ipatests/test_smartproxy/test_features.py b/ipatests/test_smartproxy/test_features.py
deleted file mode 100644
index 9c32c0c33..000000000
--- a/ipatests/test_smartproxy/test_features.py
+++ /dev/null
@@ -1,35 +0,0 @@
-# Authors:
-# Rob Crittenden <rcritten@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/>.
-
-from resttest import REST_test
-import requests
-
-class test_feature(REST_test):
-
- tests = [
-
- dict(
- desc='Get supported features',
- request=('/features', {}),
- method=requests.get,
- expected_status=200,
- expected=[u'realm'],
- ),
-
- ]
diff --git a/ipatests/test_smartproxy/test_host.py b/ipatests/test_smartproxy/test_host.py
deleted file mode 100644
index 376fb1558..000000000
--- a/ipatests/test_smartproxy/test_host.py
+++ /dev/null
@@ -1,145 +0,0 @@
-# Authors:
-# Rob Crittenden <rcritten@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/>.
-
-from ipalib import api
-from ipapython.dn import DN
-from resttest import REST_test, fuzzy_uuid, fuzzy_password
-from ipatests.test_xmlrpc import objectclasses
-import requests
-
-fqdn1 = u'testhost.example.com'
-dn1 = DN(('fqdn',fqdn1),('cn','computers'),('cn','accounts'),
- api.env.basedn)
-fqdn2 = u'testhost2.example.com'
-dn2 = DN(('fqdn',fqdn2),('cn','computers'),('cn','accounts'),
- api.env.basedn)
-
-class test_host(REST_test):
-
- cleanup = [
- ('/ipa/smartproxy/host/%s' % fqdn1, {}),
- ('/ipa/smartproxy/host/%s' % fqdn2, {}),
- ]
-
- tests = [
-
- dict(
- desc='Get a non-existent host',
- request=('/ipa/smartproxy/host/notfound', {}),
- method=requests.get,
- expected_status=404,
- expected={},
- ),
-
- dict(
- desc='Create a host',
- request=('/ipa/smartproxy/host', {'hostname': fqdn1,
- 'description': 'test',
- 'macaddress': '00:50:56:30:F6:5F'}),
- method=requests.post,
- expected_status=201,
- expected=dict(
- dn=dn1,
- has_keytab=False,
- objectclass=[u'ipasshhost', u'ipaSshGroupOfPubKeys',
- u'ieee802device', u'ipaobject',
- u'nshost', u'ipahost', u'pkiuser',
- u'ipaservice', u'top',],
- description=[u'test'],
- macaddress=[u'00:50:56:30:F6:5F'],
- fqdn=[fqdn1],
- has_password=True,
- randompassword=fuzzy_password,
- ipauniqueid=[fuzzy_uuid],
- managedby_host=[fqdn1],
- ),
- ),
-
- dict(
- desc='Get the host',
- request=('/ipa/smartproxy/host/%s' % fqdn1, {}),
- method=requests.get,
- expected_status=200,
- expected=dict(
- dn=dn1,
- description=[u'test'],
- macaddress=[u'00:50:56:30:F6:5F'],
- has_keytab=False,
- fqdn=[u'testhost.example.com'],
- has_password=True,
- managedby_host=[fqdn1],
- ),
- ),
-
- # Note that this has the side-effect of confirming that description,
- # macaddress, etc. doesn't get wiped on update.
- dict(
- desc='Update the host',
- request=('/ipa/smartproxy/host/%s' % fqdn1, {'userclass': 'test'}),
- method=requests.post,
- expected_status=200,
- expected=dict(
- has_keytab=False,
- description=[u'test'],
- macaddress=[u'00:50:56:30:F6:5F'],
- fqdn=[u'testhost.example.com'],
- has_password=True,
- managedby_host=[fqdn1],
- randompassword=fuzzy_password,
- userclass=[u'test']
-
- ),
- ),
-
- dict(
- desc='Remove the host',
- request=('/ipa/smartproxy/host/%s' % fqdn1, {}),
- method=requests.delete,
- expected_status=200,
- expected=dict(failed=[]),
- ),
-
- dict(
- desc='Create a host with a fixed password',
- request=('/ipa/smartproxy/host', {'hostname': fqdn2, 'password': 'Secret123'}),
- method=requests.post,
- expected_status=201,
- expected=dict(
- dn=dn2,
- has_keytab=False,
- objectclass=[u'ipasshhost', u'ipaSshGroupOfPubKeys',
- u'ieee802device', u'ipaobject',
- u'nshost', u'ipahost', u'pkiuser',
- u'ipaservice', u'top',],
- fqdn=[fqdn2],
- has_password=True,
- ipauniqueid=[fuzzy_uuid],
- managedby_host=[fqdn2],
- ),
- ),
-
- dict(
- desc='Remove a non-existent host',
- request=('/ipa/smartproxy/host/notfound', {}),
- method=requests.delete,
- expected_status=404,
- expected={},
- ),
-
- ]
diff --git a/ipatests/test_smartproxy/test_hostgroup.py b/ipatests/test_smartproxy/test_hostgroup.py
deleted file mode 100644
index e82ed54f9..000000000
--- a/ipatests/test_smartproxy/test_hostgroup.py
+++ /dev/null
@@ -1,97 +0,0 @@
-# Authors:
-# Rob Crittenden <rcritten@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/>.
-
-from ipalib import api
-from ipapython.dn import DN
-from resttest import REST_test, fuzzy_uuid
-from ipatests.test_xmlrpc import objectclasses
-import requests
-
-hostgroup1 = u'testhostgroup'
-dn1 = DN(('cn', hostgroup1),('cn','hostgroups'),('cn','accounts'),
- api.env.basedn)
-
-class test_hostgroup(REST_test):
-
- cleanup = [
- ('/ipa/smartproxy/hostgroup/%s' % hostgroup1, {}),
- ]
-
- tests = [
-
- dict(
- desc='Get a non-existent hostgroup',
- request=('/ipa/smartproxy/hostgroup/notfound', {}),
- method=requests.get,
- expected_status=404,
- expected={},
- ),
-
- dict(
- desc='Create a hostgroup',
- request=('/ipa/smartproxy/hostgroup', {'name': hostgroup1, 'description': u'test'}),
- method=requests.post,
- expected_status=201,
- expected=dict(
- dn=dn1,
- cn=[hostgroup1],
- objectclass=objectclasses.hostgroup,
- description=[u'test'],
- mepmanagedentry=[DN(('cn',hostgroup1),('cn','ng'),('cn','alt'),
- api.env.basedn)],
- ipauniqueid=[fuzzy_uuid],
- ),
- ),
-
- dict(
- desc='Get the hostgroup',
- request=('/ipa/smartproxy/hostgroup/%s' % hostgroup1, {}),
- method=requests.get,
- expected_status=200,
- expected=dict(
- dn=dn1,
- cn=[u'testhostgroup'],
- description=[u'test'],
- ),
- ),
-
- dict(
- desc='Add a duplicate hostgroup',
- request=('/ipa/smartproxy/hostgroup', {'name': hostgroup1, 'description': u'test'}),
- method=requests.post,
- expected_status=400,
- expected={},
- ),
-
- dict(
- desc='Remove the hostgroup',
- request=('/ipa/smartproxy/hostgroup/%s' % hostgroup1, {}),
- method=requests.delete,
- expected_status=200,
- expected=dict(failed=[]),
- ),
-
- dict(
- desc='Remove a non-existent hostgroup',
- request=('/ipa/smartproxy/hostgroup/%s' % hostgroup1, {}),
- method=requests.delete,
- expected_status=404,
- expected={},
- ),
- ]