def test_ssl_custom_cert(mocker, request): ENV_KEY = 'SSL_CERT_FILE' os.environ[ENV_KEY] = 'cert.pem' def cleanup(): os.environ.pop(ENV_KEY) request.addfinalizer(cleanup) port = 9637 t = Thread(target=ssl_bad_socket_server, args=(port, )) t.start() time.sleep(1) # wait for socket server to startup params = BASE_TEST_PARAMS.copy() params['server_ip'] = '127.0.0.1' # disable-secrets-detection params['secure_connection'] = 'SSL' params['port'] = port mocker.patch.object(demisto, 'params', return_value=params) return_error_mock = mocker.patch(RETURN_ERROR_TARGET) # validate our mock of params assert demisto.params().get('secure_connection') == 'SSL' main() t.join(5) assert return_error_mock.call_count == 1 # call_args last call with a tuple of args list and kwargs err_msg = return_error_mock.call_args[0][0] assert len(err_msg) < 100 assert 'Failed to access' in err_msg assert 'SSL error' not in err_msg
def test_bad_host_no_ssl(mocker): mocker.patch.object(demisto, 'params', return_value=BASE_TEST_PARAMS) return_error_mock = mocker.patch(RETURN_ERROR_TARGET) # validate our mock of params assert demisto.params().get('server_ip') == '127.0.0.1' main() assert return_error_mock.call_count == 1 # call_args last call with a tuple of args list and kwargs err_msg = return_error_mock.call_args[0][0] assert len(err_msg) < 100 assert 'Failed to access' in err_msg
def test_bad_host_no_ssl(mocker): mocker.patch.object(demisto, 'params', return_value=BASE_TEST_PARAMS) return_error_mock = mocker.patch(RETURN_ERROR_TARGET) # validate our mock of params assert demisto.params().get('server_ip') == '127.0.0.1' main() assert return_error_mock.call_count == 1 # call_args last call with a tuple of args list and kwargs err_msg = return_error_mock.call_args[0][0] assert len(err_msg) < 100 assert 'Failed to access' in err_msg
def test_bad_ssl(mocker): params = BASE_TEST_PARAMS.copy() params['server_ip'] = '185.199.108.153' # disable-secrets-detection params['secure_connection'] = 'SSL' params['port'] = 443 mocker.patch.object(demisto, 'params', return_value=params) return_error_mock = mocker.patch(RETURN_ERROR_TARGET) # validate our mock of params assert demisto.params().get('secure_connection') == 'SSL' main() assert return_error_mock.call_count == 1 # call_args last call with a tuple of args list and kwargs err_msg = return_error_mock.call_args[0][0] assert len(err_msg) < 100 assert 'Failed to access' in err_msg assert 'SSL error' in err_msg
def test_bad_ssl(mocker): params = BASE_TEST_PARAMS.copy() params['server_ip'] = '185.199.108.153' # disable-secrets-detection params['secure_connection'] = 'SSL' params['port'] = 443 mocker.patch.object(demisto, 'params', return_value=params) return_error_mock = mocker.patch(RETURN_ERROR_TARGET) # validate our mock of params assert demisto.params().get('secure_connection') == 'SSL' main() assert return_error_mock.call_count == 1 # call_args last call with a tuple of args list and kwargs err_msg = return_error_mock.call_args[0][0] assert len(err_msg) < 100 assert 'Failed to access' in err_msg assert 'SSL error' in err_msg
def test_faulty_server(mocker): t = Thread(target=ssl_bad_socket_server) t.start() time.sleep(1) # wait for socket server to startup params = BASE_TEST_PARAMS.copy() params['server_ip'] = '127.0.0.1' # disable-secrets-detection params['secure_connection'] = 'SSL' params['unsecure'] = True params['port'] = 9636 mocker.patch.object(demisto, 'params', return_value=params) return_error_mock = mocker.patch(RETURN_ERROR_TARGET) # validate our mock of params assert demisto.params().get('secure_connection') == 'SSL' main() t.join(5) assert return_error_mock.call_count == 1 # call_args last call with a tuple of args list and kwargs err_msg = return_error_mock.call_args[0][0] assert len(err_msg) < 100 assert 'Failed to access' in err_msg
def test_bad_ssl(mocker): params = BASE_TEST_PARAMS.copy() params['server_ip'] = '185.199.108.153' # disable-secrets-detection params['secure_connection'] = 'SSL' params['port'] = 443 mocker.patch.object(demisto, 'params', return_value=params) return_error_mock = mocker.patch(RETURN_ERROR_TARGET) demisto_info_mock = mocker.patch.object(demisto, "info") # validate our mock of params assert demisto.params().get('secure_connection') == 'SSL' main() assert return_error_mock.call_count == 1 # call_args last call with a tuple of args list and kwargs err_msg = return_error_mock.call_args[0][0] assert len(err_msg) < 100 assert 'Failed to access' in err_msg assert 'SSL error' in err_msg # call_args_list holds all calls (we need the first) with a tuple of args list and kwargs info_msg = demisto_info_mock.call_args_list[0][0][0] # ip is not in the certificate. so it should fail on host match assert "doesn't match any name" in info_msg
def test_faulty_server(mocker): t = Thread(target=ssl_bad_socket_server) t.start() time.sleep(1) # wait for socket server to startup params = BASE_TEST_PARAMS.copy() params['server_ip'] = '127.0.0.1' # disable-secrets-detection params['secure_connection'] = 'SSL' params['unsecure'] = True params['port'] = 9636 mocker.patch.object(demisto, 'params', return_value=params) return_error_mock = mocker.patch(RETURN_ERROR_TARGET) # validate our mock of params assert demisto.params().get('secure_connection') == 'SSL' main() t.join(5) assert return_error_mock.call_count == 1 # call_args last call with a tuple of args list and kwargs err_msg = return_error_mock.call_args[0][0] assert len(err_msg) < 100 assert 'Failed to access' in err_msg