|
9 | 9 | from celery.beat import DEFAULT_MAX_INTERVAL |
10 | 10 | from celery.schedules import schedstate, schedule |
11 | 11 | from celery.utils.time import maybe_timedelta |
| 12 | +from redis import CredentialProvider |
12 | 13 | from redis.exceptions import ConnectionError |
13 | 14 |
|
14 | 15 | from redbeat import RedBeatScheduler |
@@ -389,6 +390,42 @@ def test_ssl_connection_scheduler(self): |
389 | 390 | assert 'ssl_ca_certs' not in redis_client.connection_pool.connection_kwargs |
390 | 391 |
|
391 | 392 |
|
| 393 | +class RedisWithCredentialProvider(AppCase): |
| 394 | + class UserCredProvider(CredentialProvider): |
| 395 | + def __init__(self, username, password): |
| 396 | + self.username = username |
| 397 | + self.password = password |
| 398 | + |
| 399 | + def get_credential(self): |
| 400 | + return self.username, self.password |
| 401 | + |
| 402 | + config_dict = { |
| 403 | + 'REDBEAT_KEY_PREFIX': 'rb-tests:', |
| 404 | + 'REDBEAT_REDIS_URL': 'rediss://redishost:26379/0', |
| 405 | + 'REDBEAT_REDIS_OPTIONS': { |
| 406 | + 'credential_provider': UserCredProvider("test_user", "test_pass") |
| 407 | + }, |
| 408 | + 'REDBEAT_REDIS_USE_SSL': True, |
| 409 | + } |
| 410 | + |
| 411 | + def setup(self): # celery3 |
| 412 | + self.app.conf.add_defaults(deepcopy(self.config_dict)) |
| 413 | + |
| 414 | + def test_redis_with_credential_provider_scheduler(self): |
| 415 | + redis_client = get_redis(app=self.app) |
| 416 | + |
| 417 | + # existing ssl checks |
| 418 | + assert 'SSLConnection' in str(redis_client.connection_pool) |
| 419 | + assert redis_client.connection_pool.connection_kwargs['ssl_cert_reqs'] == ssl.CERT_REQUIRED |
| 420 | + |
| 421 | + # check for credential provider |
| 422 | + assert 'username' not in redis_client.connection_pool.connection_kwargs |
| 423 | + assert 'password' not in redis_client.connection_pool.connection_kwargs |
| 424 | + assert 'credential_provider' in redis_client.connection_pool.connection_kwargs |
| 425 | + cred_provider = redis_client.connection_pool.connection_kwargs['credential_provider'] |
| 426 | + assert isinstance(cred_provider, CredentialProvider) |
| 427 | + |
| 428 | + |
392 | 429 | class RedBeatLockTimeoutDefaultValues(RedBeatCase): |
393 | 430 | def test_no_values(self): |
394 | 431 | scheduler = RedBeatScheduler(app=self.app) |
|
0 commit comments