Esempio n. 1
0
 def setUp(self):
     super(SqlToken, self).setUp()
     CONF(config_files=[test.etcdir('keystone.conf'),
                        test.testsdir('test_overrides.conf'),
                        test.testsdir('backend_sql.conf')])
     sql_util.setup_test_database()
     self.token_api = token_sql.Token()
Esempio n. 2
0
    def test_flush_expired_tokens_batch(self):
        # TODO(dstanek): This test should be rewritten to be less
        # brittle. The code will likely need to be changed first. I
        # just copied the spirit of the existing test when I rewrote
        # mox -> mock. These tests are brittle because they have the
        # call structure for SQLAlchemy encoded in them.

        # test sqlite dialect
        with mock.patch.object(token_sql, 'sql') as mock_sql:
            mock_sql.get_session().bind.dialect.name = 'sqlite'
            tok = token_sql.Token()
            tok.flush_expired_tokens()

        self.assertFalse(mock_sql.get_session().query().filter().limit.called)
Esempio n. 3
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.

        expected_query_args = (token_sql.TokenModel.id,
                               token_sql.TokenModel.expires)

        with mock.patch.object(token_sql, 'sql') as mock_sql:
            tok = token_sql.Token()
            tok.list_revoked_tokens()

        mock_query = mock_sql.get_session().query
        mock_query.assert_called_with(*expected_query_args)
Esempio n. 4
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. 5
0
    def test_flush_expired_tokens_batch_ibm_db_sa(self):
        # TODO(dstanek): This test should be rewritten to be less
        # brittle. The code will likely need to be changed first. I
        # just copied the spirit of the existing test when I rewrote
        # mox -> mock. These tests are brittle because they have the
        # call structure for SQLAlchemy encoded in them.

        # test ibm_db_sa
        with mock.patch.object(token_sql, 'sql') as mock_sql:
            # NOTE(dstanek): this will allow us to break out of the
            # 'while True' loop
            mock_sql.get_session().query().filter().delete.return_value = 0

            mock_sql.get_session().bind.dialect.name = 'ibm_db_sa'
            tok = token_sql.Token()
            tok.flush_expired_tokens()

        mock_limit = mock_sql.get_session().query().filter().limit
        mock_limit.assert_called_with(100)
 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 test_token_flush_batch_size_db2(self):
     tok = token_sql.Token()
     db2_batch = tok.token_flush_batch_size('ibm_db_sa')
     self.assertEqual(db2_batch, 100)
 def test_token_flush_batch_size_default(self):
     tok = token_sql.Token()
     sqlite_batch = tok.token_flush_batch_size('sqlite')
     self.assertEqual(sqlite_batch, 0)