1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012, Red Hat, Inc.
5
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6
# not use this file except in compliance with the License. You may obtain
7
# a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
# License for the specific language governing permissions and limitations
18
Unit Tests for nova.consoleauth.rpcapi
21
from nova.consoleauth import rpcapi as consoleauth_rpcapi
22
from nova import context
23
from nova import flags
31
class ConsoleAuthRpcAPITestCase(test.TestCase):
34
super(ConsoleAuthRpcAPITestCase, self).setUp()
37
super(ConsoleAuthRpcAPITestCase, self).tearDown()
39
def _test_consoleauth_api(self, method, **kwargs):
40
ctxt = context.RequestContext('fake_user', 'fake_project')
41
rpcapi = consoleauth_rpcapi.ConsoleAuthAPI()
42
expected_retval = 'foo'
43
expected_msg = rpcapi.make_msg(method, **kwargs)
44
expected_msg['version'] = rpcapi.RPC_API_VERSION
47
self.call_topic = None
49
self.call_timeout = None
51
def _fake_call(_ctxt, _topic, _msg, _timeout):
52
self.call_ctxt = _ctxt
53
self.call_topic = _topic
55
self.call_timeout = _timeout
56
return expected_retval
58
self.stubs.Set(rpc, 'call', _fake_call)
60
retval = getattr(rpcapi, method)(ctxt, **kwargs)
62
self.assertEqual(retval, expected_retval)
63
self.assertEqual(self.call_ctxt, ctxt)
64
self.assertEqual(self.call_topic, FLAGS.consoleauth_topic)
65
self.assertEqual(self.call_msg, expected_msg)
66
self.assertEqual(self.call_timeout, None)
68
def test_authorize_console(self):
69
self._test_consoleauth_api('authorize_console', token='token',
70
console_type='ctype', host='h', port='p',
71
internal_access_path='iap')
73
def test_check_token(self):
74
self._test_consoleauth_api('check_token', token='t')