Merge "Remove auth_with_unscoped_saml decorator"
This commit is contained in:
@@ -18,35 +18,14 @@ the user can list domains and projects they are allowed to access, and request
|
|||||||
a scoped token."""
|
a scoped token."""
|
||||||
|
|
||||||
from osc_lib.command import command
|
from osc_lib.command import command
|
||||||
from osc_lib import exceptions
|
|
||||||
from osc_lib import utils
|
from osc_lib import utils
|
||||||
|
|
||||||
from openstackclient.i18n import _
|
from openstackclient.i18n import _
|
||||||
|
|
||||||
|
|
||||||
UNSCOPED_AUTH_PLUGINS = ['v3unscopedsaml', 'v3unscopedadfs', 'v3oidc']
|
|
||||||
|
|
||||||
|
|
||||||
def auth_with_unscoped_saml(func):
|
|
||||||
"""Check the unscoped federated context"""
|
|
||||||
|
|
||||||
def _decorated(self, parsed_args):
|
|
||||||
auth_plugin_name = self.app.client_manager.auth_plugin_name
|
|
||||||
if auth_plugin_name in UNSCOPED_AUTH_PLUGINS:
|
|
||||||
return func(self, parsed_args)
|
|
||||||
else:
|
|
||||||
msg = (_('This command requires the use of an unscoped SAML '
|
|
||||||
'authentication plugin. Please use argument '
|
|
||||||
'--os-auth-type with one of the following '
|
|
||||||
'plugins: %s') % ', '.join(UNSCOPED_AUTH_PLUGINS))
|
|
||||||
raise exceptions.CommandError(msg)
|
|
||||||
return _decorated
|
|
||||||
|
|
||||||
|
|
||||||
class ListAccessibleDomains(command.Lister):
|
class ListAccessibleDomains(command.Lister):
|
||||||
_description = _("List accessible domains")
|
_description = _("List accessible domains")
|
||||||
|
|
||||||
@auth_with_unscoped_saml
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
columns = ('ID', 'Enabled', 'Name', 'Description')
|
columns = ('ID', 'Enabled', 'Name', 'Description')
|
||||||
identity_client = self.app.client_manager.identity
|
identity_client = self.app.client_manager.identity
|
||||||
@@ -61,7 +40,6 @@ class ListAccessibleDomains(command.Lister):
|
|||||||
class ListAccessibleProjects(command.Lister):
|
class ListAccessibleProjects(command.Lister):
|
||||||
_description = _("List accessible projects")
|
_description = _("List accessible projects")
|
||||||
|
|
||||||
@auth_with_unscoped_saml
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
columns = ('ID', 'Domain ID', 'Enabled', 'Name')
|
columns = ('ID', 'Domain ID', 'Enabled', 'Name')
|
||||||
identity_client = self.app.client_manager.identity
|
identity_client = self.app.client_manager.identity
|
||||||
|
@@ -12,8 +12,6 @@
|
|||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from osc_lib import exceptions
|
|
||||||
|
|
||||||
from openstackclient.identity.v3 import unscoped_saml
|
from openstackclient.identity.v3 import unscoped_saml
|
||||||
from openstackclient.tests.unit import fakes
|
from openstackclient.tests.unit import fakes
|
||||||
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
|
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
|
||||||
@@ -48,7 +46,6 @@ class TestDomainList(TestUnscopedSAML):
|
|||||||
self.cmd = unscoped_saml.ListAccessibleDomains(self.app, None)
|
self.cmd = unscoped_saml.ListAccessibleDomains(self.app, None)
|
||||||
|
|
||||||
def test_accessible_domains_list(self):
|
def test_accessible_domains_list(self):
|
||||||
self.app.client_manager.auth_plugin_name = 'v3unscopedsaml'
|
|
||||||
arglist = []
|
arglist = []
|
||||||
verifylist = []
|
verifylist = []
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
@@ -70,17 +67,6 @@ class TestDomainList(TestUnscopedSAML):
|
|||||||
), )
|
), )
|
||||||
self.assertEqual(datalist, tuple(data))
|
self.assertEqual(datalist, tuple(data))
|
||||||
|
|
||||||
def test_accessible_domains_list_wrong_auth(self):
|
|
||||||
auth = identity_fakes.FakeAuth("wrong auth")
|
|
||||||
self.app.client_manager.identity.session.auth = auth
|
|
||||||
arglist = []
|
|
||||||
verifylist = []
|
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
||||||
|
|
||||||
self.assertRaises(exceptions.CommandError,
|
|
||||||
self.cmd.take_action,
|
|
||||||
parsed_args)
|
|
||||||
|
|
||||||
|
|
||||||
class TestProjectList(TestUnscopedSAML):
|
class TestProjectList(TestUnscopedSAML):
|
||||||
|
|
||||||
@@ -99,7 +85,6 @@ class TestProjectList(TestUnscopedSAML):
|
|||||||
self.cmd = unscoped_saml.ListAccessibleProjects(self.app, None)
|
self.cmd = unscoped_saml.ListAccessibleProjects(self.app, None)
|
||||||
|
|
||||||
def test_accessible_projects_list(self):
|
def test_accessible_projects_list(self):
|
||||||
self.app.client_manager.auth_plugin_name = 'v3unscopedsaml'
|
|
||||||
arglist = []
|
arglist = []
|
||||||
verifylist = []
|
verifylist = []
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
@@ -120,14 +105,3 @@ class TestProjectList(TestUnscopedSAML):
|
|||||||
identity_fakes.project_name,
|
identity_fakes.project_name,
|
||||||
), )
|
), )
|
||||||
self.assertEqual(datalist, tuple(data))
|
self.assertEqual(datalist, tuple(data))
|
||||||
|
|
||||||
def test_accessible_projects_list_wrong_auth(self):
|
|
||||||
auth = identity_fakes.FakeAuth("wrong auth")
|
|
||||||
self.app.client_manager.identity.session.auth = auth
|
|
||||||
arglist = []
|
|
||||||
verifylist = []
|
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
|
||||||
|
|
||||||
self.assertRaises(exceptions.CommandError,
|
|
||||||
self.cmd.take_action,
|
|
||||||
parsed_args)
|
|
||||||
|
Reference in New Issue
Block a user