From 8d4c9d2fa65275630056b46e3f7cf007020b33f8 Mon Sep 17 00:00:00 2001 From: Ganesh Murthy Date: Thu, 10 Nov 2016 16:39:18 -0500 Subject: [PATCH] DISPATCH-557 - Moved management of connections from python agent to router core --- include/qpid/dispatch/router_core.h | 41 ++- src/CMakeLists.txt | 1 + src/router_core/agent.c | 21 +- src/router_core/agent_connection.c | 344 ++++++++++++++++++++++++++ src/router_core/agent_connection.h | 36 +++ src/router_core/connections.c | 101 +++++++- src/router_core/management_agent.c | 7 +- src/router_core/router_core.c | 4 + src/router_core/router_core_private.h | 19 ++ src/router_node.c | 73 +++++- src/server.c | 134 ---------- tests/system_test.py | 8 +- tests/system_tests_deprecated.py | 6 +- tests/system_tests_management.py | 2 +- tests/system_tests_one_router.py | 6 +- tests/system_tests_qdmanage.py | 24 +- tests/system_tests_sasl_plain.py | 29 ++- tests/system_tests_user_id.py | 28 +-- 18 files changed, 673 insertions(+), 211 deletions(-) create mode 100644 src/router_core/agent_connection.c create mode 100644 src/router_core/agent_connection.h diff --git a/include/qpid/dispatch/router_core.h b/include/qpid/dispatch/router_core.h index 942148140a..7a0b7fa836 100644 --- a/include/qpid/dispatch/router_core.h +++ b/include/qpid/dispatch/router_core.h @@ -23,6 +23,7 @@ #include #include #include +typedef struct qdr_core_t qdr_core_t; #include @@ -32,13 +33,14 @@ * exclusive access to that connection. */ -typedef struct qdr_core_t qdr_core_t; -typedef struct qdr_subscription_t qdr_subscription_t; -typedef struct qdr_connection_t qdr_connection_t; -typedef struct qdr_link_t qdr_link_t; -typedef struct qdr_delivery_t qdr_delivery_t; -typedef struct qdr_terminus_t qdr_terminus_t; -typedef struct qdr_error_t qdr_error_t; + +typedef struct qdr_subscription_t qdr_subscription_t; +typedef struct qdr_connection_t qdr_connection_t; +typedef struct qdr_link_t qdr_link_t; +typedef struct qdr_delivery_t qdr_delivery_t; +typedef struct qdr_terminus_t qdr_terminus_t; +typedef struct qdr_error_t qdr_error_t; +typedef struct qdr_connection_info_t qdr_connection_info_t; typedef enum { QD_ROUTER_MODE_STANDALONE, ///< Standalone router. No routing protocol participation @@ -140,7 +142,6 @@ typedef enum { QDR_ROLE_ON_DEMAND } qdr_connection_role_t; - /** * qdr_connection_opened * @@ -168,7 +169,8 @@ qdr_connection_t *qdr_connection_opened(qdr_core_t *core, const char *remote_container_id, bool strip_annotations_in, bool strip_annotations_out, - int link_capacity); + int link_capacity, + qdr_connection_info_t *connection_info); /** * qdr_connection_closed @@ -668,4 +670,25 @@ void qdr_query_free(qdr_query_t *query); typedef void (*qdr_manage_response_t) (void *context, const qd_amqp_error_t *status, bool more); void qdr_manage_handler(qdr_core_t *core, qdr_manage_response_t response_handler); +qdr_connection_info_t *qdr_connection_info(bool is_encrypted, + bool is_authenticated, + bool opened, + char *sasl_mechanisms, + const char *dir, + char *host, + char *ssl_proto, + char *ssl_cipher, + char *user, + const char *container, + pn_data_t *connection_properties, + int ssl_ssf); + +extern const char * const QDR_CONNECTION_ROLE_NORMAL; +extern const char * const QDR_CONNECTION_ROLE_INTER_ROUTER; +extern const char * const QDR_CONNECTION_ROLE_ROUTE_CONTAINER; +extern const char * const QDR_CONNECTION_ROLE_ON_DEMAND; + +extern const char * const QDR_CONNECTION_DIR_IN; +extern const char * const QDR_CONNECTION_DIR_OUT; + #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c5aa58978d..502fbb0edb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -69,6 +69,7 @@ set(qpid_dispatch_SOURCES router_core/agent_address.c router_core/agent_config_address.c router_core/agent_config_auto_link.c + router_core/agent_connection.c router_core/agent_config_link_route.c router_core/agent_link.c router_core/connections.c diff --git a/src/router_core/agent.c b/src/router_core/agent.c index 5b46e01feb..e300921e5a 100644 --- a/src/router_core/agent.c +++ b/src/router_core/agent.c @@ -23,6 +23,7 @@ #include "agent_config_auto_link.h" #include "agent_address.h" #include "agent_link.h" +#include "agent_connection.h" #include "router_core_private.h" #include @@ -136,8 +137,8 @@ void qdr_manage_delete(qdr_core_t *core, } -void qdr_manage_read(qdr_core_t *core, - void *context, +void qdr_manage_read(qdr_core_t *core, + void *context, qd_router_entity_type_t entity_type, qd_field_iterator_t *name, qd_field_iterator_t *identity, @@ -185,7 +186,7 @@ qdr_query_t *qdr_manage_query(qdr_core_t *core, case QD_ROUTER_CONFIG_ADDRESS: qdr_agent_set_columns(query, attribute_names, qdr_config_address_columns, QDR_CONFIG_ADDRESS_COLUMN_COUNT); break; case QD_ROUTER_CONFIG_LINK_ROUTE: qdr_agent_set_columns(query, attribute_names, qdr_config_link_route_columns, QDR_CONFIG_LINK_ROUTE_COLUMN_COUNT); break; case QD_ROUTER_CONFIG_AUTO_LINK: qdr_agent_set_columns(query, attribute_names, qdr_config_auto_link_columns, QDR_CONFIG_AUTO_LINK_COLUMN_COUNT); break; - case QD_ROUTER_CONNECTION: break; + case QD_ROUTER_CONNECTION: qdr_agent_set_columns(query, attribute_names, qdr_connection_columns, QDR_CONNECTION_COLUMN_COUNT); break; case QD_ROUTER_LINK: qdr_agent_set_columns(query, attribute_names, qdr_link_columns, QDR_LINK_COLUMN_COUNT); break; case QD_ROUTER_ADDRESS: qdr_agent_set_columns(query, attribute_names, qdr_address_columns, QDR_ADDRESS_COLUMN_COUNT); break; case QD_ROUTER_FORBIDDEN: break; @@ -203,7 +204,7 @@ void qdr_query_add_attribute_names(qdr_query_t *query) case QD_ROUTER_CONFIG_ADDRESS: qdr_agent_emit_columns(query, qdr_config_address_columns, QDR_CONFIG_ADDRESS_COLUMN_COUNT); break; case QD_ROUTER_CONFIG_LINK_ROUTE: qdr_agent_emit_columns(query, qdr_config_link_route_columns, QDR_CONFIG_LINK_ROUTE_COLUMN_COUNT); break; case QD_ROUTER_CONFIG_AUTO_LINK: qdr_agent_emit_columns(query, qdr_config_auto_link_columns, QDR_CONFIG_AUTO_LINK_COLUMN_COUNT); break; - case QD_ROUTER_CONNECTION: break; + case QD_ROUTER_CONNECTION: qdr_agent_emit_columns(query, qdr_connection_columns, QDR_CONNECTION_COLUMN_COUNT); break; case QD_ROUTER_LINK: qdr_agent_emit_columns(query, qdr_link_columns, QDR_LINK_COLUMN_COUNT); break; case QD_ROUTER_ADDRESS: qdr_agent_emit_columns(query, qdr_address_columns, QDR_ADDRESS_COLUMN_COUNT); break; case QD_ROUTER_FORBIDDEN: qd_compose_empty_list(query->body); break; @@ -297,7 +298,11 @@ static void qdr_agent_set_columns(qdr_query_t *query, } } } - query->columns[idx+1] = -1; + + if (count == 1 && idx == 1) + query->columns[idx] = -1; + else + query->columns[idx+1] = -1; } @@ -339,7 +344,7 @@ static void qdr_manage_read_CT(qdr_core_t *core, qdr_action_t *action, bool disc case QD_ROUTER_CONFIG_ADDRESS: qdra_config_address_get_CT(core, name, identity, query, qdr_config_address_columns); break; case QD_ROUTER_CONFIG_LINK_ROUTE: qdra_config_link_route_get_CT(core, name, identity, query, qdr_config_link_route_columns); break; case QD_ROUTER_CONFIG_AUTO_LINK: qdra_config_auto_link_get_CT(core, name, identity, query, qdr_config_auto_link_columns); break; - case QD_ROUTER_CONNECTION: break; + case QD_ROUTER_CONNECTION: qdra_connection_get_CT(core, name, identity, query, qdr_connection_columns); break; case QD_ROUTER_LINK: break; case QD_ROUTER_ADDRESS: qdra_address_get_CT(core, name, identity, query, qdr_address_columns); break; case QD_ROUTER_FORBIDDEN: qdr_agent_forbidden(core, query, false); break; @@ -435,7 +440,7 @@ static void qdrh_query_get_first_CT(qdr_core_t *core, qdr_action_t *action, bool case QD_ROUTER_CONFIG_ADDRESS: qdra_config_address_get_first_CT(core, query, offset); break; case QD_ROUTER_CONFIG_LINK_ROUTE: qdra_config_link_route_get_first_CT(core, query, offset); break; case QD_ROUTER_CONFIG_AUTO_LINK: qdra_config_auto_link_get_first_CT(core, query, offset); break; - case QD_ROUTER_CONNECTION: break; + case QD_ROUTER_CONNECTION: qdra_connection_get_first_CT(core, query, offset); break; case QD_ROUTER_LINK: qdra_link_get_first_CT(core, query, offset); break; case QD_ROUTER_ADDRESS: qdra_address_get_first_CT(core, query, offset); break; case QD_ROUTER_FORBIDDEN: qdr_agent_forbidden(core, query, true); break; @@ -455,7 +460,7 @@ static void qdrh_query_get_next_CT(qdr_core_t *core, qdr_action_t *action, bool case QD_ROUTER_CONFIG_ADDRESS: qdra_config_address_get_next_CT(core, query); break; case QD_ROUTER_CONFIG_LINK_ROUTE: qdra_config_link_route_get_next_CT(core, query); break; case QD_ROUTER_CONFIG_AUTO_LINK: qdra_config_auto_link_get_next_CT(core, query); break; - case QD_ROUTER_CONNECTION: break; + case QD_ROUTER_CONNECTION: qdra_connection_get_next_CT(core, query); break; case QD_ROUTER_LINK: qdra_link_get_next_CT(core, query); break; case QD_ROUTER_ADDRESS: qdra_address_get_next_CT(core, query); break; case QD_ROUTER_FORBIDDEN: break; diff --git a/src/router_core/agent_connection.c b/src/router_core/agent_connection.c new file mode 100644 index 0000000000..22d8063995 --- /dev/null +++ b/src/router_core/agent_connection.c @@ -0,0 +1,344 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include +#include "agent_connection.h" +#include +#include + +#define QDR_CONNECTION_IDENTITY 0 +#define QDR_CONNECTION_HOST 1 +#define QDR_CONNECTION_ROLE 2 +#define QDR_CONNECTION_DIR 3 +#define QDR_CONNECTION_CONTAINER_ID 4 +#define QDR_CONNECTION_SASL_MECHANISMS 5 +#define QDR_CONNECTION_IS_AUTHENTICATED 6 +#define QDR_CONNECTION_USER 7 +#define QDR_CONNECTION_IS_ENCRYPTED 8 +#define QDR_CONNECTION_SSLPROTO 9 +#define QDR_CONNECTION_SSLCIPHER 10 +#define QDR_CONNECTION_PROPERTIES 11 +#define QDR_CONNECTION_SSLSSF 12 + +const char *qdr_connection_columns[] = + {"identity", + "host", + "role", + "dir", + "container", + "sasl", + "isAuthenticated", + "user", + "isEncrypted", + "sslProto", + "sslCipher", + "properties", + "sslSsf", + 0}; + +const char *CONFIG_CONNECTION_TYPE = "org.apache.qpid.dispatch.connection"; + + +static void qd_get_next_pn_data(pn_data_t **data, const char **d, int *d1) +{ + if (pn_data_next(*data)) { + switch (pn_data_type(*data)) { + case PN_STRING: + *d = pn_data_get_string(*data).start; + break; + case PN_SYMBOL: + *d = pn_data_get_symbol(*data).start; + break; + case PN_INT: + *d1 = pn_data_get_int(*data); + break; + default: + break; + } + } + } + + +static void qdr_connection_insert_column_CT(qdr_connection_t *conn, int col, qd_composed_field_t *body, bool as_map) +{ + char id_str[100]; + + if (as_map) + qd_compose_insert_string(body, qdr_connection_columns[col]); + + switch(col) { + case QDR_CONNECTION_IDENTITY: { + snprintf(id_str, 100, "%"PRId64, conn->identity); + qd_compose_insert_string(body, id_str); + break; + } + + case QDR_CONNECTION_HOST: + qd_compose_insert_string(body, conn->connection_info->host); + break; + + case QDR_CONNECTION_ROLE: + qd_compose_insert_string(body, conn->connection_info->role); + break; + + case QDR_CONNECTION_DIR: + qd_compose_insert_string(body, conn->connection_info->dir); + break; + + case QDR_CONNECTION_CONTAINER_ID: + if (conn->connection_info->container) + qd_compose_insert_string(body, conn->connection_info->container); + else + qd_compose_insert_null(body); + break; + + case QDR_CONNECTION_SASL_MECHANISMS: + qd_compose_insert_string(body, conn->connection_info->sasl_mechanisms); + break; + + case QDR_CONNECTION_IS_AUTHENTICATED: + qd_compose_insert_bool(body, conn->connection_info->is_authenticated); + break; + + case QDR_CONNECTION_USER: + qd_compose_insert_string(body, conn->connection_info->user); + break; + + case QDR_CONNECTION_IS_ENCRYPTED: + qd_compose_insert_bool(body, conn->connection_info->is_encrypted); + break; + + case QDR_CONNECTION_SSLPROTO: + if (conn->connection_info->ssl_proto[0] != '\0') + qd_compose_insert_string(body, conn->connection_info->ssl_proto); + else + qd_compose_insert_null(body); + break; + + case QDR_CONNECTION_SSLCIPHER: + if (conn->connection_info->ssl_cipher[0] != '\0') + qd_compose_insert_string(body, conn->connection_info->ssl_cipher); + else + qd_compose_insert_null(body); + break; + case QDR_CONNECTION_SSLSSF: + qd_compose_insert_long(body, conn->connection_info->ssl_ssf); + break; + case QDR_CONNECTION_PROPERTIES: { + pn_data_t *data = conn->connection_info->connection_properties; + qd_compose_start_map(body); + if (data) { + pn_data_next(data); + size_t count = pn_data_get_map(data); + pn_data_enter(data); + + if (count > 0) { + + for (size_t i = 0; i < count/2; i++) { + const char *key = 0; + // We are assuming for now that all keys are strings + qd_get_next_pn_data(&data, &key, 0); + + const char *value_string = 0; + int value_int = 0; + // We are assuming for now that all values are either strings or integers + qd_get_next_pn_data(&data, &value_string, &value_int); + + qd_compose_insert_string(body, key); + + if (value_string) + qd_compose_insert_string(body, value_string); + else if (value_int) + qd_compose_insert_int(body, value_int); + + } + } + + pn_data_exit(data); + + } + qd_compose_end_map(body); + } + break; + } +} + + +static void qdr_agent_write_connection_CT(qdr_query_t *query, qdr_connection_t *conn) +{ + qd_composed_field_t *body = query->body; + + qd_compose_start_list(body); + int i = 0; + while (query->columns[i] >= 0) { + qdr_connection_insert_column_CT(conn, query->columns[i], body, false); + i++; + } + qd_compose_end_list(body); +} + + +static void qdr_manage_advance_connection_CT(qdr_query_t *query, qdr_connection_t *conn) +{ + query->next_offset++; + conn = DEQ_NEXT(conn); + query->more = !!conn; +} + + +void qdra_connection_get_first_CT(qdr_core_t *core, qdr_query_t *query, int offset) +{ + // + // Queries that get this far will always succeed. + // + query->status = QD_AMQP_OK; + + // + // If the offset goes beyond the set of objects, end the query now. + // + if (offset >= DEQ_SIZE(core->open_connections)) { + query->more = false; + qdr_agent_enqueue_response_CT(core, query); + return; + } + + // + // Run to the object at the offset. + // + qdr_connection_t *conn = DEQ_HEAD(core->open_connections); + for (int i = 0; i < offset && conn; i++) + conn = DEQ_NEXT(conn); + assert(conn); + + // + // Write the columns of the object into the response body. + // + qdr_agent_write_connection_CT(query, conn); + + // + // Advance to the next connection + // + query->next_offset = offset; + qdr_manage_advance_connection_CT(query, conn); + + // + // Enqueue the response. + // + qdr_agent_enqueue_response_CT(core, query); +} + +void qdra_connection_get_next_CT(qdr_core_t *core, qdr_query_t *query) +{ + qdr_connection_t *conn = 0; + + if (query->next_offset < DEQ_SIZE(core->open_connections)) { + conn = DEQ_HEAD(core->open_connections); + for (int i = 0; i < query->next_offset && conn; i++) + conn = DEQ_NEXT(conn); + } + + if (conn) { + // + // Write the columns of the connection entity into the response body. + // + qdr_agent_write_connection_CT(query, conn); + + // + // Advance to the next object + // + qdr_manage_advance_connection_CT(query, conn); + } else + query->more = false; + + // + // Enqueue the response. + // + qdr_agent_enqueue_response_CT(core, query); +} + +static void qdr_manage_write_connection_map_CT(qdr_core_t *core, + qdr_connection_t *conn, + qd_composed_field_t *body, + const char *qdr_connection_columns[]) +{ + qd_compose_start_map(body); + + for(int i = 0; i < QDR_CONNECTION_COLUMN_COUNT; i++) { + qd_compose_insert_string(body, qdr_connection_columns[i]); + qdr_connection_insert_column_CT(conn, i, body, false); + } + + qd_compose_end_map(body); +} + + +static qdr_connection_t *qdr_connection_find_by_identity_CT(qdr_core_t *core, qd_field_iterator_t *identity) +{ + if (!identity) + return 0; + + qdr_connection_t *conn = DEQ_HEAD(core->open_connections); + while (conn) { + // Convert the passed in identity to a char* + char id[100]; + snprintf(id, 100, "%"PRId64, conn->identity); + if (qd_field_iterator_equal(identity, (const unsigned char*) id)) + break; + conn = DEQ_NEXT(conn); + } + + return conn; + +} + + +void qdra_connection_get_CT(qdr_core_t *core, + qd_field_iterator_t *name, + qd_field_iterator_t *identity, + qdr_query_t *query, + const char *qdr_connection_columns[]) +{ + qdr_connection_t *conn = 0; + + if (!identity) { + query->status = QD_AMQP_BAD_REQUEST; + query->status.description = "Name not supported. Identity required"; + qd_log(core->agent_log, QD_LOG_ERROR, "Error performing READ of %s: %s", CONFIG_CONNECTION_TYPE, query->status.description); + } + else { + conn = qdr_connection_find_by_identity_CT(core, identity); + + if (conn == 0) { + // Send back a 404 + query->status = QD_AMQP_NOT_FOUND; + } + else { + // + // Write the columns of the connection entity into the response body. + // + qdr_manage_write_connection_map_CT(core, conn, query->body, qdr_connection_columns); + query->status = QD_AMQP_OK; + } + } + + // + // Enqueue the response. + // + qdr_agent_enqueue_response_CT(core, query); +} diff --git a/src/router_core/agent_connection.h b/src/router_core/agent_connection.h new file mode 100644 index 0000000000..74cac963ac --- /dev/null +++ b/src/router_core/agent_connection.h @@ -0,0 +1,36 @@ +#ifndef qdr_agent_connection +#define qdr_agent_connection 1 +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "router_core_private.h" + +void qdra_connection_get_first_CT(qdr_core_t *core, qdr_query_t *query, int offset); +void qdra_connection_get_next_CT(qdr_core_t *core, qdr_query_t *query); +void qdra_connection_get_CT(qdr_core_t *core, + qd_field_iterator_t *name, + qd_field_iterator_t *identity, + qdr_query_t *query, + const char *qdr_connection_columns[]); + + +#define QDR_CONNECTION_COLUMN_COUNT 13 +const char *qdr_connection_columns[QDR_CONNECTION_COLUMN_COUNT + 1]; + +#endif diff --git a/src/router_core/connections.c b/src/router_core/connections.c index 4dabeebf38..d5f2bf9eaa 100644 --- a/src/router_core/connections.c +++ b/src/router_core/connections.c @@ -17,10 +17,11 @@ * under the License. */ -#include "router_core_private.h" +#include #include "route_control.h" #include #include +#include "router_core_private.h" static void qdr_connection_opened_CT(qdr_core_t *core, qdr_action_t *action, bool discard); static void qdr_connection_closed_CT(qdr_core_t *core, qdr_action_t *action, bool discard); @@ -31,6 +32,11 @@ static void qdr_link_inbound_detach_CT(qdr_core_t *core, qdr_action_t *action, b ALLOC_DEFINE(qdr_connection_t); ALLOC_DEFINE(qdr_connection_work_t); +const char * const QDR_CONNECTION_ROLE_NORMAL = "normal"; +const char * const QDR_CONNECTION_ROLE_INTER_ROUTER = "inter-router"; +const char * const QDR_CONNECTION_ROLE_ROUTE_CONTAINER = "route-container"; +const char * const QDR_CONNECTION_ROLE_ON_DEMAND = "on-demand"; + //================================================================================== // Internal Functions //================================================================================== @@ -64,12 +70,15 @@ qdr_connection_t *qdr_connection_opened(qdr_core_t *core, const char *remote_container_id, bool strip_annotations_in, bool strip_annotations_out, - int link_capacity) + int link_capacity, + qdr_connection_info_t *connection_info) { qdr_action_t *action = qdr_action(qdr_connection_opened_CT, "connection_opened"); qdr_connection_t *conn = new_qdr_connection_t(); ZERO(conn); + conn->identity = qdr_identifier(core); + conn->connection_info = connection_info; conn->core = core; conn->user_context = 0; conn->incoming = incoming; @@ -83,6 +92,20 @@ qdr_connection_t *qdr_connection_opened(qdr_core_t *core, DEQ_INIT(conn->links); DEQ_INIT(conn->work_list); conn->work_lock = sys_mutex(); + switch (conn->role) { + case QDR_ROLE_NORMAL: + conn->connection_info->role = QDR_CONNECTION_ROLE_NORMAL; + break; + case QDR_ROLE_INTER_ROUTER: + conn->connection_info->role = QDR_CONNECTION_ROLE_INTER_ROUTER; + break; + case QDR_ROLE_ROUTE_CONTAINER: + conn->connection_info->role = QDR_CONNECTION_ROLE_ROUTE_CONTAINER; + break; + case QDR_ROLE_ON_DEMAND: + conn->connection_info->role = QDR_CONNECTION_ROLE_ON_DEMAND; + break; + } action->args.connection.conn = conn; action->args.connection.connection_label = qdr_field(label); @@ -107,6 +130,61 @@ void qdr_connection_set_context(qdr_connection_t *conn, void *context) conn->user_context = context; } +qdr_connection_info_t *qdr_connection_info(bool is_encrypted, + bool is_authenticated, + bool opened, + char *sasl_mechanisms, + const char *dir, + char *host, + char *ssl_proto, + char *ssl_cipher, + char *user, + const char *container, + pn_data_t *connection_properties, + int ssl_ssf) +{ + qdr_connection_info_t *connection_info = new_qdr_connection_info_t(); + connection_info->is_encrypted = is_encrypted; + connection_info->is_authenticated = is_authenticated; + connection_info->opened = opened; + connection_info->container = container; + + if (sasl_mechanisms) + connection_info->sasl_mechanisms = strdup(sasl_mechanisms); + else + connection_info->sasl_mechanisms = 0; + + connection_info->dir = dir; + + if (host) + connection_info->host = strdup(host); + else + connection_info->host = 0; + + if (ssl_proto) + connection_info->ssl_proto = strdup(ssl_proto); + else + connection_info->ssl_proto = 0; + + if (ssl_cipher) + connection_info->ssl_cipher = strdup(ssl_cipher); + else + connection_info->ssl_cipher = 0; + + if (user) + connection_info->user = strdup(user); + else + connection_info->user = 0; + + pn_data_t *qdr_conn_properties = pn_data(0); + pn_data_copy(qdr_conn_properties, connection_properties); + + connection_info->connection_properties = qdr_conn_properties; + connection_info->ssl_ssf = ssl_ssf; + + return connection_info; +} + void *qdr_connection_get_context(const qdr_connection_t *conn) { @@ -946,6 +1024,21 @@ static void qdr_connection_opened_CT(qdr_core_t *core, qdr_action_t *action, boo qdr_field_free(action->args.connection.container_id); } +static void qdr_connection_free(qdr_connection_t *conn) +{ + if (conn->connection_info) { + free(conn->connection_info->sasl_mechanisms); + free(conn->connection_info->host); + free(conn->connection_info->ssl_proto); + free(conn->connection_info->ssl_cipher); + free(conn->connection_info->user); + pn_data_free(conn->connection_info->connection_properties); + } + + free_qdr_connection_info_t(conn->connection_info); + free_qdr_connection_t(conn); +} + static void qdr_connection_closed_CT(qdr_core_t *core, qdr_action_t *action, bool discard) { @@ -1005,7 +1098,9 @@ static void qdr_connection_closed_CT(qdr_core_t *core, qdr_action_t *action, boo DEQ_REMOVE(core->open_connections, conn); sys_mutex_free(conn->work_lock); - free_qdr_connection_t(conn); + + qdr_connection_free(conn); + } diff --git a/src/router_core/management_agent.c b/src/router_core/management_agent.c index 030499afff..0b8decb6bd 100644 --- a/src/router_core/management_agent.c +++ b/src/router_core/management_agent.c @@ -46,6 +46,7 @@ const unsigned char *auto_link_entity_type = (unsigned char*) "org.apache.q const unsigned char *address_entity_type = (unsigned char*) "org.apache.qpid.dispatch.router.address"; const unsigned char *link_entity_type = (unsigned char*) "org.apache.qpid.dispatch.router.link"; const unsigned char *console_entity_type = (unsigned char*) "org.apache.qpid.dispatch.console"; +const unsigned char *connection_entity_type = (unsigned char*) "org.apache.qpid.dispatch.connection"; const char * const status_description = "statusDescription"; const char * const correlation_id = "correlation-id"; @@ -120,13 +121,10 @@ static void qd_set_response_status(const qd_amqp_error_t *error, qd_composed_fie // *field = qd_compose(QD_PERFORMATIVE_APPLICATION_PROPERTIES, *field); qd_compose_start_map(*field); - qd_compose_insert_string(*field, status_description); qd_compose_insert_string(*field, error->description); - qd_compose_insert_string(*field, status_code); qd_compose_insert_uint(*field, error->status); - qd_compose_end_map(*field); } @@ -196,6 +194,7 @@ static void qd_manage_response_handler(void *context, const qd_amqp_error_t *sta // Finally, compose and send the message. qd_message_compose_3(ctx->msg, fld, ctx->field); + qdr_send_to1(ctx->core, ctx->msg, reply_to, true, false); // We have come to the very end. Free the appropriate memory. @@ -404,6 +403,8 @@ static bool qd_can_handle_request(qd_parsed_field_t *properties_fld, *entity_type = QD_ROUTER_CONFIG_LINK_ROUTE; else if (qd_field_iterator_equal(qd_parse_raw(parsed_field), auto_link_entity_type)) *entity_type = QD_ROUTER_CONFIG_AUTO_LINK; + else if (qd_field_iterator_equal(qd_parse_raw(parsed_field), connection_entity_type)) + *entity_type = QD_ROUTER_CONNECTION; else if (qd_field_iterator_equal(qd_parse_raw(parsed_field), console_entity_type)) *entity_type = QD_ROUTER_FORBIDDEN; else diff --git a/src/router_core/router_core.c b/src/router_core/router_core.c index 07b7035400..0ebca4cf2a 100644 --- a/src/router_core/router_core.c +++ b/src/router_core/router_core.c @@ -30,6 +30,10 @@ ALLOC_DEFINE(qdr_router_ref_t); ALLOC_DEFINE(qdr_link_ref_t); ALLOC_DEFINE(qdr_general_work_t); ALLOC_DEFINE(qdr_connection_ref_t); +ALLOC_DEFINE(qdr_connection_info_t); + +const char * const QDR_CONNECTION_DIR_IN = "in"; +const char * const QDR_CONNECTION_DIR_OUT = "out"; static void qdr_general_handler(void *context); diff --git a/src/router_core/router_core_private.h b/src/router_core/router_core_private.h index f8e702fefe..a30de7f615 100644 --- a/src/router_core/router_core_private.h +++ b/src/router_core/router_core_private.h @@ -433,10 +433,28 @@ typedef struct qdr_connection_work_t { ALLOC_DECLARE(qdr_connection_work_t); DEQ_DECLARE(qdr_connection_work_t, qdr_connection_work_list_t); +struct qdr_connection_info_t { + const char *container; + char *sasl_mechanisms; + char *host; + bool is_encrypted; + char *ssl_proto; + char *ssl_cipher; + char *user; + bool is_authenticated; + bool opened; + const char *dir; + const char *role; + pn_data_t *connection_properties; + int ssl_ssf; //ssl strength factor +}; + +ALLOC_DECLARE(qdr_connection_info_t); struct qdr_connection_t { DEQ_LINKS(qdr_connection_t); DEQ_LINKS_N(ACTIVATE, qdr_connection_t); + uint64_t identity; qdr_core_t *core; void *user_context; bool incoming; @@ -454,6 +472,7 @@ struct qdr_connection_t { qdr_link_ref_list_t links; qdr_link_ref_list_t links_with_deliveries; qdr_link_ref_list_t links_with_credit; + qdr_connection_info_t *connection_info; }; ALLOC_DECLARE(qdr_connection_t); diff --git a/src/router_node.c b/src/router_node.c index 09449891c9..5a5010771d 100644 --- a/src/router_node.c +++ b/src/router_node.c @@ -26,6 +26,7 @@ #include "dispatch_private.h" #include "entity_cache.h" #include "router_private.h" +#include const char *QD_ROUTER_NODE_TYPE = "router.node"; const char *QD_ROUTER_ADDRESS_TYPE = "router.address"; @@ -560,14 +561,52 @@ static void AMQP_opened_handler(qd_router_t *router, qd_connection_t *conn, bool uint64_t connection_id = qd_connection_connection_id(conn); pn_connection_t *pn_conn = qd_connection_pn(conn); + + + pn_transport_t *tport = 0; + pn_sasl_t *sasl = 0; + pn_ssl_t *ssl = 0; + const char *mech = 0; + const char *user = 0; + const char *container = conn->pn_conn ? pn_connection_remote_container(conn->pn_conn) : 0; + if (conn->pn_conn) { + tport = pn_connection_transport(conn->pn_conn); + ssl = conn->ssl; + } + if (tport) { + sasl = pn_sasl(tport); + if(conn->user_id) + user = conn->user_id; + else + user = pn_transport_get_user(tport); + } + + if (sasl) + mech = pn_sasl_get_mech(sasl); + + char *host = 0; + + const qd_server_config_t *config; + if (conn->connector) { + char host_local[255]; + config = conn->connector->config; + snprintf(host_local, strlen(config->host)+strlen(config->port)+2, "%s:%s", config->host, config->port); + host = &host_local[0]; + } + else + host = (char *)qdpn_connector_name(conn->pn_cxtr); + + qd_router_connection_get_config(conn, &role, &cost, &name, &strip_annotations_in, &strip_annotations_out, &link_capacity); + pn_data_t *props = pn_conn ? pn_connection_remote_properties(pn_conn) : 0; + if (role == QDR_ROLE_INTER_ROUTER) { // // Check the remote properties for an inter-router cost value. // - pn_data_t *props = pn_conn ? pn_connection_remote_properties(pn_conn) : 0; + if (props) { pn_data_rewind(props); pn_data_next(props); @@ -595,9 +634,39 @@ static void AMQP_opened_handler(qd_router_t *router, qd_connection_t *conn, bool cost = remote_cost; } + char proto[50]; + memset(proto, 0, 50); + char cipher[50]; + memset(cipher, 0, 50); + + int ssl_ssf = 0; + + if (ssl) { + pn_ssl_get_protocol_name(ssl, proto, 50); + pn_ssl_get_cipher_name(ssl, cipher, 50); + ssl_ssf = pn_ssl_get_ssf(ssl); + } + + + qdr_connection_info_t *connection_info = qdr_connection_info(tport && pn_transport_is_encrypted(tport), + tport && pn_transport_is_authenticated(tport), + conn->opened, + (char *)mech, + conn->connector ? QDR_CONNECTION_DIR_OUT : QDR_CONNECTION_DIR_IN, + host, + proto, + cipher, + (char *)user, + container, + props, + ssl_ssf); + qdr_connection_t *qdrc = qdr_connection_opened(router->router_core, inbound, role, cost, connection_id, name, pn_connection_remote_container(pn_conn), - strip_annotations_in, strip_annotations_out, link_capacity); + strip_annotations_in, + strip_annotations_out, + link_capacity, + connection_info); qd_connection_set_context(conn, qdrc); qdr_connection_set_context(qdrc, conn); diff --git a/src/server.c b/src/server.c index 86ebc88631..db2213a02b 100644 --- a/src/server.c +++ b/src/server.c @@ -121,19 +121,6 @@ static void qd_transport_tracer(pn_transport_t *transport, const char *message) qd_log(ctx->server->log_source, QD_LOG_TRACE, "[%"PRIu64"]:%s", ctx->connection_id, message); } -static qd_error_t connection_entity_update_host(qd_entity_t* entity, qd_connection_t *conn) -{ - const qd_server_config_t *config; - if (conn->connector) { - config = conn->connector->config; - char host[strlen(config->host)+strlen(config->port)+2]; - snprintf(host, sizeof(host), "%s:%s", config->host, config->port); - return qd_entity_set_string(entity, "host", host); - } - else - return qd_entity_set_string(entity, "host", qdpn_connector_name(conn->pn_cxtr)); -} - /** * Save displayNameService object instance and ImportModule address @@ -389,131 +376,12 @@ void qd_connection_set_user(qd_connection_t *conn) } -static void qd_get_next_pn_data(pn_data_t *data, const char **d, int *d1) -{ - if (pn_data_next(data)) { - switch (pn_data_type(data)) { - case PN_STRING: - *d = pn_data_get_string(data).start; - break; - case PN_SYMBOL: - *d = pn_data_get_symbol(data).start; - break; - case PN_INT: - *d1 = pn_data_get_int(data); - break; - default: - break; - } - } -} - - -/** - * Obtains the remote connection properties and sets it as a map on the passed in entity. - * @param - */ -static qd_error_t qd_set_connection_properties(qd_entity_t* entity, qd_connection_t *conn) -{ - // Get the connection properties and stick it into the entity as a map - pn_data_t *data = pn_connection_remote_properties(conn->pn_conn); - const char *props = "properties"; - if (data) { - size_t count = pn_data_get_map(data); - pn_data_enter(data); - - // Create a new map. - qd_error_t error_t = qd_entity_set_map(entity, props); - - if (error_t != QD_ERROR_NONE) - return error_t; - - for (size_t i = 0; i < count/2; i++) { - const char *key = 0; - // We are assuming for now that all keys are strings - qd_get_next_pn_data(data, &key, 0); - const char *value_string = 0; - int value_int = 0; - // We are assuming for now that all values are either strings or integers - qd_get_next_pn_data(data, &value_string, &value_int); - - if (value_string) - error_t = qd_entity_set_map_key_value_string(entity, props, key, value_string); - else if (value_int) - error_t = qd_entity_set_map_key_value_int(entity, props, key, value_int); - - if (error_t != QD_ERROR_NONE) - return error_t; - } - pn_data_exit(data); - } - - return QD_ERROR_NONE; -} - - qd_error_t qd_entity_refresh_sslProfile(qd_entity_t* entity, void *impl) { return QD_ERROR_NONE; } -qd_error_t qd_entity_refresh_connection(qd_entity_t* entity, void *impl) -{ - qd_connection_t *conn = (qd_connection_t*)impl; - pn_transport_t *tport = 0; - pn_sasl_t *sasl = 0; - pn_ssl_t *ssl = 0; - const char *mech = 0; - const char *user = 0; - - if (conn->pn_conn) { - tport = pn_connection_transport(conn->pn_conn); - ssl = conn->ssl; - } - if (tport) { - sasl = pn_sasl(tport); - if(conn->user_id) - user = conn->user_id; - else - user = pn_transport_get_user(tport); - } - if (sasl) - mech = pn_sasl_get_mech(sasl); - - if (qd_entity_set_bool(entity, "opened", conn->opened) == 0 && - qd_entity_set_string(entity, "container", - conn->pn_conn ? pn_connection_remote_container(conn->pn_conn) : 0) == 0 && - connection_entity_update_host(entity, conn) == 0 && - qd_entity_set_string(entity, "sasl", mech) == 0 && - qd_entity_set_string(entity, "role", conn->role) == 0 && - qd_entity_set_string(entity, "dir", conn->connector ? "out" : "in") == 0 && - qd_entity_set_string(entity, "user", user) == 0 && - qd_set_connection_properties(entity, conn) == 0 && - qd_entity_set_long(entity, "identity", conn->connection_id) == 0 && - qd_entity_set_bool(entity, "isAuthenticated", tport && pn_transport_is_authenticated(tport)) == 0 && - qd_entity_set_bool(entity, "isEncrypted", tport && pn_transport_is_encrypted(tport)) == 0 && - qd_entity_set_bool(entity, "ssl", ssl != 0) == 0) { - - if (ssl) { - #define SSL_ATTR_SIZE 50 - char proto[SSL_ATTR_SIZE]; - char cipher[SSL_ATTR_SIZE]; - pn_ssl_get_protocol_name(ssl, proto, SSL_ATTR_SIZE); - pn_ssl_get_cipher_name(ssl, cipher, SSL_ATTR_SIZE); - if (qd_entity_set_string(entity, "sslProto", proto) == 0 && - qd_entity_set_string(entity, "sslCipher", cipher) == 0 && - qd_entity_set_long(entity, "sslSsf", pn_ssl_get_ssf(ssl)) == 0) { - return QD_ERROR_NONE; - } - } - else - return QD_ERROR_NONE; - } - - return qd_error_code(); -} - static qd_error_t listener_setup_ssl(qd_connection_t *ctx, const qd_server_config_t *config, pn_transport_t *tport) { pn_ssl_domain_t *domain = pn_ssl_domain(PN_SSL_MODE_SERVER); @@ -661,7 +529,6 @@ static void thread_process_listeners_LH(qd_server_t *qd_server) // qd_server->lock is already locked DEQ_INSERT_TAIL(qd_server->connections, ctx); - qd_entity_cache_add(QD_CONNECTION_TYPE, ctx); // // Get a pointer to the transport so we can insert security components into it @@ -1199,7 +1066,6 @@ static void cxtr_try_open(void *context) ctx->pn_cxtr = qdpn_connector(ct->server->driver, ct->config->host, ct->config->port, ct->config->protocol_family, (void*) ctx); if (ctx->pn_cxtr) { DEQ_INSERT_TAIL(ct->server->connections, ctx); - qd_entity_cache_add(QD_CONNECTION_TYPE, ctx); } sys_mutex_unlock(ct->server->lock); diff --git a/tests/system_test.py b/tests/system_test.py index 194239dd8c..8519a0b988 100755 --- a/tests/system_test.py +++ b/tests/system_test.py @@ -341,7 +341,6 @@ def __init__(self, name=None, config=Config(), pyinclude=None, wait=True): if wait: self.wait_ready() - @property def management(self): """Return a management agent proxy for this router""" @@ -414,11 +413,10 @@ def is_connected(self, port, host='127.0.0.1'): try: ret_val = False response = self.management.query(type="org.apache.qpid.dispatch.connection") - index_name = response.attribute_names.index('name') - index_identity = response.attribute_names.index('identity') + index_host = response.attribute_names.index('host') for result in response.results: - outs = 'connection/%s:%s:%s' % (host, port, str(result[index_identity])) - if result[index_name] == outs: + outs = '%s:%s' % (host, port) + if result[index_host] == outs: ret_val = True return ret_val except: diff --git a/tests/system_tests_deprecated.py b/tests/system_tests_deprecated.py index f66e14a2a6..da7c19af1a 100644 --- a/tests/system_tests_deprecated.py +++ b/tests/system_tests_deprecated.py @@ -100,13 +100,13 @@ def test_deprecated(self): # ContainerEntity has been deprecated. # role should be inter-router - self.assertEqual(u'inter-router', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][9]) + self.assertEqual(u'inter-router', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][2]) # sasl must be plain - self.assertEqual(u'PLAIN', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][12]) + self.assertEqual(u'PLAIN', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][5]) # user must be test@domain.com - self.assertEqual(u'test@domain.com', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][16]) + self.assertEqual(u'test@domain.com', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][7]) # Make sure that the deprecated linkRoutePattern is set up correctly query_response = local_node.query(type='org.apache.qpid.dispatch.router.config.linkRoute') diff --git a/tests/system_tests_management.py b/tests/system_tests_management.py index 129e70f046..19f69fcaed 100644 --- a/tests/system_tests_management.py +++ b/tests/system_tests_management.py @@ -325,7 +325,7 @@ def test_link(self): def test_connection(self): """Verify there is at least one connection""" - response = self.node.query(type='connection') + response = self.node.query(type='org.apache.qpid.dispatch.connection') self.assertTrue(response.results) def test_router(self): diff --git a/tests/system_tests_one_router.py b/tests/system_tests_one_router.py index d993549b30..7821a55d1f 100644 --- a/tests/system_tests_one_router.py +++ b/tests/system_tests_one_router.py @@ -1123,10 +1123,10 @@ def test_connection_properties(self): node = Node.connect(self.router.addresses[0]) - results = [[{u'connection': u'properties', u'int_property': 6451}], [{}]] + results = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=[u'properties']).results - self.assertEqual(node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['properties']).results, - results) + self.assertEqual(results[0][0][u'connection'], u'properties') + self.assertEqual(results[0][0][u'int_property'], 6451) client.connection.close() diff --git a/tests/system_tests_qdmanage.py b/tests/system_tests_qdmanage.py index 346bd725f6..2d55b3efbb 100644 --- a/tests/system_tests_qdmanage.py +++ b/tests/system_tests_qdmanage.py @@ -252,14 +252,15 @@ def test_create_delete_connector(self): # Re-create the connector and then try wait_connectors self.create(long_type, name, str(QdmanageTest.inter_router_port)) - results = json.loads(self.run_qdmanage('QUERY --type=org.apache.qpid.dispatch.connection')) - + outputs = json.loads(self.run_qdmanage(query_command)) created = False - for result in results: - name = result['name'] - conn_name = 'connection/0.0.0.0:%s:' % QdmanageTest.inter_router_port - if conn_name in name: + for output in outputs: + conn_name = 'connector/127.0.0.1:%s' % QdmanageTest.inter_router_port + conn_name_1 = 'connector/0.0.0.0:%s' % QdmanageTest.inter_router_port + if conn_name == output['name'] or conn_name_1 == output['name']: created = True + break + self.assertTrue(created) def test_zzz_add_connector(self): @@ -392,14 +393,15 @@ def test_create_delete_connector(self): # Re-create the connector and then try wait_connectors self.create(long_type, name, str(QdmanageTestSsl.inter_router_port)) - results = json.loads(self.run_qdmanage('QUERY --type=org.apache.qpid.dispatch.connection')) + outputs = json.loads(self.run_qdmanage(query_command)) created = False - for result in results: - name = result['name'] - conn_name = 'connection/0.0.0.0:%s:' % QdmanageTestSsl.inter_router_port - if conn_name in name: + for output in outputs: + conn_name = 'connector/127.0.0.1:%s' % QdmanageTestSsl.inter_router_port + conn_name_1 = 'connector/0.0.0.0:%s' % QdmanageTestSsl.inter_router_port + if conn_name == output['name'] or conn_name_1 == output['name']: created = True + break self.assertTrue(created) def test_create_delete_ssl_profile(self): diff --git a/tests/system_tests_sasl_plain.py b/tests/system_tests_sasl_plain.py index 1894f51017..cc138a1d47 100644 --- a/tests/system_tests_sasl_plain.py +++ b/tests/system_tests_sasl_plain.py @@ -284,16 +284,16 @@ def test_inter_router_plain_over_ssl_exists(self): local_node = Node.connect(self.routers[0].addresses[1], timeout=TIMEOUT) # sslProto should be TLSv1/SSLv3 - self.assertEqual(u'TLSv1/SSLv3', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][4]) + self.assertEqual(u'TLSv1/SSLv3', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][9]) # role should be inter-router - self.assertEqual(u'inter-router', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][9]) + self.assertEqual(u'inter-router', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][2]) # sasl must be plain - self.assertEqual(u'PLAIN', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][12]) + self.assertEqual(u'PLAIN', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][5]) # user must be test@domain.com - self.assertEqual(u'test@domain.com', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][16]) + self.assertEqual(u'test@domain.com', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][7]) class RouterTestVerifyHostNameYes(RouterTestPlainSaslCommon): @@ -374,12 +374,11 @@ def test_no_inter_router_connection(self): # There should be only two connections. # There will be no inter-router connection self.assertEqual(2, len(local_node.query(type='org.apache.qpid.dispatch.connection').results)) - self.assertEqual('in', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][15]) - self.assertEqual('normal', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][9]) - self.assertEqual('anonymous', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][16]) - - self.assertEqual('normal', local_node.query(type='org.apache.qpid.dispatch.connection').results[1][9]) - self.assertEqual('anonymous', local_node.query(type='org.apache.qpid.dispatch.connection').results[1][16]) + self.assertEqual('in', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][3]) + self.assertEqual('normal', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][2]) + self.assertEqual('anonymous', local_node.query(type='org.apache.qpid.dispatch.connection').results[0][7]) + self.assertEqual('normal', local_node.query(type='org.apache.qpid.dispatch.connection').results[1][2]) + self.assertEqual('anonymous', local_node.query(type='org.apache.qpid.dispatch.connection').results[1][7]) class RouterTestVerifyHostNameNo(RouterTestPlainSaslCommon): @@ -472,23 +471,23 @@ def common_asserts(self, results): found = False for N in range(0, len(results)): - if results[N][0] == search: + if results[N][4] == search: found = True break self.assertTrue(found, "Connection to %s not found" % search) # sslProto should be TLSv1/SSLv3 - self.assertEqual(u'TLSv1/SSLv3', results[N][4]) + self.assertEqual(u'TLSv1/SSLv3', results[N][9]) # role should be inter-router - self.assertEqual(u'inter-router', results[N][9]) + self.assertEqual(u'inter-router', results[N][2]) # sasl must be plain - self.assertEqual(u'PLAIN', results[N][12]) + self.assertEqual(u'PLAIN', results[N][5]) # user must be test@domain.com - self.assertEqual(u'test@domain.com', results[N][16]) + self.assertEqual(u'test@domain.com', results[N][7]) def test_inter_router_plain_over_ssl_exists(self): """ diff --git a/tests/system_tests_user_id.py b/tests/system_tests_user_id.py index a62e148779..e183de2403 100644 --- a/tests/system_tests_user_id.py +++ b/tests/system_tests_user_id.py @@ -240,73 +240,73 @@ def test_ssl_user_id(self): addr = self.address(0).replace("amqp", "amqps") node = Node.connect(addr, ssl_domain=domain) - user_id = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[0][0] + user_id = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=[u'user']).results[0][0] self.assertEqual("60f5dbd7ed14a5ea243785e81745ac8463494298", user_id) addr = self.address(1).replace("amqp", "amqps") node = Node.connect(addr, ssl_domain=domain) self.assertEqual("7c87f0c974f9e1aa5cb98f13fae9675625f240c98034b888753140da28094879", - node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[1][0]) + node.query(type='org.apache.qpid.dispatch.connection', attribute_names=[u'user']).results[1][0]) addr = self.address(2).replace("amqp", "amqps") node = Node.connect(addr, ssl_domain=domain) self.assertEqual("82244216b6d02ffdfb886c8da3c803e0f7a7b330a7b665dccabd30bd25d0f35e2a4fff5f0a2a01d56eb7dbae085c108e71a32b84bab16c9ec243a1f6d014900d", - node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[2][0]) + node.query(type='org.apache.qpid.dispatch.connection', attribute_names=[u'user']).results[2][0]) addr = self.address(3).replace("amqp", "amqps") node = Node.connect(addr, ssl_domain=domain) self.assertEqual("7c87f0c974f9e1aa5cb98f13fae9675625f240c98034b888753140da28094879;127.0.0.1;Client;Dev;US;NC", - node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[3][0]) + node.query(type='org.apache.qpid.dispatch.connection', attribute_names=[u'user']).results[3][0]) addr = self.address(4).replace("amqp", "amqps") node = Node.connect(addr, ssl_domain=domain) self.assertEqual("60f5dbd7ed14a5ea243785e81745ac8463494298;US;NC", - node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[4][0]) + node.query(type='org.apache.qpid.dispatch.connection', attribute_names=[u'user']).results[4][0]) addr = self.address(5).replace("amqp", "amqps") node = Node.connect(addr, ssl_domain=domain) self.assertEqual("US;NC;82244216b6d02ffdfb886c8da3c803e0f7a7b330a7b665dccabd30bd25d0f35e2a4fff5f0a2a01d56eb7dbae085c108e71a32b84bab16c9ec243a1f6d014900d", - node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[5][0]) + node.query(type='org.apache.qpid.dispatch.connection', attribute_names=[u'user']).results[5][0]) addr = self.address(6).replace("amqp", "amqps") node = Node.connect(addr, ssl_domain=domain) self.assertEqual("127.0.0.1;NC;Dev;US;Client", - node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[6][0]) + node.query(type='org.apache.qpid.dispatch.connection', attribute_names=[u'user']).results[6][0]) addr = self.address(7).replace("amqp", "amqps") node = Node.connect(addr, ssl_domain=domain) self.assertEqual("NC;US;Client;Dev;127.0.0.1;Raleigh", - node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[7][0]) + node.query(type='org.apache.qpid.dispatch.connection', attribute_names=[u'user']).results[7][0]) addr = self.address(8).replace("amqp", "amqps") node = Node.connect(addr, ssl_domain=domain) self.assertEqual("C=US,ST=NC,L=Raleigh,OU=Dev,O=Client,CN=127.0.0.1", - node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[8][0]) + node.query(type='org.apache.qpid.dispatch.connection', attribute_names=[u'user']).results[8][0]) addr = self.address(9).replace("amqp", "amqps") node = Node.connect(addr, ssl_domain=domain) self.assertEqual("C=US,ST=NC,L=Raleigh,OU=Dev,O=Client,CN=127.0.0.1", - node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[9][0]) + node.query(type='org.apache.qpid.dispatch.connection', attribute_names=[u'user']).results[9][0]) addr = self.address(10).replace("amqp", "amqps") node = Node.connect(addr, ssl_domain=domain) - user = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[10][0] + user = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=[u'user']).results[10][0] self.assertEqual("C=US,ST=NC,L=Raleigh,OU=Dev,O=Client,CN=127.0.0.1", str(user)) addr = self.address(11).replace("amqp", "amqps") node = Node.connect(addr) - user = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[11][0] + user = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=[u'user']).results[11][0] self.assertEqual("anonymous", user) addr = self.address(12).replace("amqp", "amqps") node = Node.connect(addr, ssl_domain=domain) - user = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[12][0] + user = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=[u'user']).results[12][0] self.assertEqual("user12", str(user)) addr = self.address(13).replace("amqp", "amqps") node = Node.connect(addr, ssl_domain=domain) - user_id = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=['user']).results[13][0] + user_id = node.query(type='org.apache.qpid.dispatch.connection', attribute_names=[u'user']).results[13][0] self.assertEqual("user13", user_id) node.close()