From b98c08fed2c1c3d7eb14726e8ceab893f7f71cfd Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Wed, 17 Jun 2020 10:41:45 +0200 Subject: [PATCH 1/2] Ensure bytes --- ibm_mq/datadog_checks/ibm_mq/connection.py | 4 ++-- ibm_mq/tests/test_ibm_mq_unit.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ibm_mq/datadog_checks/ibm_mq/connection.py b/ibm_mq/datadog_checks/ibm_mq/connection.py index 7dc3bfa4cedc7..0159de89fa4a4 100644 --- a/ibm_mq/datadog_checks/ibm_mq/connection.py +++ b/ibm_mq/datadog_checks/ibm_mq/connection.py @@ -51,10 +51,10 @@ def get_ssl_connection(config): Get the connection with SSL """ cd = _get_channel_definition(config) - cd.SSLCipherSpec = config.ssl_cipher_spec + cd.SSLCipherSpec = pymqi.ensure_bytes(config.ssl_cipher_spec) sco = pymqi.SCO() - sco.KeyRepository = config.ssl_key_repository_location + sco.KeyRepository = pymqi.ensure_bytes(config.ssl_key_repository_location) queue_manager = pymqi.QueueManager(None) queue_manager.connect_with_options(config.queue_manager_name, cd, sco) diff --git a/ibm_mq/tests/test_ibm_mq_unit.py b/ibm_mq/tests/test_ibm_mq_unit.py index ea21367b73941..9b60e9f96bccd 100644 --- a/ibm_mq/tests/test_ibm_mq_unit.py +++ b/ibm_mq/tests/test_ibm_mq_unit.py @@ -172,3 +172,22 @@ def test_channel_queue_config_error(instance_config): IBMMQConfig(instance_config) assert 'channel, queue_manager are required configurations' in str(excinfo.value) + + +def test_ssl_connection(instance): + # TODO: We should test SSL in e2e + instance['ssl_auth'] = 'yes' + instance['ssl_cipher_spec'] = 'TLS_RSA_WITH_AES_256_CBC_SHA256' + instance['ssl_key_repository_location'] = '/dummy' + + check = IbmMqCheck('ibm_mq', {}, [instance]) + + check.check(instance) + + assert len(check.warnings) == 1 + warning = check.warnings[0] + + # Check that we are not getting a unicode/bytes type error but a MQRC_KEY_REPOSITORY_ERROR (dummy location) + assert 'bytes' not in warning + assert 'unicode' not in warning + assert 'MQRC_KEY_REPOSITORY_ERROR' in warning From c184d9451a4cdb13a27b772a32c611062b67bdfc Mon Sep 17 00:00:00 2001 From: Alexandre Yang Date: Fri, 26 Jun 2020 12:09:16 +0200 Subject: [PATCH 2/2] Better doc --- ibm_mq/tests/test_ibm_mq_unit.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ibm_mq/tests/test_ibm_mq_unit.py b/ibm_mq/tests/test_ibm_mq_unit.py index 9b60e9f96bccd..edaf5c0c54154 100644 --- a/ibm_mq/tests/test_ibm_mq_unit.py +++ b/ibm_mq/tests/test_ibm_mq_unit.py @@ -174,8 +174,12 @@ def test_channel_queue_config_error(instance_config): assert 'channel, queue_manager are required configurations' in str(excinfo.value) -def test_ssl_connection(instance): - # TODO: We should test SSL in e2e +def test_ssl_connection_creation(instance): + """ + Test that we are not getting unicode/bytes type error. + + TODO: We should test SSL in e2e + """ instance['ssl_auth'] = 'yes' instance['ssl_cipher_spec'] = 'TLS_RSA_WITH_AES_256_CBC_SHA256' instance['ssl_key_repository_location'] = '/dummy'