From c9a4141ab776427c5f77693630542450cd5167a7 Mon Sep 17 00:00:00 2001 From: Ralf Haferkamp Date: Thu, 20 Sep 2012 17:29:12 +0200 Subject: Return a meaningful Error when token_id is missing To make keystone return HTTP 401 Unauthorized instead of 500 Internal Server Error when processing request that miss the X-Auth-Token Header. Fixes Bug 1053474 Change-Id: Ib830fce7bb3b29fa1bc385f64c7c0ecdf5cd1644 --- keystone/token/backends/memcache.py | 2 ++ keystone/token/backends/sql.py | 2 ++ 2 files changed, 4 insertions(+) (limited to 'keystone/token/backends') diff --git a/keystone/token/backends/memcache.py b/keystone/token/backends/memcache.py index fc57cf4d..db60e9b4 100644 --- a/keystone/token/backends/memcache.py +++ b/keystone/token/backends/memcache.py @@ -49,6 +49,8 @@ class Token(token.Driver): return 'token-%s' % token_id.encode('utf-8') def get_token(self, token_id): + if token_id is None: + raise exception.TokenNotFound(token_id=token_id) ptk = self._prefix_token_id(token_id) token = self.client.get(ptk) if token is None: diff --git a/keystone/token/backends/sql.py b/keystone/token/backends/sql.py index 02e89476..36a24359 100644 --- a/keystone/token/backends/sql.py +++ b/keystone/token/backends/sql.py @@ -52,6 +52,8 @@ class TokenModel(sql.ModelBase, sql.DictBase): class Token(sql.Base, token.Driver): # Public interface def get_token(self, token_id): + if token_id is None: + raise exception.TokenNotFound(token_id=token_id) session = self.get_session() token_ref = session.query(TokenModel)\ .filter_by(id=self.token_to_key(token_id), -- cgit