Example #1
0
    def test_auth_token_no_empty_headers(self):
        f = fakes.FakeAuthManager()
        user = nova.auth.manager.User('id1', 'user1', 'user1_key', None, None)
        f.add_user(user)

        req = webob.Request.blank('/v2/')
        req.headers['X-Auth-User'] = '******'
        req.headers['X-Auth-Key'] = 'user1_key'
        req.headers['X-Auth-Project-Id'] = 'user1_project'
        result = req.get_response(fakes.wsgi_app(fake_auth=False))
        self.assertEqual(result.status, '204 No Content')
        self.assertEqual(len(result.headers['X-Auth-Token']), 40)
        self.assertFalse('X-CDN-Management-Url' in result.headers)
        self.assertFalse('X-Storage-Url' in result.headers)
Example #2
0
    def setUp(self):
        super(AccountsTest, self).setUp()
        self.flags(verbose=True)
        self.stubs.Set(accounts.Controller, '__init__', fake_init)
        fakes.FakeAuthManager.clear_fakes()
        fakes.FakeAuthDatabase.data = {}
        fakes.stub_out_networking(self.stubs)
        fakes.stub_out_rate_limiting(self.stubs)

        fakemgr = fakes.FakeAuthManager()
        joeuser = auth_manager.User('id1', 'guy1', 'acc1', 'secret1', False)
        superuser = auth_manager.User('id2', 'guy2', 'acc2', 'secret2', True)
        fakemgr.add_user(joeuser)
        fakemgr.add_user(superuser)
        fakemgr.create_project('test1', joeuser)
        fakemgr.create_project('test2', superuser)
Example #3
0
    def setUp(self):
        super(UsersTest, self).setUp()
        self.flags(verbose=True)
        self.stubs.Set(users.Controller, '__init__', fake_init)
        fakes.FakeAuthManager.clear_fakes()
        fakes.FakeAuthManager.projects = dict(
            testacct=Project('testacct', 'testacct', 'id1', 'test', []))
        fakes.FakeAuthDatabase.data = {}
        fakes.stub_out_networking(self.stubs)
        fakes.stub_out_rate_limiting(self.stubs)
        fakes.stub_out_auth(self.stubs)

        fakemgr = fakes.FakeAuthManager()
        fakemgr.add_user(User('id1', 'guy1', 'acc1', 'secret1', False))
        fakemgr.add_user(User('id2', 'guy2', 'acc2', 'secret2', True))

        self.controller = users.Controller()
Example #4
0
    def setUp(self):
        super(UsersTest, self).setUp()
        self.stubs = stubout.StubOutForTesting()
        self.stubs.Set(users.Controller, '__init__', fake_init)
        self.stubs.Set(users.Controller, '_check_admin', fake_admin_check)
        fakes.FakeAuthManager.clear_fakes()
        fakes.FakeAuthManager.projects = dict(
            testacct=Project('testacct', 'testacct', 'id1', 'test', []))
        fakes.FakeAuthDatabase.data = {}
        fakes.stub_out_networking(self.stubs)
        fakes.stub_out_rate_limiting(self.stubs)
        fakes.stub_out_auth(self.stubs)

        self.allow_admin = FLAGS.allow_admin_api
        FLAGS.allow_admin_api = True
        fakemgr = fakes.FakeAuthManager()
        fakemgr.add_user(User('id1', 'guy1', 'acc1', 'secret1', False))
        fakemgr.add_user(User('id2', 'guy2', 'acc2', 'secret2', True))
Example #5
0
    def test_not_existing_project(self):
        f = fakes.FakeAuthManager()
        user1 = nova.auth.manager.User('id1', 'user1', 'user1_key', None, None)
        f.add_user(user1)
        f.create_project('user1_project', user1)

        req = webob.Request.blank('/v1.0/', {'HTTP_HOST': 'foo'})
        req.headers['X-Auth-User'] = '******'
        req.headers['X-Auth-Key'] = 'user1_key'
        result = req.get_response(fakes.wsgi_app(fake_auth=False))
        self.assertEqual(result.status, '204 No Content')

        token = result.headers['X-Auth-Token']
        self.stubs.Set(nova.api.openstack, 'APIRouterV10', fakes.FakeRouter)
        req = webob.Request.blank('/v1.0/fake')
        req.headers['X-Auth-Token'] = token
        req.headers['X-Auth-Project-Id'] = 'unknown_project'
        result = req.get_response(fakes.wsgi_app(fake_auth=False))
        self.assertEqual(result.status, '401 Unauthorized')
Example #6
0
    def test_authorize_token(self):
        f = fakes.FakeAuthManager()
        user = nova.auth.manager.User('id1', 'user1', 'user1_key', None, None)
        f.add_user(user)
        f.create_project('test', user)

        req = webob.Request.blank('/v1.0/')
        req.headers['X-Auth-User'] = '******'
        req.headers['X-Auth-Key'] = 'user1_key'
        result = req.get_response(fakes.wsgi_app())
        self.assertEqual(len(result.headers['X-Auth-Token']), 40)

        token = result.headers['X-Auth-Token']
        self.stubs.Set(nova.api.openstack, 'APIRouter', fakes.FakeRouter)
        req = webob.Request.blank('/v1.0/fake')
        req.method = 'POST'
        req.headers['X-Auth-Token'] = token
        result = req.get_response(fakes.wsgi_app())
        self.assertEqual(result.status, '200 OK')
        self.assertEqual(result.headers['X-Test-Success'], 'True')
Example #7
0
    def test_authorize_project(self):
        f = fakes.FakeAuthManager()
        user = nova.auth.manager.User('id1', 'user1', 'user1_key', None, None)
        f.add_user(user)
        f.create_project('user1_project', user)
        f.create_project('user2_project', user)

        req = webob.Request.blank('/v2/', {'HTTP_HOST': 'foo'})
        req.headers['X-Auth-User'] = '******'
        req.headers['X-Auth-Key'] = 'user1_key'
        result = req.get_response(fakes.wsgi_app(fake_auth=False))
        self.assertEqual(result.status, '204 No Content')

        token = result.headers['X-Auth-Token']
        self.stubs.Set(nova.api.openstack.v2, 'APIRouter', fakes.FakeRouter)
        req = webob.Request.blank('/v2/user2_project')
        req.headers['X-Auth-Token'] = token
        result = req.get_response(fakes.wsgi_app(fake_auth=False))
        self.assertEqual(result.status, '200 OK')
        self.assertEqual(result.headers['X-Test-Success'], 'True')
Example #8
0
    def setUp(self):
        super(AccountsTest, self).setUp()
        self.stubs = stubout.StubOutForTesting()
        self.stubs.Set(accounts.Controller, '__init__', fake_init)
        self.stubs.Set(accounts.Controller, '_check_admin', fake_admin_check)
        fakes.FakeAuthManager.clear_fakes()
        fakes.FakeAuthDatabase.data = {}
        fakes.stub_out_networking(self.stubs)
        fakes.stub_out_rate_limiting(self.stubs)
        fakes.stub_out_auth(self.stubs)

        self.allow_admin = FLAGS.allow_admin_api
        FLAGS.allow_admin_api = True
        fakemgr = fakes.FakeAuthManager()
        joeuser = User('id1', 'guy1', 'acc1', 'secret1', False)
        superuser = User('id2', 'guy2', 'acc2', 'secret2', True)
        fakemgr.add_user(joeuser)
        fakemgr.add_user(superuser)
        fakemgr.create_project('test1', joeuser)
        fakemgr.create_project('test2', superuser)
Example #9
0
    def test_authorize_token(self):
        f = fakes.FakeAuthManager()
        user = nova.auth.manager.User('id1', 'user1', 'user1_key', None, None)
        f.add_user(user)
        f.create_project('user1_project', user)

        req = webob.Request.blank('/v1.0/', {'HTTP_HOST': 'foo'})
        req.headers['X-Auth-User'] = '******'
        req.headers['X-Auth-Key'] = 'user1_key'
        result = req.get_response(fakes.wsgi_app())
        self.assertEqual(result.status, '204 No Content')
        self.assertEqual(len(result.headers['X-Auth-Token']), 40)
        self.assertEqual(result.headers['X-Server-Management-Url'],
                         "http://foo/v1.0/")
        self.assertEqual(result.headers['X-CDN-Management-Url'], "")
        self.assertEqual(result.headers['X-Storage-Url'], "")

        token = result.headers['X-Auth-Token']
        self.stubs.Set(nova.api.openstack, 'APIRouter', fakes.FakeRouter)
        req = webob.Request.blank('/v1.0/fake')
        req.headers['X-Auth-Token'] = token
        result = req.get_response(fakes.wsgi_app())
        self.assertEqual(result.status, '200 OK')
        self.assertEqual(result.headers['X-Test-Success'], 'True')
Example #10
0
def fake_init(self):
    self.manager = fakes.FakeAuthManager()