@@ -34,7 +34,7 @@ fs::path find_matching_file(const boost::regex& re) {
34
34
fs::recursive_directory_iterator (fs::current_path ()),
35
35
fs::recursive_directory_iterator (),
36
36
[re](const fs::path& f) { return boost::regex_match (f.filename ().string (), re); });
37
-
37
+
38
38
// throw exception, as this means that the matching file does not exist.
39
39
if (file == fs::recursive_directory_iterator ()) {
40
40
throw std::runtime_error (" matching file not found" );
@@ -297,18 +297,43 @@ TEST_CASE("curl::client CA bundle and SSL setup") {
297
297
}
298
298
299
299
SECTION (" cURL should make an HTTP request with the specified HTTP protocol" ) {
300
- test_client.set_supported_protocols (CURLPROTO_HTTP);
300
+ test_client.set_supported_protocols (" http" );
301
+ auto resp = test_client.get (test_request);
302
+ CURL* const & handle = test_client.get_handle ();
303
+ auto test_impl = reinterpret_cast <curl_impl* const >(handle);
304
+ REQUIRE (test_impl->protocols == " http" );
305
+ }
306
+
307
+ SECTION (" cURL should make an HTTP request with multiple specified protocols" ) {
308
+ test_client.set_supported_protocols (" http,https" );
309
+ auto resp = test_client.get (test_request);
310
+ CURL* const & handle = test_client.get_handle ();
311
+ auto test_impl = reinterpret_cast <curl_impl* const >(handle);
312
+ // Either order is fine
313
+ REQUIRE ((test_impl->protocols == " http,https" || test_impl->protocols == " https,http" ));
314
+ }
315
+
316
+ SECTION (" leatherman should throw an error when multiple specified protocols include anything other than http, https" ) {
317
+ REQUIRE_THROWS_AS (test_client.set_supported_protocols (CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_SFTP), http_exception);
318
+ }
319
+
320
+ SECTION (" cURL should make an HTTP request with the HTTPS protocol when given the CURLPROTO_HTTPS bitmask" ) {
321
+ test_client.set_supported_protocols (CURLPROTO_HTTPS);
301
322
auto resp = test_client.get (test_request);
302
323
CURL* const & handle = test_client.get_handle ();
303
324
auto test_impl = reinterpret_cast <curl_impl* const >(handle);
304
- REQUIRE (test_impl->protocols == CURLPROTO_HTTP);
325
+ REQUIRE (test_impl->protocols == " https" );
326
+ }
327
+
328
+ SECTION (" leatherman should throw an error when any bitmask other than CURLPROTO_HTTP/HTTPS/ALL is given to set_supported_protocols" ) {
329
+ REQUIRE_THROWS_AS (test_client.set_supported_protocols (CURLPROTO_SCP), http_exception);
305
330
}
306
331
307
332
SECTION (" cURL defaults to all protocols if no protocols are specified" ) {
308
333
auto resp = test_client.get (test_request);
309
334
CURL* const & handle = test_client.get_handle ();
310
335
auto test_impl = reinterpret_cast <curl_impl* const >(handle);
311
- REQUIRE (test_impl->protocols == CURLPROTO_ALL );
336
+ REQUIRE (test_impl->protocols == " all " );
312
337
}
313
338
}
314
339
@@ -418,7 +443,7 @@ TEST_CASE("curl::client errors") {
418
443
}
419
444
420
445
SECTION (" client fails to make http call with https protocol only enabled" ) {
421
- test_client.set_supported_protocols (CURLPROTO_HTTPS );
446
+ test_client.set_supported_protocols (" https " );
422
447
test_impl->test_failure_mode = curl_impl::error_mode::protocol_error;
423
448
REQUIRE_THROWS_AS (test_client.get (test_request), http_curl_setup_exception);
424
449
}
@@ -427,7 +452,7 @@ TEST_CASE("curl::client errors") {
427
452
TEST_CASE (" curl::client download_file" ) {
428
453
mock_client test_client;
429
454
temp_directory temp_dir;
430
- fs::path temp_dir_path = fs::path (temp_dir.get_dir_name ());
455
+ fs::path temp_dir_path = fs::path (temp_dir.get_dir_name ());
431
456
CURL* const & handle = test_client.get_handle ();
432
457
auto test_impl = reinterpret_cast <curl_impl* const >(handle);
433
458
std::string url = " https://download.com" ;
@@ -440,7 +465,7 @@ TEST_CASE("curl::client errors") {
440
465
441
466
test_client.set_ca_cert (ca_file);
442
467
test_client.set_client_cert (cert_file, key_file);
443
- test_client.set_supported_protocols (CURLPROTO_HTTPS );
468
+ test_client.set_supported_protocols (" https " );
444
469
445
470
std::string file_path = (temp_dir_path / " test_file" ).string ();
446
471
std::string token = " token" ;
@@ -455,7 +480,7 @@ TEST_CASE("curl::client errors") {
455
480
REQUIRE (test_impl->cacert == ca_file);
456
481
REQUIRE (test_impl->client_cert == cert_file);
457
482
REQUIRE (test_impl->client_key == key_file);
458
- REQUIRE (test_impl->protocols == CURLPROTO_HTTPS );
483
+ REQUIRE (test_impl->protocols == " https " );
459
484
REQUIRE (test_impl->connect_timeout == connect_timeout);
460
485
REQUIRE (std::string (test_impl->header ->data ) == (" X-Authentication: " + token));
461
486
if (test_impl->header ->next ) {
@@ -487,7 +512,7 @@ TEST_CASE("curl::client errors") {
487
512
std::string url = " https://download_trigger_404.com" ;
488
513
auto file_path = (temp_dir_path / " 404_test_file" ).string ();
489
514
request req (url);
490
- test_client.download_file (req, file_path);
515
+ test_client.download_file (req, file_path);
491
516
492
517
// now check that the file was actually downloaded and written with the right
493
518
// contents.
@@ -507,7 +532,7 @@ TEST_CASE("curl::client errors") {
507
532
508
533
test_client.set_ca_cert (ca_file);
509
534
test_client.set_client_cert (cert_file, key_file);
510
- test_client.set_supported_protocols (CURLPROTO_HTTPS );
535
+ test_client.set_supported_protocols (" https " );
511
536
512
537
std::string file_path = (temp_dir_path / " test_file" ).string ();
513
538
std::string token = " token" ;
@@ -523,7 +548,7 @@ TEST_CASE("curl::client errors") {
523
548
REQUIRE (test_impl->cacert == ca_file);
524
549
REQUIRE (test_impl->client_cert == cert_file);
525
550
REQUIRE (test_impl->client_key == key_file);
526
- REQUIRE (test_impl->protocols == CURLPROTO_HTTPS );
551
+ REQUIRE (test_impl->protocols == " https " );
527
552
REQUIRE (test_impl->connect_timeout == connect_timeout);
528
553
REQUIRE (std::string (test_impl->header ->data ) == (" X-Authentication: " + token));
529
554
if (test_impl->header ->next ) {
@@ -561,11 +586,11 @@ TEST_CASE("curl::client errors") {
561
586
auto file_path = (temp_dir_path / " 404_test_file" ).string ();
562
587
request req (url);
563
588
response res;
564
- test_client.download_file (req, file_path, res);
589
+ test_client.download_file (req, file_path, res);
565
590
566
591
REQUIRE (res.status_code () == 404 );
567
592
REQUIRE (res.body () == " Not found" );
568
- // check that the file was not downloaded
593
+ // check that the file was not downloaded
569
594
REQUIRE (!fs::exists (file_path));
570
595
}
571
596
}
@@ -574,7 +599,7 @@ TEST_CASE("curl::client errors") {
574
599
TEST_CASE (" curl::client download_file errors" ) {
575
600
mock_client test_client;
576
601
temp_directory temp_dir;
577
- fs::path temp_dir_path = fs::path (temp_dir.get_dir_name ());
602
+ fs::path temp_dir_path = fs::path (temp_dir.get_dir_name ());
578
603
CURL* const & handle = test_client.get_handle ();
579
604
auto test_impl = reinterpret_cast <curl_impl* const >(handle);
580
605
@@ -600,7 +625,7 @@ TEST_CASE("curl::client download_file errors") {
600
625
SECTION (" when curl_easy_perform fails due to a CURLE_WRITE_ERROR, but the temporary file is removed, an http_file_operation_exception is thrown" ) {
601
626
std::string file_path = (temp_dir_path / " file" ).string ();
602
627
request req (" " );
603
- test_impl->test_failure_mode = curl_impl::error_mode::easy_perform_write_error;
628
+ test_impl->test_failure_mode = curl_impl::error_mode::easy_perform_write_error;
604
629
REQUIRE_THROWS_AS_WITH (
605
630
test_client.download_file (req, file_path),
606
631
http_file_operation_exception,
@@ -610,7 +635,7 @@ TEST_CASE("curl::client download_file errors") {
610
635
SECTION (" when curl_easy_perform fails for reasons other than a CURLE_WRITE_ERROR, but the temporary file is removed, only the errbuf message is contained in the thrown http_file_download_exception" ) {
611
636
std::string file_path = (temp_dir_path / " file" ).string ();
612
637
request req (" " );
613
- test_impl->test_failure_mode = curl_impl::error_mode::easy_perform_error;
638
+ test_impl->test_failure_mode = curl_impl::error_mode::easy_perform_error;
614
639
REQUIRE_THROWS_AS_WITH (
615
640
test_client.download_file (req, file_path),
616
641
http_file_download_exception,
@@ -623,7 +648,7 @@ TEST_CASE("curl::client download_file errors") {
623
648
SECTION (" when renaming the temporary file to the user-provided file path fails, an http_file_operation_exception is thrown" ) {
624
649
std::string file_path = (temp_dir_path / " file" ).string ();
625
650
request req (" https://download.com" );
626
- test_impl->trigger_external_failure = remove_temp_file;
651
+ test_impl->trigger_external_failure = remove_temp_file;
627
652
REQUIRE_THROWS_AS_WITH (
628
653
test_client.download_file (req, file_path),
629
654
http_file_operation_exception,
0 commit comments