• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

RegressionHttpTransact.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 #include "Regression.h"
00025 #include "HttpTransact.h"
00026 #include "HttpSM.h"
00027 
00028 void forceLinkRegressionHttpTransact()
00029 {
00030 }
00031 
00032 static void
00033 init_sm(HttpSM *sm)
00034 {
00035 
00036   sm->init();
00037   sm->t_state.hdr_info.client_request.create(HTTP_TYPE_REQUEST, NULL);
00038 
00039 }
00040 
00041 static void
00042 setup_client_request(HttpSM * sm, const char * scheme, const char * request)
00043 {
00044   init_sm(sm);
00045 
00046   MIOBuffer * read_buffer = new_MIOBuffer(HTTP_HEADER_BUFFER_SIZE_INDEX);
00047   IOBufferReader * buffer_reader = read_buffer->alloc_reader();
00048   read_buffer->write(request, strlen(request));
00049 
00050   HTTPParser httpParser;
00051   http_parser_init(&httpParser);
00052   int bytes_used = 0;
00053   sm->t_state.hdr_info.client_request.parse_req(&httpParser, buffer_reader, &bytes_used, true /* eos */);
00054   sm->t_state.hdr_info.client_request.url_get()->scheme_set(scheme, strlen(scheme));
00055   free_MIOBuffer(read_buffer);
00056 }
00057 
00058 /*
00059 pstatus return values
00060 REGRESSION_TEST_PASSED
00061 REGRESSION_TEST_INPROGRESS
00062 REGRESSION_TEST_FAILED
00063 REGRESSION_TEST_NOT_RUN
00064  */
00065 REGRESSION_TEST(HttpTransact_is_request_valid)(RegressionTest *t, int /* level */, int *pstatus)
00066 {
00067   HttpTransact transaction;
00068   HttpSM sm;
00069   *pstatus = REGRESSION_TEST_PASSED;
00070 
00071   struct
00072   {
00073     const char *scheme;
00074     const char *req;
00075     bool result;
00076   } requests[] = {
00077     // missing host header
00078     { "http", "GET / HTTP/1.1\r\n\r\n", false},
00079     // good get request
00080     { "http", "GET / HTTP/1.1\r\nHost: abc.com\r\n\r\n", true},
00081     // content len < 0
00082     { "http", "POST / HTTP/1.1\r\nHost: abc.com\r\nContent-Length: -1\r\n\r\n", false},
00083     { "http", "PUSH / HTTP/1.1\r\nHost: abc.com\r\nContent-Length: -1\r\n\r\n", false},
00084     { "http", "PUT / HTTP/1.1\r\nHost: abc.com\r\nContent-Length: -1\r\n\r\n", false},
00085     // valid content len
00086     { "http", "POST / HTTP/1.1\r\nHost: abc.com\r\nContent-Length: 10\r\n\r\n", true},
00087     { "http", "PUSH / HTTP/1.1\r\nHost: abc.com\r\nContent-Length: 10\r\n\r\n", true},
00088     { "http", "PUT / HTTP/1.1\r\nHost: abc.com\r\nContent-Length: 10\r\n\r\n", true},
00089     // Content Length missing
00090     { "http", "POST / HTTP/1.1\r\nHost: abc.com\r\n\r\n", false},
00091     { "http", "PUSH / HTTP/1.1\r\nHost: abc.com\r\n\r\n", false},
00092     { "http", "PUT / HTTP/1.1\r\nHost: abc.com\r\n\r\n", false},
00093     { NULL, NULL, false}
00094   };
00095   for (int i = 0; requests[i].req; i++) {
00096     setup_client_request(&sm, requests[i].scheme, requests[i].req);
00097 
00098     if (requests[i].result != transaction.is_request_valid(&sm.t_state, &sm.t_state.hdr_info.client_request)) {
00099       rprintf(t, "HttpTransact::is_request_valid - failed for request = '%s'.  Expected result was %s request\n", requests[i].req,(requests[i].result ? "valid" :"invalid") );
00100       *pstatus = REGRESSION_TEST_FAILED;
00101     }
00102   }
00103 }

Generated by  doxygen 1.7.1