forked from Corvusoft/restbed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Regression test covering PR Corvusoft#207, incorrect IPv4 endpoint st…
…ring.
- Loading branch information
1 parent
0b04c22
commit 464f819
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
test/regression/source/ipv4_session_origin_destination_malformed.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( ); | ||
} |