~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to .pc/security-fix-tenant-bypass.patch/nova/tests/api/openstack/v2/contrib/test_multinic_xs.py

  • Committer: Package Import Robot
  • Author(s): Jamie Strandboge
  • Date: 2012-01-05 08:58:46 UTC
  • Revision ID: package-import@ubuntu.com-20120105085846-gtvbb26sr3r3v2mu
Tags: 2012.1~e2-0ubuntu4
* SECURITY UPDATE: fix tenant bypass by authenticated users via OpenStack
  API (LP: #904072)
  - CVE-2012-XXXX

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2011 OpenStack LLC.
 
2
# All Rights Reserved.
 
3
#
 
4
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
5
#    not use this file except in compliance with the License. You may obtain
 
6
#    a copy of the License at
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
10
#    Unless required by applicable law or agreed to in writing, software
 
11
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
12
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
13
#    License for the specific language governing permissions and limitations
 
14
#    under the License.
 
15
 
 
16
import json
 
17
 
 
18
import webob
 
19
 
 
20
from nova import compute
 
21
from nova import context
 
22
from nova import test
 
23
from nova.tests.api.openstack import fakes
 
24
 
 
25
 
 
26
UUID = '70f6db34-de8d-4fbd-aafb-4065bdfa6114'
 
27
last_add_fixed_ip = (None, None)
 
28
last_remove_fixed_ip = (None, None)
 
29
 
 
30
 
 
31
def compute_api_add_fixed_ip(self, context, instance, network_id):
 
32
    global last_add_fixed_ip
 
33
 
 
34
    last_add_fixed_ip = (instance['uuid'], network_id)
 
35
 
 
36
 
 
37
def compute_api_remove_fixed_ip(self, context, instance, address):
 
38
    global last_remove_fixed_ip
 
39
 
 
40
    last_remove_fixed_ip = (instance['uuid'], address)
 
41
 
 
42
 
 
43
def compute_api_get(self, context, instance_id):
 
44
    return {'id': 1, 'uuid': instance_id}
 
45
 
 
46
 
 
47
class FixedIpTest(test.TestCase):
 
48
    def setUp(self):
 
49
        super(FixedIpTest, self).setUp()
 
50
        fakes.stub_out_networking(self.stubs)
 
51
        fakes.stub_out_rate_limiting(self.stubs)
 
52
        self.stubs.Set(compute.api.API, "add_fixed_ip",
 
53
                       compute_api_add_fixed_ip)
 
54
        self.stubs.Set(compute.api.API, "remove_fixed_ip",
 
55
                       compute_api_remove_fixed_ip)
 
56
        self.stubs.Set(compute.api.API, 'get', compute_api_get)
 
57
        self.context = context.get_admin_context()
 
58
 
 
59
    def test_add_fixed_ip(self):
 
60
        global last_add_fixed_ip
 
61
        last_add_fixed_ip = (None, None)
 
62
 
 
63
        body = dict(addFixedIp=dict(networkId='test_net'))
 
64
        req = webob.Request.blank('/v2/123/servers/%s/action' % UUID)
 
65
        req.method = 'POST'
 
66
        req.body = json.dumps(body)
 
67
        req.headers['content-type'] = 'application/json'
 
68
 
 
69
        resp = req.get_response(fakes.wsgi_app())
 
70
        self.assertEqual(resp.status_int, 202)
 
71
        self.assertEqual(last_add_fixed_ip, (UUID, 'test_net'))
 
72
 
 
73
    def test_add_fixed_ip_no_network(self):
 
74
        global last_add_fixed_ip
 
75
        last_add_fixed_ip = (None, None)
 
76
 
 
77
        body = dict(addFixedIp=dict())
 
78
        req = webob.Request.blank('/v2/123/servers/%s/action' % UUID)
 
79
        req.method = 'POST'
 
80
        req.body = json.dumps(body)
 
81
        req.headers['content-type'] = 'application/json'
 
82
 
 
83
        resp = req.get_response(fakes.wsgi_app())
 
84
        self.assertEqual(resp.status_int, 422)
 
85
        self.assertEqual(last_add_fixed_ip, (None, None))
 
86
 
 
87
    def test_remove_fixed_ip(self):
 
88
        global last_remove_fixed_ip
 
89
        last_remove_fixed_ip = (None, None)
 
90
 
 
91
        body = dict(removeFixedIp=dict(address='10.10.10.1'))
 
92
        req = webob.Request.blank('/v2/123/servers/%s/action' % UUID)
 
93
        req.method = 'POST'
 
94
        req.body = json.dumps(body)
 
95
        req.headers['content-type'] = 'application/json'
 
96
 
 
97
        resp = req.get_response(fakes.wsgi_app())
 
98
        self.assertEqual(resp.status_int, 202)
 
99
        self.assertEqual(last_remove_fixed_ip, (UUID, '10.10.10.1'))
 
100
 
 
101
    def test_remove_fixed_ip_no_address(self):
 
102
        global last_remove_fixed_ip
 
103
        last_remove_fixed_ip = (None, None)
 
104
 
 
105
        body = dict(removeFixedIp=dict())
 
106
        req = webob.Request.blank('/v2/123/servers/%s/action' % UUID)
 
107
        req.method = 'POST'
 
108
        req.body = json.dumps(body)
 
109
        req.headers['content-type'] = 'application/json'
 
110
 
 
111
        resp = req.get_response(fakes.wsgi_app())
 
112
        self.assertEqual(resp.status_int, 422)
 
113
        self.assertEqual(last_remove_fixed_ip, (None, None))