Skip to content

Commit

Permalink
Regression test covering PR Corvusoft#207, incorrect IPv4 endpoint st…
Browse files Browse the repository at this point in the history
…ring.
  • Loading branch information
ben-crowhurst committed May 7, 2017
1 parent 0b04c22 commit 464f819
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,7 @@ add_test( allow_hyphen_in_path_parameter_name_regression_test_suite ${EXECUTABLE
add_executable( allow_underscore_in_path_parameter_name_regression_test_suite ${SOURCE_DIR}/allow_underscore_in_path_parameter_name.cpp )
target_link_libraries( allow_underscore_in_path_parameter_name_regression_test_suite ${CMAKE_PROJECT_NAME} )
add_test( allow_underscore_in_path_parameter_name_regression_test_suite ${EXECUTABLE_OUTPUT_PATH}/allow_underscore_in_path_parameter_name_regression_test_suite )

add_executable( ipv4_session_origin_destination_malformed_regression_test_suite ${SOURCE_DIR}/ipv4_session_origin_destination_malformed.cpp )
target_link_libraries( ipv4_session_origin_destination_malformed_regression_test_suite ${CMAKE_PROJECT_NAME} )
add_test( ipv4_session_origin_destination_malformed_regression_test_suite ${EXECUTABLE_OUTPUT_PATH}/ipv4_session_origin_destination_malformed_regression_test_suite )
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2013-2017, Corvusoft Ltd, All Rights Reserved.
*/

//System Includes
#include <regex>
#include <thread>
#include <memory>
#include <functional>

//Project Includes
#include <restbed>

//External Includes
#include <catch.hpp>

//System Namespaces
using std::regex;
using std::thread;
using std::function;
using std::shared_ptr;
using std::make_shared;
using std::regex_match;

//Project Namespaces
using namespace restbed;

//External Namespaces

void get_method_handler( const shared_ptr< Session > session )
{
const auto origin = session->get_origin( );
const auto destination = session->get_destination( );
const auto pattern = regex{ ".*\\:[0-9]+$" };

if ( regex_match( origin, pattern ) and regex_match( destination, pattern ) )
{
session->close( 200 );
}
else
{
session->close( 400 );
}
}

TEST_CASE( "malformed origin/destination string", "[session]" )
{
auto resource = make_shared< Resource >( );
resource->set_path( "/query" );
resource->set_method_handler( "GET", get_method_handler );

auto settings = make_shared< Settings >( );
settings->set_port( 1984 );

shared_ptr< thread > worker = nullptr;

Service service;
service.publish( resource );
service.set_ready_handler( [ &worker ]( Service & service )
{
worker = make_shared< thread >( [ &service ] ( )
{
auto request = make_shared< Request >( );
request->set_port( 1984 );
request->set_host( "localhost" );
request->set_path( "/query" );

auto response = Http::sync( request );

REQUIRE( 200 == response->get_status_code( ) );

service.stop( );
} );
} );
service.start( settings );
worker->join( );
}

0 comments on commit 464f819

Please sign in to comment.