• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at https://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22 #include "curlcheck.h"
23 
24 #include "urldata.h"
25 #include "altsvc.h"
26 
27 static CURLcode
unit_setup(void)28 unit_setup(void)
29 {
30   return CURLE_OK;
31 }
32 
33 static void
unit_stop(void)34 unit_stop(void)
35 {
36   curl_global_cleanup();
37 }
38 
39 #if defined(CURL_DISABLE_HTTP) || !defined(USE_ALTSVC)
40 UNITTEST_START
41 {
42   return 0; /* nothing to do when HTTP is disabled or alt-svc support is
43                missing */
44 }
45 UNITTEST_STOP
46 #else
47 UNITTEST_START
48 {
49   char outname[256];
50   CURL *curl;
51   CURLcode result;
52   struct altsvcinfo *asi = Curl_altsvc_init();
53   if(!asi)
54     return 1;
55   result = Curl_altsvc_load(asi, arg);
56   if(result)
57     return result;
58   curl = curl_easy_init();
59   if(!curl)
60     goto fail;
61   fail_unless(asi->num == 4, "wrong number of entries");
62   msnprintf(outname, sizeof(outname), "%s-out", arg);
63 
64   result = Curl_altsvc_parse(curl, asi, "h2=\"example.com:8080\"",
65                              ALPN_h1, "example.org", 8080);
66   if(result) {
67     fprintf(stderr, "Curl_altsvc_parse() failed!\n");
68     unitfail++;
69   }
70   fail_unless(asi->num == 5, "wrong number of entries");
71 
72   result = Curl_altsvc_parse(curl, asi, "h3=\":8080\"",
73                              ALPN_h1, "2.example.org", 8080);
74   if(result) {
75     fprintf(stderr, "Curl_altsvc_parse(2) failed!\n");
76     unitfail++;
77   }
78   fail_unless(asi->num == 6, "wrong number of entries");
79 
80   result = Curl_altsvc_parse(curl, asi,
81                              "h2=\"example.com:8080\", h3=\"yesyes.com\"",
82                              ALPN_h1, "3.example.org", 8080);
83   if(result) {
84     fprintf(stderr, "Curl_altsvc_parse(3) failed!\n");
85     unitfail++;
86   }
87   /* that one should make two entries */
88   fail_unless(asi->num == 8, "wrong number of entries");
89 
90   result = Curl_altsvc_parse(curl, asi, "h2=\"example.com:443\"; ma = 120;",
91                              ALPN_h2c, "example.org", 80);
92   if(result) {
93     fprintf(stderr, "Curl_altsvc_parse(4) failed!\n");
94     unitfail++;
95   }
96   fail_unless(asi->num == 9, "wrong number of entries");
97 
98   result = Curl_altsvc_parse(curl, asi,
99                              "h2=\":443\", h3=\":443\"; ma = 120; persist = 1",
100                              ALPN_h1, "curl.haxx.se", 80);
101   if(result) {
102     fprintf(stderr, "Curl_altsvc_parse(5) failed!\n");
103     unitfail++;
104   }
105   fail_unless(asi->num == 11, "wrong number of entries");
106 
107   /* clear that one again and decrease the counter */
108   result = Curl_altsvc_parse(curl, asi, "clear;",
109                              ALPN_h1, "curl.haxx.se", 80);
110   if(result) {
111     fprintf(stderr, "Curl_altsvc_parse(6) failed!\n");
112     unitfail++;
113   }
114   fail_unless(asi->num == 9, "wrong number of entries");
115 
116   Curl_altsvc_save(asi, outname);
117 
118   curl_easy_cleanup(curl);
119   fail:
120   Curl_altsvc_cleanup(asi);
121   return unitfail;
122 }
123 UNITTEST_STOP
124 #endif
125