summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2011-01-13 14:29:16 -0500
committerSimo Sorce <ssorce@redhat.com>2011-01-14 14:26:22 -0500
commitc69d8084c17c5d94240bda9447ed9546159608a5 (patch)
treecbb69cb18d98ddea93c0bd1ea1c706026d0fe94e /tests
parentc94d20cfd8cc1bd8cd8152b19d6807b654286197 (diff)
downloadfreeipa-c69d8084c17c5d94240bda9447ed9546159608a5.tar.gz
freeipa-c69d8084c17c5d94240bda9447ed9546159608a5.tar.xz
freeipa-c69d8084c17c5d94240bda9447ed9546159608a5.zip
Add API version and have server reject incompatible clients.
This patch contains 2 parts. The first part is a small utility to create and validate the current API. To do this it needs to load ipalib which on a fresh system introduces a few problems, namely that it relies on a python plugin to set the default encoding to utf8. For our purposes we can skip that. It is also important that any optional plugins be loadable so the API can be examined. The second part is a version exchange between the client and server. The version has a major and a minor version. The major verion is updated whenever existing API changes. The minor version is updated when new API is added. A request will be rejected if either the major versions don't match or if the client major version is higher than then server major version (though by implication new API would return a command not found if allowed to proceed). To determine the API version of the server from a client use the ping command. ticket 584
Diffstat (limited to 'tests')
-rw-r--r--tests/test_ipalib/test_crud.py13
-rw-r--r--tests/test_ipalib/test_frontend.py8
2 files changed, 13 insertions, 8 deletions
diff --git a/tests/test_ipalib/test_crud.py b/tests/test_ipalib/test_crud.py
index 04a8fa797..3700c5081 100644
--- a/tests/test_ipalib/test_crud.py
+++ b/tests/test_ipalib/test_crud.py
@@ -74,12 +74,13 @@ class test_Create(CrudChecker):
"""
api = self.get_api()
assert list(api.Method.user_verb.options) == \
- ['givenname', 'sn', 'initials', 'all', 'raw']
+ ['givenname', 'sn', 'initials', 'all', 'raw', 'version']
for param in api.Method.user_verb.options():
- assert param.required is True
+ if param.name != 'version':
+ assert param.required is True
api = self.get_api(options=('extra?',))
assert list(api.Method.user_verb.options) == \
- ['givenname', 'sn', 'initials', 'extra', 'all', 'raw']
+ ['givenname', 'sn', 'initials', 'extra', 'all', 'raw', 'version']
assert api.Method.user_verb.options.extra.required is False
@@ -104,7 +105,7 @@ class test_Update(CrudChecker):
"""
api = self.get_api()
assert list(api.Method.user_verb.options) == \
- ['givenname', 'initials', 'uidnumber', 'all', 'raw']
+ ['givenname', 'initials', 'uidnumber', 'all', 'raw', 'version']
for param in api.Method.user_verb.options():
if param.name in ['all', 'raw']:
assert param.required is True
@@ -132,7 +133,7 @@ class test_Retrieve(CrudChecker):
Test the `ipalib.crud.Retrieve.get_options` method.
"""
api = self.get_api()
- assert list(api.Method.user_verb.options) == ['all', 'raw']
+ assert list(api.Method.user_verb.options) == ['all', 'raw', 'version']
class test_Delete(CrudChecker):
@@ -180,7 +181,7 @@ class test_Search(CrudChecker):
"""
api = self.get_api()
assert list(api.Method.user_verb.options) == \
- ['givenname', 'sn', 'uid', 'initials', 'all', 'raw']
+ ['givenname', 'sn', 'uid', 'initials', 'all', 'raw', 'version']
for param in api.Method.user_verb.options():
if param.name in ['all', 'raw']:
assert param.required is True
diff --git a/tests/test_ipalib/test_frontend.py b/tests/test_ipalib/test_frontend.py
index 18b918c97..200dfe0a9 100644
--- a/tests/test_ipalib/test_frontend.py
+++ b/tests/test_ipalib/test_frontend.py
@@ -29,6 +29,7 @@ from ipalib.base import NameSpace
from ipalib import frontend, backend, plugable, errors, parameters, config
from ipalib import output
from ipalib.parameters import Str
+from ipapython.version import API_VERSION
def test_RULE_FLAG():
assert frontend.RULE_FLAG == 'validation_rule'
@@ -431,6 +432,7 @@ class test_Command(ClassChecker):
option0=u'option0',
option1=u'option1',
another_option='some value',
+ version=API_VERSION,
)
sub.validate(**okay)
@@ -561,7 +563,7 @@ class test_Command(ClassChecker):
return ('forward', args, kw)
args = ('Hello,', 'world,')
- kw = dict(how_are='you', on_this='fine day?')
+ kw = dict(how_are='you', on_this='fine day?', version=API_VERSION)
# Test in server context:
(api, home) = create_test_api(in_server=True)
@@ -569,7 +571,9 @@ class test_Command(ClassChecker):
o = my_cmd()
o.set_api(api)
assert o.run.im_func is self.cls.run.im_func
- assert ('execute', args, kw) == o.run(*args, **kw)
+ out = o.run(*args, **kw)
+ del kw['version']
+ assert ('execute', args, kw) == out
# Test in non-server context
(api, home) = create_test_api(in_server=False)