From e1be8254534898fccafc5d6cd04f6235f283cfbd Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Sun, 3 Mar 2019 11:17:52 +0100 Subject: alt-svc: the libcurl bits --- tests/FILEFORMAT | 1 + tests/data/Makefile.inc | 2 +- tests/data/test1654 | 57 ++++++++++++++++++++++ tests/runtests.pl | 10 ++++ tests/unit/Makefile.inc | 5 +- tests/unit/unit1654.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 197 insertions(+), 2 deletions(-) create mode 100644 tests/data/test1654 create mode 100644 tests/unit/unit1654.c (limited to 'tests') diff --git a/tests/FILEFORMAT b/tests/FILEFORMAT index 505c573cb..85e731966 100644 --- a/tests/FILEFORMAT +++ b/tests/FILEFORMAT @@ -249,6 +249,7 @@ unittest unix-sockets WinSSL ld_preload +alt-svc as well as each protocol that curl supports. A protocol only needs to be specified if it is different from the server (useful when the server diff --git a/tests/data/Makefile.inc b/tests/data/Makefile.inc index 0dcbedfe5..bd24b4ba2 100644 --- a/tests/data/Makefile.inc +++ b/tests/data/Makefile.inc @@ -183,7 +183,7 @@ test1590 test1591 test1592 \ test1600 test1601 test1602 test1603 test1604 test1605 test1606 test1607 \ test1608 test1609 test1620 test1621 \ \ -test1650 test1651 test1652 test1653 \ +test1650 test1651 test1652 test1653 test1654 \ \ test1700 test1701 test1702 \ \ diff --git a/tests/data/test1654 b/tests/data/test1654 new file mode 100644 index 000000000..cae49d663 --- /dev/null +++ b/tests/data/test1654 @@ -0,0 +1,57 @@ + + + +unittest +alt-svc +altsvc + + + + + +none + + +unittest +alt-svc + + +# This date is exactly "20190124 22:34:21" UTC + +CURL_TIME=1548369261 + + +alt-svc + + +log/1654 + + +unit1654 + + +h2 example.com 443 h3 shiny.example.com 8443 "20191231 00:00:00" 0 1 +# a comment +h2c example.com 443 h3 shiny.example.com 8443 "20291231 23:30:00" 0 1 + h1 example.com 443 h3 shiny.example.com 8443 "20121231 00:00:01" 0 1 + h3 example.com 443 h3 shiny.example.com 8443 "20131231 00:00:00" 0 1 + # also a comment +bad example.com 443 h3 shiny.example.com 8443 "20191231 00:00:00" 0 1 +rubbish + + + + +# Your alt-svc cache. https://curl.haxx.se/docs/alt-svc.html +# This file was generated by libcurl! Edit at your own risk. +h2 example.com 443 h3 shiny.example.com 8443 "20191231 00:00:00" 0 1 +h2c example.com 443 h3 shiny.example.com 8443 "20291231 23:30:00" 0 1 +h1 example.com 443 h3 shiny.example.com 8443 "20121231 00:00:01" 0 1 +h3 example.com 443 h3 shiny.example.com 8443 "20131231 00:00:00" 0 1 +h1 example.org 8080 h2 example.com 8080 "20190125 22:34:21" 0 0 +h1 2.example.org 8080 h3 2.example.org 8080 "20190125 22:34:21" 0 0 +h1 3.example.org 8080 h2 example.com 8080 "20190125 22:34:21" 0 0 +h1 3.example.org 8080 h3 yesyes.com 8080 "20190125 22:34:21" 0 0 +h2c example.org 80 h2 example.com 443 "20190124 22:36:21" 0 0 + + diff --git a/tests/runtests.pl b/tests/runtests.pl index 5a1d1b6cd..1fb7354ec 100755 --- a/tests/runtests.pl +++ b/tests/runtests.pl @@ -233,6 +233,7 @@ my $has_crypto; # set if libcurl is built with cryptographic support my $has_cares; # set if built with c-ares my $has_threadedres;# set if built with threaded resolver my $has_psl; # set if libcurl is built with PSL support +my $has_altsvc; # set if libcurl is built with alt-svc support my $has_ldpreload; # set if curl is built for systems supporting LD_PRELOAD my $has_multissl; # set if curl is build with MultiSSL support my $has_manual; # set if curl is built with built-in manual @@ -2838,6 +2839,10 @@ sub checksystem { # PSL enabled $has_psl=1; } + if($feat =~ /alt-svc/i) { + # alt-svc enabled + $has_altsvc=1; + } if($feat =~ /AsynchDNS/i) { if(!$has_cares) { # this means threaded resolver @@ -3387,6 +3392,11 @@ sub singletest { next; } } + elsif($1 eq "alt-svc") { + if($has_altsvc) { + next; + } + } elsif($1 eq "manual") { if($has_manual) { next; diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc index 82eaec797..f3cba1c2a 100644 --- a/tests/unit/Makefile.inc +++ b/tests/unit/Makefile.inc @@ -11,7 +11,7 @@ UNITPROGS = unit1300 unit1301 unit1302 unit1303 unit1304 unit1305 unit1307 \ unit1399 \ unit1600 unit1601 unit1602 unit1603 unit1604 unit1605 unit1606 unit1607 \ unit1608 unit1609 unit1620 unit1621 \ - unit1650 unit1651 unit1652 unit1653 + unit1650 unit1651 unit1652 unit1653 unit1654 unit1300_SOURCES = unit1300.c $(UNITFILES) unit1300_CPPFLAGS = $(AM_CPPFLAGS) @@ -115,3 +115,6 @@ unit1652_CPPFLAGS = $(AM_CPPFLAGS) unit1653_SOURCES = unit1653.c $(UNITFILES) unit1653_CPPFLAGS = $(AM_CPPFLAGS) + +unit1654_SOURCES = unit1654.c $(UNITFILES) +unit1654_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/tests/unit/unit1654.c b/tests/unit/unit1654.c new file mode 100644 index 000000000..7532c6d61 --- /dev/null +++ b/tests/unit/unit1654.c @@ -0,0 +1,124 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 2019, Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +#include "curlcheck.h" + +#include "urldata.h" +#include "altsvc.h" + +static CURLcode +unit_setup(void) +{ + return CURLE_OK; +} + +static void +unit_stop(void) +{ + curl_global_cleanup(); +} + +#if defined(CURL_DISABLE_HTTP) || !defined(USE_ALTSVC) +UNITTEST_START +{ + return 0; /* nothing to do when HTTP is disabled or alt-svc support is + missing */ +} +UNITTEST_STOP +#else +UNITTEST_START +{ + char outname[256]; + CURL *curl; + CURLcode result; + struct altsvcinfo *asi = Curl_altsvc_init(); + if(!asi) + return 1; + result = Curl_altsvc_load(asi, arg); + if(result) + return result; + curl = curl_easy_init(); + if(!curl) + goto fail; + fail_unless(asi->num == 4, "wrong number of entries"); + msnprintf(outname, sizeof(outname), "%s-out", arg); + + result = Curl_altsvc_parse(curl, asi, "h2=\"example.com:8080\"", + ALPN_h1, "example.org", 8080); + if(result) { + fprintf(stderr, "Curl_altsvc_parse() failed!\n"); + unitfail++; + } + fail_unless(asi->num == 5, "wrong number of entries"); + + result = Curl_altsvc_parse(curl, asi, "h3=\":8080\"", + ALPN_h1, "2.example.org", 8080); + if(result) { + fprintf(stderr, "Curl_altsvc_parse(2) failed!\n"); + unitfail++; + } + fail_unless(asi->num == 6, "wrong number of entries"); + + result = Curl_altsvc_parse(curl, asi, + "h2=\"example.com:8080\", h3=\"yesyes.com\"", + ALPN_h1, "3.example.org", 8080); + if(result) { + fprintf(stderr, "Curl_altsvc_parse(3) failed!\n"); + unitfail++; + } + /* that one should make two entries */ + fail_unless(asi->num == 8, "wrong number of entries"); + + result = Curl_altsvc_parse(curl, asi, "h2=\"example.com:443\"; ma = 120;", + ALPN_h2c, "example.org", 80); + if(result) { + fprintf(stderr, "Curl_altsvc_parse(4) failed!\n"); + unitfail++; + } + fail_unless(asi->num == 9, "wrong number of entries"); + + result = Curl_altsvc_parse(curl, asi, + "h2=\":443\", h3=\":443\"; ma = 120; persist = 1", + ALPN_h1, "curl.haxx.se", 80); + if(result) { + fprintf(stderr, "Curl_altsvc_parse(5) failed!\n"); + unitfail++; + } + fail_unless(asi->num == 11, "wrong number of entries"); + + /* clear that one again and decrease the counter */ + result = Curl_altsvc_parse(curl, asi, "clear;", + ALPN_h1, "curl.haxx.se", 80); + if(result) { + fprintf(stderr, "Curl_altsvc_parse(6) failed!\n"); + unitfail++; + } + fail_unless(asi->num == 9, "wrong number of entries"); + + Curl_altsvc_save(asi, outname); + + curl_easy_cleanup(curl); + fail: + Curl_altsvc_cleanup(asi); + return unitfail; +} +UNITTEST_STOP +#endif -- cgit v1.2.3