From ffaf5587a308f9564cc7212ef1997158c447320e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Mon, 16 Jul 2012 15:05:22 +0200 Subject: [PATCH] test: Check for end point path --- test/simline/server.c | 34 ++++++++++++++++++++++++++-------- test/simline/service.c | 9 +++++---- test/simline/service.h | 3 ++- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/test/simline/server.c b/test/simline/server.c index 15a5dfa..d5ef04b 100644 --- a/test/simline/server.c +++ b/test/simline/server.c @@ -29,6 +29,9 @@ static const char *as_path_dontsendsms = "/as/processLogin?type=totp&uri="; static const char *as_path_logout = "/as/processLogout?uri="; static const char *ws_path = "/apps/DS/dz"; +static const char *ws_base_path_basic = "/"; +static const char *ws_base_path_otp = "/apps/"; + static const char *authorization_cookie_name = "IPCZ-X-COOKIE"; static char *authorization_cookie_value = NULL; @@ -111,14 +114,27 @@ char *socket2address(int socket) { /* Process ISDS WS ping */ -static void do_ws(int client_socket, const struct http_request *request) { +static void do_ws(int client_socket, const struct http_request *request, + const char *required_base_path) { + char *end_point = request->uri; /* Pointer to string in request */ + if (request->method != HTTP_METHOD_POST) { http_send_response_400(client_socket, "Regular ISDS web service request must be POST"); return; } - soap(client_socket, request->body, request->body_length); + if (required_base_path != NULL) { + size_t required_base_path_length = strlen(required_base_path); + if (strncmp(end_point, required_base_path, required_base_path_length)) { + http_send_response_400(client_socket, + "Request sent to invalid path"); + return; + } + end_point += required_base_path_length; + } + + soap(client_socket, request->body, request->body_length, end_point); } @@ -160,7 +176,7 @@ void server_basic_authentication(int server_socket, switch(http_authenticate_basic(request, arguments->username, arguments->password)) { case HTTP_ERROR_SUCCESS: - do_ws(client_socket, request); + do_ws(client_socket, request, ws_base_path_basic); break; case HTTP_ERROR_CLIENT: if (arguments->isds_deviations) @@ -177,7 +193,7 @@ void server_basic_authentication(int server_socket, http_send_response_401_basic(client_socket); } } else { - do_ws(client_socket, request); + do_ws(client_socket, request, ws_base_path_basic); } } else { /* HTTP method unsupported per ISDS specification */ @@ -400,13 +416,14 @@ static void do_as_logout(int client_socket, const struct http_request *request, /* Process ISDS WS ping authorized by cookie */ static void do_ws_with_cookie(int client_socket, const struct http_request *request, - const struct arguments_otp_authentication *arguments) { + const struct arguments_otp_authentication *arguments, + const char *valid_base_path) { const char *received_cookie = http_find_cookie(request, authorization_cookie_name); if (authorization_cookie_value != NULL && received_cookie != NULL && !strcmp(authorization_cookie_value, received_cookie)) - do_ws(client_socket, request); + do_ws(client_socket, request, valid_base_path); else http_send_response_403(client_socket); } @@ -459,14 +476,15 @@ void server_otp_authentication(int server_socket, strlen(as_path_logout))) { do_as_logout(client_socket, request, arguments); } else if (!strcmp(request->uri, ws_path)) { - do_ws_with_cookie(client_socket, request, arguments); + do_ws_with_cookie(client_socket, request, arguments, + ws_base_path_otp); } else { http_send_response_400(client_socket, "Unknown path for TOTP authenticating service"); } } else { if (!strcmp(request->uri, ws_path)) { - do_ws(client_socket, request); + do_ws(client_socket, request, ws_base_path_otp); } else { http_send_response_400(client_socket, "Unknown path for TOTP authenticating service"); diff --git a/test/simline/service.c b/test/simline/service.c index 51b9b15..90ec5fa 100644 --- a/test/simline/service.c +++ b/test/simline/service.c @@ -44,7 +44,7 @@ static void service_DummyOperation(int socket, const xmlDocPtr soap_request, /* List of implemented services */ static struct service services[] = { - { "dz", BAD_CAST "DummyOperation", service_DummyOperation }, + { "DS/dz", BAD_CAST "DummyOperation", service_DummyOperation }, }; @@ -90,7 +90,8 @@ static int register_namespaces(xmlXPathContextPtr xpath_ctx, /* Parse soap request, pass it to service endpoint and respond to it. * It sends final HTTP response. */ -void soap(int socket, const void *request, size_t request_length) { +void soap(int socket, const void *request, size_t request_length, + const char *end_point) { xmlDocPtr request_doc = NULL; xmlXPathContextPtr xpath_ctx = NULL; xmlXPathObjectPtr request_soap_body = NULL; @@ -168,9 +169,9 @@ void soap(int socket, const void *request, size_t request_length) { /* Dispatch request to service */ - /* TODO: Use end point */ for (int i = 0; i < sizeof(services)/sizeof(services[0]); i++) { - if (!xmlStrcmp(services[i].name, isds_request->name)) { + if (!strcmp(services[i].end_point, end_point) && + !xmlStrcmp(services[i].name, isds_request->name)) { services[i].function(socket, request_doc, xpath_ctx, isds_request); service_handled = 1; break; diff --git a/test/simline/service.h b/test/simline/service.h index ccdae45..92a2c42 100644 --- a/test/simline/service.h +++ b/test/simline/service.h @@ -5,6 +5,7 @@ /* Parse soap request, pass it to service endpoint and respond to it. * It sends final HTTP response. */ -void soap(int socket, const void *request, size_t request_length); +void soap(int socket, const void *request, size_t request_length, + const char *end_point); #endif -- 2.11.4.GIT