Publish and accept OCCI/1.1 as a valid version

Change d5ad90a fixed the publication of OCCI/1.1 as the supported OCCI
version, but it introduced a new bug that prevented users from passing
OCCI/1.1 in the user agent, forcing them to be OCCI/1.2. Even if the
OCCI spec says that: "The 'User-Agent' header MUST include the same
value (OCCI/X.Y) as advertised by the server" we should continue
accepting OCCI/1.1 as a valid version.

Change-Id: Iabcd8fda367876568b6f221d0ecc5ab2ffa06c90
Closes-Bug: #1683317
This commit is contained in:
Alvaro Lopez Garcia 2017-04-17 13:16:44 +02:00
parent 5032dbdf08
commit b3d479729a
2 changed files with 24 additions and 3 deletions

View File

@ -114,6 +114,13 @@ class TestMiddleware(base.TestCase):
self.assertEqual(404, result.status_code)
self.assertDefaults(result)
def test_good_user_agent_11(self):
req = self._build_req("/", "tenant")
req.user_agent = "foo OCCI/1.1 bar"
result = req.get_response(self.get_app())
self.assertEqual(404, result.status_code)
self.assertDefaults(result)
def test_bad_user_agent(self):
req = self._build_req("/", "tenant")
req.user_agent = "foo OCCI/2.2 bar"

View File

@ -111,7 +111,20 @@ class Request(webob.Request):
class OCCIMiddleware(object):
occi_version = "1.2"
occi_string = "OCCI/%s" % occi_version
supported_occi_versions = ["1.1", occi_version]
_occi_string = "OCCI/%(occi_version)s"
@property
def occi_string(self):
"""Return the default OCCI supported version string."""
return self._occi_string % {"occi_version": self.occi_version}
@property
def supported_occi_strings(self):
"""Return all the OCCI supported version strings."""
return [self._occi_string % {"occi_version": occi_version}
for occi_version in self.supported_occi_versions]
@classmethod
def factory(cls, global_conf, **local_conf):
@ -276,7 +289,8 @@ class OCCIMiddleware(object):
# FIXME(aloga): review the regexp, since it will only match the
# first string
match = re.search(r"\bOCCI/\d\.\d\b", req.user_agent)
if match and self.occi_string != match.group():
if match and not any([i == match.group()
for i in self.supported_occi_strings]):
return Fault(webob.exc.HTTPNotImplemented(
explanation="%s not supported" % match.group()))
@ -289,7 +303,7 @@ class OCCIMiddleware(object):
def process_response(self, response):
"""Process a response by adding our headers."""
server_string = "ooi/%s %s" % (version.version_string,
self.occi_string)
" ".join(self.supported_occi_strings))
headers = (("server", server_string),)
if isinstance(response, Fault):