Esempio n. 1
0
    def setUp(self):
        super(PolicyTestCase, self).setUp()
        rules.reset()
        self.addCleanup(rules.reset)
        # NOTE(vish): preload rules to circumvent reloading from file
        rules.init()
        self.rules = {
            "true": [],
            "example:allowed": [],
            "example:denied": [["false:false"]],
            "example:get_http": [["http:http://www.example.com"]],
            "example:my_file": [["role:compute_admin"],
                                ["project_id:%(project_id)s"]],
            "example:early_and_fail": [["false:false", "rule:true"]],
            "example:early_or_success": [["rule:true"], ["false:false"]],
            "example:lowercase_admin": [["role:admin"], ["role:sysadmin"]],
            "example:uppercase_admin": [["role:ADMIN"], ["role:sysadmin"]],
        }

        # NOTE(vish): then overload underlying policy engine
        self._set_rules()
        self.credentials = {}
        self.target = {}

        fixture = self.useFixture(moxstubout.MoxStubout())
        self.stubs = fixture.stubs
Esempio n. 2
0
    def setUp(self):
        super(NotificationsTestCase, self).setUp()
        fixture = self.useFixture(moxstubout.MoxStubout())
        self.stubs = fixture.stubs

        # these should use self.opt(), but they haven't been registered yet
        CONF.rpc_backend = 'fake'
        CONF.notification_driver = ['fake']
Esempio n. 3
0
    def setUp(self):
        super(LocalizedResponseTest, self).setUp()

        gettextutils._AVAILABLE_LANGUAGES.clear()
        self.addCleanup(gettextutils._AVAILABLE_LANGUAGES.clear)

        fixture = self.useFixture(moxstubout.MoxStubout())
        self.stubs = fixture.stubs
Esempio n. 4
0
    def setUp(self):
        super(XmlVersionTestCase, self).setUp()
        self.load_backends()
        self.public_app = self.loadapp('keystone', 'main')
        self.admin_app = self.loadapp('keystone', 'admin')

        self.public_server = self.serveapp('keystone', name='main')
        self.admin_server = self.serveapp('keystone', name='admin')

        fixture = self.useFixture(moxstubout.MoxStubout())
        self.stubs = fixture.stubs
Esempio n. 5
0
    def setUp(self):
        super(XmlVersionTestCase, self).setUp()
        self.load_backends()
        self.public_app = self.loadapp('keystone', 'main')
        self.admin_app = self.loadapp('keystone', 'admin')

        port = random.randint(10000, 30000)
        self.opt(public_port=port, admin_port=port)

        fixture = self.useFixture(moxstubout.MoxStubout())
        self.stubs = fixture.stubs
Esempio n. 6
0
    def setUp(self):
        super(XmlVersionTestCase, self).setUp()
        self.load_backends()
        self.public_app = self.loadapp('keystone', 'main')
        self.admin_app = self.loadapp('keystone', 'admin')

        self.config_fixture.config(
            public_endpoint='http://localhost:%(public_port)d',
            admin_endpoint='http://localhost:%(admin_port)d')

        fixture = self.useFixture(moxstubout.MoxStubout())
        self.stubs = fixture.stubs
Esempio n. 7
0
 def test_token_revocation_list_uses_right_columns(self):
     # This query used to be heavy with too many columns. We want
     # to make sure it is only running with the minimum columns
     # necessary.
     fixture = self.useFixture(moxstubout.MoxStubout())
     self.mox = fixture.mox
     tok = token_sql.Token()
     session = tok.get_session()
     q = session.query(token_sql.TokenModel.id,
                       token_sql.TokenModel.expires)
     self.mox.StubOutWithMock(session, 'query')
     session.query(token_sql.TokenModel.id,
                   token_sql.TokenModel.expires).AndReturn(q)
     self.mox.StubOutWithMock(tok, 'get_session')
     tok.get_session().AndReturn(session)
     self.mox.ReplayAll()
     tok.list_revoked_tokens()
Esempio n. 8
0
    def setUp(self):
        super(NotificationsWrapperTestCase, self).setUp()

        self.exp_resource_id = None
        self.exp_operation = None
        self.send_notification_called = False

        def fake_notify(operation, resource_type, resource_id, public=True):
            self.assertEqual(self.exp_operation, operation)
            self.assertEqual(EXP_RESOURCE_TYPE, resource_type)
            self.assertEqual(self.exp_resource_id, resource_id)
            self.send_notification_called = True

        fixture = self.useFixture(moxstubout.MoxStubout())
        self.stubs = fixture.stubs

        self.stubs.Set(notifications, '_send_notification', fake_notify)
Esempio n. 9
0
    def setUp(self):
        super(NotificationsForEntities, self).setUp()
        self._notifications = []

        def fake_notify(operation, resource_type, resource_id,
                        public=True):
            note = {
                'resource_id': resource_id,
                'operation': operation,
                'resource_type': resource_type,
                'send_notification_called': True,
                'public': public}
            self._notifications.append(note)

        fixture = self.useFixture(moxstubout.MoxStubout())
        self.stubs = fixture.stubs

        self.stubs.Set(notifications, '_send_notification', fake_notify)
    def setUp(self):
        super(NotificationsForEntities, self).setUp()

        self.exp_resource_id = None
        self.exp_operation = None
        self.exp_resource_type = None
        self.send_notification_called = False

        def fake_notify(operation, resource_type, resource_id, host=None):
            self.exp_resource_id = resource_id
            self.exp_operation = operation
            self.exp_resource_type = resource_type
            self.send_notification_called = True

        fixture = self.useFixture(moxstubout.MoxStubout())
        self.stubs = fixture.stubs

        self.stubs.Set(notifications, '_send_notification', fake_notify)
Esempio n. 11
0
    def setUp(self):
        super(CadfNotificationsWrapperTestCase, self).setUp()
        self._notifications = []

        def fake_notify(action, initiator, outcome):
            note = {
                'action': action,
                'initiator': initiator,
                # NOTE(stevemar): outcome has 2 stages, pending and success
                # so we are ignoring it for now.
                #'outcome': outcome,
                'send_notification_called': True}
            self._notifications.append(note)

        # TODO(stevemar): Look into using mock instead of mox
        fixture = self.useFixture(moxstubout.MoxStubout())
        self.stubs = fixture.stubs
        self.stubs.Set(notifications, '_send_audit_notification',
                       fake_notify)
 def test_flush_expired_tokens_batch(self):
     # This test simply executes the code under test to verify
     # that the code is legal.  It is not possible to test
     # whether records are deleted in batches using sqlite,
     # because the limit function does not seem to affect
     # delete subqueries; these are, however, legal.
     # After several failed attempts of using mox, it would
     # seem that the use of mock objects for testing
     # the target code does not seem possible, because of
     # the unique way the SQLAlchemy Query class's filter
     # method works.
     fixture = self.useFixture(moxstubout.MoxStubout())
     self.mox = fixture.mox
     tok = token_sql.Token()
     self.mox.StubOutWithMock(tok, 'token_flush_batch_size')
     # Just need a batch larger than 0; note that the code
     # path with batch_size = 0 is covered by test_backend,
     # where all backends' flush_expired_tokens methods
     # are tested.
     tok.token_flush_batch_size('sqlite').AndReturn(1)
     self.mox.ReplayAll()
     tok.flush_expired_tokens()
 def setUp(self):
     super(NotificationsTestCase, self).setUp()
     fixture = self.useFixture(moxstubout.MoxStubout())
     self.stubs = fixture.stubs