Jiri Stransky 3e2415b6d2 Argument parsing and checking - allow token authentication
This expands the argument parser and ensure_auth_info method to
provide alternative means of authentication. Up to now the CLI
required username, password, tenant and Keystone URL. Now user can
also provide auth token and Tuskar URL (alternatively Keystone URL
instead of Tuskar URL, in that case the Tuskar URL would be fetched
from Keystone).
2013-08-02 14:50:09 +02:00

57 lines
1.8 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from tuskarclient import shell
import tuskarclient.tests.utils as tutils
class ShellTest(tutils.TestCase):
def setUp(self):
super(ShellTest, self).setUp()
self.s = shell.TuskarShell({})
def empty_args(self):
args = lambda: None # i'd use object(), but it can't have attributes
args_attributes = [
'os_username', 'os_password', 'os_tenant_name', 'os_tenant_id',
'os_auth_url', 'os_auth_token', 'tuskar_url',
]
for attr in args_attributes:
setattr(args, attr, None)
return args
def test_ensure_auth_info_with_credentials(self):
ensure = self.s._ensure_auth_info
usage_error = shell.UsageError
args = self.empty_args()
args.os_username = 'user'
args.os_password = 'pass'
args.os_tenant_name = 'tenant'
self.assertRaises(usage_error, ensure, args)
args.os_auth_url = 'keystone'
ensure(args) # doesn't raise
def test_ensure_auth_info_with_token(self):
ensure = self.s._ensure_auth_info
usage_error = shell.UsageError
args = self.empty_args()
args.os_auth_token = 'token'
self.assertRaises(usage_error, ensure, args)
args.tuskar_url = 'tuskar'
ensure(args) # doesn't raise