File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / curl / tests / unit / unit1653.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 3 10:01:16 2020 UTC (5 years ago) by misho
Branches: curl, MAIN
CVS tags: v7_70_0p4, HEAD
curl

    1: /***************************************************************************
    2:  *                                  _   _ ____  _
    3:  *  Project                     ___| | | |  _ \| |
    4:  *                             / __| | | | |_) | |
    5:  *                            | (__| |_| |  _ <| |___
    6:  *                             \___|\___/|_| \_\_____|
    7:  *
    8:  * Copyright (C) 1998 - 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 "curl/urlapi.h"
   26: #include "urlapi-int.h"
   27: 
   28: 
   29: static CURLU *u;
   30: 
   31: static CURLcode
   32: unit_setup(void)
   33: {
   34:   return CURLE_OK;
   35: }
   36: 
   37: static void
   38: unit_stop(void)
   39: {
   40:   curl_global_cleanup();
   41: }
   42: 
   43: #define free_and_clear(x) free(x); x = NULL
   44: 
   45: UNITTEST_START
   46: {
   47:   CURLUcode ret;
   48:   char *ipv6port = NULL;
   49:   char *portnum;
   50: 
   51:   /* Valid IPv6 */
   52:   u = curl_url();
   53:   if(!u)
   54:     goto fail;
   55:   ipv6port = strdup("[fe80::250:56ff:fea7:da15]");
   56:   if(!ipv6port)
   57:     goto fail;
   58:   ret = Curl_parse_port(u, ipv6port);
   59:   fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
   60:   ret = curl_url_get(u, CURLUPART_PORT, &portnum, CURLU_NO_DEFAULT_PORT);
   61:   fail_unless(ret != CURLUE_OK, "curl_url_get portnum returned something");
   62:   free_and_clear(ipv6port);
   63:   curl_url_cleanup(u);
   64: 
   65:   /* Invalid IPv6 */
   66:   u = curl_url();
   67:   if(!u)
   68:     goto fail;
   69:   ipv6port = strdup("[fe80::250:56ff:fea7:da15|");
   70:   if(!ipv6port)
   71:     goto fail;
   72:   ret = Curl_parse_port(u, ipv6port);
   73:   fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
   74:   free_and_clear(ipv6port);
   75:   curl_url_cleanup(u);
   76: 
   77:   u = curl_url();
   78:   if(!u)
   79:     goto fail;
   80:   ipv6port = strdup("[fe80::250:56ff;fea7:da15]:80");
   81:   if(!ipv6port)
   82:     goto fail;
   83:   ret = Curl_parse_port(u, ipv6port);
   84:   fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
   85:   free_and_clear(ipv6port);
   86:   curl_url_cleanup(u);
   87: 
   88:   /* Valid IPv6 with zone index and port number */
   89:   u = curl_url();
   90:   if(!u)
   91:     goto fail;
   92:   ipv6port = strdup("[fe80::250:56ff:fea7:da15%25eth3]:80");
   93:   if(!ipv6port)
   94:     goto fail;
   95:   ret = Curl_parse_port(u, ipv6port);
   96:   fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
   97:   ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0);
   98:   fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error");
   99:   fail_unless(portnum && !strcmp(portnum, "80"), "Check portnumber");
  100:   curl_free(portnum);
  101:   free_and_clear(ipv6port);
  102:   curl_url_cleanup(u);
  103: 
  104:   /* Valid IPv6 with zone index without port number */
  105:   u = curl_url();
  106:   if(!u)
  107:     goto fail;
  108:   ipv6port = strdup("[fe80::250:56ff:fea7:da15%25eth3]");
  109:   if(!ipv6port)
  110:     goto fail;
  111:   ret = Curl_parse_port(u, ipv6port);
  112:   fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
  113:   free_and_clear(ipv6port);
  114:   curl_url_cleanup(u);
  115: 
  116:   /* Valid IPv6 with port number */
  117:   u = curl_url();
  118:   if(!u)
  119:     goto fail;
  120:   ipv6port = strdup("[fe80::250:56ff:fea7:da15]:81");
  121:   if(!ipv6port)
  122:     goto fail;
  123:   ret = Curl_parse_port(u, ipv6port);
  124:   fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
  125:   ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0);
  126:   fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error");
  127:   fail_unless(portnum && !strcmp(portnum, "81"), "Check portnumber");
  128:   curl_free(portnum);
  129:   free_and_clear(ipv6port);
  130:   curl_url_cleanup(u);
  131: 
  132:   /* Valid IPv6 with syntax error in the port number */
  133:   u = curl_url();
  134:   if(!u)
  135:     goto fail;
  136:   ipv6port = strdup("[fe80::250:56ff:fea7:da15];81");
  137:   if(!ipv6port)
  138:     goto fail;
  139:   ret = Curl_parse_port(u, ipv6port);
  140:   fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
  141:   free_and_clear(ipv6port);
  142:   curl_url_cleanup(u);
  143: 
  144:   u = curl_url();
  145:   if(!u)
  146:     goto fail;
  147:   ipv6port = strdup("[fe80::250:56ff:fea7:da15]80");
  148:   if(!ipv6port)
  149:     goto fail;
  150:   ret = Curl_parse_port(u, ipv6port);
  151:   fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
  152:   free_and_clear(ipv6port);
  153:   curl_url_cleanup(u);
  154: 
  155:   /* Valid IPv6 with no port after the colon, should use default */
  156:   u = curl_url();
  157:   if(!u)
  158:     goto fail;
  159:   ipv6port = strdup("[fe80::250:56ff:fea7:da15]:");
  160:   if(!ipv6port)
  161:     goto fail;
  162:   ret = Curl_parse_port(u, ipv6port);
  163:   fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
  164:   free_and_clear(ipv6port);
  165:   curl_url_cleanup(u);
  166: 
  167:   /* Incorrect zone index syntax */
  168:   u = curl_url();
  169:   if(!u)
  170:     goto fail;
  171:   ipv6port = strdup("[fe80::250:56ff:fea7:da15!25eth3]:80");
  172:   if(!ipv6port)
  173:     goto fail;
  174:   ret = Curl_parse_port(u, ipv6port);
  175:   fail_unless(ret != CURLUE_OK, "Curl_parse_port returned non-error");
  176:   free_and_clear(ipv6port);
  177:   curl_url_cleanup(u);
  178: 
  179:   /* Non percent-encoded zone index */
  180:   u = curl_url();
  181:   if(!u)
  182:     goto fail;
  183:   ipv6port = strdup("[fe80::250:56ff:fea7:da15%eth3]:80");
  184:   if(!ipv6port)
  185:     goto fail;
  186:   ret = Curl_parse_port(u, ipv6port);
  187:   fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
  188:   fail:
  189:   free(ipv6port);
  190:   curl_url_cleanup(u);
  191: }
  192: UNITTEST_STOP

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>