Merge lp:~eday/nova/lp660668 into lp:~hudson-openstack/nova/trunk

Proposed by Eric Day
Status: Merged
Approved by: Devin Carlen
Approved revision: 354
Merged at revision: 362
Proposed branch: lp:~eday/nova/lp660668
Merge into: lp:~hudson-openstack/nova/trunk
Prerequisite: lp:~eday/nova/lp660818
Diff against target: 62 lines (+37/-2)
2 files modified
nova/api/openstack/__init__.py (+2/-2)
nova/tests/api/openstack/test_auth.py (+35/-0)
To merge this branch: bzr merge lp:~eday/nova/lp660668
Reviewer Review Type Date Requested Status
Devin Carlen (community) Approve
Jay Pipes (community) Approve
Review via email: mp+38484@code.launchpad.net

Commit message

Added test case to reproduce bug #660668 and provided a fix by using the user_id from the auth layer instead of the username header.

Description of the change

Added test case to reproduce bug #660668 and provided a fix by using the user_id from the auth layer instead of the username header.

To post a comment you must log in.
Revision history for this message
Jay Pipes (jaypipes) wrote :

lgtm.

review: Approve
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/api/openstack/__init__.py'
2--- nova/api/openstack/__init__.py 2010-10-08 20:39:00 +0000
3+++ nova/api/openstack/__init__.py 2010-10-15 01:20:29 +0000
4@@ -106,11 +106,11 @@
5 If the request should be rate limited, return a 413 status with a
6 Retry-After header giving the time when the request would succeed.
7 """
8- username = req.headers['X-Auth-User']
9+ user_id = req.environ['nova.context']['user']['id']
10 action_name = self.get_action_name(req)
11 if not action_name: # not rate limited
12 return self.application
13- delay = self.get_delay(action_name, username)
14+ delay = self.get_delay(action_name, user_id)
15 if delay:
16 # TODO(gundlach): Get the retry-after format correct.
17 exc = webob.exc.HTTPRequestEntityTooLarge(
18
19=== modified file 'nova/tests/api/openstack/test_auth.py'
20--- nova/tests/api/openstack/test_auth.py 2010-10-13 20:36:05 +0000
21+++ nova/tests/api/openstack/test_auth.py 2010-10-15 01:20:29 +0000
22@@ -106,5 +106,40 @@
23 result = req.get_response(nova.api.API())
24 self.assertEqual(result.status, '401 Unauthorized')
25
26+
27+class TestLimiter(unittest.TestCase):
28+ def setUp(self):
29+ self.stubs = stubout.StubOutForTesting()
30+ self.stubs.Set(nova.api.openstack.auth.BasicApiAuthManager,
31+ '__init__', fakes.fake_auth_init)
32+ fakes.FakeAuthManager.auth_data = {}
33+ fakes.FakeAuthDatabase.data = {}
34+ fakes.stub_out_networking(self.stubs)
35+
36+ def tearDown(self):
37+ self.stubs.UnsetAll()
38+ fakes.fake_data_store = {}
39+
40+ def test_authorize_token(self):
41+ f = fakes.FakeAuthManager()
42+ f.add_user('derp', nova.auth.manager.User(1, 'herp', None, None, None))
43+
44+ req = webob.Request.blank('/v1.0/')
45+ req.headers['X-Auth-User'] = 'herp'
46+ req.headers['X-Auth-Key'] = 'derp'
47+ result = req.get_response(nova.api.API())
48+ self.assertEqual(len(result.headers['X-Auth-Token']), 40)
49+
50+ token = result.headers['X-Auth-Token']
51+ self.stubs.Set(nova.api.openstack, 'APIRouter',
52+ fakes.FakeRouter)
53+ req = webob.Request.blank('/v1.0/fake')
54+ req.method = 'POST'
55+ req.headers['X-Auth-Token'] = token
56+ result = req.get_response(nova.api.API())
57+ self.assertEqual(result.status, '200 OK')
58+ self.assertEqual(result.headers['X-Test-Success'], 'True')
59+
60+
61 if __name__ == '__main__':
62 unittest.main()