int main (int argc, char **argv) { int fail=0; if (loglevel) printf("\n *** Testing query parameter array encoding.\n"); fail|=test_request("GET", "http://example.com" "?k1=v1" "&a1[ak1]=av1" "&a1[aa1][aak2]=aav2" "&a1[aa1][aak1]=aav1" "&k2=v2" "&a1[ak2]=av2", "GET&http%3A%2F%2Fexample.com%2F&a1%255Baa1%255D%255Baak1%255D%3Daav1%26a1%255Baa1%255D%255Baak2%255D%3Daav2%26a1%255Bak1%255D%3Dav1%26a1%255Bak2%255D%3Dav2%26k1%3Dv1%26k2%3Dv2"); if (loglevel) printf("\n *** Testing http://tools.ietf.org/html/rfc5849 example.\n"); fail|=test_request("GET", "http://example.com" "/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b" "&c2&a3=2+q" "&oauth_consumer_key=9djdj82h48djs9d2" "&oauth_token=kkk9d7dh3k39sjv7" "&oauth_signature_method=HMAC-SHA1" "&oauth_timestamp=137131201" "&oauth_nonce=7d8f3e4a" "&oauth_signature=djosJKDKJSD8743243%2Fjdk33klY%3D", "GET&http%3A%2F%2Fexample.com%2Frequest&a2%3Dr%2520b%26a3%3D2%2520q%26a3%3Da%26b5%3D%253D%25253D%26c%2540%3D%26c2%3D%26oauth_consumer_key%3D9djdj82h48djs9d2%26oauth_nonce%3D7d8f3e4a%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D137131201%26oauth_token%3Dkkk9d7dh3k39sjv7"); if (loglevel) printf("\n *** Testing body hash calculation.\n"); char *bh; const char *teststring="Hello World!"; bh=oauth_body_hash_data(strlen(teststring), teststring); if (bh) { if (strcmp(bh,"oauth_body_hash=Lve95gjOVATpfV8EL5X4nxwjKHE=")) fail|=1; free(bh); } else { fail|=1; } if (loglevel) printf("\n *** Testing PLAINTEXT signature.\n"); fail |= test_sign_get( "http://host.net/resource" "?" "name=value&name=value" "&oauth_nonce=fake&&oauth_timestamp=1", OA_PLAINTEXT, "abcd", "&", "1234", "&", "http://host.net/resource?name=value&name=value&oauth_consumer_key=abcd&oauth_nonce=fake&oauth_signature_method=PLAINTEXT&oauth_timestamp=1&oauth_token=1234&oauth_version=1.0&oauth_signature=%2526%26%2526" ); // report if (fail) { printf("\n !!! One or more test cases failed.\n\n"); } else { printf(" *** Test cases verified sucessfully.\n"); } return (fail?1:0); }
int main(int argc, char *argv[]) { gtk_init (&argc, &argv); g_set_prgname ("frob-request"); if (argc > 1) test_request (argv[1]); else test_request (SRCDIR "/ui/fixtures/der-rsa-2048.p10"); return 0; }
int main(int argc, char* argv[]) { if(argc != 4) error("usage: host port [tcp, udp]"); char* host = argv[1]; int port = atoi(argv[2]); char* proto = argv[3]; int sock_fd = init_client(host, port, proto); test_request(sock_fd, proto); }
int main( int argc, const char* argv[] ) { int test = argc > 1 ? atoi(argv[1]) : 0; if (argc >= 3) { verbosity = atoi(argv[2]); verbose = verbosity > 0 ? true : false; veryVerbose = verbosity > 1 ? true : false; veryVeryVerbose = verbosity > 2 ? true : false; std::cout << verbosity << std::endl; } set_up_signal_handler(); if (verbose) std::cout << "TEST " << __FILE__ << " CASE " << test << std::endl; switch (test) { case 0: case 1: { mrm::HTTPServer server; if (server.startServer() < 0) exit(1); // main loop while (server.acceptConnection() >= 0); } break; case 2: { if (verbose) std::cout << "TEST RESPONSE" << std::endl; test_response(); } break; case 3: { if (verbose) std::cout << "TEST REQUEST" << std::endl; test_request(); } break; case 4 : { if (verbose) std::cout << "TEST CLIENT" << std::endl; test_client(); } break; default: { std::cerr << "WARNING: CASE `" << test << "' NOT FOUND." << std::endl; testStatus = -1; } } return testStatus; }
void run() { TestSink sink {*this}; sink.severity (beast::Journal::Severity::kAll); beast::Journal journal {sink}; TestHandler handler; Server s (handler, journal); Ports ports; std::unique_ptr <RippleSSLContext> c ( RippleSSLContext::createBare ()); ports.emplace_back (testPort, beast::IP::Endpoint ( beast::IP::AddressV4 (127, 0, 0, 1), 0), Port::Security::no_ssl, c.get()); s.setPorts (ports); test_request(); //test_keepalive(); s.stop(); pass(); }
void basicTests() { TestSink sink {*this}; TestThread thread; sink.threshold (beast::severities::Severity::kAll); beast::Journal journal {sink}; TestHandler handler; auto s = make_Server (handler, thread.get_io_service(), journal); std::vector<Port> list; list.resize(1); list.back().port = testPort; list.back().ip = boost::asio::ip::address::from_string ( "127.0.0.1"); list.back().protocol.insert("http"); s->ports (list); test_request(); //test_keepalive(); //s->close(); s = nullptr; pass(); }
void filter_latency(grpc_end2end_test_config config) { g_enable_filter = true; test_request(config); g_enable_filter = false; }
int main(void) { // invalid temperature: test_request("{" "\"jsonrpc\": \"2.0\"," "\"method\": \"set_light_from_hsbk\"," "\"params\": {" "\"target\": \"*\", " "\"hue\": 324.2341514, " "\"saturation\": 0.234, " "\"brightness\": 1.0, " "\"kelvin\": -4200," "\"transition\": 42" "}," "\"id\": \"42\"" "}"); // saturation to big test_request("{" "\"jsonrpc\": \"2.0\"," "\"method\": \"set_light_from_hsbk\"," "\"params\": {" "\"target\": \"*\", " "\"hue\": 324.2341514, " "\"saturation\": 3.234, " "\"brightness\": 1.0, " "\"kelvin\": 4200," "\"transition\": 42" "}," "\"id\": \"42\"" "}"); // hue too big test_request("{" "\"jsonrpc\": \"2.0\"," "\"method\": \"set_light_from_hsbk\"," "\"params\": {" "\"target\": \"*\", " "\"hue\": 424.2341514, " "\"saturation\": 0.234, " "\"brightness\": 1.0, " "\"kelvin\": 4200," "\"transition\": 42" "}," "\"id\": \"42\"" "}"); // brightness too small test_request("{" "\"jsonrpc\": \"2.0\"," "\"method\": \"set_light_from_hsbk\"," "\"params\": {" "\"target\": \"*\", " "\"hue\": 224.2341514, " "\"saturation\": 0.234, " "\"brightness\": -1.0, " "\"kelvin\": 4200," "\"transition\": 42" "}," "\"id\": \"42\"" "}"); // negative transition test_request("{" "\"jsonrpc\": \"2.0\"," "\"method\": \"set_light_from_hsbk\"," "\"params\": {" "\"target\": \"*\", " "\"hue\": 224.2341514, " "\"saturation\": 0.234, " "\"brightness\": -1.0, " "\"kelvin\": 4200," "\"transition\": -42" "}," "\"id\": \"42\"" "}"); // invalid temperature: test_request("{" "\"jsonrpc\": \"2.0\"," "\"method\": \"set_light_from_hsbk\"," "\"params\": {" "\"target\": \"*\", " "\"hue\": 324.2341514, " "\"saturation\": 0.234, " "\"brightness\": 1.0, " "\"kelvin\": -4200," "\"transition\": 42" "}," "\"id\": \"42\"" "}"); // too many params test_request("{" "\"jsonrpc\": \"2.0\"," "\"method\": \"set_light_from_hsbk\"," "\"params\": [\"*\", 324.2341514, 0.234, 1.0, 4200, 600, \"extraarg\"]," "\"id\": \"42\"" "}"); return 0; }
void filter_call_init_fails(grpc_end2end_test_config config) { g_enable_filter = true; test_request(config); g_enable_filter = false; }
void filter_causes_close(grpc_end2end_test_config config) { g_enable_filter = true; test_request(config); g_enable_filter = false; }
void test_lib__http2__hpack(void) { h2o_mem_pool_t pool; h2o_mem_init_pool(&pool); note("decode_int"); { h2o_iovec_t in; const uint8_t *p; int32_t out; #define TEST(input, output) \ in = h2o_iovec_init(H2O_STRLIT(input)); \ p = (const uint8_t*)in.base; \ out = decode_int(&p, p + in.len, 7); \ ok(out == output); \ ok(p == (const uint8_t*)in.base + in.len); TEST("\x00", 0); TEST("\x03", 3); TEST("\x81", 1); TEST("\x7f\x00", 127); TEST("\x7f\x01", 128); TEST("\x7f\x7f", 254); TEST("\x7f\x81\x00", 128); TEST("\x7f\x80\x01", 255); TEST("\x7f\xff\xff\xff\x7f", 0xfffffff + 127); /* failures */ TEST("", -1); TEST("\x7f", -1); TEST("\x7f\xff", -1); TEST("\x7f\xff\xff\xff\xff", -1); #undef TEST } note("decode_huffman"); { h2o_iovec_t huffcode = { H2O_STRLIT("\xf1\xe3\xc2\xe5\xf2\x3a\x6b\xa0\xab\x90\xf4\xff") }; h2o_iovec_t *decoded = decode_huffman(&pool, (const uint8_t*)huffcode.base, huffcode.len); ok(decoded->len == sizeof("www.example.com") -1); ok(strcmp(decoded->base, "www.example.com") == 0); } h2o_mem_clear_pool(&pool); note("decode_header (literal header field with indexing)"); { struct st_h2o_decode_header_result_t result; h2o_hpack_header_table_t header_table; h2o_iovec_t in; int r; memset(&header_table, 0, sizeof(header_table)); header_table.hpack_capacity = 4096; in = h2o_iovec_init(H2O_STRLIT("\x40\x0a\x63\x75\x73\x74\x6f\x6d\x2d\x6b\x65\x79\x0d\x63\x75\x73\x74\x6f\x6d\x2d\x68\x65\x61\x64\x65\x72")); const uint8_t *p = (const uint8_t*)in.base; r = decode_header(&pool, &result, &header_table, &p, p + in.len); ok(r == 0); ok(result.name->len == 10); ok(strcmp(result.name->base, "custom-key") == 0); ok(result.value->len == 13); ok(strcmp(result.value->base, "custom-header") == 0); ok(header_table.hpack_size == 55); } h2o_mem_clear_pool(&pool); note("decode_header (literal header field without indexing)"); { struct st_h2o_decode_header_result_t result; h2o_hpack_header_table_t header_table; h2o_iovec_t in; int r; memset(&header_table, 0, sizeof(header_table)); header_table.hpack_capacity = 4096; in = h2o_iovec_init(H2O_STRLIT("\x04\x0c\x2f\x73\x61\x6d\x70\x6c\x65\x2f\x70\x61\x74\x68")); const uint8_t *p = (const uint8_t*)in.base; r = decode_header(&pool, &result, &header_table, &p, p + in.len); ok(r == 0); ok(result.name == &H2O_TOKEN_PATH->buf); ok(result.value->len == 12); ok(strcmp(result.value->base, "/sample/path") == 0); ok(header_table.hpack_size == 0); } h2o_mem_clear_pool(&pool); note("decode_header (literal header field never indexed)"); { struct st_h2o_decode_header_result_t result; h2o_hpack_header_table_t header_table; h2o_iovec_t in; int r; memset(&header_table, 0, sizeof(header_table)); header_table.hpack_capacity = 4096; in = h2o_iovec_init(H2O_STRLIT("\x10\x08\x70\x61\x73\x73\x77\x6f\x72\x64\x06\x73\x65\x63\x72\x65\x74")); const uint8_t *p = (const uint8_t*)in.base; r = decode_header(&pool, &result, &header_table, &p, p + in.len); ok(r == 0); ok(result.name->len == 8); ok(strcmp(result.name->base, "password") == 0); ok(result.value->len == 6); ok(strcmp(result.value->base, "secret") == 0); ok(header_table.hpack_size == 0); } h2o_mem_clear_pool(&pool); note("decode_header (indexed header field)"); { struct st_h2o_decode_header_result_t result; h2o_hpack_header_table_t header_table; h2o_iovec_t in; int r; memset(&header_table, 0, sizeof(header_table)); header_table.hpack_capacity = 4096; in = h2o_iovec_init(H2O_STRLIT("\x82")); const uint8_t *p = (const uint8_t*)in.base; r = decode_header(&pool, &result, &header_table, &p, p + in.len); ok(r == 0); ok(result.name == &H2O_TOKEN_METHOD->buf); ok(result.value->len == 3); ok(strcmp(result.value->base, "GET") == 0); ok(header_table.hpack_size == 0); } h2o_mem_clear_pool(&pool); note("request examples without huffman coding"); test_request( h2o_iovec_init(H2O_STRLIT("\x82\x86\x84\x41\x0f\x77\x77\x77\x2e\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d")), h2o_iovec_init(H2O_STRLIT("\x82\x86\x84\xbe\x58\x08\x6e\x6f\x2d\x63\x61\x63\x68\x65")), h2o_iovec_init(H2O_STRLIT("\x82\x87\x85\xbf\x40\x0a\x63\x75\x73\x74\x6f\x6d\x2d\x6b\x65\x79\x0c\x63\x75\x73\x74\x6f\x6d\x2d\x76\x61\x6c\x75\x65"))); note("request examples with huffman coding"); test_request( h2o_iovec_init(H2O_STRLIT("\x82\x86\x84\x41\x8c\xf1\xe3\xc2\xe5\xf2\x3a\x6b\xa0\xab\x90\xf4\xff")), h2o_iovec_init(H2O_STRLIT("\x82\x86\x84\xbe\x58\x86\xa8\xeb\x10\x64\x9c\xbf")), h2o_iovec_init(H2O_STRLIT("\x82\x87\x85\xbf\x40\x88\x25\xa8\x49\xe9\x5b\xa9\x7d\x7f\x89\x25\xa8\x49\xe9\x5b\xb8\xe8\xb4\xbf"))); note("encode_huffman"); { h2o_iovec_t huffcode = { H2O_STRLIT("\xf1\xe3\xc2\xe5\xf2\x3a\x6b\xa0\xab\x90\xf4\xff") }; char buf[sizeof("www.example.com")]; size_t l = encode_huffman((uint8_t*)buf, (uint8_t*)H2O_STRLIT("www.example.com")); ok(l == huffcode.len); ok(memcmp(buf, huffcode.base, huffcode.len) == 0); } note("response examples with huffmann coding"); { h2o_hpack_header_table_t header_table; h2o_res_t res; memset(&header_table, 0, sizeof(header_table)); header_table.hpack_capacity = 256; memset(&res, 0, sizeof(res)); res.status = 302; res.reason = "Found"; h2o_add_header(&pool, &res.headers, H2O_TOKEN_CACHE_CONTROL, H2O_STRLIT("private")); h2o_add_header(&pool, &res.headers, H2O_TOKEN_DATE, H2O_STRLIT("Mon, 21 Oct 2013 20:13:21 GMT")); h2o_add_header(&pool, &res.headers, H2O_TOKEN_LOCATION, H2O_STRLIT("https://www.example.com")); check_flatten(&header_table, &res, H2O_STRLIT("\x08\x03\x33\x30\x32\x58\x85\xae\xc3\x77\x1a\x4b\x61\x96\xd0\x7a\xbe\x94\x10\x54\xd4\x44\xa8\x20\x05\x95\x04\x0b\x81\x66\xe0\x82\xa6\x2d\x1b\xff\x6e\x91\x9d\x29\xad\x17\x18\x63\xc7\x8f\x0b\x97\xc8\xe9\xae\x82\xae\x43\xd3")); memset(&res, 0, sizeof(res)); res.status = 307; res.reason = "Temporary Redirect"; h2o_add_header(&pool, &res.headers, H2O_TOKEN_CACHE_CONTROL, H2O_STRLIT("private")); h2o_add_header(&pool, &res.headers, H2O_TOKEN_DATE, H2O_STRLIT("Mon, 21 Oct 2013 20:13:21 GMT")); h2o_add_header(&pool, &res.headers, H2O_TOKEN_LOCATION, H2O_STRLIT("https://www.example.com")); check_flatten(&header_table, &res, H2O_STRLIT("\x08\x03\x33\x30\x37\xc0\xbf\xbe")); #if 0 h2o_iovec_init(H2O_STRLIT("\x48\x03\x33\x30\x37\xc1\xc0\xbf")), h2o_iovec_init(H2O_STRLIT("\x88\xc1\x61\x1d\x4d\x6f\x6e\x2c\x20\x32\x31\x20\x4f\x63\x74\x20\x32\x30\x31\x33\x20\x32\x30\x3a\x31\x33\x3a\x32\x32\x20\x47\x4d\x54\xc0\x5a\x04\x67\x7a\x69\x70\x77\x38\x66\x6f\x6f\x3d\x41\x53\x44\x4a\x4b\x48\x51\x4b\x42\x5a\x58\x4f\x51\x57\x45\x4f\x50\x49\x55\x41\x58\x51\x57\x45\x4f\x49\x55\x3b\x20\x6d\x61\x78\x2d\x61\x67\x65\x3d\x33\x36\x30\x30\x3b\x20\x76\x65\x72\x73\x69\x6f\x6e\x3d\x31"))); #endif } h2o_mem_clear_pool(&pool); }