Update networking layer w/ CURL and emscripten impl

This commit is contained in:
2025-11-08 01:50:36 +11:00
parent a17925904d
commit f6874dc55a
4105 changed files with 694617 additions and 179 deletions
+54
View File
@@ -0,0 +1,54 @@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
#
# SPDX-License-Identifier: curl
#
###########################################################################
# Get BUNDLE, FIRST_C, TESTS_C variables
curl_transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
add_custom_command(OUTPUT "${BUNDLE}.c"
COMMAND ${PERL_EXECUTABLE} "${PROJECT_SOURCE_DIR}/scripts/mk-unity.pl"
--test ${TESTS_C} > "${BUNDLE}.c"
DEPENDS
"${PROJECT_SOURCE_DIR}/scripts/mk-unity.pl" "${CMAKE_CURRENT_SOURCE_DIR}/Makefile.inc"
${FIRST_C} ${TESTS_C}
VERBATIM)
add_executable(${BUNDLE} EXCLUDE_FROM_ALL "${BUNDLE}.c")
add_dependencies(${BUNDLE} curlu-unitprotos)
add_dependencies(testdeps ${BUNDLE})
target_link_libraries(${BUNDLE} curlu)
target_include_directories(${BUNDLE} PRIVATE
"${PROJECT_BINARY_DIR}/lib" # for "curl_config.h", "unitprotos.h"
"${PROJECT_SOURCE_DIR}/lib" # for "curl_setup.h", curlx
"${PROJECT_SOURCE_DIR}/tests/libtest" # for "first.h", "unitcheck.h"
"${CMAKE_CURRENT_SOURCE_DIR}" # for the generated bundle source to find included test sources
)
# unit tests are small pretend-libcurl-programs, pass BUILDING_LIBCURL to reflect that
target_compile_definitions(${BUNDLE} PRIVATE ${CURL_DEBUG_MACROS} "BUILDING_LIBCURL")
set_target_properties(${BUNDLE} PROPERTIES OUTPUT_NAME "${BUNDLE}" PROJECT_LABEL "Test ${BUNDLE}" UNITY_BUILD OFF C_CLANG_TIDY "")
curl_add_clang_tidy_test_target("${BUNDLE}-clang-tidy" ${BUNDLE} ${FIRST_C} ${TESTS_C})
if(TARGET "${BUNDLE}-clang-tidy")
add_dependencies("${BUNDLE}-clang-tidy" curlu-unitprotos)
endif()
+92
View File
@@ -0,0 +1,92 @@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
#
# SPDX-License-Identifier: curl
#
###########################################################################
AUTOMAKE_OPTIONS = foreign nostdinc
# Specify our include paths here, and do it relative to $(top_srcdir) and
# $(top_builddir), to ensure that these paths which belong to the library
# being currently built and tested are searched before the library which
# might possibly already be installed in the system.
#
# $(top_srcdir)/include is for libcurl's external include files
# $(top_builddir)/lib is for libcurl's generated lib/curl_config.h file
# $(top_srcdir)/lib for libcurl's lib/curl_setup.h and other "borrowed" files
# $(srcdir) for the generated bundle source to find included test sources
AM_CPPFLAGS = -I$(top_srcdir)/include \
-I$(top_builddir)/lib \
-I$(top_srcdir)/lib \
-I$(top_srcdir)/tests/libtest \
-I$(srcdir)
# Get BUNDLE, FIRST_C, TESTS_C variables
include Makefile.inc
EXTRA_DIST = CMakeLists.txt README.md $(TESTS_C)
CFLAGS += @CURL_CFLAG_EXTRAS@
# Prevent LIBS from being used for all link targets
LIBS = $(BLANK_AT_MAKETIME)
AM_CPPFLAGS += -DCURL_STATICLIB -DUNITTESTS
if DEBUGBUILD
AM_CPPFLAGS += -DDEBUGBUILD
endif
if CURLDEBUG
AM_CPPFLAGS += -DCURLDEBUG
endif
# unit tests are small pretend-libcurl-programs, pass BUILDING_LIBCURL to reflect that
AM_CPPFLAGS += -DBUILDING_LIBCURL
if BUILD_UNITTESTS
$(BUNDLE).c: $(top_srcdir)/scripts/mk-unity.pl Makefile.inc $(FIRST_C) $(TESTS_C) $(top_builddir)/lib/unitprotos.h
@PERL@ $(top_srcdir)/scripts/mk-unity.pl --test $(TESTS_C) > $(BUNDLE).c
$(top_builddir)/lib/unitprotos.h:
(cd $(top_builddir)/lib && $(MAKE) unitprotos.h)
noinst_PROGRAMS = $(BUNDLE)
LDADD = $(top_builddir)/lib/libcurlu.la
CLEANFILES = $(BUNDLE).c
else
noinst_PROGRAMS =
endif
CHECKSRC = $(CS_$(V))
CS_0 = @echo " RUN " $@;
CS_1 =
CS_ = $(CS_0)
# ignore generated C files since they play by slightly different rules!
checksrc:
$(CHECKSRC)(@PERL@ $(top_srcdir)/scripts/checksrc.pl -D$(srcdir) \
-W$(srcdir)/$(BUNDLE).c \
$(srcdir)/*.[ch])
if NOT_CURL_CI
all-local: checksrc
endif
clean-local:
rm -f $(BUNDLE)
+782
View File
@@ -0,0 +1,782 @@
# Makefile.in generated by automake 1.16.5 from Makefile.am.
# @configure_input@
# Copyright (C) 1994-2021 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
@SET_MAKE@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
#
# SPDX-License-Identifier: curl
#
###########################################################################
# Shared between CMakeLists.txt and Makefile.am
VPATH = @srcdir@
am__is_gnu_make = { \
if test -z '$(MAKELEVEL)'; then \
false; \
elif test -n '$(MAKE_HOST)'; then \
true; \
elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
true; \
else \
false; \
fi; \
}
am__make_running_with_option = \
case $${target_option-} in \
?) ;; \
*) echo "am__make_running_with_option: internal error: invalid" \
"target option '$${target_option-}' specified" >&2; \
exit 1;; \
esac; \
has_opt=no; \
sane_makeflags=$$MAKEFLAGS; \
if $(am__is_gnu_make); then \
sane_makeflags=$$MFLAGS; \
else \
case $$MAKEFLAGS in \
*\\[\ \ ]*) \
bs=\\; \
sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
| sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
esac; \
fi; \
skip_next=no; \
strip_trailopt () \
{ \
flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
}; \
for flg in $$sane_makeflags; do \
test $$skip_next = yes && { skip_next=no; continue; }; \
case $$flg in \
*=*|--*) continue;; \
-*I) strip_trailopt 'I'; skip_next=yes;; \
-*I?*) strip_trailopt 'I';; \
-*O) strip_trailopt 'O'; skip_next=yes;; \
-*O?*) strip_trailopt 'O';; \
-*l) strip_trailopt 'l'; skip_next=yes;; \
-*l?*) strip_trailopt 'l';; \
-[dEDm]) skip_next=yes;; \
-[JT]) skip_next=yes;; \
esac; \
case $$flg in \
*$$target_option*) has_opt=yes; break;; \
esac; \
done; \
test $$has_opt = yes
am__make_dryrun = (target_option=n; $(am__make_running_with_option))
am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
pkglibdir = $(libdir)/@PACKAGE@
pkglibexecdir = $(libexecdir)/@PACKAGE@
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
install_sh_DATA = $(install_sh) -c -m 644
install_sh_PROGRAM = $(install_sh) -c
install_sh_SCRIPT = $(install_sh) -c
INSTALL_HEADER = $(INSTALL_DATA)
transform = $(program_transform_name)
NORMAL_INSTALL = :
PRE_INSTALL = :
POST_INSTALL = :
NORMAL_UNINSTALL = :
PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
@DEBUGBUILD_TRUE@am__append_1 = -DDEBUGBUILD
@CURLDEBUG_TRUE@am__append_2 = -DCURLDEBUG
@BUILD_UNITTESTS_TRUE@noinst_PROGRAMS = $(am__EXEEXT_1)
subdir = tests/unit
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/curl-amissl.m4 \
$(top_srcdir)/m4/curl-apple-sectrust.m4 \
$(top_srcdir)/m4/curl-compilers.m4 \
$(top_srcdir)/m4/curl-confopts.m4 \
$(top_srcdir)/m4/curl-functions.m4 \
$(top_srcdir)/m4/curl-gnutls.m4 \
$(top_srcdir)/m4/curl-mbedtls.m4 \
$(top_srcdir)/m4/curl-openssl.m4 \
$(top_srcdir)/m4/curl-override.m4 \
$(top_srcdir)/m4/curl-reentrant.m4 \
$(top_srcdir)/m4/curl-rustls.m4 \
$(top_srcdir)/m4/curl-schannel.m4 \
$(top_srcdir)/m4/curl-sysconfig.m4 \
$(top_srcdir)/m4/curl-wolfssl.m4 $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/xc-am-iface.m4 \
$(top_srcdir)/m4/xc-cc-check.m4 \
$(top_srcdir)/m4/xc-lt-iface.m4 \
$(top_srcdir)/m4/xc-val-flgs.m4 \
$(top_srcdir)/m4/zz40-xc-ovr.m4 \
$(top_srcdir)/m4/zz50-xc-ovr.m4 \
$(top_srcdir)/m4/zz60-xc-ovr.m4 $(top_srcdir)/acinclude.m4 \
$(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON)
mkinstalldirs = $(install_sh) -d
CONFIG_HEADER = $(top_builddir)/lib/curl_config.h
CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES =
am__EXEEXT_1 = units$(EXEEXT)
PROGRAMS = $(noinst_PROGRAMS)
units_SOURCES = units.c
units_OBJECTS = units.$(OBJEXT)
units_LDADD = $(LDADD)
@BUILD_UNITTESTS_TRUE@units_DEPENDENCIES = \
@BUILD_UNITTESTS_TRUE@ $(top_builddir)/lib/libcurlu.la
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent
am__v_lt_1 =
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
am__v_P_1 = :
AM_V_GEN = $(am__v_GEN_@AM_V@)
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
am__v_GEN_0 = @echo " GEN " $@;
am__v_GEN_1 =
AM_V_at = $(am__v_at_@AM_V@)
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
am__v_at_0 = @
am__v_at_1 =
DEFAULT_INCLUDES =
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__maybe_remake_depfiles = depfiles
am__depfiles_remade = ./$(DEPDIR)/units.Po
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
$(AM_CFLAGS) $(CFLAGS)
AM_V_CC = $(am__v_CC_@AM_V@)
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
am__v_CC_0 = @echo " CC " $@;
am__v_CC_1 =
CCLD = $(CC)
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
AM_V_CCLD = $(am__v_CCLD_@AM_V@)
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
SOURCES = units.c
DIST_SOURCES = units.c
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
*) (install-info --version) >/dev/null 2>&1;; \
esac
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
# Read a list of newline-separated strings from the standard input,
# and print each of them once, without duplicates. Input order is
# *not* preserved.
am__uniquify_input = $(AWK) '\
BEGIN { nonempty = 0; } \
{ items[$$0] = 1; nonempty = 1; } \
END { if (nonempty) { for (i in items) print i; }; } \
'
# Make sure the list of sources is unique. This is necessary because,
# e.g., the same source file might be shared among _SOURCES variables
# for different programs/libraries.
am__define_uniq_tagged_files = \
list='$(am__tagged_files)'; \
unique=`for i in $$list; do \
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
done | $(am__uniquify_input)`
am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.inc \
$(top_srcdir)/depcomp README.md
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
APXS = @APXS@
AR = @AR@
AR_FLAGS = @AR_FLAGS@
AS = @AS@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
AUTOMAKE = @AUTOMAKE@
AWK = @AWK@
BLANK_AT_MAKETIME = @BLANK_AT_MAKETIME@
CADDY = @CADDY@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@ @CURL_CFLAG_EXTRAS@
CFLAG_CURL_SYMBOL_HIDING = @CFLAG_CURL_SYMBOL_HIDING@
CONFIGURE_OPTIONS = @CONFIGURE_OPTIONS@
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
CSCOPE = @CSCOPE@
CTAGS = @CTAGS@
CURLVERSION = @CURLVERSION@
CURL_CA_BUNDLE = @CURL_CA_BUNDLE@
CURL_CA_EMBED = @CURL_CA_EMBED@
CURL_CFLAG_EXTRAS = @CURL_CFLAG_EXTRAS@
CURL_CPP = @CURL_CPP@
CURL_LIBCURL_VERSIONED_SYMBOLS_PREFIX = @CURL_LIBCURL_VERSIONED_SYMBOLS_PREFIX@
CURL_LIBCURL_VERSIONED_SYMBOLS_SONAME = @CURL_LIBCURL_VERSIONED_SYMBOLS_SONAME@
CURL_NETWORK_AND_TIME_LIBS = @CURL_NETWORK_AND_TIME_LIBS@
CYGPATH_W = @CYGPATH_W@
DANTED = @DANTED@
DEFS = @DEFS@
DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
DSYMUTIL = @DSYMUTIL@
DUMPBIN = @DUMPBIN@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
ECHO_T = @ECHO_T@
EGREP = @EGREP@
ENABLE_SHARED = @ENABLE_SHARED@
ENABLE_STATIC = @ENABLE_STATIC@
ETAGS = @ETAGS@
EXEEXT = @EXEEXT@
FGREP = @FGREP@
FILECMD = @FILECMD@
FISH_FUNCTIONS_DIR = @FISH_FUNCTIONS_DIR@
GCOV = @GCOV@
GREP = @GREP@
HAVE_LIBZ = @HAVE_LIBZ@
HTTPD = @HTTPD@
HTTPD_NGHTTPX = @HTTPD_NGHTTPX@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
LCOV = @LCOV@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBCURL_PC_CFLAGS = @LIBCURL_PC_CFLAGS@
LIBCURL_PC_CFLAGS_PRIVATE = @LIBCURL_PC_CFLAGS_PRIVATE@
LIBCURL_PC_LDFLAGS_PRIVATE = @LIBCURL_PC_LDFLAGS_PRIVATE@
LIBCURL_PC_LIBS = @LIBCURL_PC_LIBS@
LIBCURL_PC_LIBS_PRIVATE = @LIBCURL_PC_LIBS_PRIVATE@
LIBCURL_PC_REQUIRES = @LIBCURL_PC_REQUIRES@
LIBCURL_PC_REQUIRES_PRIVATE = @LIBCURL_PC_REQUIRES_PRIVATE@
LIBOBJS = @LIBOBJS@
# Prevent LIBS from being used for all link targets
LIBS = $(BLANK_AT_MAKETIME)
LIBTOOL = @LIBTOOL@
LIPO = @LIPO@
LN_S = @LN_S@
LTLIBOBJS = @LTLIBOBJS@
LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
MAINT = @MAINT@
MAKEINFO = @MAKEINFO@
MANIFEST_TOOL = @MANIFEST_TOOL@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OTOOL = @OTOOL@
OTOOL64 = @OTOOL64@
PACKAGE = @PACKAGE@
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_STRING = @PACKAGE_STRING@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
PACKAGE_URL = @PACKAGE_URL@
PACKAGE_VERSION = @PACKAGE_VERSION@
PATH_SEPARATOR = @PATH_SEPARATOR@
PERL = @PERL@
PKGCONFIG = @PKGCONFIG@
RANLIB = @RANLIB@
RC = @RC@
SED = @SED@
SET_MAKE = @SET_MAKE@
SHELL = @SHELL@
SSL_BACKENDS = @SSL_BACKENDS@
STRIP = @STRIP@
SUPPORT_FEATURES = @SUPPORT_FEATURES@
SUPPORT_PROTOCOLS = @SUPPORT_PROTOCOLS@
TEST_NGHTTPX = @TEST_NGHTTPX@
VERSION = @VERSION@
VERSIONNUM = @VERSIONNUM@
VSFTPD = @VSFTPD@
ZLIB_LIBS = @ZLIB_LIBS@
ZSH_FUNCTIONS_DIR = @ZSH_FUNCTIONS_DIR@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@
ac_ct_AR = @ac_ct_AR@
ac_ct_CC = @ac_ct_CC@
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
am__include = @am__include@
am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
am__tar = @am__tar@
am__untar = @am__untar@
bindir = @bindir@
build = @build@
build_alias = @build_alias@
build_cpu = @build_cpu@
build_os = @build_os@
build_vendor = @build_vendor@
builddir = @builddir@
datadir = @datadir@
datarootdir = @datarootdir@
docdir = @docdir@
dvidir = @dvidir@
exec_prefix = @exec_prefix@
host = @host@
host_alias = @host_alias@
host_cpu = @host_cpu@
host_os = @host_os@
host_vendor = @host_vendor@
htmldir = @htmldir@
includedir = @includedir@
infodir = @infodir@
install_sh = @install_sh@
libdir = @libdir@
libexecdir = @libexecdir@
libext = @libext@
localedir = @localedir@
localstatedir = @localstatedir@
mandir = @mandir@
mkdir_p = @mkdir_p@
oldincludedir = @oldincludedir@
pdfdir = @pdfdir@
prefix = @prefix@
program_transform_name = @program_transform_name@
psdir = @psdir@
runstatedir = @runstatedir@
sbindir = @sbindir@
sharedstatedir = @sharedstatedir@
srcdir = @srcdir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
#
# SPDX-License-Identifier: curl
#
###########################################################################
AUTOMAKE_OPTIONS = foreign nostdinc
# Specify our include paths here, and do it relative to $(top_srcdir) and
# $(top_builddir), to ensure that these paths which belong to the library
# being currently built and tested are searched before the library which
# might possibly already be installed in the system.
#
# $(top_srcdir)/include is for libcurl's external include files
# $(top_builddir)/lib is for libcurl's generated lib/curl_config.h file
# $(top_srcdir)/lib for libcurl's lib/curl_setup.h and other "borrowed" files
# $(srcdir) for the generated bundle source to find included test sources
# unit tests are small pretend-libcurl-programs, pass BUILDING_LIBCURL to reflect that
AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/lib \
-I$(top_srcdir)/lib -I$(top_srcdir)/tests/libtest -I$(srcdir) \
-DCURL_STATICLIB -DUNITTESTS $(am__append_1) $(am__append_2) \
-DBUILDING_LIBCURL
BUNDLE = units
# Files referenced from the bundle source
FIRST_C = ../libtest/first.c
# All unit test programs
TESTS_C = \
unit1300.c unit1302.c unit1303.c unit1304.c unit1305.c \
unit1307.c unit1309.c \
unit1323.c unit1330.c \
unit1395.c unit1396.c unit1397.c unit1398.c unit1399.c \
unit1600.c unit1601.c unit1602.c unit1603.c unit1605.c unit1606.c \
unit1607.c unit1608.c unit1609.c unit1610.c unit1611.c unit1612.c unit1614.c \
unit1615.c unit1616.c unit1620.c \
unit1650.c unit1651.c unit1652.c unit1653.c unit1654.c unit1655.c unit1656.c \
unit1657.c unit1658.c unit1660.c unit1661.c unit1663.c unit1664.c \
unit1979.c unit1980.c \
unit2600.c unit2601.c unit2602.c unit2603.c unit2604.c \
unit3200.c unit3205.c \
unit3211.c unit3212.c unit3213.c unit3214.c
# Get BUNDLE, FIRST_C, TESTS_C variables
EXTRA_DIST = CMakeLists.txt README.md $(TESTS_C)
@BUILD_UNITTESTS_TRUE@LDADD = $(top_builddir)/lib/libcurlu.la
@BUILD_UNITTESTS_TRUE@CLEANFILES = $(BUNDLE).c
CHECKSRC = $(CS_$(V))
CS_0 = @echo " RUN " $@;
CS_1 =
CS_ = $(CS_0)
all: all-am
.SUFFIXES:
.SUFFIXES: .c .lo .o .obj
$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(srcdir)/Makefile.inc $(am__configure_deps)
@for dep in $?; do \
case '$(am__configure_deps)' in \
*$$dep*) \
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
&& { if test -f $@; then exit 0; else break; fi; }; \
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign tests/unit/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --foreign tests/unit/Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \
*config.status*) \
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
*) \
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \
esac;
$(srcdir)/Makefile.inc $(am__empty):
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
$(am__aclocal_m4_deps):
clean-noinstPROGRAMS:
@list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \
echo " rm -f" $$list; \
rm -f $$list || exit $$?; \
test -n "$(EXEEXT)" || exit 0; \
list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
echo " rm -f" $$list; \
rm -f $$list
units$(EXEEXT): $(units_OBJECTS) $(units_DEPENDENCIES) $(EXTRA_units_DEPENDENCIES)
@rm -f units$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(units_OBJECTS) $(units_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/units.Po@am__quote@ # am--include-marker
$(am__depfiles_remade):
@$(MKDIR_P) $(@D)
@echo '# dummy' >$@-t && $(am__mv) $@-t $@
am--depfiles: $(am__depfiles_remade)
.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
.c.obj:
@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\
@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
.c.lo:
@am__fastdepCC_TRUE@ $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\
@am__fastdepCC_TRUE@ $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\
@am__fastdepCC_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
mostlyclean-libtool:
-rm -f *.lo
clean-libtool:
-rm -rf .libs _libs
ID: $(am__tagged_files)
$(am__define_uniq_tagged_files); mkid -fID $$unique
tags: tags-am
TAGS: tags
tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
set x; \
here=`pwd`; \
$(am__define_uniq_tagged_files); \
shift; \
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
test -n "$$unique" || unique=$$empty_fix; \
if test $$# -gt 0; then \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
"$$@" $$unique; \
else \
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
$$unique; \
fi; \
fi
ctags: ctags-am
CTAGS: ctags
ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
$(am__define_uniq_tagged_files); \
test -z "$(CTAGS_ARGS)$$unique" \
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
$$unique
GTAGS:
here=`$(am__cd) $(top_builddir) && pwd` \
&& $(am__cd) $(top_srcdir) \
&& gtags -i $(GTAGS_ARGS) "$$here"
cscopelist: cscopelist-am
cscopelist-am: $(am__tagged_files)
list='$(am__tagged_files)'; \
case "$(srcdir)" in \
[\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
*) sdir=$(subdir)/$(srcdir) ;; \
esac; \
for i in $$list; do \
if test -f "$$i"; then \
echo "$(subdir)/$$i"; \
else \
echo "$$sdir/$$i"; \
fi; \
done >> $(top_builddir)/cscope.files
distclean-tags:
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
distdir: $(BUILT_SOURCES)
$(MAKE) $(AM_MAKEFLAGS) distdir-am
distdir-am: $(DISTFILES)
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
list='$(DISTFILES)'; \
dist_files=`for file in $$list; do echo $$file; done | \
sed -e "s|^$$srcdirstrip/||;t" \
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
case $$dist_files in \
*/*) $(MKDIR_P) `echo "$$dist_files" | \
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
sort -u` ;; \
esac; \
for file in $$dist_files; do \
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
if test -d $$d/$$file; then \
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
if test -d "$(distdir)/$$file"; then \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
fi; \
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
else \
test -f "$(distdir)/$$file" \
|| cp -p $$d/$$file "$(distdir)/$$file" \
|| exit 1; \
fi; \
done
check-am: all-am
check: check-am
@NOT_CURL_CI_FALSE@all-local:
all-am: Makefile $(PROGRAMS) all-local
installdirs:
install: install-am
install-exec: install-exec-am
install-data: install-data-am
uninstall: uninstall-am
install-am: all-am
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
installcheck: installcheck-am
install-strip:
if test -z '$(STRIP)'; then \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
install; \
else \
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
fi
mostlyclean-generic:
clean-generic:
-test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
distclean-generic:
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
maintainer-clean-generic:
@echo "This command is intended for maintainers to use"
@echo "it deletes files that may require special tools to rebuild."
clean: clean-am
clean-am: clean-generic clean-libtool clean-local clean-noinstPROGRAMS \
mostlyclean-am
distclean: distclean-am
-rm -f ./$(DEPDIR)/units.Po
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
dvi: dvi-am
dvi-am:
html: html-am
html-am:
info: info-am
info-am:
install-data-am:
install-dvi: install-dvi-am
install-dvi-am:
install-exec-am:
install-html: install-html-am
install-html-am:
install-info: install-info-am
install-info-am:
install-man:
install-pdf: install-pdf-am
install-pdf-am:
install-ps: install-ps-am
install-ps-am:
installcheck-am:
maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/units.Po
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic
mostlyclean: mostlyclean-am
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
mostlyclean-libtool
pdf: pdf-am
pdf-am:
ps: ps-am
ps-am:
uninstall-am:
.MAKE: install-am install-strip
.PHONY: CTAGS GTAGS TAGS all all-am all-local am--depfiles check \
check-am clean clean-generic clean-libtool clean-local \
clean-noinstPROGRAMS cscopelist-am ctags ctags-am distclean \
distclean-compile distclean-generic distclean-libtool \
distclean-tags distdir dvi dvi-am html html-am info info-am \
install install-am install-data install-data-am install-dvi \
install-dvi-am install-exec install-exec-am install-html \
install-html-am install-info install-info-am install-man \
install-pdf install-pdf-am install-ps install-ps-am \
install-strip installcheck installcheck-am installdirs \
maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am
.PRECIOUS: Makefile
@BUILD_UNITTESTS_TRUE@$(BUNDLE).c: $(top_srcdir)/scripts/mk-unity.pl Makefile.inc $(FIRST_C) $(TESTS_C) $(top_builddir)/lib/unitprotos.h
@BUILD_UNITTESTS_TRUE@ @PERL@ $(top_srcdir)/scripts/mk-unity.pl --test $(TESTS_C) > $(BUNDLE).c
@BUILD_UNITTESTS_TRUE@$(top_builddir)/lib/unitprotos.h:
@BUILD_UNITTESTS_TRUE@ (cd $(top_builddir)/lib && $(MAKE) unitprotos.h)
# ignore generated C files since they play by slightly different rules!
checksrc:
$(CHECKSRC)(@PERL@ $(top_srcdir)/scripts/checksrc.pl -D$(srcdir) \
-W$(srcdir)/$(BUNDLE).c \
$(srcdir)/*.[ch])
@NOT_CURL_CI_TRUE@all-local: checksrc
clean-local:
rm -f $(BUNDLE)
# Tell versions [3.59,3.63) of GNU make to not export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
+45
View File
@@ -0,0 +1,45 @@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
#
# SPDX-License-Identifier: curl
#
###########################################################################
# Shared between CMakeLists.txt and Makefile.am
BUNDLE = units
# Files referenced from the bundle source
FIRST_C = ../libtest/first.c
# All unit test programs
TESTS_C = \
unit1300.c unit1302.c unit1303.c unit1304.c unit1305.c \
unit1307.c unit1309.c \
unit1323.c unit1330.c \
unit1395.c unit1396.c unit1397.c unit1398.c unit1399.c \
unit1600.c unit1601.c unit1602.c unit1603.c unit1605.c unit1606.c \
unit1607.c unit1608.c unit1609.c unit1610.c unit1611.c unit1612.c unit1614.c \
unit1615.c unit1616.c unit1620.c \
unit1650.c unit1651.c unit1652.c unit1653.c unit1654.c unit1655.c unit1656.c \
unit1657.c unit1658.c unit1660.c unit1661.c unit1663.c unit1664.c \
unit1979.c unit1980.c \
unit2600.c unit2601.c unit2602.c unit2603.c unit2604.c \
unit3200.c unit3205.c \
unit3211.c unit3212.c unit3213.c unit3214.c
+97
View File
@@ -0,0 +1,97 @@
<!--
Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
SPDX-License-Identifier: curl
-->
# Unit tests
The goal is to add tests for *all* functions in libcurl. If functions are too
big and complicated, we should split them into smaller and testable ones.
## Build Unit Tests
`./configure --enable-debug` is required for the unit tests to build. To
enable unit tests, there is a separate static libcurl built that is used
exclusively for linking unit test programs. Just build everything as normal,
and then you can run the unit test cases as well.
## Run Unit Tests
Unit tests are run as part of the regular test suite. If you have built
everything to run unit tests, to can do 'make test' at the root level. Or you
can `cd tests` and `make` and then invoke individual unit tests with
`./runtests.pl NNNN` where `NNNN` is the specific test number.
## Debug Unit Tests
If a specific test fails you get told. The test case then has output left in
the %LOGDIR subdirectory, but most importantly you can re-run the test again
using gdb by doing `./runtests.pl -g NNNN`. That is, add a `-g` to make it
start up gdb and run the same case using that.
## Write Unit Tests
We put tests that focus on an area or a specific function into a single C
source file. The source file should be named `unitNNNN.c` where `NNNN` is a
previously unused number.
Add your test to `tests/unit/Makefile.inc` (if it is a unit test). Add your
test data filename to `tests/data/Makefile.am`
You also need a separate file called `tests/data/testNNNN` (using the same
number) that describes your test case. See the test1300 file for inspiration
and the `tests/FILEFORMAT.md` documentation.
For the actual C file, here's a simple example:
~~~c
#include "unitcheck.h"
#include "a libcurl header.h" /* from the lib dir */
static CURLcode test_unit9998(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
/* here you start doing things and checking that the results are good */
fail_unless( size == 0 , "initial size should be zero" );
fail_if( head == NULL , "head should not be initiated to NULL" );
/* you end the test code like this: */
UNITTEST_END_SIMPLE
}
~~~
Here's an example using optional initialization and cleanup:
~~~c
#include "unitcheck.h"
#include "a libcurl header.h" /* from the lib dir */
static CURLcode t9999_setup(void)
{
/* whatever you want done first */
return CURLE_OK;
}
static void t9999_stop(void)
{
/* done before shutting down and exiting */
}
static CURLcode test_unit9999(const char *arg)
{
UNITTEST_BEGIN(t9999_setup())
/* here you start doing things and checking that the results are good */
fail_unless( size == 0 , "initial size should be zero" );
fail_if( head == NULL , "head should not be initiated to NULL" );
/* you end the test code like this: */
UNITTEST_END(t9999_stop())
}
~~~
+270
View File
@@ -0,0 +1,270 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "llist.h"
#include "unitprotos.h"
static void test_Curl_llist_dtor(void *key, void *value)
{
/* used by the llist API, does nothing here */
(void)key;
(void)value;
}
static CURLcode test_unit1300(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
struct Curl_llist llist;
struct Curl_llist llist_destination;
int unusedData_case1 = 1;
int unusedData_case2 = 2;
int unusedData_case3 = 3;
struct Curl_llist_node case1_list;
struct Curl_llist_node case2_list;
struct Curl_llist_node case3_list;
struct Curl_llist_node case4_list;
struct Curl_llist_node *head;
struct Curl_llist_node *element_next;
struct Curl_llist_node *element_prev;
struct Curl_llist_node *to_remove;
size_t llist_size;
Curl_llist_init(&llist, test_Curl_llist_dtor);
Curl_llist_init(&llist_destination, test_Curl_llist_dtor);
/**
* testing llist_init
* case 1:
* list initiation
* @assumptions:
* 1: list size will be 0
* 2: list head will be NULL
* 3: list tail will be NULL
* 4: list dtor will be NULL
*/
fail_unless(Curl_llist_count(&llist) == 0,
"list initial size should be zero");
fail_unless(Curl_llist_head(&llist) == NULL,
"list head should initiate to NULL");
fail_unless(Curl_llist_tail(&llist) == NULL,
"list tail should initiate to NULL");
/**
* testing Curl_llist_insert_next
* case 1:
* list is empty
* @assumptions:
* 1: list size will be 1
* 2: list head will hold the data "unusedData_case1"
* 3: list tail will be the same as list head
*/
Curl_llist_insert_next(&llist, Curl_llist_head(&llist), &unusedData_case1,
&case1_list);
fail_unless(Curl_llist_count(&llist) == 1,
"List size should be 1 after adding a new element");
/* test that the list head data holds my unusedData */
fail_unless(Curl_node_elem(Curl_llist_head(&llist)) == &unusedData_case1,
"head ptr should be first entry");
/* same goes for the list tail */
fail_unless(Curl_llist_tail(&llist) == Curl_llist_head(&llist),
"tail and head should be the same");
/**
* testing Curl_llist_insert_next
* case 2:
* list has 1 element, adding one element after the head
* @assumptions:
* 1: the element next to head should be our newly created element
* 2: the list tail should be our newly created element
*/
Curl_llist_insert_next(&llist, Curl_llist_head(&llist),
&unusedData_case3, &case3_list);
fail_unless(Curl_node_elem(Curl_node_next(Curl_llist_head(&llist))) ==
&unusedData_case3,
"the node next to head is not getting set correctly");
fail_unless(Curl_node_elem(Curl_llist_tail(&llist)) == &unusedData_case3,
"the list tail is not getting set correctly");
/**
* testing Curl_llist_insert_next
* case 3:
* list has >1 element, adding one element after "NULL"
* @assumptions:
* 1: the element next to head should be our newly created element
* 2: the list tail should different from newly created element
*/
Curl_llist_insert_next(&llist, Curl_llist_head(&llist),
&unusedData_case2, &case2_list);
fail_unless(Curl_node_elem(Curl_node_next(Curl_llist_head(&llist))) ==
&unusedData_case2,
"the node next to head is not getting set correctly");
/* better safe than sorry, check that the tail isn't corrupted */
fail_unless(Curl_node_elem(Curl_llist_tail(&llist)) != &unusedData_case2,
"the list tail is not getting set correctly");
/* unit tests for Curl_node_remove */
/**
* case 1:
* list has >1 element, removing head
* @assumptions:
* 1: list size will be decremented by one
* 2: head will be the head->next
* 3: "new" head's previous will be NULL
*/
head = Curl_llist_head(&llist);
abort_unless(head, "llist.head is NULL");
element_next = Curl_node_next(head);
llist_size = Curl_llist_count(&llist);
Curl_node_remove(Curl_llist_head(&llist));
fail_unless(Curl_llist_count(&llist) == (llist_size-1),
"llist size not decremented as expected");
fail_unless(Curl_llist_head(&llist) == element_next,
"llist new head not modified properly");
abort_unless(Curl_llist_head(&llist), "llist.head is NULL");
fail_unless(Curl_node_prev(Curl_llist_head(&llist)) == NULL,
"new head previous not set to null");
/**
* case 2:
* removing non head element, with list having >=2 elements
* @setup:
* 1: insert another element to the list to make element >=2
* @assumptions:
* 1: list size will be decremented by one ; tested
* 2: element->previous->next will be element->next
* 3: element->next->previous will be element->previous
*/
Curl_llist_insert_next(&llist, Curl_llist_head(&llist), &unusedData_case3,
&case4_list);
llist_size = Curl_llist_count(&llist);
fail_unless(llist_size == 3, "should be 3 list members");
to_remove = Curl_node_next(Curl_llist_head(&llist));
abort_unless(to_remove, "to_remove is NULL");
element_next = Curl_node_next(to_remove);
element_prev = Curl_node_prev(to_remove);
Curl_node_uremove(to_remove, NULL);
fail_unless(Curl_node_next(element_prev) == element_next,
"element previous->next is not being adjusted");
abort_unless(element_next, "element_next is NULL");
fail_unless(Curl_node_prev(element_next) == element_prev,
"element next->previous is not being adjusted");
/**
* case 3:
* removing the tail with list having >=1 element
* @assumptions
* 1: list size will be decremented by one ;tested
* 2: element->previous->next will be element->next ;tested
* 3: element->next->previous will be element->previous ;tested
* 4: list->tail will be tail->previous
*/
to_remove = Curl_llist_tail(&llist);
element_prev = Curl_node_prev(to_remove);
Curl_node_remove(to_remove);
fail_unless(Curl_llist_tail(&llist) == element_prev,
"llist tail is not being adjusted when removing tail");
/**
* case 4:
* removing head with list having 1 element
* @assumptions:
* 1: list size will be decremented by one ;tested
* 2: list head will be null
* 3: list tail will be null
*/
to_remove = Curl_llist_head(&llist);
Curl_node_remove(to_remove);
fail_unless(Curl_llist_head(&llist) == NULL,
"llist head is not NULL while the llist is empty");
fail_unless(Curl_llist_tail(&llist) == NULL,
"llist tail is not NULL while the llist is empty");
/**
* testing Curl_llist_append
* case 1:
* list is empty
* @assumptions:
* 1: the element next to head should be our newly created element
* 2: the list tail should different from newly created element
*/
Curl_llist_append(&llist, &unusedData_case1, &case1_list);
fail_unless(Curl_llist_count(&llist) == 1,
"List size should be 1 after appending a new element");
/* test that the list head data holds my unusedData */
fail_unless(Curl_node_elem(Curl_llist_head(&llist)) == &unusedData_case1,
"head ptr should be first entry");
/* same goes for the list tail */
fail_unless(Curl_llist_tail(&llist) == Curl_llist_head(&llist),
"tail and head should be the same");
/**
* testing Curl_llist_append
* case 2:
* list is not empty
* @assumptions:
* 1: the list head-next should be the newly created element
* 2: the list tail should be the newly created element
*/
Curl_llist_append(&llist, &unusedData_case2, &case2_list);
fail_unless(Curl_node_elem(Curl_node_next(Curl_llist_head(&llist))) ==
&unusedData_case2,
"the node next to head is not getting set correctly");
fail_unless(Curl_node_elem(Curl_llist_tail(&llist)) == &unusedData_case2,
"the list tail is not getting set correctly");
/**
* testing Curl_llist_append
* case 3:
* list is has 2 members
* @assumptions:
* 1: the list head-next should remain the same
* 2: the list tail should be the newly created element
*/
Curl_llist_append(&llist, &unusedData_case3, &case3_list);
fail_unless(Curl_node_elem(Curl_node_next(Curl_llist_head(&llist))) ==
&unusedData_case2,
"the node next to head did not stay the same");
fail_unless(Curl_node_elem(Curl_llist_tail(&llist)) == &unusedData_case3,
"the list tail is not getting set correctly");
Curl_llist_destroy(&llist, NULL);
Curl_llist_destroy(&llist_destination, NULL);
UNITTEST_END_SIMPLE
}
+199
View File
@@ -0,0 +1,199 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "url.h" /* for Curl_safefree */
#include "memdebug.h" /* LAST include file */
struct etest {
const char *input;
size_t ilen;
const char *output;
size_t olen;
};
static CURLcode test_unit1302(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
CURLcode rc;
unsigned int i;
/* common base64 encoding */
struct etest encode[] = {
{"iiiiii", 1, "aQ==", 4 },
{"iiiiii", 2, "aWk=", 4 },
{"iiiiii", 3, "aWlp", 4 },
{"iiiiii", 4, "aWlpaQ==", 8 },
{"iiiiii", 5, "aWlpaWk=", 8 },
{"iiiiii", 6, "aWlpaWlp", 8 },
{"iiiiiii", 7, "aWlpaWlpaQ==", 12 },
{"iiiiiiii", 8, "aWlpaWlpaWk=", 12 },
{"iiiiiiiii", 9, "aWlpaWlpaWlp", 12 },
{"iiiiiiiiii", 10, "aWlpaWlpaWlpaQ==", 16 },
{"iiiiiiiiiii", 11, "aWlpaWlpaWlpaWk=", 16 },
{"iiiiiiiiiiii", 12, "aWlpaWlpaWlpaWlp", 16 },
{"\xff\x01\xfe\x02", 4, "/wH+Ag==", 8 },
{"\xff\xff\xff\xff", 4, "/////w==", 8 },
{"\x00\x00\x00\x00", 4, "AAAAAA==", 8 },
{"\x00\x00\x00\x00", 1, "AA==", 4 },
};
/* base64 URL encoding */
struct etest url[] = {
{"", 0, "", 0 },
{"iiiiiiiiiii", 1, "aQ", 2 },
{"iiiiiiiiiii", 2, "aWk", 3 },
{"iiiiiiiiiii", 3, "aWlp", 4 },
{"iiiiiiiiiii", 4, "aWlpaQ", 6 },
{"iiiiiiiiiii", 5, "aWlpaWk", 7 },
{"iiiiiiiiiii", 6, "aWlpaWlp", 8 },
{"iiiiiiiiiii", 7, "aWlpaWlpaQ", 10 },
{"iiiiiiiiiii", 8, "aWlpaWlpaWk", 11 },
{"iiiiiiiiiii", 9, "aWlpaWlpaWlp", 12 },
{"iiiiiiiiiii", 10, "aWlpaWlpaWlpaQ", 14 },
{"iiiiiiiiiii", 11, "aWlpaWlpaWlpaWk", 15 },
{"iiiiiiiiiiii", 12, "aWlpaWlpaWlpaWlp", 16 },
{"\xff\x01\xfe\x02", 4, "_wH-Ag", 6 },
{"\xff\xff\xff\xff", 4, "_____w", 6 },
{"\xff\x00\xff\x00", 4, "_wD_AA", 6 },
{"\x00\xff\x00\xff", 4, "AP8A_w", 6 },
{"\x00\x00\x00\x00", 4, "AAAAAA", 6 },
{"\x00", 1, "AA", 2 },
{"\x01", 1, "AQ", 2 },
{"\x02", 1, "Ag", 2 },
{"\x03", 1, "Aw", 2 },
{"\x04", 1, "BA", 2 }, /* spellchecker:disable-line */
{"\x05", 1, "BQ", 2 },
{"\x06", 1, "Bg", 2 },
{"\x07", 1, "Bw", 2 },
{"\x08", 1, "CA", 2 },
{"\x09", 1, "CQ", 2 },
{"\x0a", 1, "Cg", 2 },
{"\x0b", 1, "Cw", 2 },
{"\x0c", 1, "DA", 2 },
{"\x0d", 1, "DQ", 2 },
{"\x0e", 1, "Dg", 2 },
{"\x0f", 1, "Dw", 2 },
{"\x10", 1, "EA", 2 },
};
/* bad decode inputs */
struct etest badecode[] = {
{"", 0, "", 0 }, /* no dats means error */
{"", 0, "a", 1 }, /* data is too short */
{"", 0, "aQ", 2 }, /* data is too short */
{"", 0, "aQ=", 3 }, /* data is too short */
{"", 0, "====", 1 }, /* data is only padding characters */
{"", 0, "====", 2 }, /* data is only padding characters */
{"", 0, "====", 3 }, /* data is only padding characters */
{"", 0, "====", 4 }, /* data is only padding characters */
{"", 0, "a===", 4 }, /* contains three padding characters */
{"", 0, "a=Q=", 4 }, /* contains a padding character mid input */
{"", 0, "aWlpa=Q=", 8 }, /* contains a padding character mid input */
{"", 0, "a\x1f==", 4 }, /* contains illegal base64 character */
{"", 0, "abcd ", 5 }, /* contains illegal base64 character */
{"", 0, "abcd ", 6 }, /* contains illegal base64 character */
{"", 0, " abcd", 5 }, /* contains illegal base64 character */
{"", 0, "_abcd", 5 }, /* contains illegal base64 character */
{"", 0, "abcd-", 5 }, /* contains illegal base64 character */
{"", 0, "abcd_", 5 }, /* contains illegal base64 character */
{"", 0, "aWlpaWlpaQ==-", 17}, /* bad character after padding */
{"", 0, "aWlpaWlpaQ==_", 17}, /* bad character after padding */
{"", 0, "aWlpaWlpaQ== ", 17}, /* bad character after padding */
{"", 0, "aWlpaWlpaQ=", 15} /* unaligned size, missing a padding char */
};
for(i = 0 ; i < CURL_ARRAYSIZE(encode); i++) {
struct etest *e = &encode[i];
char *out;
unsigned char *decoded;
size_t olen;
size_t dlen;
/* first encode */
rc = curlx_base64_encode(e->input, e->ilen, &out, &olen);
abort_unless(rc == CURLE_OK, "return code should be CURLE_OK");
abort_unless(olen == e->olen, "wrong output size");
if(memcmp(out, e->output, e->olen)) {
curl_mfprintf(stderr, "Test %u encoded badly\n", i);
unitfail++;
}
Curl_safefree(out);
/* then verify decode */
rc = curlx_base64_decode(e->output, &decoded, &dlen);
if(rc != CURLE_OK) {
curl_mfprintf(stderr, "Test %u URL decode returned %d\n", i, (int)rc);
unitfail++;
}
if(dlen != e->ilen) {
curl_mfprintf(stderr, "Test %u URL decode output length %zu "
"instead of %zu\n", i, dlen, e->ilen);
unitfail++;
}
if(memcmp(decoded, e->input, dlen)) {
curl_mfprintf(stderr, "Test %u URL decoded badly. Got '%s', "
"expected '%s'\n", i, decoded, e->input);
unitfail++;
}
Curl_safefree(decoded);
}
for(i = 0 ; i < CURL_ARRAYSIZE(url); i++) {
struct etest *e = &url[i];
char *out;
size_t olen;
rc = curlx_base64url_encode(e->input, e->ilen, &out, &olen);
abort_unless(rc == CURLE_OK, "return code should be CURLE_OK");
if(olen != e->olen) {
curl_mfprintf(stderr, "Test %u URL encoded output length %zu "
"instead of %zu\n", i, olen, e->olen);
}
if(out && memcmp(out, e->output, e->olen)) {
curl_mfprintf(stderr, "Test %u URL encoded badly. Got '%s', "
"expected '%s'\n", i, out, e->output);
unitfail++;
}
Curl_safefree(out);
}
for(i = 0 ; i < CURL_ARRAYSIZE(badecode); i++) {
struct etest *e = &badecode[i];
unsigned char *decoded;
size_t dlen;
/* then verify decode with illegal inputs */
rc = curlx_base64_decode(e->output, &decoded, &dlen);
if(rc != CURLE_BAD_CONTENT_ENCODING) {
curl_mfprintf(stderr, "Test %u URL bad decoded badly. "
"Returned '%d', expected '%d'\n",
i, (int)rc, CURLE_BAD_CONTENT_ENCODING);
unitfail++;
}
}
UNITTEST_END_SIMPLE
}
+157
View File
@@ -0,0 +1,157 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "connect.h"
#include "memdebug.h" /* LAST include file */
static CURLcode t1303_setup(struct Curl_easy **easy)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
*easy = curl_easy_init();
if(!*easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
return res;
}
static void t1303_stop(struct Curl_easy *easy)
{
curl_easy_cleanup(easy);
curl_global_cleanup();
}
/* BASE is just a define to make us fool around with decently large number so
that we aren't zero-based */
#define BASE 1000000
/* macro to set the pretended current time */
#define NOW(x,y) now.tv_sec = x; now.tv_usec = y
/* macro to set the millisecond based timeouts to use */
#define TIMEOUTS(x,y) easy->set.timeout = x; \
easy->set.connecttimeout = y
/*
* To test:
*
* 00/10/01/11 timeouts set
* 0/1 during connect
* T various values on the timeouts
* N various values of now
*/
static CURLcode test_unit1303(const char *arg)
{
struct Curl_easy *easy;
UNITTEST_BEGIN(t1303_setup(&easy))
struct curltime now;
unsigned int i;
struct timetest {
int now_s;
int now_us;
unsigned int timeout_ms;
unsigned int connecttimeout_ms;
bool connecting;
timediff_t result;
const char *comment;
};
const struct timetest run[] = {
/* both timeouts set, not connecting */
{BASE + 4, 0, 10000, 8000, FALSE, 6000, "6 seconds should be left"},
{BASE + 4, 990000, 10000, 8000, FALSE, 5010, "5010 ms should be left"},
{BASE + 10, 0, 10000, 8000, FALSE, -1, "timeout is -1, expired"},
{BASE + 12, 0, 10000, 8000, FALSE, -2000, "-2000, overdue 2 seconds"},
/* both timeouts set, connecting */
{BASE + 4, 0, 10000, 8000, TRUE, 4000, "4 seconds should be left"},
{BASE + 4, 990000, 10000, 8000, TRUE, 3010, "3010 ms should be left"},
{BASE + 8, 0, 10000, 8000, TRUE, -1, "timeout is -1, expired"},
{BASE + 10, 0, 10000, 8000, TRUE, -2000, "-2000, overdue 2 seconds"},
/* no connect timeout set, not connecting */
{BASE + 4, 0, 10000, 0, FALSE, 6000, "6 seconds should be left"},
{BASE + 4, 990000, 10000, 0, FALSE, 5010, "5010 ms should be left"},
{BASE + 10, 0, 10000, 0, FALSE, -1, "timeout is -1, expired"},
{BASE + 12, 0, 10000, 0, FALSE, -2000, "-2000, overdue 2 seconds"},
/* no connect timeout set, connecting */
{BASE + 4, 0, 10000, 0, TRUE, 6000, "6 seconds should be left"},
{BASE + 4, 990000, 10000, 0, TRUE, 5010, "5010 ms should be left"},
{BASE + 10, 0, 10000, 0, TRUE, -1, "timeout is -1, expired"},
{BASE + 12, 0, 10000, 0, TRUE, -2000, "-2000, overdue 2 seconds"},
/* only connect timeout set, not connecting */
{BASE + 4, 0, 0, 10000, FALSE, 0, "no timeout active"},
{BASE + 4, 990000, 0, 10000, FALSE, 0, "no timeout active"},
{BASE + 10, 0, 0, 10000, FALSE, 0, "no timeout active"},
{BASE + 12, 0, 0, 10000, FALSE, 0, "no timeout active"},
/* only connect timeout set, connecting */
{BASE + 4, 0, 0, 10000, TRUE, 6000, "6 seconds should be left"},
{BASE + 4, 990000, 0, 10000, TRUE, 5010, "5010 ms should be left"},
{BASE + 10, 0, 0, 10000, TRUE, -1, "timeout is -1, expired"},
{BASE + 12, 0, 0, 10000, TRUE, -2000, "-2000, overdue 2 seconds"},
/* no timeout set, not connecting */
{BASE + 4, 0, 0, 0, FALSE, 0, "no timeout active"},
{BASE + 4, 990000, 0, 0, FALSE, 0, "no timeout active"},
{BASE + 10, 0, 0, 0, FALSE, 0, "no timeout active"},
{BASE + 12, 0, 0, 0, FALSE, 0, "no timeout active"},
/* no timeout set, connecting */
{BASE + 4, 0, 0, 0, TRUE, 296000, "no timeout active"},
{BASE + 4, 990000, 0, 0, TRUE, 295010, "no timeout active"},
{BASE + 10, 0, 0, 0, TRUE, 290000, "no timeout active"},
{BASE + 12, 0, 0, 0, TRUE, 288000, "no timeout active"},
/* both timeouts set, connecting, connect timeout the longer one */
{BASE + 4, 0, 10000, 12000, TRUE, 6000, "6 seconds should be left"},
};
/* this is the pretended start time of the transfer */
easy->progress.t_startsingle.tv_sec = BASE;
easy->progress.t_startsingle.tv_usec = 0;
easy->progress.t_startop.tv_sec = BASE;
easy->progress.t_startop.tv_usec = 0;
for(i = 0; i < CURL_ARRAYSIZE(run); i++) {
timediff_t timeout;
NOW(run[i].now_s, run[i].now_us);
TIMEOUTS(run[i].timeout_ms, run[i].connecttimeout_ms);
timeout = Curl_timeleft(easy, &now, run[i].connecting);
if(timeout != run[i].result)
fail(run[i].comment);
}
UNITTEST_END(t1303_stop(easy))
}
+187
View File
@@ -0,0 +1,187 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "netrc.h"
#include "memdebug.h" /* LAST include file */
#ifndef CURL_DISABLE_NETRC
static void t1304_stop(char **password, char **login)
{
Curl_safefree(*password);
Curl_safefree(*login);
}
static CURLcode test_unit1304(const char *arg)
{
char *login = NULL;
char *password = NULL;
UNITTEST_BEGIN_SIMPLE
int result;
struct store_netrc store;
/*
* Test a non existent host in our netrc file.
*/
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"test.example.com", &login, &password, arg);
fail_unless(result == 1, "Host not found should return 1");
abort_unless(password == NULL, "password did not return NULL!");
abort_unless(login == NULL, "user did not return NULL!");
Curl_netrc_cleanup(&store);
/*
* Test a non existent login in our netrc file.
*/
login = (char *)CURL_UNCONST("me");
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"example.com", &login, &password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(password == NULL, "password is not NULL!");
Curl_netrc_cleanup(&store);
/*
* Test a non existent login and host in our netrc file.
*/
login = (char *)CURL_UNCONST("me");
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"test.example.com", &login, &password, arg);
fail_unless(result == 1, "Host not found should return 1");
abort_unless(password == NULL, "password is not NULL!");
Curl_netrc_cleanup(&store);
/*
* Test a non existent login (substring of an existing one) in our
* netrc file.
*/
login = (char *)CURL_UNCONST("admi"); /* spellchecker:disable-line */
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"example.com", &login, &password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(password == NULL, "password is not NULL!");
Curl_netrc_cleanup(&store);
/*
* Test a non existent login (superstring of an existing one)
* in our netrc file.
*/
login = (char *)CURL_UNCONST("adminn");
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"example.com", &login, &password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(password == NULL, "password is not NULL!");
Curl_netrc_cleanup(&store);
/*
* Test for the first existing host in our netrc file
* with login[0] = 0.
*/
login = NULL;
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"example.com", &login, &password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "passwd", 6) == 0,
"password should be 'passwd'");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
Curl_netrc_cleanup(&store);
/*
* Test for the first existing host in our netrc file
* with login[0] != 0.
*/
free(password);
free(login);
password = NULL;
login = NULL;
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"example.com", &login, &password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "passwd", 6) == 0,
"password should be 'passwd'");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
Curl_netrc_cleanup(&store);
/*
* Test for the second existing host in our netrc file
* with login[0] = 0.
*/
free(password);
password = NULL;
free(login);
login = NULL;
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"curl.example.com", &login, &password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "none", 4) == 0,
"password should be 'none'");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
Curl_netrc_cleanup(&store);
/*
* Test for the second existing host in our netrc file
* with login[0] != 0.
*/
free(password);
password = NULL;
free(login);
login = NULL;
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"curl.example.com", &login, &password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "none", 4) == 0,
"password should be 'none'");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
Curl_netrc_cleanup(&store);
UNITTEST_END(t1304_stop(&password, &login))
}
#else
static CURLcode test_unit1304(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
UNITTEST_END_SIMPLE
}
#endif
+121
View File
@@ -0,0 +1,121 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#include "hash.h"
#include "hostip.h"
#include "memdebug.h" /* LAST include file */
static struct Curl_dnscache hp;
static char *data_key;
static struct Curl_dns_entry *data_node;
static CURLcode t1305_setup(void)
{
Curl_dnscache_init(&hp, 7);
return CURLE_OK;
}
static void t1305_stop(void)
{
if(data_node) {
Curl_freeaddrinfo(data_node->addr);
free(data_node);
}
free(data_key);
Curl_dnscache_destroy(&hp);
}
static struct Curl_addrinfo *fake_ai(void)
{
static struct Curl_addrinfo *ai;
static const char dummy[] = "dummy";
size_t namelen = sizeof(dummy); /* including the null-terminator */
ai = calloc(1, sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_in) +
namelen);
if(!ai)
return NULL;
ai->ai_addr = (void *)((char *)ai + sizeof(struct Curl_addrinfo));
ai->ai_canonname = (void *)((char *)ai->ai_addr +
sizeof(struct sockaddr_in));
memcpy(ai->ai_canonname, dummy, namelen);
ai->ai_family = AF_INET;
ai->ai_addrlen = sizeof(struct sockaddr_in);
return ai;
}
static CURLcode create_node(void)
{
data_key = curl_maprintf("%s:%d", "dummy", 0);
if(!data_key)
return CURLE_OUT_OF_MEMORY;
data_node = calloc(1, sizeof(struct Curl_dns_entry));
if(!data_node)
return CURLE_OUT_OF_MEMORY;
data_node->addr = fake_ai();
if(!data_node->addr)
return CURLE_OUT_OF_MEMORY;
return CURLE_OK;
}
static CURLcode test_unit1305(const char *arg)
{
UNITTEST_BEGIN(t1305_setup())
struct Curl_dns_entry *nodep;
size_t key_len;
/* Test 1305 exits without adding anything to the hash */
if(testnum == 1306) {
CURLcode rc = create_node();
abort_unless(rc == CURLE_OK, "data node creation failed");
key_len = strlen(data_key);
data_node->refcount = 1; /* hash will hold the reference */
nodep = Curl_hash_add(&hp.entries, data_key, key_len + 1, data_node);
abort_unless(nodep, "insertion into hash failed");
/* Freeing will now be done by Curl_hash_destroy */
data_node = NULL;
}
UNITTEST_END(t1305_stop())
}
+320
View File
@@ -0,0 +1,320 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "curl_fnmatch.h"
#ifndef CURL_DISABLE_FTP
/*
CURL_FNMATCH_MATCH 0
CURL_FNMATCH_NOMATCH 1
CURL_FNMATCH_FAIL 2
*/
#define MATCH CURL_FNMATCH_MATCH
#define NOMATCH CURL_FNMATCH_NOMATCH
#define LINUX_DIFFER 0x80
#define LINUX_SHIFT 8
#define LINUX_MATCH ((CURL_FNMATCH_MATCH << LINUX_SHIFT) | LINUX_DIFFER)
#define LINUX_NOMATCH ((CURL_FNMATCH_NOMATCH << LINUX_SHIFT) | LINUX_DIFFER)
#define LINUX_FAIL ((CURL_FNMATCH_FAIL << LINUX_SHIFT) | LINUX_DIFFER)
#define MAC_DIFFER 0x40
#define MAC_SHIFT 16
#define MAC_MATCH ((CURL_FNMATCH_MATCH << MAC_SHIFT) | MAC_DIFFER)
#define MAC_NOMATCH ((CURL_FNMATCH_NOMATCH << MAC_SHIFT) | MAC_DIFFER)
#define MAC_FAIL ((CURL_FNMATCH_FAIL << MAC_SHIFT) | MAC_DIFFER)
static const char *ret2name(int i)
{
switch(i) {
case 0:
return "MATCH";
case 1:
return "NOMATCH";
case 2:
return "FAIL";
default:
return "unknown";
}
/* not reached */
}
static CURLcode test_unit1307(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
struct testcase {
const char *pattern;
const char *string;
int result;
};
static const struct testcase tests[] = {
/* brackets syntax */
{"*[*[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[\001\177[[[[[[[[[[[[[[[[[[[[[",
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[",
NOMATCH|MAC_FAIL},
{ "\\[", "[", MATCH },
{ "[", "[", NOMATCH|LINUX_MATCH|MAC_FAIL},
{ "[]", "[]", NOMATCH|LINUX_MATCH|MAC_FAIL},
{ "[][]", "[", MATCH },
{ "[][]", "]", MATCH },
{ "[[]", "[", MATCH },
{ "[[[]", "[", MATCH },
{ "[[[[]", "[", MATCH },
{ "[[[[]", "[", MATCH },
{ "[][[]", "]", MATCH },
{ "[][[[]", "[", MATCH },
{ "[[]", "]", NOMATCH },
{ "[a@]", "a", MATCH },
{ "[a-z]", "a", MATCH },
{ "[a-z]", "A", NOMATCH },
{ "?[a-z]", "?Z", NOMATCH },
{ "[A-Z]", "C", MATCH },
{ "[A-Z]", "c", NOMATCH },
{ "[0-9]", "7", MATCH },
{ "[7-8]", "7", MATCH },
{ "[7-]", "7", MATCH },
{ "[7-]", "-", MATCH },
{ "[7-]", "[", NOMATCH },
{ "[a-bA-F]", "F", MATCH },
{ "[a-bA-B9]", "9", MATCH },
{ "[a-bA-B98]", "8", MATCH },
{ "[a-bA-B98]", "C", NOMATCH },
{ "[a-bA-Z9]", "F", MATCH },
{ "[a-bA-Z9]ero*", "Zero chance.", MATCH },
{ "S[a-][x]opho*", "Saxophone", MATCH },
{ "S[a-][x]opho*", "SaXophone", NOMATCH },
{ "S[a-][x]*.txt", "S-x.txt", MATCH },
{ "[\\a-\\b]", "a", MATCH },
{ "[\\a-\\b]", "b", MATCH },
{ "[?*[][?*[][?*[]", "?*[", MATCH },
{ "[][?*-]", "]", MATCH },
{ "[][?*-]", "[", MATCH },
{ "[][?*-]", "?", MATCH },
{ "[][?*-]", "*", MATCH },
{ "[][?*-]", "-", MATCH },
{ "[]?*-]", "-", MATCH },
{ "[\xFF]", "\xFF", MATCH|LINUX_FAIL|MAC_FAIL},
{ "?/b/c", "a/b/c", MATCH },
{ "^_{}~", "^_{}~", MATCH },
{ "!#%+,-./01234567889", "!#%+,-./01234567889", MATCH },
{ "PQRSTUVWXYZ]abcdefg", "PQRSTUVWXYZ]abcdefg", MATCH },
{ ":;=@ABCDEFGHIJKLMNO", ":;=@ABCDEFGHIJKLMNO", MATCH },
/* negate */
{ "[!a]", "b", MATCH },
{ "[!a]", "a", NOMATCH },
{ "[^a]", "b", MATCH },
{ "[^a]", "a", NOMATCH },
{ "[^a-z0-9A-Z]", "a", NOMATCH },
{ "[^a-z0-9A-Z]", "-", MATCH },
{ "curl[!a-z]lib", "curl lib", MATCH },
{ "curl[! ]lib", "curl lib", NOMATCH },
{ "[! ][ ]", " ", NOMATCH },
{ "[! ][ ]", "a ", MATCH },
{ "*[^a].t?t", "a.txt", NOMATCH },
{ "*[^a].t?t", "ca.txt", NOMATCH },
{ "*[^a].t?t", "ac.txt", MATCH },
{ "*[^a]", "", NOMATCH },
{ "[!\xFF]", "", NOMATCH|LINUX_FAIL},
{ "[!\xFF]", "\xFF", NOMATCH|LINUX_FAIL|MAC_FAIL},
{ "[!\xFF]", "a", MATCH|LINUX_FAIL|MAC_FAIL},
{ "[!?*[]", "?", NOMATCH },
{ "[!!]", "!", NOMATCH },
{ "[!!]", "x", MATCH },
{ "[[:alpha:]]", "a", MATCH },
{ "[[:alpha:]]", "9", NOMATCH },
{ "[[:alnum:]]", "a", MATCH },
{ "[[:alnum:]]", "[", NOMATCH },
{ "[[:alnum:]]", "]", NOMATCH },
{ "[[:alnum:]]", "9", MATCH },
{ "[[:digit:]]", "9", MATCH },
{ "[[:xdigit:]]", "9", MATCH },
{ "[[:xdigit:]]", "F", MATCH },
{ "[[:xdigit:]]", "G", NOMATCH },
{ "[[:upper:]]", "U", MATCH },
{ "[[:upper:]]", "u", NOMATCH },
{ "[[:lower:]]", "l", MATCH },
{ "[[:lower:]]", "L", NOMATCH },
{ "[[:print:]]", "L", MATCH },
{ "[[:print:]]", "\10", NOMATCH },
{ "[[:print:]]", "\10", NOMATCH },
{ "[[:space:]]", " ", MATCH },
{ "[[:space:]]", "x", NOMATCH },
{ "[[:graph:]]", " ", NOMATCH },
{ "[[:graph:]]", "x", MATCH },
{ "[[:blank:]]", "\t", MATCH },
{ "[[:blank:]]", " ", MATCH },
{ "[[:blank:]]", "\r", NOMATCH },
{ "[^[:blank:]]", "\t", NOMATCH },
{ "[^[:print:]]", "\10", MATCH },
{ "[[:lower:]][[:lower:]]", "ll", MATCH },
{ "[[:foo:]]", "bar", NOMATCH|MAC_FAIL},
{ "[[:foo:]]", "f]", MATCH|LINUX_NOMATCH|MAC_FAIL},
{ "Curl[[:blank:]];-)", "Curl ;-)", MATCH },
{ "*[[:blank:]]*", " ", MATCH },
{ "*[[:blank:]]*", "", NOMATCH },
{ "*[[:blank:]]*", "hi, im_Pavel", MATCH },
/* common using */
{ "filename.dat", "filename.dat", MATCH },
{ "*curl*", "lets use curl!!", MATCH },
{ "filename.txt", "filename.dat", NOMATCH },
{ "*.txt", "text.txt", MATCH },
{ "*.txt", "a.txt", MATCH },
{ "*.txt", ".txt", MATCH },
{ "*.txt", "txt", NOMATCH },
{ "??.txt", "99.txt", MATCH },
{ "??.txt", "a99.txt", NOMATCH },
{ "?.???", "a.txt", MATCH },
{ "*.???", "somefile.dat", MATCH },
{ "*.???", "photo.jpeg", NOMATCH },
{ ".*", ".htaccess", MATCH },
{ ".*", ".", MATCH },
{ ".*", "..", MATCH },
/* many stars => one star */
{ "**.txt", "text.txt", MATCH },
{ "***.txt", "t.txt", MATCH },
{ "****.txt", ".txt", MATCH },
/* empty string or pattern */
{ "", "", MATCH },
{ "", "hello", NOMATCH },
{ "file", "", NOMATCH },
{ "?", "", NOMATCH },
{ "*", "", MATCH },
{ "x", "", NOMATCH },
/* backslash */
{ "\\", "\\", MATCH|LINUX_NOMATCH},
{ "\\\\", "\\", MATCH },
{ "\\\\", "\\\\", NOMATCH },
{ "\\?", "?", MATCH },
{ "\\*", "*", MATCH },
{ "?.txt", "?.txt", MATCH },
{ "*.txt", "*.txt", MATCH },
{ "\\?.txt", "?.txt", MATCH },
{ "\\*.txt", "*.txt", MATCH },
{ "\\?.txt", "x.txt", NOMATCH },
{ "\\*.txt", "x.txt", NOMATCH },
{ "\\*\\\\.txt", "*\\.txt", MATCH },
{ "*\\**\\?*\\\\*", "cc*cc?cccc", NOMATCH },
{ "*\\?*\\**", "cc?cc", NOMATCH },
{ "\\\"\\$\\&\\'\\(\\)", "\"$&'()", MATCH },
{ "\\*\\?\\[\\\\\\`\\|", "*?[\\`|", MATCH },
{ "[\\a\\b]c", "ac", MATCH },
{ "[\\a\\b]c", "bc", MATCH },
{ "[\\a\\b]d", "bc", NOMATCH },
{ "[a-bA-B\\?]", "?", MATCH },
{ "cu[a-ab-b\\r]l", "curl", MATCH },
{ "[\\a-z]", "c", MATCH },
{ "?*?*?.*?*", "abc.c", MATCH },
{ "?*?*?.*?*", "abcc", NOMATCH },
{ "?*?*?.*?*", "abc.", NOMATCH },
{ "?*?*?.*?*", "abc.c++", MATCH },
{ "?*?*?.*?*", "abcdef.c++", MATCH },
{ "?*?*?.?", "abcdef.c", MATCH },
{ "?*?*?.?", "abcdef.cd", NOMATCH },
/* https://codepoints.net/U+00E4 Latin Small Letter A with Diaeresis */
{ "Lindm\xc3\xa4tarv", "Lindm\xc3\xa4tarv", MATCH },
{ "", "", MATCH},
{"**]*[*[\x13]**[*\x13)]*]*[**[*\x13~r-]*]**[.*]*[\xe3\xe3\xe3\xe3\xe3\xe3"
"\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3"
"\xe3\xe3\xe3\xe3\xe3*[\x13]**[*\x13)]*]*[*[\x13]*[~r]*]*\xba\x13\xa6~b-]"
"*",
"a", NOMATCH|LINUX_FAIL}
};
size_t i;
enum system {
SYSTEM_CUSTOM,
SYSTEM_LINUX,
SYSTEM_MACOS
};
enum system machine;
#ifdef HAVE_FNMATCH
#ifdef __APPLE__
machine = SYSTEM_MACOS;
#else
machine = SYSTEM_LINUX;
#endif
curl_mprintf("Tested with system fnmatch(), %s-style\n",
machine == SYSTEM_LINUX ? "linux" : "mac");
#else
curl_mprintf("Tested with custom fnmatch()\n");
machine = SYSTEM_CUSTOM;
#endif
for(i = 0; i < CURL_ARRAYSIZE(tests); i++) {
int result = tests[i].result;
int rc = Curl_fnmatch(NULL, tests[i].pattern, tests[i].string);
if(result & (LINUX_DIFFER|MAC_DIFFER)) {
if((result & LINUX_DIFFER) && (machine == SYSTEM_LINUX))
result >>= LINUX_SHIFT;
else if((result & MAC_DIFFER) && (machine == SYSTEM_MACOS))
result >>= MAC_SHIFT;
result &= 0x03; /* filter off all high bits */
}
if(rc != result) {
curl_mprintf("Curl_fnmatch(\"%s\", \"%s\") should return %s (returns %s)"
" [%zu]\n",
tests[i].pattern, tests[i].string, ret2name(result),
ret2name(rc), i);
fail("pattern mismatch");
}
}
UNITTEST_END_SIMPLE
}
#else
static CURLcode test_unit1307(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
UNITTEST_END_SIMPLE
}
#endif
+134
View File
@@ -0,0 +1,134 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "splay.h"
static void splayprint(struct Curl_tree *t, int d, char output)
{
struct Curl_tree *node;
int i;
int count;
if(!t)
return;
splayprint(t->larger, d + 1, output);
for(i = 0; i < d; i++)
if(output)
curl_mprintf(" ");
if(output) {
curl_mprintf("%ld.%ld[%d]", (long)t->key.tv_sec, (long)t->key.tv_usec, i);
}
for(count = 0, node = t->samen; node != t; node = node->samen, count++)
;
if(output) {
if(count)
curl_mprintf(" [%d more]\n", count);
else
curl_mprintf("\n");
}
splayprint(t->smaller, d + 1, output);
}
static CURLcode test_unit1309(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
/* number of nodes to add to the splay tree */
#define NUM_NODES 50
struct Curl_tree *root, *removed;
struct Curl_tree nodes[NUM_NODES*3];
size_t storage[NUM_NODES*3];
int rc;
int i, j;
struct curltime tv_now = {0, 0};
root = NULL; /* the empty tree */
/* add nodes */
for(i = 0; i < NUM_NODES; i++) {
struct curltime key;
key.tv_sec = 0;
key.tv_usec = (541*i)%1023;
storage[i] = key.tv_usec;
Curl_splayset(&nodes[i], &storage[i]);
root = Curl_splayinsert(key, root, &nodes[i]);
}
puts("Result:");
splayprint(root, 0, 1);
for(i = 0; i < NUM_NODES; i++) {
int rem = (i + 7)%NUM_NODES;
curl_mprintf("Tree look:\n");
splayprint(root, 0, 1);
curl_mprintf("remove pointer %d, payload %zu\n", rem,
*(size_t *)Curl_splayget(&nodes[rem]));
rc = Curl_splayremove(root, &nodes[rem], &root);
if(rc) {
/* failed! */
curl_mprintf("remove %d failed!\n", rem);
fail("remove");
}
}
fail_unless(root == NULL, "tree not empty after removing all nodes");
/* rebuild tree */
for(i = 0; i < NUM_NODES; i++) {
struct curltime key;
key.tv_sec = 0;
key.tv_usec = (541*i)%1023;
/* add some nodes with the same key */
for(j = 0; j <= i % 3; j++) {
storage[i * 3 + j] = key.tv_usec*10 + j;
Curl_splayset(&nodes[i * 3 + j], &storage[i * 3 + j]);
root = Curl_splayinsert(key, root, &nodes[i * 3 + j]);
}
}
removed = NULL;
for(i = 0; i <= 1100; i += 100) {
curl_mprintf("Removing nodes not larger than %d\n", i);
tv_now.tv_usec = i;
root = Curl_splaygetbest(tv_now, root, &removed);
while(removed) {
curl_mprintf("removed payload %zu[%zu]\n",
*(size_t *)Curl_splayget(removed) / 10,
*(size_t *)Curl_splayget(removed) % 10);
root = Curl_splaygetbest(tv_now, root, &removed);
}
}
fail_unless(root == NULL, "tree not empty when it should be");
UNITTEST_END_SIMPLE
}
+61
View File
@@ -0,0 +1,61 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
static CURLcode test_unit1323(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
struct a {
struct curltime first;
struct curltime second;
timediff_t result;
};
struct a tests[] = {
{ {36762, 8345}, {36761, 995926}, 13 },
{ {36761, 995926}, {36762, 8345}, -13 },
{ {36761, 995926}, {0, 0}, 36761995 },
{ {0, 0}, {36761, 995926}, -36761995 },
};
size_t i;
for(i = 0; i < CURL_ARRAYSIZE(tests); i++) {
timediff_t result = curlx_timediff(tests[i].first, tests[i].second);
if(result != tests[i].result) {
curl_mprintf("%ld.%06u to %ld.%06u got %" FMT_TIMEDIFF_T
", but expected %" FMT_TIMEDIFF_T "\n",
(long)tests[i].first.tv_sec,
tests[i].first.tv_usec,
(long)tests[i].second.tv_sec,
tests[i].second.tv_usec,
result,
tests[i].result);
fail("unexpected result!");
}
}
UNITTEST_END_SIMPLE
}
+36
View File
@@ -0,0 +1,36 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "memdebug.h"
static CURLcode test_unit1330(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
char *ptr = malloc(1330);
Curl_safefree(ptr);
UNITTEST_END_SIMPLE
}
+142
View File
@@ -0,0 +1,142 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "memdebug.h"
#include "unitprotos.h"
static CURLcode test_unit1395(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
unsigned int i;
int fails = 0;
struct dotdot {
const char *input;
const char *output;
};
const struct dotdot pairs[] = {
{ "%2f%2e%2e%2f/../a", "%2f%2e%2e%2f/a" },
{ "%2f%2e%2e%2f/../", "%2f%2e%2e%2f/" },
{ "%2f%2e%2e%2f/.", "%2f%2e%2e%2f/" },
{ "%2f%2e%2e%2f/", "%2f%2e%2e%2f/" },
{ "%2f%2e%2e%2f", "%2f%2e%2e%2f" },
{ "%2f%2e%2e%2", "%2f%2e%2e%2" },
{ "%2f%2e%2e%", "%2f%2e%2e%" },
{ "%2f%2e%2e", "%2f%2e%2e" },
{ "%2f%2e%2", "%2f%2e%2" },
{ "%2f%2e%", "%2f%2e%" },
{ "%2f%2e", "%2f%2e" },
{ "%2f%2", "%2f%2" },
{ "%2f%", "%2f%" },
{ "%2f", "%2f" },
{ "%2", "%2" },
{ "%", NULL },
{ "2", NULL },
{ "e", NULL },
{ ".", NULL },
{ "./", "" },
{ "..", "" },
{ "../", "" },
{ "../a", "a" },
{ "///moo.", "///moo." },
{ ".///moo.", "//moo." },
{ "./moo..", "moo.." },
{ "./moo../", "moo../" },
{ "./moo../.m", "moo../.m" },
{ "./moo", "moo" },
{ "../moo", "moo" },
{ "../moo?", "moo?" },
{ "../moo?#", "moo?#" },
{ "../moo?#?..", "moo?#?.." },
{ "/../moo/..", "/" },
{ "/a/c/%2e%2E/b", "/a/b" },
{ "/a/%2e/g", "/a/g" },
{ "/a/b/c/./g", "/a/b/c/g" },
{ "/a/c/../b", "/a/b" },
{ "/a/b/c/./../../g", "/a/g" },
{ "/a/b/c/./%2e%2E/../g", "/a/g" },
{ "/a/b/c/./../%2e%2E/g", "/a/g" },
{ "/a/b/c/%2E/%2e%2E/%2e%2E/g", "/a/g" },
{ "mid/content=5/../6", "mid/6" },
{ "/hello/../moo", "/moo" },
{ "/1/../1", "/1" },
{ "/1/./1", "/1/1" },
{ "/1/%2e/1", "/1/1" },
{ "/1/%2E/1", "/1/1" },
{ "/1/..", "/" },
{ "/1/.", "/1/" },
{ "/1/%2e", "/1/" },
{ "/1/%2E", "/1/" },
{ "/1/./..", "/" },
{ "/1/%2e/.%2E", "/" },
{ "/1/./%2e.", "/" },
{ "/1/./../2", "/2" },
{ "/hello/1/./../2", "/hello/2" },
{ "test/this", "test/this" },
{ "test/this/../now", "test/now" },
{ "/1../moo../foo", "/1../moo../foo"},
{ "/../../moo", "/moo"},
{ "/../../moo?", "/moo?"},
{ "/123?", "/123?" },
{ "/", NULL },
{ "", NULL },
{ "/.../", "/.../" },
{ "/.", "/" },
{ "/..", "/" },
{ "/moo/..", "/" },
{ "/..", "/" },
{ "/.", "/" },
};
for(i = 0; i < CURL_ARRAYSIZE(pairs); i++) {
char *out;
int err = dedotdotify(pairs[i].input, strlen(pairs[i].input), &out);
abort_unless(err == 0, "returned error");
abort_if(err && out, "returned error with output");
if(out && pairs[i].output && strcmp(out, pairs[i].output)) {
curl_mfprintf(stderr, "Test %u: '%s' gave '%s' instead of '%s'\n",
i, pairs[i].input, out, pairs[i].output);
fail("Test case output mismatched");
fails++;
}
else if((!out && pairs[i].output) ||
(out && !pairs[i].output)) {
curl_mfprintf(stderr, "Test %u: '%s' gave '%s' instead of '%s'\n",
i, pairs[i].input, out ? out : "(null)",
pairs[i].output ? pairs[i].output : "(null)");
fail("Test case output mismatched");
fails++;
}
else
curl_mfprintf(stderr, "Test %u: OK\n", i);
free(out);
}
fail_if(fails, "output mismatched");
UNITTEST_END_SIMPLE
}
+119
View File
@@ -0,0 +1,119 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
static CURLcode t1396_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
return res;
}
static void t1396_stop(CURL *easy)
{
if(easy)
curl_easy_cleanup(easy);
curl_global_cleanup();
}
static CURLcode test_unit1396(const char *arg)
{
CURL *easy;
UNITTEST_BEGIN(t1396_setup())
struct test {
const char *in;
int inlen;
const char *out;
int outlen;
};
/* unescape, this => that */
const struct test list1[] = {
{"%61", 3, "a", 1},
{"%61a", 4, "aa", 2},
{"%61b", 4, "ab", 2},
{"%6 1", 4, "%6 1", 4},
{"%61", 1, "%", 1},
{"%61", 2, "%6", 2},
{"%6%a", 4, "%6%a", 4},
{"%6a", 0, "j", 1},
{"%FF", 0, "\xff", 1},
{"%FF%00%ff", 9, "\xff\x00\xff", 3},
{"%-2", 0, "%-2", 3},
{"%FG", 0, "%FG", 3},
{NULL, 0, NULL, 0} /* end of list marker */
};
/* escape, this => that */
const struct test list2[] = {
{"a", 1, "a", 1},
{"/", 1, "%2F", 3},
{"a=b", 3, "a%3Db", 5},
{"a=b", 0, "a%3Db", 5},
{"a=b", 1, "a", 1},
{"a=b", 2, "a%3D", 4},
{"1/./0", 5, "1%2F.%2F0", 9},
{"-._~!#%&", 0, "-._~%21%23%25%26", 16},
{"a", 2, "a%00", 4},
{"a\xff\x01g", 4, "a%FF%01g", 8},
{NULL, 0, NULL, 0} /* end of list marker */
};
int i;
easy = curl_easy_init();
abort_unless(easy != NULL, "returned NULL!");
for(i = 0; list1[i].in; i++) {
int outlen;
char *out = curl_easy_unescape(easy,
list1[i].in, list1[i].inlen,
&outlen);
abort_unless(out != NULL, "returned NULL!");
fail_unless(outlen == list1[i].outlen, "wrong output length returned");
fail_unless(!memcmp(out, list1[i].out, list1[i].outlen),
"bad output data returned");
curl_mprintf("curl_easy_unescape test %d DONE\n", i);
curl_free(out);
}
for(i = 0; list2[i].in; i++) {
int outlen;
char *out = curl_easy_escape(easy, list2[i].in, list2[i].inlen);
abort_unless(out != NULL, "returned NULL!");
outlen = (int)strlen(out);
fail_unless(outlen == list2[i].outlen, "wrong output length returned");
fail_unless(!memcmp(out, list2[i].out, list2[i].outlen),
"bad output data returned");
curl_mprintf("curl_easy_escape test %d DONE (%s)\n", i, out);
curl_free(out);
}
UNITTEST_END(t1396_stop(easy))
}
+113
View File
@@ -0,0 +1,113 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "vtls/hostcheck.h"
static CURLcode test_unit1397(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
/* only these backends define the tested functions */
#if defined(USE_OPENSSL) || defined(USE_SCHANNEL)
struct testcase {
const char *host;
const char *pattern;
bool match;
};
static const struct testcase tests[] = {
{"", "", FALSE},
{"a", "", FALSE},
{"", "b", FALSE},
{"a", "b", FALSE},
{"aa", "bb", FALSE},
{"\xff", "\xff", TRUE},
{"aa.aa.aa", "aa.aa.bb", FALSE},
{"aa.aa.aa", "aa.aa.aa", TRUE},
{"aa.aa.aa", "*.aa.bb", FALSE},
{"aa.aa.aa", "*.aa.aa", TRUE},
{"192.168.0.1", "192.168.0.1", TRUE},
{"192.168.0.1", "*.168.0.1", FALSE},
{"192.168.0.1", "*.0.1", FALSE},
{"h.ello", "*.ello", FALSE},
{"h.ello.", "*.ello", FALSE},
{"h.ello", "*.ello.", FALSE},
{"h.e.llo", "*.e.llo", TRUE},
{"h.e.llo", " *.e.llo", FALSE},
{" h.e.llo", "*.e.llo", TRUE},
{"h.e.llo.", "*.e.llo", TRUE},
{"*.e.llo.", "*.e.llo", TRUE},
{"************.e.llo.", "*.e.llo", TRUE},
{"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
".e.llo.", "*.e.llo", TRUE},
{"\xfe\xfe.e.llo.", "*.e.llo", TRUE},
{"h.e.llo.", "*.e.llo.", TRUE},
{"h.e.llo", "*.e.llo.", TRUE},
{".h.e.llo", "*.e.llo.", FALSE},
{"h.e.llo", "*.*.llo.", FALSE},
{"h.e.llo", "h.*.llo", FALSE},
{"h.e.llo", "h.e.*", FALSE},
{"hello", "*.ello", FALSE},
{"hello", "**llo", FALSE},
{"bar.foo.example.com", "*.example.com", FALSE},
{"foo.example.com", "*.example.com", TRUE},
{"baz.example.net", "b*z.example.net", FALSE},
{"foobaz.example.net", "*baz.example.net", FALSE},
{"xn--l8j.example.local", "x*.example.local", FALSE},
{"xn--l8j.example.net", "*.example.net", TRUE},
{"xn--l8j.example.net", "*j.example.net", FALSE},
{"xn--l8j.example.net", "xn--l8j.example.net", TRUE},
{"xn--l8j.example.net", "xn--l8j.*.net", FALSE},
{"xl8j.example.net", "*.example.net", TRUE},
{"fe80::3285:a9ff:fe46:b619", "*::3285:a9ff:fe46:b619", FALSE},
{"fe80::3285:a9ff:fe46:b619", "fe80::3285:a9ff:fe46:b619", TRUE},
{NULL, NULL, FALSE}
};
int i;
for(i = 0; tests[i].host; i++) {
if(tests[i].match != Curl_cert_hostcheck(tests[i].pattern,
strlen(tests[i].pattern),
tests[i].host,
strlen(tests[i].host))) {
curl_mfprintf(stderr,
"HOST: %s\n"
"PTRN: %s\n"
"did %sMATCH\n",
tests[i].host,
tests[i].pattern,
tests[i].match ? "NOT ": "");
unitfail++;
}
}
#endif
UNITTEST_END_SIMPLE
}
+200
View File
@@ -0,0 +1,200 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
#endif
static CURLcode test_unit1398(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
int rc;
char buf[3] = {'b', 'u', 'g'};
static const char *str = "bug";
int width = 3;
char output[130];
/*#define curl_msnprintf snprintf */
/* without a trailing zero */
rc = curl_msnprintf(output, 4, "%.*s", width, buf);
fail_unless(rc == 3, "return code should be 3");
fail_unless(!strcmp(output, "bug"), "wrong output");
/* with a trailing zero */
rc = curl_msnprintf(output, 4, "%.*s", width, str);
fail_unless(rc == 3, "return code should be 3");
fail_unless(!strcmp(output, "bug"), "wrong output");
width = 2;
/* one byte less */
rc = curl_msnprintf(output, 4, "%.*s", width, buf);
fail_unless(rc == 2, "return code should be 2");
fail_unless(!strcmp(output, "bu"), "wrong output");
/* string with larger precision */
rc = curl_msnprintf(output, 8, "%.8s", str);
fail_unless(rc == 3, "return code should be 3");
fail_unless(!strcmp(output, "bug"), "wrong output");
/* longer string with precision */
rc = curl_msnprintf(output, 8, "%.3s", "0123456789");
fail_unless(rc == 3, "return code should be 3");
fail_unless(!strcmp(output, "012"), "wrong output");
/* negative width */
rc = curl_msnprintf(output, 8, "%-8s", str);
fail_unless(rc == 7, "return code should be 7");
fail_unless(!strcmp(output, "bug "), "wrong output");
/* larger width that string length */
rc = curl_msnprintf(output, 8, "%8s", str);
fail_unless(rc == 7, "return code should be 7");
fail_unless(!strcmp(output, " bu"), "wrong output");
/* output a number in a limited output */
rc = curl_msnprintf(output, 4, "%d", 10240);
fail_unless(rc == 3, "return code should be 3");
fail_unless(!strcmp(output, "102"), "wrong output");
/* padded strings */
rc = curl_msnprintf(output, 16, "%8s%8s", str, str);
fail_unless(rc == 15, "return code should be 15");
fail_unless(!strcmp(output, " bug bu"), "wrong output");
/* padded numbers */
rc = curl_msnprintf(output, 16, "%8d%8d", 1234, 5678);
fail_unless(rc == 15, "return code should be 15");
fail_unless(!strcmp(output, " 1234 567"), "wrong output");
#if defined(__clang__) && \
(__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1))
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-non-iso"
#endif
/* double precision */
rc = curl_msnprintf(output, 24, "%2$.*1$.99d", 3, 5678);
fail_unless(rc == 0, "return code should be 0");
#if defined(__clang__) && \
(__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1))
#pragma clang diagnostic pop
#endif
/* 129 input % flags */
rc = curl_msnprintf(output, 130,
"%s%s%s%s%s%s%s%s%s%s" /* 10 */
"%s%s%s%s%s%s%s%s%s%s" /* 20 */
"%s%s%s%s%s%s%s%s%s%s" /* 30 */
"%s%s%s%s%s%s%s%s%s%s" /* 40 */
"%s%s%s%s%s%s%s%s%s%s" /* 50 */
"%s%s%s%s%s%s%s%s%s%s" /* 60 */
"%s%s%s%s%s%s%s%s%s%s" /* 70 */
"%s%s%s%s%s%s%s%s%s%s" /* 80 */
"%s%s%s%s%s%s%s%s%s%s" /* 90 */
"%s%s%s%s%s%s%s%s%s%s" /* 100 */
"%s%s%s%s%s%s%s%s%s%s" /* 110 */
"%s%s%s%s%s%s%s%s%s%s" /* 120 */
"%s%s%s%s%s%s%s%s%s", /* 129 */
"a", "", "", "", "", "", "", "", "", "", /* 10 */
"b", "", "", "", "", "", "", "", "", "", /* 20 */
"c", "", "", "", "", "", "", "", "", "", /* 30 */
"d", "", "", "", "", "", "", "", "", "", /* 40 */
"e", "", "", "", "", "", "", "", "", "", /* 50 */
"f", "", "", "", "", "", "", "", "", "", /* 60 */
"g", "", "", "", "", "", "", "", "", "", /* 70 */
"h", "", "", "", "", "", "", "", "", "", /* 80 */
"i", "", "", "", "", "", "", "", "", "", /* 90 */
"j", "", "", "", "", "", "", "", "", "", /* 100 */
"k", "", "", "", "", "", "", "", "", "", /* 110 */
"l", "", "", "", "", "", "", "", "", "", /* 120 */
"m", "", "", "", "", "", "", "", "" /* 129 */
);
fail_unless(rc == 0, "return code should be 0");
/* 128 input % flags */
rc = curl_msnprintf(output, 130,
"%s%s%s%s%s%s%s%s%s%s" /* 10 */
"%s%s%s%s%s%s%s%s%s%s" /* 20 */
"%s%s%s%s%s%s%s%s%s%s" /* 30 */
"%s%s%s%s%s%s%s%s%s%s" /* 40 */
"%s%s%s%s%s%s%s%s%s%s" /* 50 */
"%s%s%s%s%s%s%s%s%s%s" /* 60 */
"%s%s%s%s%s%s%s%s%s%s" /* 70 */
"%s%s%s%s%s%s%s%s%s%s" /* 80 */
"%s%s%s%s%s%s%s%s%s%s" /* 90 */
"%s%s%s%s%s%s%s%s%s%s" /* 100 */
"%s%s%s%s%s%s%s%s%s%s" /* 110 */
"%s%s%s%s%s%s%s%s%s%s" /* 120 */
"%s%s%s%s%s%s%s%s", /* 128 */
"a", "", "", "", "", "", "", "", "", "", /* 10 */
"b", "", "", "", "", "", "", "", "", "", /* 20 */
"c", "", "", "", "", "", "", "", "", "", /* 30 */
"d", "", "", "", "", "", "", "", "", "", /* 40 */
"e", "", "", "", "", "", "", "", "", "", /* 50 */
"f", "", "", "", "", "", "", "", "", "", /* 60 */
"g", "", "", "", "", "", "", "", "", "", /* 70 */
"h", "", "", "", "", "", "", "", "", "", /* 80 */
"i", "", "", "", "", "", "", "", "", "", /* 90 */
"j", "", "", "", "", "", "", "", "", "", /* 100 */
"k", "", "", "", "", "", "", "", "", "", /* 110 */
"l", "", "", "", "", "", "", "", "", "", /* 120 */
"m", "", "", "", "", "", "", "" /* 128 */
);
fail_unless(rc == 13, "return code should be 13");
/* 129 output segments */
rc = curl_msnprintf(output, 130,
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 20 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 40 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 60 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 80 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 100 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 120 */
"%%%%%%%%%%%%%%%%%%" /* 129 */
);
fail_unless(rc == 0, "return code should be 0");
/* 128 output segments */
rc = curl_msnprintf(output, 129,
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 20 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 40 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 60 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 80 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 100 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 120 */
"%%%%%%%%%%%%%%%%" /* 128 */
);
fail_unless(rc == 128, "return code should be 128");
UNITTEST_END_SIMPLE
}
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
+115
View File
@@ -0,0 +1,115 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "progress.h"
/*
* Invoke Curl_pgrsTime for TIMER_STARTSINGLE to trigger the behavior that
* manages is_t_startransfer_set, but fake the t_startsingle time for purposes
* of the test.
*/
static void fake_t_startsingle_time(struct Curl_easy *data,
struct curltime fake_now,
int seconds_offset)
{
Curl_pgrsTime(data, TIMER_STARTSINGLE);
data->progress.t_startsingle.tv_sec = fake_now.tv_sec + seconds_offset;
data->progress.t_startsingle.tv_usec = fake_now.tv_usec;
}
static bool usec_matches_seconds(timediff_t time_usec, int expected_seconds)
{
static int usec_magnitude = 1000000;
int time_sec = (int)(time_usec / usec_magnitude);
bool same = (time_sec == expected_seconds);
curl_mfprintf(stderr, "is %d us same as %d seconds? %s\n",
(int)time_usec, expected_seconds,
same ? "Yes" : "No");
return same;
}
static void expect_timer_seconds(struct Curl_easy *data, int seconds)
{
char msg[64];
curl_msnprintf(msg, sizeof(msg), "about %d seconds should have passed",
seconds);
fail_unless(usec_matches_seconds(data->progress.t_nslookup, seconds), msg);
fail_unless(usec_matches_seconds(data->progress.t_connect, seconds), msg);
fail_unless(usec_matches_seconds(data->progress.t_appconnect, seconds), msg);
fail_unless(usec_matches_seconds(data->progress.t_pretransfer, seconds),
msg);
fail_unless(usec_matches_seconds(data->progress.t_starttransfer, seconds),
msg);
}
/* Scenario: simulate a redirect. When a redirect occurs, t_nslookup,
* t_connect, t_appconnect, t_pretransfer, and t_starttransfer are additive.
* E.g., if t_starttransfer took 2 seconds initially and took another 1
* second for the redirect request, then the resulting t_starttransfer should
* be 3 seconds. */
static CURLcode test_unit1399(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
struct Curl_easy data;
struct curltime now = curlx_now();
data.progress.t_nslookup = 0;
data.progress.t_connect = 0;
data.progress.t_appconnect = 0;
data.progress.t_pretransfer = 0;
data.progress.t_starttransfer = 0;
data.progress.t_redirect = 0;
data.progress.start.tv_sec = now.tv_sec - 2;
data.progress.start.tv_usec = now.tv_usec;
fake_t_startsingle_time(&data, now, -2);
Curl_pgrsTime(&data, TIMER_NAMELOOKUP);
Curl_pgrsTime(&data, TIMER_CONNECT);
Curl_pgrsTime(&data, TIMER_APPCONNECT);
Curl_pgrsTime(&data, TIMER_PRETRANSFER);
Curl_pgrsTime(&data, TIMER_STARTTRANSFER);
expect_timer_seconds(&data, 2);
/* now simulate the redirect */
data.progress.t_redirect = data.progress.t_starttransfer + 1;
fake_t_startsingle_time(&data, now, -1);
Curl_pgrsTime(&data, TIMER_NAMELOOKUP);
Curl_pgrsTime(&data, TIMER_CONNECT);
Curl_pgrsTime(&data, TIMER_APPCONNECT);
Curl_pgrsTime(&data, TIMER_PRETRANSFER);
/* ensure t_starttransfer is only set on the first invocation by attempting
* to set it twice */
Curl_pgrsTime(&data, TIMER_STARTTRANSFER);
Curl_pgrsTime(&data, TIMER_STARTTRANSFER);
expect_timer_seconds(&data, 3);
UNITTEST_END_SIMPLE
}
+78
View File
@@ -0,0 +1,78 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "curl_ntlm_core.h"
static CURLcode t1600_setup(CURL **easy)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
*easy = curl_easy_init();
if(!*easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
return res;
}
static void t1600_stop(CURL *easy)
{
curl_easy_cleanup(easy);
curl_global_cleanup();
}
static CURLcode test_unit1600(const char *arg)
{
CURL *easy;
UNITTEST_BEGIN(t1600_setup(&easy))
#if defined(USE_NTLM) && (!defined(USE_WINDOWS_SSPI) || \
defined(USE_WIN32_CRYPTO))
unsigned char output[21];
unsigned char *testp = output;
Curl_ntlm_core_mk_nt_hash("1", output);
verify_memory(testp,
"\x69\x94\x3c\x5e\x63\xb4\xd2\xc1\x04\xdb"
"\xbc\xc1\x51\x38\xb7\x2b\x00\x00\x00\x00\x00", 21);
Curl_ntlm_core_mk_nt_hash("hello-you-fool", output);
verify_memory(testp,
"\x39\xaf\x87\xa6\x75\x0a\x7a\x00\xba\xa0"
"\xd3\x4f\x04\x9e\xc1\xd0\x00\x00\x00\x00\x00", 21);
/* !checksrc! disable LONGLINE 2 */
Curl_ntlm_core_mk_nt_hash("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", output);
verify_memory(testp,
"\x36\x9d\xae\x06\x84\x7e\xe1\xc1\x4a\x94\x39\xea\x6f\x44\x8c\x65\x00\x00\x00\x00\x00", 21);
#endif
UNITTEST_END(t1600_stop(easy))
}
+52
View File
@@ -0,0 +1,52 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "curl_md5.h"
static CURLcode test_unit1601(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#if (defined(USE_CURL_NTLM_CORE) && !defined(USE_WINDOWS_SSPI)) || \
!defined(CURL_DISABLE_DIGEST_AUTH)
static const char string1[] = "1";
static const char string2[] = "hello-you-fool";
unsigned char output[MD5_DIGEST_LEN];
unsigned char *testp = output;
Curl_md5it(output, (const unsigned char *) string1, strlen(string1));
verify_memory(testp, "\xc4\xca\x42\x38\xa0\xb9\x23\x82\x0d\xcc\x50\x9a\x6f"
"\x75\x84\x9b", MD5_DIGEST_LEN);
Curl_md5it(output, (const unsigned char *) string2, strlen(string2));
verify_memory(testp, "\x88\x67\x0b\x6d\x5d\x74\x2f\xad\xa5\xcd\xf9\xb6\x82"
"\x87\x5f\x22", MD5_DIGEST_LEN);
#endif
UNITTEST_END_SIMPLE
}
+81
View File
@@ -0,0 +1,81 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "hash.h"
#include "memdebug.h" /* LAST include file */
static void t1602_mydtor(void *p)
{
int *ptr = (int *)p;
free(ptr);
}
static CURLcode t1602_setup(struct Curl_hash *hash)
{
Curl_hash_init(hash, 7, Curl_hash_str,
curlx_str_key_compare, t1602_mydtor);
return CURLE_OK;
}
static void t1602_stop(struct Curl_hash *hash)
{
Curl_hash_destroy(hash);
}
static CURLcode test_unit1602(const char *arg)
{
struct Curl_hash hash;
UNITTEST_BEGIN(t1602_setup(&hash))
int *value;
int *value2;
int *nodep;
size_t klen = sizeof(int);
int key = 20;
int key2 = 25;
value = malloc(sizeof(int));
abort_unless(value != NULL, "Out of memory");
*value = 199;
nodep = Curl_hash_add(&hash, &key, klen, value);
if(!nodep)
free(value);
abort_unless(nodep, "insertion into hash failed");
Curl_hash_clean(&hash);
/* Attempt to add another key/value pair */
value2 = malloc(sizeof(int));
abort_unless(value2 != NULL, "Out of memory");
*value2 = 204;
nodep = Curl_hash_add(&hash, &key2, klen, value2);
if(!nodep)
free(value2);
abort_unless(nodep, "insertion into hash failed");
UNITTEST_END(t1602_stop(&hash))
}
+181
View File
@@ -0,0 +1,181 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "hash.h"
#include "memdebug.h" /* LAST include file */
static const size_t slots = 3;
static void t1603_mydtor(void *p)
{
/* Data are statically allocated */
(void)p;
}
static size_t elem_dtor_calls;
static void my_elem_dtor(void *key, size_t key_len, void *p)
{
(void)p;
(void)key;
(void)key_len;
++elem_dtor_calls;
}
static CURLcode t1603_setup(struct Curl_hash *hash_static)
{
Curl_hash_init(hash_static, slots, Curl_hash_str,
curlx_str_key_compare, t1603_mydtor);
return CURLE_OK;
}
static void t1603_stop(struct Curl_hash *hash_static)
{
Curl_hash_destroy(hash_static);
}
static CURLcode test_unit1603(const char *arg)
{
struct Curl_hash hash_static;
UNITTEST_BEGIN(t1603_setup(&hash_static))
char key1[] = "key1";
char key2[] = "key2b";
char key3[] = "key3";
char key4[] = "key4";
char notakey[] = "notakey";
char *nodep;
int rc;
/* Ensure the key hashes are as expected in order to test both hash
collisions and a full table. Unfortunately, the hashes can vary
between architectures. */
if(Curl_hash_str(key1, strlen(key1), slots) != 1 ||
Curl_hash_str(key2, strlen(key2), slots) != 0 ||
Curl_hash_str(key3, strlen(key3), slots) != 2 ||
Curl_hash_str(key4, strlen(key4), slots) != 1)
curl_mfprintf(stderr,
"Warning: hashes are not computed as expected on this "
"architecture; test coverage will be less comprehensive\n");
nodep = Curl_hash_add(&hash_static, &key1, strlen(key1), &key1);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(nodep == key1, "hash retrieval failed");
nodep = Curl_hash_add(&hash_static, &key2, strlen(key2), &key2);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key2, strlen(key2));
fail_unless(nodep == key2, "hash retrieval failed");
nodep = Curl_hash_add(&hash_static, &key3, strlen(key3), &key3);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key3, strlen(key3));
fail_unless(nodep == key3, "hash retrieval failed");
/* The fourth element exceeds the number of slots & collides */
nodep = Curl_hash_add(&hash_static, &key4, strlen(key4), &key4);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
fail_unless(nodep == key4, "hash retrieval failed");
/* Make sure all elements are still accessible */
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(nodep == key1, "hash retrieval failed");
nodep = Curl_hash_pick(&hash_static, &key2, strlen(key2));
fail_unless(nodep == key2, "hash retrieval failed");
nodep = Curl_hash_pick(&hash_static, &key3, strlen(key3));
fail_unless(nodep == key3, "hash retrieval failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
fail_unless(nodep == key4, "hash retrieval failed");
/* Delete the second of two entries in a bucket */
rc = Curl_hash_delete(&hash_static, &key4, strlen(key4));
fail_unless(rc == 0, "hash delete failed");
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(nodep == key1, "hash retrieval failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
fail_unless(!nodep, "hash retrieval should have failed");
/* Insert that deleted node again */
nodep = Curl_hash_add(&hash_static, &key4, strlen(key4), &key4);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
fail_unless(nodep == key4, "hash retrieval failed");
/* Delete the first of two entries in a bucket */
rc = Curl_hash_delete(&hash_static, &key1, strlen(key1));
fail_unless(rc == 0, "hash delete failed");
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(!nodep, "hash retrieval should have failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
fail_unless(nodep == key4, "hash retrieval failed");
/* Delete the remaining one of two entries in a bucket */
rc = Curl_hash_delete(&hash_static, &key4, strlen(key4));
fail_unless(rc == 0, "hash delete failed");
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(!nodep, "hash retrieval should have failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
fail_unless(!nodep, "hash retrieval should have failed");
/* Delete an already deleted node */
rc = Curl_hash_delete(&hash_static, &key4, strlen(key4));
fail_unless(rc, "hash delete should have failed");
/* Replace an existing node */
nodep = Curl_hash_add(&hash_static, &key1, strlen(key1), &notakey);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(nodep == notakey, "hash retrieval failed");
/* Make sure all remaining elements are still accessible */
nodep = Curl_hash_pick(&hash_static, &key2, strlen(key2));
fail_unless(nodep == key2, "hash retrieval failed");
nodep = Curl_hash_pick(&hash_static, &key3, strlen(key3));
fail_unless(nodep == key3, "hash retrieval failed");
/* Add element with own destructor */
nodep = Curl_hash_add2(&hash_static, &key1, strlen(key1), &key1,
my_elem_dtor);
fail_unless(nodep, "add2 insertion into hash failed");
fail_unless(elem_dtor_calls == 0, "element destructor count should be 0");
/* Add it again, should invoke destructor on first */
nodep = Curl_hash_add2(&hash_static, &key1, strlen(key1), &key1,
my_elem_dtor);
fail_unless(nodep, "add2 again, insertion into hash failed");
fail_unless(elem_dtor_calls == 1, "element destructor count should be 1");
/* remove, should invoke destructor */
rc = Curl_hash_delete(&hash_static, &key1, strlen(key1));
fail_unless(rc == 0, "hash delete failed");
fail_unless(elem_dtor_calls == 2, "element destructor count should be 1");
/* Clean up */
Curl_hash_clean(&hash_static);
UNITTEST_END(t1603_stop(&hash_static))
}
+63
View File
@@ -0,0 +1,63 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "llist.h"
static CURLcode t1605_setup(CURL **easy)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
*easy = curl_easy_init();
if(!*easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
return res;
}
static void t1605_stop(CURL *easy)
{
curl_easy_cleanup(easy);
curl_global_cleanup();
}
static CURLcode test_unit1605(const char *arg)
{
CURL *easy;
UNITTEST_BEGIN(t1605_setup(&easy))
int len;
char *esc;
esc = curl_easy_escape(easy, "", -1);
fail_unless(esc == NULL, "negative string length can't work");
esc = curl_easy_unescape(easy, "%41%41%41%41", -1, &len);
fail_unless(esc == NULL, "negative string length can't work");
UNITTEST_END(t1605_stop(easy))
}
+99
View File
@@ -0,0 +1,99 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "speedcheck.h"
#include "urldata.h"
static CURLcode t1606_setup(struct Curl_easy **easy)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
*easy = curl_easy_init();
if(!*easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
return res;
}
static void t1606_stop(struct Curl_easy *easy)
{
curl_easy_cleanup(easy);
curl_global_cleanup();
}
static int runawhile(struct Curl_easy *easy,
long time_limit,
long speed_limit,
curl_off_t speed,
int dec)
{
int counter = 1;
struct curltime now = {1, 0};
CURLcode result;
int finaltime;
curl_easy_setopt(easy, CURLOPT_LOW_SPEED_LIMIT, speed_limit);
curl_easy_setopt(easy, CURLOPT_LOW_SPEED_TIME, time_limit);
Curl_speedinit(easy);
do {
/* fake the current transfer speed */
easy->progress.current_speed = speed;
result = Curl_speedcheck(easy, now);
if(result)
break;
/* step the time */
now.tv_sec = ++counter;
speed -= dec;
} while(counter < 100);
finaltime = (int)(now.tv_sec - 1);
return finaltime;
}
static CURLcode test_unit1606(const char *arg)
{
struct Curl_easy *easy;
UNITTEST_BEGIN(t1606_setup(&easy))
fail_unless(runawhile(easy, 41, 41, 40, 0) == 41,
"wrong low speed timeout");
fail_unless(runawhile(easy, 21, 21, 20, 0) == 21,
"wrong low speed timeout");
fail_unless(runawhile(easy, 60, 60, 40, 0) == 60,
"wrong log speed timeout");
fail_unless(runawhile(easy, 50, 50, 40, 0) == 50,
"wrong log speed timeout");
fail_unless(runawhile(easy, 40, 40, 40, 0) == 99,
"should not time out");
fail_unless(runawhile(easy, 10, 50, 100, 2) == 36,
"bad timeout");
UNITTEST_END(t1606_stop(easy))
}
+234
View File
@@ -0,0 +1,234 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "connect.h"
#include "share.h"
#include "memdebug.h" /* LAST include file */
static CURLcode t1607_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
return res;
}
static CURLcode test_unit1607(const char *arg)
{
/* In builds without IPv6 support CURLOPT_RESOLVE should skip over those
addresses, so we have to do that as well. */
static const char skip = 0;
#ifdef USE_IPV6
#define IPV6ONLY(x) x
#else
#define IPV6ONLY(x) &skip
#endif
UNITTEST_BEGIN(t1607_setup())
struct testcase {
/* host:port:address[,address]... */
const char *optval;
/* lowercase host and port to retrieve the addresses from hostcache */
const char *host;
int port;
/* whether we expect a permanent or non-permanent cache entry */
bool permanent;
/* 0 to 9 addresses expected from hostcache */
const char *address[10];
};
/* CURLOPT_RESOLVE address parsing tests */
static const struct testcase tests[] = {
/* spaces aren't allowed, for now */
{ "test.com:80:127.0.0.1, 127.0.0.2",
"test.com", 80, TRUE, { NULL, }
},
{ "TEST.com:80:,,127.0.0.1,,,127.0.0.2,,,,::1,,,",
"test.com", 80, TRUE, { "127.0.0.1", "127.0.0.2", IPV6ONLY("::1"), }
},
{ "test.com:80:::1,127.0.0.1",
"test.com", 80, TRUE, { IPV6ONLY("::1"), "127.0.0.1", }
},
{ "test.com:80:[::1],127.0.0.1",
"test.com", 80, TRUE, { IPV6ONLY("::1"), "127.0.0.1", }
},
{ "test.com:80:::1",
"test.com", 80, TRUE, { IPV6ONLY("::1"), }
},
{ "test.com:80:[::1]",
"test.com", 80, TRUE, { IPV6ONLY("::1"), }
},
{ "test.com:80:127.0.0.1",
"test.com", 80, TRUE, { "127.0.0.1", }
},
{ "test.com:80:,127.0.0.1",
"test.com", 80, TRUE, { "127.0.0.1", }
},
{ "test.com:80:127.0.0.1,",
"test.com", 80, TRUE, { "127.0.0.1", }
},
{ "test.com:0:127.0.0.1",
"test.com", 0, TRUE, { "127.0.0.1", }
},
{ "+test.com:80:127.0.0.1,",
"test.com", 80, FALSE, { "127.0.0.1", }
},
};
size_t i;
struct Curl_multi *multi = NULL;
struct Curl_easy *easy = NULL;
struct curl_slist *list = NULL;
for(i = 0; i < CURL_ARRAYSIZE(tests); ++i) {
size_t j;
size_t addressnum = CURL_ARRAYSIZE(tests[i].address);
struct Curl_addrinfo *addr;
struct Curl_dns_entry *dns;
void *entry_id;
bool problem = false;
easy = curl_easy_init();
if(!easy)
goto error;
/* create a multi handle and add the easy handle to it so that the
hostcache is setup */
multi = curl_multi_init();
curl_multi_add_handle(multi, easy);
list = curl_slist_append(NULL, tests[i].optval);
if(!list)
goto error;
curl_easy_setopt(easy, CURLOPT_RESOLVE, list);
Curl_loadhostpairs(easy);
entry_id = (void *)curl_maprintf("%s:%d", tests[i].host, tests[i].port);
if(!entry_id)
goto error;
dns = Curl_hash_pick(&multi->dnscache.entries,
entry_id, strlen(entry_id) + 1);
free(entry_id);
entry_id = NULL;
addr = dns ? dns->addr : NULL;
for(j = 0; j < addressnum; ++j) {
int port = 0;
char ipaddress[MAX_IPADR_LEN] = {0};
if(!addr && !tests[i].address[j])
break;
if(tests[i].address[j] == &skip)
continue;
if(addr && !Curl_addr2string(addr->ai_addr, addr->ai_addrlen,
ipaddress, &port)) {
curl_mfprintf(stderr, "%s:%d tests[%zu] failed. "
"getaddressinfo failed.\n",
__FILE__, __LINE__, i);
problem = true;
break;
}
if(addr && !tests[i].address[j]) {
curl_mfprintf(stderr, "%s:%d tests[%zu] failed. the retrieved addr "
"is %s but tests[%zu].address[%zu] is NULL.\n",
__FILE__, __LINE__, i, ipaddress, i, j);
problem = true;
break;
}
if(!addr && tests[i].address[j]) {
curl_mfprintf(stderr, "%s:%d tests[%zu] failed. the retrieved addr "
"is NULL but tests[%zu].address[%zu] is %s.\n",
__FILE__, __LINE__, i, i, j, tests[i].address[j]);
problem = true;
break;
}
if(!curl_strequal(ipaddress, tests[i].address[j])) {
curl_mfprintf(stderr, "%s:%d tests[%zu] failed. the retrieved addr "
"%s is not equal to tests[%zu].address[%zu] %s.\n",
__FILE__, __LINE__, i, ipaddress, i, j,
tests[i].address[j]);
problem = true;
break;
}
if(port != tests[i].port) {
curl_mfprintf(stderr, "%s:%d tests[%zu] failed. the retrieved port "
"for tests[%zu].address[%zu] is %d "
"but tests[%zu].port is %d.\n",
__FILE__, __LINE__, i, i, j, port, i, tests[i].port);
problem = true;
break;
}
if(dns->timestamp.tv_sec && tests[i].permanent) {
curl_mfprintf(stderr,
"%s:%d tests[%zu] failed. the timestamp is not zero "
"but tests[%zu].permanent is TRUE\n",
__FILE__, __LINE__, i, i);
problem = true;
break;
}
if(dns->timestamp.tv_sec == 0 && !tests[i].permanent) {
curl_mfprintf(stderr, "%s:%d tests[%zu] failed. the timestamp is zero "
"but tests[%zu].permanent is FALSE\n",
__FILE__, __LINE__, i, i);
problem = true;
break;
}
addr = addr->ai_next;
}
curl_easy_cleanup(easy);
easy = NULL;
curl_multi_cleanup(multi);
multi = NULL;
curl_slist_free_all(list);
list = NULL;
if(problem) {
unitfail++;
continue;
}
}
error:
curl_easy_cleanup(easy);
curl_multi_cleanup(multi);
curl_slist_free_all(list);
UNITTEST_END(curl_global_cleanup())
}
+83
View File
@@ -0,0 +1,83 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "hostip.h"
#ifndef CURL_DISABLE_SHUFFLE_DNS
CURLcode Curl_shuffle_addr(struct Curl_easy *data,
struct Curl_addrinfo **addr);
static struct Curl_addrinfo addrs[8];
static CURLcode t1608_setup(void)
{
size_t i;
for(i = 0; i < CURL_ARRAYSIZE(addrs) - 1; i++) {
addrs[i].ai_next = &addrs[i + 1];
}
return CURLE_OK;
}
static CURLcode test_unit1608(const char *arg)
{
UNITTEST_BEGIN(t1608_setup())
int i;
CURLcode code;
struct Curl_addrinfo *addrhead = addrs;
struct Curl_easy *easy = curl_easy_init();
abort_unless(easy, "out of memory");
code = curl_easy_setopt(easy, CURLOPT_DNS_SHUFFLE_ADDRESSES, 1L);
abort_unless(code == CURLE_OK, "curl_easy_setopt failed");
/* Shuffle repeatedly and make sure that the list changes */
for(i = 0; i < 10; i++) {
if(CURLE_OK != Curl_shuffle_addr(easy, &addrhead))
break;
if(addrhead != addrs)
break;
}
curl_easy_cleanup(easy);
curl_global_cleanup();
abort_unless(addrhead != addrs, "addresses are not being reordered");
UNITTEST_END(curl_global_cleanup())
}
#else
static CURLcode test_unit1608(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
UNITTEST_END_SIMPLE
}
#endif
+217
View File
@@ -0,0 +1,217 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "connect.h"
#include "share.h"
#include "memdebug.h" /* LAST include file */
static CURLcode t1609_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
return res;
}
/* CURLOPT_RESOLVE address parsing test - to test the following defect fix:
1) if there is already existing host:port pair in the DNS cache and
we call CURLOPT_RESOLVE, it should also replace addresses.
for example, if there is "test.com:80" with address "1.1.1.1"
and we called CURLOPT_RESOLVE with address "2.2.2.2", then DNS entry needs to
reflect that.
2) when cached address is already there and close to expire, then by the
time request is made, it can get expired. This happens because, when
we set address using CURLOPT_RESOLVE,
it usually marks as permanent (by setting timestamp to zero). However,
if address already exists
in the cache, then it does not mark it, but just leaves it as it is.
So we fixing this by timestamp to zero if address already exists too.
Test:
- insert new entry
- verify that timestamp is not zero
- call set options with CURLOPT_RESOLVE
- then, call Curl_loadhostpairs
expected result: cached address has zero timestamp.
- call set options with CURLOPT_RESOLVE with same host:port pair,
different address.
- then, call Curl_loadhostpairs
expected result: cached address has zero timestamp and new address
*/
static CURLcode test_unit1609(const char *arg)
{
UNITTEST_BEGIN(t1609_setup())
struct testcase {
/* host:port:address[,address]... */
const char *optval;
/* lowercase host and port to retrieve the addresses from hostcache */
const char *host;
int port;
/* 0 to 9 addresses expected from hostcache */
const char *address[10];
};
static const struct testcase tests[] = {
/* spaces aren't allowed, for now */
{ "test.com:80:127.0.0.1",
"test.com", 80, { "127.0.0.1", }
},
{ "test.com:80:127.0.0.2",
"test.com", 80, { "127.0.0.2", }
},
};
size_t i;
struct Curl_multi *multi = NULL;
struct Curl_easy *easy = NULL;
struct curl_slist *list = NULL;
/* important: we setup cache outside of the loop
and also clean cache after the loop. In contrast,for example,
test 1607 sets up and cleans cache on each iteration. */
for(i = 0; i < CURL_ARRAYSIZE(tests); ++i) {
size_t j;
size_t addressnum = CURL_ARRAYSIZE(tests[i].address);
struct Curl_addrinfo *addr;
struct Curl_dns_entry *dns;
void *entry_id;
bool problem = false;
easy = curl_easy_init();
if(!easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
/* create a multi handle and add the easy handle to it so that the
hostcache is setup */
multi = curl_multi_init();
if(!multi)
goto error;
curl_multi_add_handle(multi, easy);
list = curl_slist_append(NULL, tests[i].optval);
if(!list)
goto error;
curl_easy_setopt(easy, CURLOPT_RESOLVE, list);
if(Curl_loadhostpairs(easy))
goto error;
entry_id = (void *)curl_maprintf("%s:%d", tests[i].host, tests[i].port);
if(!entry_id)
goto error;
dns = Curl_hash_pick(&multi->dnscache.entries,
entry_id, strlen(entry_id) + 1);
free(entry_id);
entry_id = NULL;
addr = dns ? dns->addr : NULL;
for(j = 0; j < addressnum; ++j) {
int port = 0;
char ipaddress[MAX_IPADR_LEN] = {0};
if(!addr && !tests[i].address[j])
break;
if(addr && !Curl_addr2string(addr->ai_addr, addr->ai_addrlen,
ipaddress, &port)) {
curl_mfprintf(stderr,
"%s:%d tests[%zu] failed. Curl_addr2string failed.\n",
__FILE__, __LINE__, i);
problem = true;
break;
}
if(addr && !tests[i].address[j]) {
curl_mfprintf(stderr, "%s:%d tests[%zu] failed. the retrieved addr "
"is %s but tests[%zu].address[%zu] is NULL.\n",
__FILE__, __LINE__, i, ipaddress, i, j);
problem = true;
break;
}
if(!addr && tests[i].address[j]) {
curl_mfprintf(stderr, "%s:%d tests[%zu] failed. the retrieved addr "
"is NULL but tests[%zu].address[%zu] is %s.\n",
__FILE__, __LINE__, i, i, j, tests[i].address[j]);
problem = true;
break;
}
if(!curl_strequal(ipaddress, tests[i].address[j])) {
curl_mfprintf(stderr, "%s:%d tests[%zu] failed. the retrieved addr "
"%s is not equal to tests[%zu].address[%zu] %s.\n",
__FILE__, __LINE__, i, ipaddress, i, j,
tests[i].address[j]);
problem = true;
break;
}
if(port != tests[i].port) {
curl_mfprintf(stderr, "%s:%d tests[%zu] failed. the retrieved port "
"for tests[%zu].address[%zu] is %d "
"but tests[%zu].port is %d.\n",
__FILE__, __LINE__, i, i, j, port, i, tests[i].port);
problem = true;
break;
}
addr = addr->ai_next;
}
curl_easy_cleanup(easy);
easy = NULL;
curl_multi_cleanup(multi);
multi = NULL;
curl_slist_free_all(list);
list = NULL;
if(problem) {
unitfail++;
continue;
}
}
goto unit_test_abort;
error:
curl_easy_cleanup(easy);
curl_multi_cleanup(multi);
curl_slist_free_all(list);
UNITTEST_END(curl_global_cleanup())
}
+63
View File
@@ -0,0 +1,63 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "curl_sha256.h"
static CURLcode t1610_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
return res;
}
static CURLcode test_unit1610(const char *arg)
{
UNITTEST_BEGIN(t1610_setup())
#if !defined(CURL_DISABLE_AWS) || !defined(CURL_DISABLE_DIGEST_AUTH) || \
defined(USE_LIBSSH2)
static const char string1[] = "1";
static const char string2[] = "hello-you-fool";
unsigned char output[CURL_SHA256_DIGEST_LENGTH];
unsigned char *testp = output;
Curl_sha256it(output, (const unsigned char *) string1, strlen(string1));
verify_memory(testp,
"\x6b\x86\xb2\x73\xff\x34\xfc\xe1\x9d\x6b\x80\x4e\xff\x5a\x3f"
"\x57\x47\xad\xa4\xea\xa2\x2f\x1d\x49\xc0\x1e\x52\xdd\xb7\x87"
"\x5b\x4b", CURL_SHA256_DIGEST_LENGTH);
Curl_sha256it(output, (const unsigned char *) string2, strlen(string2));
verify_memory(testp,
"\xcb\xb1\x6a\x8a\xb9\xcb\xb9\x35\xa8\xcb\xa0\x2e\x28\xc0\x26"
"\x30\xd1\x19\x9c\x1f\x02\x17\xf4\x7c\x96\x20\xf3\xef\xe8\x27"
"\x15\xae", CURL_SHA256_DIGEST_LENGTH);
#endif
UNITTEST_END(curl_global_cleanup())
}
+52
View File
@@ -0,0 +1,52 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "curl_md4.h"
static CURLcode test_unit1611(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#ifdef USE_CURL_NTLM_CORE
static const char string1[] = "1";
static const char string2[] = "hello-you-fool";
unsigned char output[MD4_DIGEST_LENGTH];
unsigned char *testp = output;
Curl_md4it(output, (const unsigned char *) string1, strlen(string1));
verify_memory(testp,
"\x8b\xe1\xec\x69\x7b\x14\xad\x3a\x53\xb3\x71\x43\x61\x20\x64"
"\x1d", MD4_DIGEST_LENGTH);
Curl_md4it(output, (const unsigned char *) string2, strlen(string2));
verify_memory(testp,
"\xa7\x16\x1c\xad\x7e\xbe\xdb\xbc\xf8\xc7\x23\x10\x2d\x2c\xe2"
"\x0b", MD4_DIGEST_LENGTH);
#endif
UNITTEST_END_SIMPLE
}
+62
View File
@@ -0,0 +1,62 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "curl_hmac.h"
#include "curl_md5.h"
static CURLcode test_unit1612(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#if (defined(USE_CURL_NTLM_CORE) && !defined(USE_WINDOWS_SSPI)) || \
!defined(CURL_DISABLE_DIGEST_AUTH)
static const char password[] = "Pa55worD";
static const char string1[] = "1";
static const char string2[] = "hello-you-fool";
unsigned char output[HMAC_MD5_LENGTH];
unsigned char *testp = output;
Curl_hmacit(&Curl_HMAC_MD5,
(const unsigned char *) password, strlen(password),
(const unsigned char *) string1, strlen(string1),
output);
verify_memory(testp,
"\xd1\x29\x75\x43\x58\xdc\xab\x78\xdf\xcd\x7f\x2b\x29\x31\x13"
"\x37", HMAC_MD5_LENGTH);
Curl_hmacit(&Curl_HMAC_MD5,
(const unsigned char *) password, strlen(password),
(const unsigned char *) string2, strlen(string2),
output);
verify_memory(testp,
"\x75\xf1\xa7\xb9\xf5\x40\xe5\xa4\x98\x83\x9f\x64\x5a\x27\x6d"
"\xd0", HMAC_MD5_LENGTH);
#endif
UNITTEST_END_SIMPLE
}
+180
View File
@@ -0,0 +1,180 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "noproxy.h"
static CURLcode test_unit1614(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_PROXY)
int i;
int err = 0;
struct check {
const char *a;
const char *n;
unsigned int bits;
bool match;
};
struct check list4[]= {
{ "192.160.0.1", "192.160.0.1", 33, FALSE},
{ "192.160.0.1", "192.160.0.1", 32, TRUE},
{ "192.160.0.1", "192.160.0.1", 0, TRUE},
{ "192.160.0.1", "192.160.0.1", 24, TRUE},
{ "192.160.0.1", "192.160.0.1", 26, TRUE},
{ "192.160.0.1", "192.160.0.1", 20, TRUE},
{ "192.160.0.1", "192.160.0.1", 18, TRUE},
{ "192.160.0.1", "192.160.0.1", 12, TRUE},
{ "192.160.0.1", "192.160.0.1", 8, TRUE},
{ "192.160.0.1", "10.0.0.1", 8, FALSE},
{ "192.160.0.1", "10.0.0.1", 32, FALSE},
{ "192.160.0.1", "10.0.0.1", 0, FALSE},
{ NULL, NULL, 0, FALSE} /* end marker */
};
#ifdef USE_IPV6
struct check list6[]= {
{ "::1", "::1", 0, TRUE},
{ "::1", "::1", 128, TRUE},
{ "::1", "0:0::1", 128, TRUE},
{ "::1", "0:0::1", 129, FALSE},
{ "fe80::ab47:4396:55c9:8474", "fe80::ab47:4396:55c9:8474", 64, TRUE},
{ NULL, NULL, 0, FALSE} /* end marker */
};
#endif
struct noproxy {
const char *a;
const char *n;
bool match;
};
struct noproxy list[]= {
{ "www.example.com", "localhost .example.com .example.de", FALSE},
{ "www.example.com", "localhost,.example.com,.example.de", TRUE},
{ "www.example.com.", "localhost,.example.com,.example.de", TRUE},
{ "example.com", "localhost,.example.com,.example.de", TRUE},
{ "example.com.", "localhost,.example.com,.example.de", TRUE},
{ "www.example.com", "localhost,.example.com.,.example.de", TRUE},
{ "www.example.com", "localhost,www.example.com.,.example.de", TRUE},
{ "example.com", "localhost,example.com,.example.de", TRUE},
{ "example.com.", "localhost,example.com,.example.de", TRUE},
{ "nexample.com", "localhost,example.com,.example.de", FALSE},
{ "www.example.com", "localhost,example.com,.example.de", TRUE},
{ "127.0.0.1", "127.0.0.1,localhost", TRUE},
{ "127.0.0.1", "127.0.0.1,localhost,", TRUE},
{ "127.0.0.1", "127.0.0.1/8,localhost,", TRUE},
{ "127.0.0.1", "127.0.0.1/28,localhost,", TRUE},
{ "127.0.0.1", "127.0.0.1/31,localhost,", TRUE},
{ "127.0.0.1", "localhost,127.0.0.1", TRUE},
{ "127.0.0.1", "localhost,127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1."
"127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127."
"0.0.1.127.0.0.1.127.0.0." /* 128 bytes "address" */, FALSE},
{ "127.0.0.1", "localhost,127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1."
"127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127.0.0.1.127."
"0.0.1.127.0.0.1.127.0.0" /* 127 bytes "address" */, FALSE},
{ "localhost", "localhost,127.0.0.1", TRUE},
{ "localhost", "127.0.0.1,localhost", TRUE},
{ "foobar", "barfoo", FALSE},
{ "foobar", "foobar", TRUE},
{ "192.168.0.1", "foobar", FALSE},
{ "192.168.0.1", "192.168.0.0/16", TRUE},
{ "192.168.0.1", "192.168.0.0/24", TRUE},
{ "192.168.0.1", "192.168.0.0/32", FALSE},
{ "192.168.0.1", "192.168.0.0", FALSE},
{ "192.168.1.1", "192.168.0.0/24", FALSE},
{ "192.168.1.1", "192.168.0.0/33", FALSE},
{ "192.168.1.1", "foo, bar, 192.168.0.0/24", FALSE},
{ "192.168.1.1", "foo, bar, 192.168.0.0/16", TRUE},
#ifdef USE_IPV6
{ "[::1]", "foo, bar, 192.168.0.0/16", FALSE},
{ "[::1]", "foo, bar, ::1/64", TRUE},
{ "[::1]", "::1/64", TRUE},
{ "[::1]", "::1/96", TRUE},
{ "[::1]", "::1/127", TRUE},
{ "[::1]", "::1/126", TRUE},
{ "[::1]", "::1/125", TRUE},
{ "[::1]", "::1/124", TRUE},
{ "[::1]", "::1/123", TRUE},
{ "[::1]", "::1/122", TRUE},
{ "[2001:db8:8000::1]", "2001:db8::/65", FALSE},
{ "[2001:db8:8000::1]", "2001:db8::/66", FALSE},
{ "[2001:db8:8000::1]", "2001:db8::/67", FALSE},
{ "[2001:db8:8000::1]", "2001:db8::/68", FALSE},
{ "[2001:db8:8000::1]", "2001:db8::/69", FALSE},
{ "[2001:db8:8000::1]", "2001:db8::/70", FALSE},
{ "[2001:db8:8000::1]", "2001:db8::/71", FALSE},
{ "[2001:db8:8000::1]", "2001:db8::/72", FALSE},
{ "[2001:db8::1]", "2001:db8::/65", TRUE},
{ "[2001:db8::1]", "2001:db8::/66", TRUE},
{ "[2001:db8::1]", "2001:db8::/67", TRUE},
{ "[2001:db8::1]", "2001:db8::/68", TRUE},
{ "[2001:db8::1]", "2001:db8::/69", TRUE},
{ "[2001:db8::1]", "2001:db8::/70", TRUE},
{ "[2001:db8::1]", "2001:db8::/71", TRUE},
{ "[2001:db8::1]", "2001:db8::/72", TRUE},
{ "[::1]", "::1/129", FALSE},
{ "bar", "foo, bar, ::1/64", TRUE},
{ "BAr", "foo, bar, ::1/64", TRUE},
{ "BAr", "foo,,,,, bar, ::1/64", TRUE},
#endif
{ "www.example.com", "foo, .example.com", TRUE},
{ "www.example.com", "www2.example.com, .example.net", FALSE},
{ "example.com", ".example.com, .example.net", TRUE},
{ "nonexample.com", ".example.com, .example.net", FALSE},
{ NULL, NULL, FALSE}
};
for(i = 0; list4[i].a; i++) {
bool match = Curl_cidr4_match(list4[i].a, list4[i].n, list4[i].bits);
if(match != list4[i].match) {
curl_mfprintf(stderr, "%s in %s/%u should %smatch\n",
list4[i].a, list4[i].n, list4[i].bits,
list4[i].match ? "": "not ");
err++;
}
}
#ifdef USE_IPV6
for(i = 0; list6[i].a; i++) {
bool match = Curl_cidr6_match(list6[i].a, list6[i].n, list6[i].bits);
if(match != list6[i].match) {
curl_mfprintf(stderr, "%s in %s/%u should %smatch\n",
list6[i].a, list6[i].n, list6[i].bits,
list6[i].match ? "": "not ");
err++;
}
}
#endif
for(i = 0; list[i].a; i++) {
bool match = Curl_check_noproxy(list[i].a, list[i].n);
if(match != list[i].match) {
curl_mfprintf(stderr, "%s in %s should %smatch\n",
list[i].a, list[i].n,
list[i].match ? "": "not ");
err++;
}
}
fail_if(err, "errors");
#endif
UNITTEST_END_SIMPLE
}
+151
View File
@@ -0,0 +1,151 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) Evgeny Grin (Karlson2k), <k2k@narod.ru>.
*
* 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "curl_sha512_256.h"
static CURLcode test_unit1615(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#ifdef CURL_HAVE_SHA512_256
static const char test_str1[] = "1";
static const unsigned char precomp_hash1[CURL_SHA512_256_DIGEST_LENGTH] = {
0x18, 0xd2, 0x75, 0x66, 0xbd, 0x1a, 0xc6, 0x6b, 0x23, 0x32, 0xd8,
0xc5, 0x4a, 0xd4, 0x3f, 0x7b, 0xb2, 0x20, 0x79, 0xc9, 0x06, 0xd0,
0x5f, 0x49, 0x1f, 0x3f, 0x07, 0xa2, 0x8d, 0x5c, 0x69, 0x90
};
static const char test_str2[] = "hello-you-fool";
static const unsigned char precomp_hash2[CURL_SHA512_256_DIGEST_LENGTH] = {
0xaf, 0x6f, 0xb4, 0xb0, 0x13, 0x9b, 0xee, 0x13, 0xd1, 0x95, 0x3c,
0xb8, 0xc7, 0xcd, 0x5b, 0x19, 0xf9, 0xcd, 0xcd, 0x21, 0xef, 0xdf,
0xa7, 0x42, 0x5c, 0x07, 0x13, 0xea, 0xcc, 0x1a, 0x39, 0x76
};
static const char test_str3[] = "abc";
static const unsigned char precomp_hash3[CURL_SHA512_256_DIGEST_LENGTH] = {
0x53, 0x04, 0x8E, 0x26, 0x81, 0x94, 0x1E, 0xF9, 0x9B, 0x2E, 0x29,
0xB7, 0x6B, 0x4C, 0x7D, 0xAB, 0xE4, 0xC2, 0xD0, 0xC6, 0x34, 0xFC,
0x6D, 0x46, 0xE0, 0xE2, 0xF1, 0x31, 0x07, 0xE7, 0xAF, 0x23
};
static const char test_str4[] = ""; /* empty, zero size input */
static const unsigned char precomp_hash4[CURL_SHA512_256_DIGEST_LENGTH] = {
0xc6, 0x72, 0xb8, 0xd1, 0xef, 0x56, 0xed, 0x28, 0xab, 0x87, 0xc3,
0x62, 0x2c, 0x51, 0x14, 0x06, 0x9b, 0xdd, 0x3a, 0xd7, 0xb8, 0xf9,
0x73, 0x74, 0x98, 0xd0, 0xc0, 0x1e, 0xce, 0xf0, 0x96, 0x7a
};
static const char test_str5[] =
"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA" \
"abcdefghijklmnopqrstuvwxyzzyxwvutsrqponMLKJIHGFEDCBA";
static const unsigned char precomp_hash5[CURL_SHA512_256_DIGEST_LENGTH] = {
0xad, 0xe9, 0x5d, 0x55, 0x3b, 0x9e, 0x45, 0x69, 0xdb, 0x53, 0xa4,
0x04, 0x92, 0xe7, 0x87, 0x94, 0xff, 0xc9, 0x98, 0x5f, 0x93, 0x03,
0x86, 0x45, 0xe1, 0x97, 0x17, 0x72, 0x7c, 0xbc, 0x31, 0x15
};
static const char test_str6[] =
"/long/long/long/long/long/long/long/long/long/long/long" \
"/long/long/long/long/long/long/long/long/long/long/long" \
"/long/long/long/long/long/long/long/long/long/long/long" \
"/long/long/long/long/long/long/long/long/long/long/long" \
"/long/long/long/long/long/long/long/long/long/long/long" \
"/long/long/long/long/long/long/long/long/long/long/long" \
"/long/long/long/long/path?with%20some=parameters";
static const unsigned char precomp_hash6[CURL_SHA512_256_DIGEST_LENGTH] = {
0xbc, 0xab, 0xc6, 0x2c, 0x0a, 0x22, 0xd5, 0xcb, 0xac, 0xac, 0xe9,
0x25, 0xcf, 0xce, 0xaa, 0xaf, 0x0e, 0xa1, 0xed, 0x42, 0x46, 0x8a,
0xe2, 0x01, 0xee, 0x2f, 0xdb, 0x39, 0x75, 0x47, 0x73, 0xf1
};
static const char test_str7[] = "Simple string.";
static const unsigned char precomp_hash7[CURL_SHA512_256_DIGEST_LENGTH] = {
0xde, 0xcb, 0x3c, 0x81, 0x65, 0x4b, 0xa0, 0xf5, 0xf0, 0x45, 0x6b,
0x7e, 0x61, 0xf5, 0x0d, 0xf5, 0x38, 0xa4, 0xfc, 0xb1, 0x8a, 0x95,
0xff, 0x59, 0xbc, 0x04, 0x82, 0xcf, 0x23, 0xb2, 0x32, 0x56
};
static const unsigned char test_seq8[]= {
255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 245, 244, 243, 242,
241, 240, 239, 238, 237, 236, 235, 234, 233, 232, 231, 230, 229, 228,
227, 226, 225, 224, 223, 222, 221, 220, 219, 218, 217, 216, 215, 214,
213, 212, 211, 210, 209, 208, 207, 206, 205, 204, 203, 202, 201, 200,
199, 198, 197, 196, 195, 194, 193, 192, 191, 190, 189, 188, 187, 186,
185, 184, 183, 182, 181, 180, 179, 178, 177, 176, 175, 174, 173, 172,
171, 170, 169, 168, 167, 166, 165, 164, 163, 162, 161, 160, 159, 158,
157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144,
143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130,
129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116,
115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102,
101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85,
84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67,
66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49,
48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31,
30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13,
12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; /* 255..1 sequence */
static const unsigned char precomp_hash8[CURL_SHA512_256_DIGEST_LENGTH] = {
0x22, 0x31, 0xf2, 0xa1, 0xb4, 0x89, 0xb2, 0x44, 0xf7, 0x66, 0xa0,
0xb8, 0x31, 0xed, 0xb7, 0x73, 0x8a, 0x34, 0xdc, 0x11, 0xc8, 0x2c,
0xf2, 0xb5, 0x88, 0x60, 0x39, 0x6b, 0x5c, 0x06, 0x70, 0x37
};
unsigned char output_buf[CURL_SHA512_256_DIGEST_LENGTH];
unsigned char *computed_hash; /* Just to mute compiler warning */
/* Mute compiler warnings in 'verify_memory' macros below */
computed_hash = output_buf;
Curl_sha512_256it(output_buf, (const unsigned char *) test_str1,
CURL_ARRAYSIZE(test_str1) - 1);
verify_memory(computed_hash, precomp_hash1, CURL_SHA512_256_DIGEST_LENGTH);
Curl_sha512_256it(output_buf, (const unsigned char *) test_str2,
CURL_ARRAYSIZE(test_str2) - 1);
verify_memory(computed_hash, precomp_hash2, CURL_SHA512_256_DIGEST_LENGTH);
Curl_sha512_256it(output_buf, (const unsigned char *) test_str3,
CURL_ARRAYSIZE(test_str3) - 1);
verify_memory(computed_hash, precomp_hash3, CURL_SHA512_256_DIGEST_LENGTH);
Curl_sha512_256it(output_buf, (const unsigned char *) test_str4,
CURL_ARRAYSIZE(test_str4) - 1);
verify_memory(computed_hash, precomp_hash4, CURL_SHA512_256_DIGEST_LENGTH);
Curl_sha512_256it(output_buf, (const unsigned char *) test_str5,
CURL_ARRAYSIZE(test_str5) - 1);
verify_memory(computed_hash, precomp_hash5, CURL_SHA512_256_DIGEST_LENGTH);
Curl_sha512_256it(output_buf, (const unsigned char *) test_str6,
CURL_ARRAYSIZE(test_str6) - 1);
verify_memory(computed_hash, precomp_hash6, CURL_SHA512_256_DIGEST_LENGTH);
Curl_sha512_256it(output_buf, (const unsigned char *) test_str7,
CURL_ARRAYSIZE(test_str7) - 1);
verify_memory(computed_hash, precomp_hash7, CURL_SHA512_256_DIGEST_LENGTH);
Curl_sha512_256it(output_buf, test_seq8,
CURL_ARRAYSIZE(test_seq8));
verify_memory(computed_hash, precomp_hash8, CURL_SHA512_256_DIGEST_LENGTH);
#endif /* CURL_HAVE_SHA512_256 */
UNITTEST_END_SIMPLE
}
+88
View File
@@ -0,0 +1,88 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "uint-hash.h"
#include "memdebug.h" /* LAST include file */
static void t1616_mydtor(unsigned int id, void *elem)
{
int *ptr = (int *)elem;
(void)id;
free(ptr);
}
static CURLcode t1616_setup(struct uint_hash *hash)
{
Curl_uint_hash_init(hash, 15, t1616_mydtor);
return CURLE_OK;
}
static void t1616_stop(struct uint_hash *hash)
{
Curl_uint_hash_destroy(hash);
}
static CURLcode test_unit1616(const char *arg)
{
struct uint_hash hash;
UNITTEST_BEGIN(t1616_setup(&hash))
int *value, *v;
int *value2;
bool ok;
unsigned int key = 20;
unsigned int key2 = 25;
value = malloc(sizeof(int));
abort_unless(value != NULL, "Out of memory");
*value = 199;
ok = Curl_uint_hash_set(&hash, key, value);
if(!ok)
free(value);
abort_unless(ok, "insertion into hash failed");
v = Curl_uint_hash_get(&hash, key);
abort_unless(v == value, "lookup present entry failed");
v = Curl_uint_hash_get(&hash, key2);
abort_unless(!v, "lookup missing entry failed");
Curl_uint_hash_clear(&hash);
/* Attempt to add another key/value pair */
value2 = malloc(sizeof(int));
abort_unless(value2 != NULL, "Out of memory");
*value2 = 204;
ok = Curl_uint_hash_set(&hash, key2, value2);
if(!ok)
free(value2);
abort_unless(ok, "insertion into hash failed");
v = Curl_uint_hash_get(&hash, key2);
abort_unless(v == value2, "lookup present entry failed");
v = Curl_uint_hash_get(&hash, key);
abort_unless(!v, "lookup missing entry failed");
UNITTEST_END(t1616_stop(&hash))
}
+129
View File
@@ -0,0 +1,129 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "url.h"
#include "memdebug.h" /* LAST include file */
static CURLcode t1620_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
return res;
}
static void t1620_parse(
const char *input,
const char *exp_username,
const char *exp_password,
const char *exp_options)
{
char *userstr = NULL;
char *passwdstr = NULL;
char *options = NULL;
CURLcode rc = Curl_parse_login_details(input, strlen(input),
&userstr, &passwdstr, &options);
fail_unless(rc == CURLE_OK, "Curl_parse_login_details() failed");
fail_unless(!!exp_username == !!userstr, "username expectation failed");
fail_unless(!!exp_password == !!passwdstr, "password expectation failed");
fail_unless(!!exp_options == !!options, "options expectation failed");
if(!unitfail) {
fail_unless(!userstr || !exp_username ||
strcmp(userstr, exp_username) == 0,
"userstr should be equal to exp_username");
fail_unless(!passwdstr || !exp_password ||
strcmp(passwdstr, exp_password) == 0,
"passwdstr should be equal to exp_password");
fail_unless(!options || !exp_options ||
strcmp(options, exp_options) == 0,
"options should be equal to exp_options");
}
free(userstr);
free(passwdstr);
free(options);
}
static CURLcode test_unit1620(const char *arg)
{
UNITTEST_BEGIN(t1620_setup())
CURLcode rc;
struct Curl_easy *empty;
enum dupstring i;
bool async = FALSE;
bool protocol_connect = FALSE;
rc = Curl_open(&empty);
if(rc)
goto unit_test_abort;
fail_unless(rc == CURLE_OK, "Curl_open() failed");
rc = Curl_connect(empty, &async, &protocol_connect);
fail_unless(rc == CURLE_URL_MALFORMAT,
"Curl_connect() failed to return CURLE_URL_MALFORMAT");
fail_unless(empty->magic == CURLEASY_MAGIC_NUMBER,
"empty->magic should be equal to CURLEASY_MAGIC_NUMBER");
/* double invoke to ensure no dependency on internal state */
rc = Curl_connect(empty, &async, &protocol_connect);
fail_unless(rc == CURLE_URL_MALFORMAT,
"Curl_connect() failed to return CURLE_URL_MALFORMAT");
rc = Curl_init_do(empty, empty->conn);
fail_unless(rc == CURLE_OK, "Curl_init_do() failed");
t1620_parse("hostname", "hostname", NULL, NULL);
t1620_parse("user:password", "user", "password", NULL);
t1620_parse("user:password;options", "user", "password", "options");
t1620_parse("user:password;options;more", "user", "password",
"options;more");
t1620_parse("", "", NULL, NULL);
t1620_parse(":", "", "", NULL);
t1620_parse(":;", "", "", NULL);
t1620_parse(":password", "", "password", NULL);
t1620_parse(":password;", "", "password", NULL);
t1620_parse(";options", "", NULL, "options");
t1620_parse("user;options", "user", NULL, "options");
t1620_parse("user:;options", "user", "", "options");
t1620_parse("user;options:password", "user", "password", "options");
t1620_parse("user;options:", "user", "", "options");
Curl_freeset(empty);
for(i = (enum dupstring)0; i < STRING_LAST; i++) {
fail_unless(empty->set.str[i] == NULL,
"Curl_free() did not set to NULL");
}
rc = Curl_close(&empty);
fail_unless(rc == CURLE_OK, "Curl_close() failed");
UNITTEST_END(curl_global_cleanup())
}
+283
View File
@@ -0,0 +1,283 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "doh.h"
static CURLcode test_unit1650(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#ifndef CURL_DISABLE_DOH
#define DNS_PREAMBLE "\x00\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00"
#define LABEL_TEST "\x04\x74\x65\x73\x74"
#define LABEL_HOST "\x04\x68\x6f\x73\x74"
#define LABEL_NAME "\x04\x6e\x61\x6d\x65"
#define DNSA_TYPE "\x01"
#define DNSAAAA_TYPE "\x1c"
#define DNSA_EPILOGUE "\x00\x00" DNSA_TYPE "\x00\x01"
#define DNSAAAA_EPILOGUE "\x00\x00" DNSAAAA_TYPE "\x00\x01"
#define DNS_Q1 DNS_PREAMBLE LABEL_TEST LABEL_HOST LABEL_NAME DNSA_EPILOGUE
#define DNS_Q2 DNS_PREAMBLE LABEL_TEST LABEL_HOST LABEL_NAME DNSAAAA_EPILOGUE
struct dohrequest {
/* input */
const char *name;
DNStype type;
/* output */
const char *packet;
size_t size;
DOHcode rc;
};
static const struct dohrequest req[] = {
{"test.host.name", CURL_DNS_TYPE_A, DNS_Q1, sizeof(DNS_Q1)-1, DOH_OK },
{"test.host.name", CURL_DNS_TYPE_AAAA, DNS_Q2, sizeof(DNS_Q2)-1, DOH_OK },
{"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
".host.name",
CURL_DNS_TYPE_AAAA, NULL, 0, DOH_DNS_BAD_LABEL }
};
struct dohresp {
/* input */
const char *packet;
size_t size;
DNStype type;
/* output */
DOHcode rc;
const char *out;
};
#define DNS_FOO_EXAMPLE_COM \
"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f" \
"\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x63\x6f\x6d\x00\x00\x01\x00" \
"\x01\xc0\x0c\x00\x01\x00\x01\x00\x00\x00\x37\x00\x04\x7f\x00\x00" \
"\x01"
static const char full49[] = DNS_FOO_EXAMPLE_COM;
static const struct dohresp resp[] = {
{"\x00\x00", 2, CURL_DNS_TYPE_A, DOH_TOO_SMALL_BUFFER, NULL },
{"\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01", 12,
CURL_DNS_TYPE_A, DOH_DNS_BAD_ID, NULL },
{"\x00\x00\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01", 12,
CURL_DNS_TYPE_A, DOH_DNS_BAD_RCODE, NULL },
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f", 16,
CURL_DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f\x00", 17,
CURL_DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f\x00"
"\x00\x01\x00\x01", 21,
CURL_DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f\x00"
"\x00\x01\x00\x01"
"\x04", 18,
CURL_DNS_TYPE_A, DOH_DNS_OUT_OF_RANGE, NULL },
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x04\x63\x75\x72"
"\x6c\x04\x63\x75\x72\x6c\x00\x00\x05\x00\x01\xc0\x0c\x00\x05\x00"
"\x01\x00\x00\x00\x37\x00\x11\x08\x61\x6e\x79\x77\x68\x65\x72\x65"
"\x06\x72\x65\x61\x6c\x6c\x79\x00", 56,
CURL_DNS_TYPE_A, DOH_OK, "anywhere.really "},
{DNS_FOO_EXAMPLE_COM, 49, CURL_DNS_TYPE_A, DOH_OK, "127.0.0.1 "},
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x04\x61\x61\x61"
"\x61\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x63\x6f\x6d\x00\x00\x1c"
"\x00\x01\xc0\x0c\x00\x1c\x00\x01\x00\x00\x00\x37\x00\x10\x20\x20"
"\x20\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x20", 62,
CURL_DNS_TYPE_AAAA, DOH_OK,
"2020:2020:0000:0000:0000:0000:0000:2020 " },
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x04\x63\x75\x72"
"\x6c\x04\x63\x75\x72\x6c\x00\x00\x05\x00\x01\xc0\x0c\x00\x05\x00"
"\x01\x00\x00\x00\x37\x00"
"\x07\x03\x61\x6e\x79\xc0\x27\x00", 46,
CURL_DNS_TYPE_A, DOH_DNS_LABEL_LOOP, NULL},
/* packet with NSCOUNT == 1 */
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x01\x00\x00\x04\x61\x61\x61"
"\x61\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x63\x6f\x6d\x00\x00\x1c"
"\x00\x01\xc0\x0c\x00\x1c\x00\x01\x00\x00\x00\x37\x00\x10\x20\x20"
"\x20\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x20"
LABEL_TEST LABEL_HOST LABEL_NAME DNSAAAA_EPILOGUE "\x00\x00\x00\x01"
"\00\x04\x01\x01\x01\x01", /* RDDATA */
62 + 30,
CURL_DNS_TYPE_AAAA, DOH_OK,
"2020:2020:0000:0000:0000:0000:0000:2020 " },
/* packet with ARCOUNT == 1 */
{"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x01\x04\x61\x61\x61"
"\x61\x07\x65\x78\x61\x6d\x70\x6c\x65\x03\x63\x6f\x6d\x00\x00\x1c"
"\x00\x01\xc0\x0c\x00\x1c\x00\x01\x00\x00\x00\x37\x00\x10\x20\x20"
"\x20\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x20"
LABEL_TEST LABEL_HOST LABEL_NAME DNSAAAA_EPILOGUE "\x00\x00\x00\x01"
"\00\x04\x01\x01\x01\x01", /* RDDATA */
62 + 30,
CURL_DNS_TYPE_AAAA, DOH_OK,
"2020:2020:0000:0000:0000:0000:0000:2020 " },
};
size_t size = 0;
unsigned char buffer[256];
size_t i;
unsigned char *p;
for(i = 0; i < CURL_ARRAYSIZE(req); i++) {
DOHcode rc = doh_req_encode(req[i].name, req[i].type,
buffer, sizeof(buffer), &size);
if(rc != req[i].rc) {
curl_mfprintf(stderr, "req %zu: Expected return code %d got %d\n", i,
req[i].rc, rc);
abort_if(rc != req[i].rc, "return code");
}
if(size != req[i].size) {
curl_mfprintf(stderr, "req %zu: Expected size %zu got %zu\n", i,
req[i].size, size);
curl_mfprintf(stderr, "DNS encode made: %s\n", hexdump(buffer, size));
abort_if(size != req[i].size, "size");
}
if(req[i].packet && memcmp(req[i].packet, buffer, size)) {
curl_mfprintf(stderr, "DNS encode made: %s\n", hexdump(buffer, size));
curl_mfprintf(stderr, "... instead of: %s\n",
hexdump((const unsigned char *)req[i].packet, size));
abort_if(req[i].packet && memcmp(req[i].packet, buffer, size),
"contents");
}
}
for(i = 0; i < CURL_ARRAYSIZE(resp); i++) {
struct dohentry d;
DOHcode rc;
char *ptr;
size_t len;
int u;
de_init(&d);
rc = doh_resp_decode((const unsigned char *)resp[i].packet, resp[i].size,
resp[i].type, &d);
if(rc != resp[i].rc) {
curl_mfprintf(stderr, "resp %zu: Expected return code %d got %d\n", i,
resp[i].rc, rc);
abort_if(rc != resp[i].rc, "return code");
}
len = sizeof(buffer);
ptr = (char *)buffer;
for(u = 0; u < d.numaddr; u++) {
size_t o;
struct dohaddr *a;
a = &d.addr[u];
if(resp[i].type == CURL_DNS_TYPE_A) {
p = &a->ip.v4[0];
curl_msnprintf(ptr, len, "%u.%u.%u.%u ", p[0], p[1], p[2], p[3]);
o = strlen(ptr);
len -= o;
ptr += o;
}
else {
int j;
for(j = 0; j < 16; j += 2) {
size_t l;
curl_msnprintf(ptr, len, "%s%02x%02x", j?":":"", a->ip.v6[j],
a->ip.v6[j + 1]);
l = strlen(ptr);
len -= l;
ptr += l;
}
curl_msnprintf(ptr, len, " ");
len--;
ptr++;
}
}
for(u = 0; u < d.numcname; u++) {
size_t o;
curl_msnprintf(ptr, len, "%s ", curlx_dyn_ptr(&d.cname[u]));
o = strlen(ptr);
len -= o;
ptr += o;
}
de_cleanup(&d);
if(resp[i].out && strcmp((char *)buffer, resp[i].out)) {
curl_mfprintf(stderr, "resp %zu: Expected %s got %s\n", i,
resp[i].out, buffer);
abort_if(resp[i].out && strcmp((char *)buffer, resp[i].out), "content");
}
}
/* pass all sizes into the decoder until full */
for(i = 0; i < sizeof(full49)-1; i++) {
struct dohentry d;
DOHcode rc;
memset(&d, 0, sizeof(d));
rc = doh_resp_decode((const unsigned char *)full49, i, CURL_DNS_TYPE_A,
&d);
if(!rc) {
/* none of them should work */
curl_mfprintf(stderr, "%zu: %d\n", i, rc);
abort_if(!rc, "error rc");
}
}
/* and try all pieces from the other end of the packet */
for(i = 1; i < sizeof(full49); i++) {
struct dohentry d;
DOHcode rc;
memset(&d, 0, sizeof(d));
rc = doh_resp_decode((const unsigned char *)&full49[i], sizeof(full49)-i-1,
CURL_DNS_TYPE_A, &d);
if(!rc) {
/* none of them should work */
curl_mfprintf(stderr, "2 %zu: %d\n", i, rc);
abort_if(!rc, "error rc");
}
}
{
DOHcode rc;
struct dohentry d;
struct dohaddr *a;
memset(&d, 0, sizeof(d));
rc = doh_resp_decode((const unsigned char *)full49, sizeof(full49)-1,
CURL_DNS_TYPE_A, &d);
fail_if(d.numaddr != 1, "missing address");
a = &d.addr[0];
p = &a->ip.v4[0];
curl_msnprintf((char *)buffer, sizeof(buffer),
"%u.%u.%u.%u", p[0], p[1], p[2], p[3]);
if(rc || strcmp((char *)buffer, "127.0.0.1")) {
curl_mfprintf(stderr, "bad address decoded: %s, rc == %d\n", buffer, rc);
abort_if(rc || strcmp((char *)buffer, "127.0.0.1"), "bad address");
}
fail_if(d.numcname, "bad cname counter");
}
#endif
UNITTEST_END_SIMPLE
}
+379
View File
@@ -0,0 +1,379 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "vtls/x509asn1.h"
static CURLcode test_unit1651(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#if defined(USE_GNUTLS) || defined(USE_SCHANNEL)
/* cert captured from gdb when connecting to curl.se on October 26
2018 */
static unsigned char cert[] = {
0x30, 0x82, 0x0F, 0x5B, 0x30, 0x82, 0x0E, 0x43, 0xA0, 0x03, 0x02, 0x01, 0x02,
0x02, 0x0C, 0x08, 0x77, 0x99, 0x2C, 0x6B, 0x67, 0xE1, 0x18, 0xD6, 0x66, 0x66,
0x9E, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01,
0x0B, 0x05, 0x00, 0x30, 0x57, 0x31, 0x0B, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
0x06, 0x13, 0x02, 0x42, 0x45, 0x31, 0x19, 0x30, 0x17, 0x06, 0x03, 0x55, 0x04,
0x0A, 0x13, 0x10, 0x47, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x53, 0x69, 0x67, 0x6E,
0x20, 0x6E, 0x76, 0x2D, 0x73, 0x61, 0x31, 0x2D, 0x30, 0x2B, 0x06, 0x03, 0x55,
0x04, 0x03, 0x13, 0x24, 0x47, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x53, 0x69, 0x67,
0x6E, 0x20, 0x43, 0x6C, 0x6F, 0x75, 0x64, 0x53, 0x53, 0x4C, 0x20, 0x43, 0x41,
0x20, 0x2D, 0x20, 0x53, 0x48, 0x41, 0x32, 0x35, 0x36, 0x20, 0x2D, 0x20, 0x47,
0x33, 0x30, 0x1E, 0x17, 0x0D, 0x31, 0x38, 0x31, 0x30, 0x32, 0x32, 0x31, 0x37,
0x31, 0x38, 0x32, 0x31, 0x5A, 0x17, 0x0D, 0x31, 0x39, 0x30, 0x33, 0x32, 0x31,
0x31, 0x33, 0x34, 0x33, 0x34, 0x34, 0x5A, 0x30, 0x77, 0x31, 0x0B, 0x30, 0x09,
0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11,
0x06, 0x03, 0x55, 0x04, 0x08, 0x0C, 0x0A, 0x43, 0x61, 0x6C, 0x69, 0x66, 0x6F,
0x72, 0x6E, 0x69, 0x61, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x07,
0x0C, 0x0D, 0x53, 0x61, 0x6E, 0x20, 0x46, 0x72, 0x61, 0x6E, 0x63, 0x69, 0x73,
0x63, 0x6F, 0x31, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0A, 0x0C, 0x0C,
0x46, 0x61, 0x73, 0x74, 0x6C, 0x79, 0x2C, 0x20, 0x49, 0x6E, 0x63, 0x2E, 0x31,
0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x1B, 0x6A, 0x32, 0x2E,
0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2E, 0x67, 0x6C, 0x6F, 0x62, 0x61, 0x6C,
0x2E, 0x66, 0x61, 0x73, 0x74, 0x6C, 0x79, 0x2E, 0x6E, 0x65, 0x74, 0x30, 0x82,
0x01, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01,
0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0F, 0x00, 0x30, 0x82, 0x01, 0x0A,
0x02, 0x82, 0x01, 0x01, 0x00, 0xC2, 0x72, 0xA2, 0x4A, 0xEF, 0x26, 0x42, 0xD7,
0x85, 0x74, 0xC9, 0xB4, 0x9F, 0xE3, 0x31, 0xD1, 0x40, 0x77, 0xC9, 0x4B, 0x4D,
0xFE, 0xC8, 0x75, 0xF3, 0x32, 0x76, 0xAD, 0xF9, 0x08, 0x22, 0x9E, 0xFA, 0x2F,
0xFE, 0xEC, 0x6C, 0xC4, 0xF5, 0x1F, 0x70, 0xC9, 0x8F, 0x07, 0x48, 0x31, 0xAD,
0x75, 0x18, 0xFC, 0x06, 0x5A, 0x4F, 0xDD, 0xFD, 0x05, 0x39, 0x6F, 0x22, 0xF9,
0xAD, 0x62, 0x1A, 0x9E, 0xA6, 0x16, 0x48, 0x75, 0x8F, 0xB8, 0x07, 0x18, 0x25,
0x1A, 0x87, 0x30, 0xB0, 0x3C, 0x6F, 0xE0, 0x9D, 0x90, 0x63, 0x2A, 0x16, 0x1F,
0x0D, 0x10, 0xFC, 0x06, 0x7E, 0xEA, 0x51, 0xE2, 0xB0, 0x6D, 0x42, 0x4C, 0x2C,
0x59, 0xF4, 0x6B, 0x99, 0x3E, 0x82, 0x1D, 0x08, 0x04, 0x2F, 0xA0, 0x63, 0x3C,
0xAA, 0x0E, 0xE1, 0x5D, 0x67, 0x2D, 0xB3, 0xF4, 0x15, 0xD6, 0x16, 0x4E, 0xAA,
0x91, 0x45, 0x6B, 0xC5, 0xA6, 0xED, 0x83, 0xAF, 0xF1, 0xD7, 0x42, 0x5E, 0x9B,
0xC8, 0x39, 0x0C, 0x06, 0x76, 0x7A, 0xB8, 0x3E, 0x16, 0x70, 0xF5, 0xEB, 0x8B,
0x33, 0x5A, 0xA9, 0x03, 0xED, 0x79, 0x0E, 0xAD, 0xBB, 0xC4, 0xF8, 0xDA, 0x93,
0x53, 0x2A, 0xC4, 0xC9, 0x1A, 0xD1, 0xC3, 0x44, 0xD7, 0xC6, 0xD0, 0xC6, 0xAC,
0x13, 0xE3, 0xB5, 0x73, 0x3A, 0xDF, 0x54, 0x15, 0xFB, 0xB4, 0x6B, 0x36, 0x39,
0x18, 0xB5, 0x61, 0x12, 0xF0, 0x37, 0xAB, 0x81, 0x5F, 0x0C, 0xE7, 0xDF, 0xC1,
0xC5, 0x5E, 0x99, 0x67, 0x85, 0xFF, 0xAD, 0xD6, 0x82, 0x09, 0x1F, 0x27, 0xE5,
0x32, 0x52, 0x18, 0xEC, 0x35, 0x2F, 0x6C, 0xC9, 0xE6, 0x87, 0xCE, 0x30, 0xF6,
0xDA, 0x04, 0x3F, 0xA5, 0x8A, 0x0C, 0xAE, 0x5B, 0xB0, 0xEC, 0x29, 0x9B, 0xEE,
0x8F, 0x52, 0x1E, 0xE2, 0x56, 0x19, 0x45, 0x80, 0x3C, 0x02, 0x57, 0x5C, 0x52,
0xD9, 0x02, 0x03, 0x01, 0x00, 0x01, 0xA3, 0x82, 0x0C, 0x05, 0x30, 0x82, 0x0C,
0x01, 0x30, 0x0E, 0x06, 0x03, 0x55, 0x1D, 0x0F, 0x01, 0x01, 0xFF, 0x04, 0x04,
0x03, 0x02, 0x05, 0xA0, 0x30, 0x81, 0x8A, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05,
0x05, 0x07, 0x01, 0x01, 0x04, 0x7E, 0x30, 0x7C, 0x30, 0x42, 0x06, 0x08, 0x2B,
0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86, 0x36, 0x68, 0x74, 0x74, 0x70,
0x3A, 0x2F, 0x2F, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x2E, 0x67, 0x6C, 0x6F,
0x62, 0x61, 0x6C, 0x73, 0x69, 0x67, 0x6E, 0x2E, 0x63, 0x6F, 0x6D, 0x2F, 0x63,
0x61, 0x63, 0x65, 0x72, 0x74, 0x2F, 0x63, 0x6C, 0x6F, 0x75, 0x64, 0x73, 0x73,
0x6C, 0x73, 0x68, 0x61, 0x32, 0x67, 0x33, 0x2E, 0x63, 0x72, 0x74, 0x30, 0x36,
0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x86, 0x2A, 0x68,
0x74, 0x74, 0x70, 0x3A, 0x2F, 0x2F, 0x6F, 0x63, 0x73, 0x70, 0x32, 0x2E, 0x67,
0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x73, 0x69, 0x67, 0x6E, 0x2E, 0x63, 0x6F, 0x6D,
0x2F, 0x63, 0x6C, 0x6F, 0x75, 0x64, 0x73, 0x73, 0x6C, 0x73, 0x68, 0x61, 0x32,
0x67, 0x33, 0x30, 0x56, 0x06, 0x03, 0x55, 0x1D, 0x20, 0x04, 0x4F, 0x30, 0x4D,
0x30, 0x41, 0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0xA0, 0x32, 0x01, 0x14,
0x30, 0x34, 0x30, 0x32, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07, 0x02,
0x01, 0x16, 0x26, 0x68, 0x74, 0x74, 0x70, 0x73, 0x3A, 0x2F, 0x2F, 0x77, 0x77,
0x77, 0x2E, 0x67, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x73, 0x69, 0x67, 0x6E, 0x2E,
0x63, 0x6F, 0x6D, 0x2F, 0x72, 0x65, 0x70, 0x6F, 0x73, 0x69, 0x74, 0x6F, 0x72,
0x79, 0x2F, 0x30, 0x08, 0x06, 0x06, 0x67, 0x81, 0x0C, 0x01, 0x02, 0x02, 0x30,
0x09, 0x06, 0x03, 0x55, 0x1D, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x82, 0x09,
0x96, 0x06, 0x03, 0x55, 0x1D, 0x11, 0x04, 0x82, 0x09, 0x8D, 0x30, 0x82, 0x09,
0x89, 0x82, 0x1B, 0x6A, 0x32, 0x2E, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2E,
0x67, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x2E, 0x66, 0x61, 0x73, 0x74, 0x6C, 0x79,
0x2E, 0x6E, 0x65, 0x74, 0x82, 0x0D, 0x2A, 0x2E, 0x61, 0x32, 0x70, 0x72, 0x65,
0x73, 0x73, 0x65, 0x2E, 0x66, 0x72, 0x82, 0x19, 0x2A, 0x2E, 0x61, 0x64, 0x76,
0x65, 0x6E, 0x74, 0x69, 0x73, 0x74, 0x62, 0x6F, 0x6F, 0x6B, 0x63, 0x65, 0x6E,
0x74, 0x65, 0x72, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x14, 0x2A, 0x2E, 0x61, 0x70,
0x69, 0x2E, 0x6C, 0x6F, 0x6C, 0x65, 0x73, 0x70, 0x6F, 0x72, 0x74, 0x73, 0x2E,
0x63, 0x6F, 0x6D, 0x82, 0x0C, 0x2A, 0x2E, 0x62, 0x61, 0x61, 0x74, 0x63, 0x68,
0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x17, 0x2A, 0x2E, 0x62, 0x69, 0x6F, 0x74, 0x65,
0x63, 0x68, 0x77, 0x65, 0x65, 0x6B, 0x62, 0x6F, 0x73, 0x74, 0x6F, 0x6E, 0x2E,
0x63, 0x6F, 0x6D, 0x82, 0x10, 0x2A, 0x2E, 0x62, 0x6F, 0x78, 0x6F, 0x66, 0x73,
0x74, 0x79, 0x6C, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x0C, 0x2A, 0x2E, 0x63,
0x61, 0x73, 0x70, 0x65, 0x72, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x11, 0x2A, 0x2E,
0x63, 0x68, 0x61, 0x6B, 0x72, 0x61, 0x6C, 0x69, 0x6E, 0x75, 0x78, 0x2E, 0x6F,
0x72, 0x67, 0x82, 0x18, 0x2A, 0x2E, 0x63, 0x6F, 0x6E, 0x76, 0x65, 0x72, 0x74,
0x2E, 0x64, 0x73, 0x2E, 0x76, 0x65, 0x72, 0x69, 0x7A, 0x6F, 0x6E, 0x2E, 0x63,
0x6F, 0x6D, 0x82, 0x15, 0x2A, 0x2E, 0x64, 0x65, 0x76, 0x73, 0x70, 0x61, 0x63,
0x65, 0x73, 0x68, 0x69, 0x70, 0x2E, 0x63, 0x6F, 0x6D, 0x2E, 0x61, 0x75, 0x82,
0x1B, 0x2A, 0x2E, 0x64, 0x65, 0x76, 0x73, 0x70, 0x61, 0x63, 0x65, 0x73, 0x68,
0x69, 0x70, 0x69, 0x6E, 0x76, 0x65, 0x73, 0x74, 0x2E, 0x63, 0x6F, 0x6D, 0x2E,
0x61, 0x75, 0x82, 0x0A, 0x2A, 0x2E, 0x65, 0x63, 0x68, 0x6C, 0x2E, 0x63, 0x6F,
0x6D, 0x82, 0x0F, 0x2A, 0x2E, 0x66, 0x69, 0x6C, 0x65, 0x73, 0x74, 0x61, 0x63,
0x6B, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x16, 0x2A, 0x2E, 0x66, 0x69, 0x6C, 0x65,
0x73, 0x74, 0x61, 0x63, 0x6B, 0x2E, 0x6F, 0x6E, 0x65, 0x6D, 0x6F, 0x62, 0x2E,
0x63, 0x6F, 0x6D, 0x82, 0x0D, 0x2A, 0x2E, 0x66, 0x69, 0x73, 0x2D, 0x73, 0x6B,
0x69, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x0C, 0x2A, 0x2E, 0x66, 0x69, 0x73, 0x73,
0x6B, 0x69, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x14, 0x2A, 0x2E, 0x66, 0x70, 0x2E,
0x62, 0x72, 0x61, 0x6E, 0x64, 0x66, 0x6F, 0x6C, 0x64, 0x65, 0x72, 0x2E, 0x63,
0x6F, 0x6D, 0x82, 0x0F, 0x2A, 0x2E, 0x66, 0x73, 0x2E, 0x65, 0x6E, 0x70, 0x6C,
0x75, 0x67, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x0E, 0x2A, 0x2E, 0x66, 0x73, 0x2E,
0x65, 0x6E, 0x70, 0x6C, 0x75, 0x67, 0x2E, 0x69, 0x6E, 0x82, 0x10, 0x2A, 0x2E,
0x66, 0x73, 0x2E, 0x68, 0x65, 0x72, 0x6F, 0x69, 0x6E, 0x65, 0x2E, 0x63, 0x6F,
0x6D, 0x82, 0x18, 0x2A, 0x2E, 0x66, 0x73, 0x2E, 0x6C, 0x65, 0x61, 0x72, 0x6E,
0x7A, 0x69, 0x6C, 0x6C, 0x69, 0x6F, 0x6E, 0x63, 0x64, 0x6E, 0x2E, 0x63, 0x6F,
0x6D, 0x82, 0x18, 0x2A, 0x2E, 0x66, 0x73, 0x2E, 0x6C, 0x6F, 0x63, 0x61, 0x6C,
0x7A, 0x69, 0x6C, 0x6C, 0x69, 0x6F, 0x6E, 0x63, 0x64, 0x6E, 0x2E, 0x63, 0x6F,
0x6D, 0x82, 0x12, 0x2A, 0x2E, 0x66, 0x73, 0x2E, 0x6D, 0x69, 0x6E, 0x64, 0x66,
0x6C, 0x61, 0x73, 0x68, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x16, 0x2A, 0x2E, 0x66,
0x73, 0x2E, 0x6F, 0x70, 0x73, 0x7A, 0x69, 0x6C, 0x6C, 0x69, 0x6F, 0x6E, 0x63,
0x64, 0x6E, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x10, 0x2A, 0x2E, 0x66, 0x73, 0x2E,
0x70, 0x69, 0x78, 0x76, 0x61, 0x6E, 0x61, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x15,
0x2A, 0x2E, 0x66, 0x73, 0x2E, 0x71, 0x61, 0x7A, 0x69, 0x6C, 0x6C, 0x69, 0x6F,
0x6E, 0x63, 0x64, 0x6E, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x17, 0x2A, 0x2E, 0x66,
0x73, 0x2E, 0x74, 0x65, 0x73, 0x74, 0x7A, 0x69, 0x6C, 0x6C, 0x69, 0x6F, 0x6E,
0x63, 0x64, 0x6E, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x09, 0x2A, 0x2E, 0x68, 0x61,
0x78, 0x78, 0x2E, 0x73, 0x65, 0x82, 0x0D, 0x2A, 0x2E, 0x68, 0x6F, 0x6D, 0x65,
0x61, 0x77, 0x61, 0x79, 0x2E, 0x6C, 0x6B, 0x82, 0x0F, 0x2A, 0x2E, 0x69, 0x64,
0x61, 0x74, 0x61, 0x6C, 0x69, 0x6E, 0x6B, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x16,
0x2A, 0x2E, 0x69, 0x64, 0x61, 0x74, 0x61, 0x6C, 0x69, 0x6E, 0x6B, 0x6D, 0x61,
0x65, 0x73, 0x74, 0x72, 0x6F, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x11, 0x2A, 0x2E,
0x69, 0x6D, 0x67, 0x2D, 0x74, 0x61, 0x62, 0x6F, 0x6F, 0x6C, 0x61, 0x2E, 0x63,
0x6F, 0x6D, 0x82, 0x0F, 0x2A, 0x2E, 0x6A, 0x75, 0x6C, 0x69, 0x61, 0x6C, 0x61,
0x6E, 0x67, 0x2E, 0x6F, 0x72, 0x67, 0x82, 0x10, 0x2A, 0x2E, 0x6B, 0x69, 0x6E,
0x64, 0x73, 0x6E, 0x61, 0x63, 0x6B, 0x73, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x10,
0x2A, 0x2E, 0x6B, 0x73, 0x73, 0x76, 0x61, 0x6E, 0x69, 0x6C, 0x6C, 0x61, 0x2E,
0x63, 0x6F, 0x6D, 0x82, 0x0E, 0x2A, 0x2E, 0x6B, 0x73, 0x74, 0x63, 0x6F, 0x72,
0x72, 0x61, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x10, 0x2A, 0x2E, 0x6B, 0x73, 0x74,
0x76, 0x61, 0x6E, 0x69, 0x6C, 0x6C, 0x61, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x0C,
0x2A, 0x2E, 0x6E, 0x65, 0x77, 0x73, 0x31, 0x32, 0x2E, 0x63, 0x6F, 0x6D, 0x82,
0x1B, 0x2A, 0x2E, 0x70, 0x61, 0x72, 0x74, 0x69, 0x64, 0x65, 0x6E, 0x74, 0x69,
0x66, 0x69, 0x65, 0x72, 0x2E, 0x73, 0x77, 0x69, 0x73, 0x63, 0x6F, 0x2E, 0x63,
0x6F, 0x6D, 0x82, 0x13, 0x2A, 0x2E, 0x73, 0x68, 0x6F, 0x70, 0x72, 0x61, 0x63,
0x68, 0x65, 0x6C, 0x7A, 0x6F, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x0A, 0x2A,
0x2E, 0x74, 0x61, 0x73, 0x74, 0x79, 0x2E, 0x63, 0x6F, 0x82, 0x0C, 0x2A, 0x2E,
0x74, 0x65, 0x64, 0x63, 0x64, 0x6E, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x15, 0x2A,
0x2E, 0x75, 0x70, 0x6C, 0x6F, 0x61, 0x64, 0x73, 0x2E, 0x66, 0x6F, 0x6C, 0x69,
0x6F, 0x68, 0x64, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x14, 0x2A, 0x2E, 0x76, 0x6F,
0x75, 0x63, 0x68, 0x65, 0x72, 0x63, 0x6F, 0x64, 0x65, 0x73, 0x2E, 0x63, 0x6F,
0x2E, 0x75, 0x6B, 0x82, 0x0D, 0x2A, 0x2E, 0x77, 0x65, 0x61, 0x74, 0x68, 0x65,
0x72, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x0D, 0x61, 0x2E, 0x69, 0x63, 0x61, 0x6E,
0x76, 0x61, 0x73, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x0B, 0x61, 0x32, 0x70, 0x72,
0x65, 0x73, 0x73, 0x65, 0x2E, 0x66, 0x72, 0x82, 0x17, 0x61, 0x64, 0x76, 0x65,
0x6E, 0x74, 0x69, 0x73, 0x74, 0x62, 0x6F, 0x6F, 0x6B, 0x63, 0x65, 0x6E, 0x74,
0x65, 0x72, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x11, 0x61, 0x70, 0x69, 0x2D, 0x6D,
0x65, 0x72, 0x72, 0x79, 0x6A, 0x61, 0x6E, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x82,
0x12, 0x61, 0x70, 0x69, 0x73, 0x2E, 0x69, 0x64, 0x61, 0x74, 0x61, 0x6C, 0x69,
0x76, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x0F, 0x61, 0x70, 0x70, 0x2D, 0x61,
0x70, 0x69, 0x2E, 0x74, 0x65, 0x64, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x12, 0x61,
0x70, 0x70, 0x2E, 0x62, 0x69, 0x72, 0x63, 0x68, 0x62, 0x6F, 0x78, 0x2E, 0x63,
0x6F, 0x2E, 0x75, 0x6B, 0x82, 0x0F, 0x61, 0x70, 0x70, 0x2E, 0x62, 0x69, 0x72,
0x63, 0x68, 0x62, 0x6F, 0x78, 0x2E, 0x65, 0x73, 0x82, 0x1A, 0x61, 0x70, 0x70,
0x2E, 0x73, 0x74, 0x61, 0x67, 0x69, 0x6E, 0x67, 0x2E, 0x62, 0x69, 0x72, 0x63,
0x68, 0x62, 0x6F, 0x78, 0x2E, 0x63, 0x6F, 0x2E, 0x75, 0x6B, 0x82, 0x17, 0x61,
0x70, 0x70, 0x2E, 0x73, 0x74, 0x61, 0x67, 0x69, 0x6E, 0x67, 0x2E, 0x62, 0x69,
0x72, 0x63, 0x68, 0x62, 0x6F, 0x78, 0x2E, 0x65, 0x73, 0x82, 0x0A, 0x62, 0x61,
0x61, 0x74, 0x63, 0x68, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x13, 0x62, 0x65, 0x72,
0x6E, 0x61, 0x72, 0x64, 0x63, 0x6F, 0x6E, 0x74, 0x72, 0x6F, 0x6C, 0x73, 0x2E,
0x63, 0x6F, 0x6D, 0x82, 0x15, 0x62, 0x69, 0x6F, 0x74, 0x65, 0x63, 0x68, 0x77,
0x65, 0x65, 0x6B, 0x62, 0x6F, 0x73, 0x74, 0x6F, 0x6E, 0x2E, 0x63, 0x6F, 0x6D,
0x82, 0x0E, 0x62, 0x6F, 0x78, 0x6F, 0x66, 0x73, 0x74, 0x79, 0x6C, 0x65, 0x2E,
0x63, 0x6F, 0x6D, 0x82, 0x0A, 0x63, 0x61, 0x73, 0x70, 0x65, 0x72, 0x2E, 0x63,
0x6F, 0x6D, 0x82, 0x0D, 0x63, 0x64, 0x6E, 0x2E, 0x69, 0x72, 0x73, 0x64, 0x6E,
0x2E, 0x6E, 0x65, 0x74, 0x82, 0x0F, 0x63, 0x68, 0x61, 0x6B, 0x72, 0x61, 0x6C,
0x69, 0x6E, 0x75, 0x78, 0x2E, 0x6F, 0x72, 0x67, 0x82, 0x13, 0x64, 0x65, 0x76,
0x73, 0x70, 0x61, 0x63, 0x65, 0x73, 0x68, 0x69, 0x70, 0x2E, 0x63, 0x6F, 0x6D,
0x2E, 0x61, 0x75, 0x82, 0x0B, 0x64, 0x69, 0x67, 0x69, 0x64, 0x61, 0x79, 0x2E,
0x63, 0x6F, 0x6D, 0x82, 0x22, 0x64, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6C, 0x4C,
0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x2E, 0x62, 0x65, 0x72, 0x6E, 0x61, 0x72,
0x64, 0x63, 0x6F, 0x6E, 0x74, 0x72, 0x6F, 0x6C, 0x73, 0x2E, 0x63, 0x6F, 0x6D,
0x82, 0x14, 0x64, 0x72, 0x77, 0x70, 0x2E, 0x73, 0x74, 0x61, 0x67, 0x69, 0x6E,
0x67, 0x2E, 0x6D, 0x6F, 0x6F, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x08, 0x65, 0x63,
0x68, 0x6C, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x14, 0x66, 0x69, 0x6C, 0x65, 0x73,
0x74, 0x61, 0x63, 0x6B, 0x2E, 0x6F, 0x6E, 0x65, 0x6D, 0x6F, 0x62, 0x2E, 0x63,
0x6F, 0x6D, 0x82, 0x0D, 0x66, 0x73, 0x2E, 0x65, 0x6E, 0x70, 0x6C, 0x75, 0x67,
0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x16, 0x66, 0x73, 0x2E, 0x6C, 0x65, 0x61, 0x72,
0x6E, 0x7A, 0x69, 0x6C, 0x6C, 0x69, 0x6F, 0x6E, 0x63, 0x64, 0x6E, 0x2E, 0x63,
0x6F, 0x6D, 0x82, 0x16, 0x66, 0x73, 0x2E, 0x6C, 0x6F, 0x63, 0x61, 0x6C, 0x7A,
0x69, 0x6C, 0x6C, 0x69, 0x6F, 0x6E, 0x63, 0x64, 0x6E, 0x2E, 0x63, 0x6F, 0x6D,
0x82, 0x14, 0x66, 0x73, 0x2E, 0x6F, 0x70, 0x73, 0x7A, 0x69, 0x6C, 0x6C, 0x69,
0x6F, 0x6E, 0x63, 0x64, 0x6E, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x13, 0x66, 0x73,
0x2E, 0x71, 0x61, 0x7A, 0x69, 0x6C, 0x6C, 0x69, 0x6F, 0x6E, 0x63, 0x64, 0x6E,
0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x15, 0x66, 0x73, 0x2E, 0x74, 0x65, 0x73, 0x74,
0x7A, 0x69, 0x6C, 0x6C, 0x69, 0x6F, 0x6E, 0x63, 0x64, 0x6E, 0x2E, 0x63, 0x6F,
0x6D, 0x82, 0x0B, 0x68, 0x6F, 0x6D, 0x65, 0x61, 0x77, 0x61, 0x79, 0x2E, 0x6C,
0x6B, 0x82, 0x12, 0x69, 0x6D, 0x67, 0x2E, 0x74, 0x72, 0x69, 0x67, 0x67, 0x65,
0x72, 0x6D, 0x61, 0x69, 0x6C, 0x2E, 0x69, 0x6F, 0x82, 0x0E, 0x6B, 0x69, 0x6E,
0x64, 0x73, 0x6E, 0x61, 0x63, 0x6B, 0x73, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x0E,
0x6B, 0x73, 0x73, 0x76, 0x61, 0x6E, 0x69, 0x6C, 0x6C, 0x61, 0x2E, 0x63, 0x6F,
0x6D, 0x82, 0x0C, 0x6B, 0x73, 0x74, 0x63, 0x6F, 0x72, 0x72, 0x61, 0x2E, 0x63,
0x6F, 0x6D, 0x82, 0x0D, 0x6D, 0x65, 0x6E, 0x75, 0x2E, 0x74, 0x72, 0x65, 0x65,
0x7A, 0x2E, 0x69, 0x6F, 0x82, 0x17, 0x6D, 0x6F, 0x62, 0x69, 0x6C, 0x65, 0x61,
0x70, 0x69, 0x2E, 0x69, 0x64, 0x61, 0x74, 0x61, 0x6C, 0x69, 0x6E, 0x6B, 0x2E,
0x63, 0x6F, 0x6D, 0x82, 0x0A, 0x6E, 0x65, 0x77, 0x73, 0x31, 0x32, 0x2E, 0x63,
0x6F, 0x6D, 0x82, 0x0B, 0x6F, 0x6D, 0x6E, 0x69, 0x67, 0x6F, 0x6E, 0x2E, 0x63,
0x6F, 0x6D, 0x82, 0x0E, 0x6F, 0x72, 0x65, 0x69, 0x6C, 0x6C, 0x79, 0x2E, 0x72,
0x65, 0x76, 0x69, 0x65, 0x77, 0x82, 0x11, 0x70, 0x6F, 0x70, 0x79, 0x6F, 0x75,
0x72, 0x62, 0x75, 0x62, 0x62, 0x6C, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x18,
0x70, 0x72, 0x6F, 0x64, 0x2E, 0x62, 0x65, 0x72, 0x6E, 0x61, 0x72, 0x64, 0x63,
0x6F, 0x6E, 0x74, 0x72, 0x6F, 0x6C, 0x73, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x18,
0x72, 0x65, 0x6C, 0x65, 0x61, 0x73, 0x65, 0x2D, 0x70, 0x72, 0x69, 0x6D, 0x65,
0x2E, 0x73, 0x70, 0x6F, 0x6B, 0x65, 0x6F, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x19,
0x72, 0x65, 0x70, 0x6F, 0x73, 0x69, 0x74, 0x6F, 0x72, 0x69, 0x65, 0x73, 0x2E,
0x73, 0x65, 0x6E, 0x73, 0x75, 0x61, 0x70, 0x70, 0x2E, 0x6F, 0x72, 0x67, 0x82,
0x0C, 0x72, 0x6C, 0x2E, 0x74, 0x61, 0x6C, 0x69, 0x73, 0x2E, 0x63, 0x6F, 0x6D,
0x82, 0x11, 0x73, 0x68, 0x6F, 0x70, 0x72, 0x61, 0x63, 0x68, 0x65, 0x6C, 0x7A,
0x6F, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x0F, 0x73, 0x74, 0x61, 0x67, 0x69,
0x6E, 0x67, 0x2E, 0x6D, 0x6F, 0x6F, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x14, 0x73,
0x74, 0x61, 0x74, 0x69, 0x63, 0x2E, 0x70, 0x6C, 0x75, 0x6D, 0x63, 0x61, 0x63,
0x68, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x14, 0x73, 0x74, 0x61, 0x79, 0x69,
0x6E, 0x67, 0x61, 0x6C, 0x69, 0x76, 0x65, 0x2E, 0x6D, 0x73, 0x66, 0x2E, 0x6F,
0x72, 0x67, 0x82, 0x08, 0x74, 0x61, 0x73, 0x74, 0x79, 0x2E, 0x63, 0x6F, 0x82,
0x0C, 0x74, 0x6F, 0x70, 0x73, 0x70, 0x65, 0x65, 0x64, 0x2E, 0x63, 0x6F, 0x6D,
0x82, 0x13, 0x75, 0x70, 0x6C, 0x6F, 0x61, 0x64, 0x73, 0x2E, 0x66, 0x6F, 0x6C,
0x69, 0x6F, 0x68, 0x64, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x1A, 0x75, 0x73, 0x2D,
0x65, 0x75, 0x2E, 0x66, 0x69, 0x6C, 0x65, 0x73, 0x74, 0x61, 0x63, 0x6B, 0x63,
0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x74, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x12, 0x76,
0x6F, 0x75, 0x63, 0x68, 0x65, 0x72, 0x63, 0x6F, 0x64, 0x65, 0x73, 0x2E, 0x63,
0x6F, 0x2E, 0x75, 0x6B, 0x82, 0x0B, 0x77, 0x65, 0x61, 0x74, 0x68, 0x65, 0x72,
0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x13, 0x77, 0x6F, 0x6D, 0x65, 0x6E, 0x73, 0x68,
0x65, 0x61, 0x6C, 0x74, 0x68, 0x2D, 0x6A, 0x70, 0x2E, 0x63, 0x6F, 0x6D, 0x82,
0x19, 0x77, 0x6F, 0x72, 0x6B, 0x65, 0x72, 0x62, 0x65, 0x65, 0x2E, 0x73, 0x74,
0x61, 0x67, 0x69, 0x6E, 0x67, 0x2E, 0x6D, 0x6F, 0x6F, 0x2E, 0x63, 0x6F, 0x6D,
0x82, 0x0A, 0x77, 0x77, 0x77, 0x2E, 0x61, 0x67, 0x66, 0x2E, 0x64, 0x6B, 0x82,
0x14, 0x77, 0x77, 0x77, 0x2E, 0x61, 0x76, 0x65, 0x6E, 0x69, 0x72, 0x2D, 0x73,
0x75, 0x69, 0x73, 0x73, 0x65, 0x2E, 0x63, 0x68, 0x82, 0x11, 0x77, 0x77, 0x77,
0x2E, 0x63, 0x61, 0x6E, 0x73, 0x74, 0x61, 0x72, 0x2E, 0x63, 0x6F, 0x2E, 0x6E,
0x7A, 0x82, 0x15, 0x77, 0x77, 0x77, 0x2E, 0x63, 0x61, 0x6E, 0x73, 0x74, 0x61,
0x72, 0x62, 0x6C, 0x75, 0x65, 0x2E, 0x63, 0x6F, 0x2E, 0x6E, 0x7A, 0x82, 0x16,
0x77, 0x77, 0x77, 0x2E, 0x63, 0x61, 0x6E, 0x73, 0x74, 0x61, 0x72, 0x62, 0x6C,
0x75, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x2E, 0x61, 0x75, 0x82, 0x1D, 0x77, 0x77,
0x77, 0x2E, 0x63, 0x68, 0x61, 0x6D, 0x70, 0x69, 0x6F, 0x6E, 0x73, 0x68, 0x6F,
0x63, 0x6B, 0x65, 0x79, 0x6C, 0x65, 0x61, 0x67, 0x75, 0x65, 0x2E, 0x6E, 0x65,
0x74, 0x82, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x65, 0x78, 0x74, 0x65, 0x72, 0x72,
0x6F, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x0C, 0x77, 0x77, 0x77, 0x2E, 0x65, 0x7A,
0x75, 0x70, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x0B, 0x77, 0x77, 0x77, 0x2E, 0x65,
0x7A, 0x75, 0x70, 0x2E, 0x64, 0x65, 0x82, 0x0B, 0x77, 0x77, 0x77, 0x2E, 0x65,
0x7A, 0x75, 0x70, 0x2E, 0x65, 0x75, 0x82, 0x0B, 0x77, 0x77, 0x77, 0x2E, 0x65,
0x7A, 0x75, 0x70, 0x2E, 0x6E, 0x6C, 0x82, 0x11, 0x77, 0x77, 0x77, 0x2E, 0x66,
0x72, 0x61, 0x6E, 0x6B, 0x62, 0x6F, 0x64, 0x79, 0x2E, 0x63, 0x6F, 0x6D, 0x82,
0x0D, 0x77, 0x77, 0x77, 0x2E, 0x67, 0x6C, 0x6F, 0x73, 0x73, 0x79, 0x2E, 0x63,
0x6F, 0x82, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x67, 0x6F, 0x6C, 0x64, 0x63, 0x75,
0x70, 0x2E, 0x6F, 0x72, 0x67, 0x82, 0x0F, 0x77, 0x77, 0x77, 0x2E, 0x69, 0x63,
0x61, 0x6E, 0x76, 0x61, 0x73, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x0D, 0x77, 0x77,
0x77, 0x2E, 0x6D, 0x6F, 0x6E, 0x69, 0x6E, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x16,
0x77, 0x77, 0x77, 0x2E, 0x6F, 0x64, 0x65, 0x6E, 0x73, 0x65, 0x2D, 0x6D, 0x61,
0x72, 0x63, 0x69, 0x70, 0x61, 0x6E, 0x2E, 0x64, 0x6B, 0x82, 0x15, 0x77, 0x77,
0x77, 0x2E, 0x6F, 0x6E, 0x65, 0x63, 0x6C, 0x69, 0x63, 0x6B, 0x64, 0x72, 0x69,
0x76, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x12, 0x77, 0x77, 0x77, 0x2E, 0x6F,
0x72, 0x65, 0x69, 0x6C, 0x6C, 0x79, 0x2E, 0x72, 0x65, 0x76, 0x69, 0x65, 0x77,
0x82, 0x15, 0x77, 0x77, 0x77, 0x2E, 0x70, 0x6F, 0x70, 0x79, 0x6F, 0x75, 0x72,
0x62, 0x75, 0x62, 0x62, 0x6C, 0x65, 0x2E, 0x63, 0x6F, 0x6D, 0x82, 0x0E, 0x77,
0x77, 0x77, 0x2E, 0x72, 0x61, 0x77, 0x6E, 0x65, 0x74, 0x2E, 0x63, 0x6F, 0x6D,
0x82, 0x0E, 0x77, 0x77, 0x77, 0x2E, 0x73, 0x70, 0x6F, 0x6B, 0x65, 0x6F, 0x2E,
0x63, 0x6F, 0x6D, 0x82, 0x10, 0x77, 0x77, 0x77, 0x2E, 0x74, 0x65, 0x61, 0x72,
0x73, 0x68, 0x65, 0x65, 0x74, 0x2E, 0x63, 0x6F, 0x82, 0x10, 0x77, 0x77, 0x77,
0x2E, 0x74, 0x6F, 0x70, 0x73, 0x70, 0x65, 0x65, 0x64, 0x2E, 0x63, 0x6F, 0x6D,
0x82, 0x16, 0x77, 0x77, 0x77, 0x2E, 0x77, 0x68, 0x69, 0x74, 0x65, 0x6B, 0x65,
0x79, 0x76, 0x69, 0x6C, 0x6C, 0x61, 0x73, 0x2E, 0x63, 0x6F, 0x6D, 0x30, 0x1D,
0x06, 0x03, 0x55, 0x1D, 0x25, 0x04, 0x16, 0x30, 0x14, 0x06, 0x08, 0x2B, 0x06,
0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05,
0x07, 0x03, 0x02, 0x30, 0x1D, 0x06, 0x03, 0x55, 0x1D, 0x0E, 0x04, 0x16, 0x04,
0x14, 0xA8, 0x29, 0xFD, 0xA9, 0xA5, 0x1A, 0x1C, 0x37, 0x0B, 0x20, 0x3B, 0x98,
0xB7, 0x25, 0x39, 0xCC, 0xE5, 0x2F, 0xF4, 0x94, 0x30, 0x1F, 0x06, 0x03, 0x55,
0x1D, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xA9, 0x2B, 0x87, 0xE1, 0xCE,
0x24, 0x47, 0x3B, 0x1B, 0xBF, 0xCF, 0x85, 0x37, 0x02, 0x55, 0x9D, 0x0D, 0x94,
0x58, 0xE6, 0x30, 0x82, 0x01, 0x04, 0x06, 0x0A, 0x2B, 0x06, 0x01, 0x04, 0x01,
0xD6, 0x79, 0x02, 0x04, 0x02, 0x04, 0x81, 0xF5, 0x04, 0x81, 0xF2, 0x00, 0xF0,
0x00, 0x77, 0x00, 0xA4, 0xB9, 0x09, 0x90, 0xB4, 0x18, 0x58, 0x14, 0x87, 0xBB,
0x13, 0xA2, 0xCC, 0x67, 0x70, 0x0A, 0x3C, 0x35, 0x98, 0x04, 0xF9, 0x1B, 0xDF,
0xB8, 0xE3, 0x77, 0xCD, 0x0E, 0xC8, 0x0D, 0xDC, 0x10, 0x00, 0x00, 0x01, 0x66,
0x9C, 0xC8, 0xE7, 0x38, 0x00, 0x00, 0x04, 0x03, 0x00, 0x48, 0x30, 0x46, 0x02,
0x21, 0x00, 0xD9, 0x58, 0x6E, 0xFC, 0x4C, 0x3C, 0xAF, 0xF9, 0x5B, 0x7F, 0xDA,
0x54, 0x95, 0xAF, 0xCF, 0xB3, 0x57, 0xB9, 0x56, 0x2C, 0xE8, 0xE0, 0xB1, 0x20,
0x9B, 0xCB, 0x75, 0xAC, 0x4E, 0x54, 0xE9, 0x9D, 0x02, 0x21, 0x00, 0xE8, 0xF0,
0xC0, 0x49, 0x23, 0x8E, 0x3D, 0x9B, 0xA5, 0x87, 0xA3, 0xBE, 0x6C, 0x21, 0x62,
0xBB, 0xD2, 0x44, 0x5C, 0xE4, 0x7A, 0xCC, 0x46, 0x26, 0x04, 0x19, 0xA4, 0x2D,
0x9B, 0x1C, 0x5D, 0x3A, 0x00, 0x75, 0x00, 0x6F, 0x53, 0x76, 0xAC, 0x31, 0xF0,
0x31, 0x19, 0xD8, 0x99, 0x00, 0xA4, 0x51, 0x15, 0xFF, 0x77, 0x15, 0x1C, 0x11,
0xD9, 0x02, 0xC1, 0x00, 0x29, 0x06, 0x8D, 0xB2, 0x08, 0x9A, 0x37, 0xD9, 0x13,
0x00, 0x00, 0x01, 0x66, 0x9C, 0xC8, 0xE6, 0x20, 0x00, 0x00, 0x04, 0x03, 0x00,
0x46, 0x30, 0x44, 0x02, 0x20, 0x14, 0xC8, 0x9F, 0xAC, 0x27, 0x48, 0xBE, 0x4D,
0x0E, 0xC3, 0x26, 0x2E, 0x34, 0xCA, 0x38, 0xBA, 0x11, 0x3A, 0x68, 0x71, 0x88,
0xEB, 0x24, 0x26, 0x59, 0x3E, 0xAC, 0xA8, 0x63, 0xCC, 0x8A, 0x0A, 0x02, 0x20,
0x0F, 0x22, 0xBF, 0x0D, 0x1F, 0x8A, 0x8D, 0x1D, 0x91, 0x33, 0x3A, 0x40, 0xE4,
0x23, 0x78, 0xFA, 0x22, 0xF5, 0x9B, 0xCB, 0x04, 0x4F, 0x53, 0x2D, 0x20, 0x75,
0x2F, 0x76, 0x8A, 0xB1, 0xCD, 0x9D, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48,
0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00,
0x03, 0x41, 0x0F, 0xF3, 0xA6, 0x62, 0xA2, 0xE5, 0xB4, 0x8D, 0xA8, 0x08, 0x71,
0x7B, 0xB3, 0xE3, 0x51, 0x61, 0x0D, 0xC0, 0x67, 0x6C, 0x3C, 0x9C, 0x00, 0x0B,
0x63, 0x77, 0xB6, 0xB6, 0x11, 0x67, 0x77, 0xA5, 0xE1, 0x49, 0xE0, 0x7F, 0xB7,
0x1D, 0x61, 0xFB, 0x83, 0x9C, 0x83, 0x42, 0xE9, 0x31, 0xCA, 0x51, 0xE3, 0xC1,
0xBD, 0x9B, 0x2F, 0xB5, 0x35, 0x05, 0x72, 0x7F, 0x40, 0xA6, 0x7C, 0xC9, 0xF1,
0x59, 0xA7, 0x15, 0xB8, 0x12, 0xDA, 0xF8, 0xCE, 0x83, 0x61, 0xFC, 0x47, 0x96,
0x9E, 0x74, 0xFE, 0xCD, 0xE4, 0x61, 0x92, 0xF2, 0x2E, 0x0C, 0x08, 0x4B, 0x60,
0x2D, 0xF6, 0x50, 0x07, 0x83, 0xCA, 0xAF, 0xB9, 0x41, 0x33, 0x4A, 0x3E, 0x84,
0xC7, 0x73, 0xC6, 0x1F, 0xFF, 0x7A, 0xDF, 0xAE, 0x47, 0x25, 0x32, 0xEB, 0xC0,
0x43, 0x0C, 0xA6, 0x23, 0x13, 0x46, 0xC3, 0xFA, 0x44, 0xEA, 0x20, 0xEA, 0xCB,
0x18, 0x17, 0x00, 0xB6, 0xE7, 0x6D, 0x8A, 0x14, 0x8C, 0x6A, 0xCA, 0x88, 0x4C,
0xDA, 0xA8, 0xB9, 0x08, 0xAF, 0x39, 0xEE, 0xCF, 0xD7, 0xF7, 0x32, 0xC0, 0xF4,
0xCF, 0x4E, 0x22, 0x38, 0xF7, 0xAF, 0xAE, 0x7D, 0x58, 0x5F, 0xA5, 0x2D, 0x4D,
0xBB, 0x86, 0x10, 0xB3, 0x93, 0x62, 0x64, 0x27, 0xBF, 0xB1, 0xBB, 0x8F, 0x9F,
0xFC, 0x07, 0x3C, 0x4B, 0x16, 0x7A, 0x84, 0x5E, 0xAF, 0xAD, 0x57, 0x9C, 0xFF,
0x7A, 0xA7, 0xE0, 0x90, 0x89, 0x1C, 0xE8, 0xE5, 0x11, 0xF7, 0xB6, 0xDC, 0xCD,
0x5E, 0xF7, 0x30, 0xA2, 0x2E, 0x67, 0x6D, 0x4A, 0x70, 0x26, 0xEA, 0xCD, 0x27,
0x70, 0x77, 0x54, 0x57, 0x09, 0x03, 0x56, 0x4A, 0x33, 0x60, 0x00, 0x27, 0xFE,
0xA7, 0xD7, 0xA9, 0xC4, 0xEC, 0x17, 0x17, 0x8D, 0x87, 0x70, 0x6B, 0x48, 0x88,
0x61, 0x54, 0x4A, 0x2B, 0xB7, 0x6A, 0x12, 0x08, 0xFB,
};
CURLcode result;
const char *beg = (const char *)&cert[0];
const char *end = (const char *)&cert[sizeof(cert)];
struct Curl_easy *data;
int i;
int byte;
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
data = curl_easy_init();
if(data) {
result = Curl_extract_certinfo(data, 0, beg, end);
fail_unless(result == CURLE_OK, "Curl_extract_certinfo returned error");
/* a poor man's fuzzing of some initial data to make sure nothing bad
happens */
for(byte = 1 ; byte < 255; byte += 17) {
for(i = 0; i < 45; i++) {
unsigned char backup = cert[i];
cert[i] = (unsigned char) (byte & 0xff);
(void)Curl_extract_certinfo(data, 0, beg, end);
cert[i] = backup;
}
}
curl_easy_cleanup(data);
}
curl_global_cleanup();
#else
puts("not tested since Curl_extract_certinfo() is not built in");
#endif
UNITTEST_END_SIMPLE
}
+165
View File
@@ -0,0 +1,165 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "sendf.h"
/*
* This test hardcodes the knowledge of the buffer size which is internal to
* Curl_infof(). If that buffer is changed in size, this tests needs to be
* updated to still be valid.
*/
static char input[4096];
static char output[4096];
/*
* This debugf callback is simply dumping the string into the static buffer
* for the unit test to inspect. Since we know that we're only dealing with
* text we can afford the luxury of skipping the type check here.
*/
static int debugf_cb(CURL *handle, curl_infotype type, char *buf, size_t size,
void *userptr)
{
(void)handle;
(void)type;
(void)userptr;
memset(output, '\0', sizeof(output));
memcpy(output, buf, size);
return 0;
}
static CURLcode t1652_setup(struct Curl_easy **easy)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
*easy = curl_easy_init();
if(!*easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
curl_easy_setopt(*easy, CURLOPT_DEBUGFUNCTION, debugf_cb);
curl_easy_setopt(*easy, CURLOPT_VERBOSE, 1L);
return res;
}
static void t1652_stop(struct Curl_easy *easy)
{
curl_easy_cleanup(easy);
curl_global_cleanup();
}
static int verify(const char *info, const char *two)
{
/* the 'info' one has a newline appended */
char *nl = strchr(info, '\n');
if(!nl)
return 1; /* nope */
return strncmp(info, two, nl - info);
}
static CURLcode test_unit1652(const char *arg)
{
struct Curl_easy *easy;
UNITTEST_BEGIN(t1652_setup(&easy))
#if defined(CURL_GNUC_DIAG) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wformat-zero-length"
#if __GNUC__ >= 7
#pragma GCC diagnostic ignored "-Wformat-overflow"
#endif
#endif
/* Injecting a simple short string via a format */
curl_msnprintf(input, sizeof(input), "Simple Test");
Curl_infof(easy, "%s", input);
fail_unless(verify(output, input) == 0, "Simple string test");
/* Injecting a few different variables with a format */
Curl_infof(easy, "%s %u testing %lu", input, 42, 43L);
fail_unless(verify(output, "Simple Test 42 testing 43\n") == 0,
"Format string");
/* Variations of empty strings */
Curl_infof(easy, "");
fail_unless(strlen(output) == 1, "Empty string");
Curl_infof(easy, "%s", (char *)NULL);
fail_unless(verify(output, "(nil)") == 0, "Passing NULL as string");
/* Note: libcurl's tracebuffer hold 2048 bytes, so the max strlen() we
* get out of it is 2047, since we need a \0 at the end.
* Curl_infof() in addition adds a \n at the end, making the effective
* output 2046 characters.
* Any input that long or longer will truncated, ending in '...\n'.
*/
/* A string just long enough to not be truncated */
memset(input, '\0', sizeof(input));
memset(input, 'A', 2045);
Curl_infof(easy, "%s", input);
curl_mfprintf(stderr, "output len %zu: %s", strlen(output), output);
/* output is input + \n */
fail_unless(strlen(output) == 2046, "No truncation of infof input");
fail_unless(verify(output, input) == 0, "No truncation of infof input");
fail_unless(output[sizeof(output) - 1] == '\0',
"No truncation of infof input");
/* Just over the limit without newline for truncation via '...' */
memset(input + 2045, 'A', 4);
Curl_infof(easy, "%s", input);
curl_mfprintf(stderr, "output len %zu: %s", strlen(output), output);
fail_unless(strlen(output) == 2047, "Truncation of infof input 1");
fail_unless(output[sizeof(output) - 1] == '\0',
"Truncation of infof input 1");
/* Just over the limit with newline for truncation via '...' */
memset(input + 2045, 'A', 4);
memset(input + 2045 + 4, '\n', 1);
Curl_infof(easy, "%s", input);
curl_mfprintf(stderr, "output len %zu: %s", strlen(output), output);
fail_unless(strlen(output) == 2047, "Truncation of infof input 2");
fail_unless(output[sizeof(output) - 1] == '\0',
"Truncation of infof input 2");
/* Way over the limit for truncation via '...' */
memset(input, '\0', sizeof(input));
memset(input, 'A', sizeof(input) - 1);
Curl_infof(easy, "%s", input);
curl_mfprintf(stderr, "output len %zu: %s", strlen(output), output);
fail_unless(strlen(output) == 2047, "Truncation of infof input 3");
fail_unless(output[sizeof(output) - 1] == '\0',
"Truncation of infof input 3");
#if defined(CURL_GNUC_DIAG) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif
UNITTEST_END(t1652_stop(easy))
}
+220
View File
@@ -0,0 +1,220 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "curl/urlapi.h"
#include "urlapi-int.h"
#define free_and_clear(x) free(x); x = NULL
static CURLUcode parse_port(CURLU *url, char *h, bool has_scheme)
{
struct dynbuf host;
CURLUcode ret;
curlx_dyn_init(&host, 10000);
if(curlx_dyn_add(&host, h))
return CURLUE_OUT_OF_MEMORY;
ret = Curl_parse_port(url, &host, has_scheme);
curlx_dyn_free(&host);
return ret;
}
static CURLcode test_unit1653(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
CURLU *u;
CURLUcode ret;
char *ipv6port = NULL;
char *portnum;
/* Valid IPv6 */
u = curl_url();
if(!u)
goto fail;
ipv6port = strdup("[fe80::250:56ff:fea7:da15]");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
ret = curl_url_get(u, CURLUPART_PORT, &portnum, CURLU_NO_DEFAULT_PORT);
fail_unless(ret != CURLUE_OK, "curl_url_get portnum returned something");
free_and_clear(ipv6port);
curl_url_cleanup(u);
/* Invalid IPv6 */
u = curl_url();
if(!u)
goto fail;
ipv6port = strdup("[fe80::250:56ff:fea7:da15|");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
fail_unless(ret != CURLUE_OK, "parse_port true on error");
free_and_clear(ipv6port);
curl_url_cleanup(u);
u = curl_url();
if(!u)
goto fail;
ipv6port = strdup("[fe80::250:56ff;fea7:da15]:808");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0);
fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error");
fail_unless(portnum && !strcmp(portnum, "808"), "Check portnumber");
curl_free(portnum);
free_and_clear(ipv6port);
curl_url_cleanup(u);
/* Valid IPv6 with zone index and port number */
u = curl_url();
if(!u)
goto fail;
ipv6port = strdup("[fe80::250:56ff:fea7:da15%25eth3]:80");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0);
fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error");
fail_unless(portnum && !strcmp(portnum, "80"), "Check portnumber");
curl_free(portnum);
free_and_clear(ipv6port);
curl_url_cleanup(u);
/* Valid IPv6 with zone index without port number */
u = curl_url();
if(!u)
goto fail;
ipv6port = strdup("[fe80::250:56ff:fea7:da15%25eth3]");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
free_and_clear(ipv6port);
curl_url_cleanup(u);
/* Valid IPv6 with port number */
u = curl_url();
if(!u)
goto fail;
ipv6port = strdup("[fe80::250:56ff:fea7:da15]:81");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0);
fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error");
fail_unless(portnum && !strcmp(portnum, "81"), "Check portnumber");
curl_free(portnum);
free_and_clear(ipv6port);
curl_url_cleanup(u);
/* Valid IPv6 with syntax error in the port number */
u = curl_url();
if(!u)
goto fail;
ipv6port = strdup("[fe80::250:56ff:fea7:da15];81");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
fail_unless(ret != CURLUE_OK, "parse_port true on error");
free_and_clear(ipv6port);
curl_url_cleanup(u);
u = curl_url();
if(!u)
goto fail;
ipv6port = strdup("[fe80::250:56ff:fea7:da15]80");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
fail_unless(ret != CURLUE_OK, "parse_port true on error");
free_and_clear(ipv6port);
curl_url_cleanup(u);
/* Valid IPv6 with no port after the colon, should use default if a scheme
was used in the URL */
u = curl_url();
if(!u)
goto fail;
ipv6port = strdup("[fe80::250:56ff:fea7:da15]:");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, TRUE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
free_and_clear(ipv6port);
curl_url_cleanup(u);
/* Incorrect zone index syntax, but the port extractor doesn't care */
u = curl_url();
if(!u)
goto fail;
ipv6port = strdup("[fe80::250:56ff:fea7:da15!25eth3]:180");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0);
fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error");
fail_unless(portnum && !strcmp(portnum, "180"), "Check portnumber");
curl_free(portnum);
free_and_clear(ipv6port);
curl_url_cleanup(u);
/* Non percent-encoded zone index */
u = curl_url();
if(!u)
goto fail;
ipv6port = strdup("[fe80::250:56ff:fea7:da15%eth3]:80");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "parse_port returned error");
free_and_clear(ipv6port);
curl_url_cleanup(u);
/* No scheme and no digits following the colon - not accepted. Because that
makes (a*50):// that looks like a scheme be an acceptable input. */
u = curl_url();
if(!u)
goto fail;
ipv6port = strdup("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaa:");
if(!ipv6port)
goto fail;
ret = parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_BAD_PORT_NUMBER, "parse_port did wrong");
fail:
free(ipv6port);
curl_url_cleanup(u);
UNITTEST_END_SIMPLE
}
+144
View File
@@ -0,0 +1,144 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "altsvc.h"
static CURLcode test_unit1654(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_ALTSVC)
char outname[256];
CURL *curl;
CURLcode result;
struct altsvcinfo *asi = Curl_altsvc_init();
abort_if(!asi, "Curl_altsvc_i");
result = Curl_altsvc_load(asi, arg);
if(result) {
fail_if(result, "Curl_altsvc_load");
goto fail;
}
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(!curl) {
fail_if(!curl, "curl_easy_init");
goto fail;
}
fail_unless(Curl_llist_count(&asi->list) == 4, "wrong number of entries");
curl_msnprintf(outname, sizeof(outname), "%s-out", arg);
result = Curl_altsvc_parse(curl, asi, "h2=\"example.com:8080\"\r\n",
ALPN_h1, "example.org", 8080);
fail_if(result, "Curl_altsvc_parse() failed!");
fail_unless(Curl_llist_count(&asi->list) == 5, "wrong number of entries");
result = Curl_altsvc_parse(curl, asi, "h3=\":8080\"\r\n",
ALPN_h1, "2.example.org", 8080);
fail_if(result, "Curl_altsvc_parse(2) failed!");
fail_unless(Curl_llist_count(&asi->list) == 6, "wrong number of entries");
result = Curl_altsvc_parse(curl, asi,
"h2=\"example.com:8080\", "
"h3=\"yesyes.com:8080\"\r\n",
ALPN_h1, "3.example.org", 8080);
fail_if(result, "Curl_altsvc_parse(3) failed!");
/* that one should make two entries */
fail_unless(Curl_llist_count(&asi->list) == 8, "wrong number of entries");
result = Curl_altsvc_parse(curl, asi,
"h2=\"example.com:443\"; ma = 120;\r\n",
ALPN_h2, "example.org", 80);
fail_if(result, "Curl_altsvc_parse(4) failed!");
fail_unless(Curl_llist_count(&asi->list) == 9, "wrong number of entries");
/* quoted 'ma' value */
result = Curl_altsvc_parse(curl, asi,
"h2=\"example.net:443\"; ma=\"180\";\r\n",
ALPN_h2, "example.net", 80);
fail_if(result, "Curl_altsvc_parse(5) failed!");
fail_unless(Curl_llist_count(&asi->list) == 10, "wrong number of entries");
result =
Curl_altsvc_parse(curl, asi,
"h2=\":443\", h3=\":443\"; "
"persist = \"1\"; ma = 120;\r\n",
ALPN_h1, "curl.se", 80);
fail_if(result, "Curl_altsvc_parse(6) failed!");
fail_unless(Curl_llist_count(&asi->list) == 12, "wrong number of entries");
/* clear that one again and decrease the counter */
result = Curl_altsvc_parse(curl, asi, "clear;\r\n",
ALPN_h1, "curl.se", 80);
fail_if(result, "Curl_altsvc_parse(7) failed!");
fail_unless(Curl_llist_count(&asi->list) == 10, "wrong number of entries");
result =
Curl_altsvc_parse(curl, asi,
"h2=\":443\", h3=\":443\"; "
"persist = \"1\"; ma = 120;\r\n",
ALPN_h1, "curl.se", 80);
fail_if(result, "Curl_altsvc_parse(6) failed!");
fail_unless(Curl_llist_count(&asi->list) == 12, "wrong number of entries");
/* clear - without semicolon */
result = Curl_altsvc_parse(curl, asi, "clear\r\n",
ALPN_h1, "curl.se", 80);
fail_if(result, "Curl_altsvc_parse(7) failed!");
fail_unless(Curl_llist_count(&asi->list) == 10, "wrong number of entries");
/* only a non-existing alpn */
result = Curl_altsvc_parse(curl, asi,
"h6=\"example.net:443\"; ma=\"180\";\r\n",
ALPN_h2, "5.example.net", 80);
fail_if(result, "Curl_altsvc_parse(8) failed!");
/* missing quote in alpn host */
result = Curl_altsvc_parse(curl, asi,
"h2=\"example.net:443,; ma=\"180\";\r\n",
ALPN_h2, "6.example.net", 80);
fail_if(result, "Curl_altsvc_parse(9) failed!");
/* missing port in host name */
result = Curl_altsvc_parse(curl, asi,
"h2=\"example.net\"; ma=\"180\";\r\n",
ALPN_h2, "7.example.net", 80);
fail_if(result, "Curl_altsvc_parse(10) failed!");
/* illegal port in host name */
result = Curl_altsvc_parse(curl, asi,
"h2=\"example.net:70000\"; ma=\"180\";\r\n",
ALPN_h2, "8.example.net", 80);
fail_if(result, "Curl_altsvc_parse(11) failed!");
Curl_altsvc_save(curl, asi, outname);
curl_easy_cleanup(curl);
fail:
Curl_altsvc_cleanup(&asi);
#endif
UNITTEST_END(curl_global_cleanup())
}
+177
View File
@@ -0,0 +1,177 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "doh.h" /* from the lib dir */
static CURLcode test_unit1655(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#ifndef CURL_DISABLE_DOH
/*
* Prove detection of write overflow using a short buffer and a name
* of maximal valid length.
*
* Prove detection of other invalid input.
*/
do {
static const char max[] =
/* ..|....1.........2.........3.........4.........5.........6... */
/* 3456789012345678901234567890123456789012345678901234567890123 */
"this.is.a.maximum-length.hostname." /* 34: 34 */
"with-no-label-of-greater-length-than-the-sixty-three-characters."
/* 64: 98 */
"specified.in.the.RFCs." /* 22: 120 */
"and.with.a.QNAME.encoding.whose.length.is.exactly." /* 50: 170 */
"the.maximum.length.allowed." /* 27: 197 */
"that.is.two-hundred.and.fifty-six." /* 34: 231 */
"including.the.last.null." /* 24: 255 */
"";
static const char toolong[] =
/* ..|....1.........2.........3.........4.........5.........6... */
/* 3456789012345678901234567890123456789012345678901234567890123 */
"here.is.a.hostname.which.is.just.barely.too.long." /* 49: 49 */
"to.be.encoded.as.a.QNAME.of.the.maximum.allowed.length."
/* 55: 104 */
"which.is.256.including.a.final.zero-length.label." /* 49: 153 */
"representing.the.root.node.so.that.a.name.with." /* 47: 200 */
"a.trailing.dot.may.have.up.to." /* 30: 230 */
"255.characters.never.more." /* 26: 256 */
"";
static const char emptylabel[] =
"this.is.an.otherwise-valid.hostname."
".with.an.empty.label.";
static const char outsizelabel[] =
"this.is.an.otherwise-valid.hostname."
"with-a-label-of-greater-length-than-the-sixty-three-characters-"
"specified.in.the.RFCs.";
size_t i;
struct test {
const char *name;
const DOHcode expected_result;
};
/* plays the role of struct dnsprobe in urldata.h */
struct demo {
unsigned char dohbuffer[255 + 16]; /* deliberately short buffer */
unsigned char canary1;
unsigned char canary2;
unsigned char canary3;
};
const struct test playlist[4] = {
{ toolong, DOH_DNS_NAME_TOO_LONG }, /* expect early failure */
{ emptylabel, DOH_DNS_BAD_LABEL }, /* also */
{ outsizelabel, DOH_DNS_BAD_LABEL }, /* also */
{ max, DOH_OK } /* expect buffer overwrite */
};
for(i = 0; i < CURL_ARRAYSIZE(playlist); i++) {
const char *name = playlist[i].name;
size_t olen = 100000;
struct demo victim;
DOHcode d;
victim.canary1 = 87; /* magic numbers, arbitrarily picked */
victim.canary2 = 35;
victim.canary3 = 41;
d = doh_req_encode(name, CURL_DNS_TYPE_A, victim.dohbuffer,
sizeof(struct demo), /* allow room for overflow */
&olen);
fail_unless(d == playlist[i].expected_result,
"result returned was not as expected");
if(d == playlist[i].expected_result) {
if(name == max) {
fail_if(victim.canary1 == 87,
"demo one-byte buffer overwrite did not happen");
}
else {
fail_unless(victim.canary1 == 87,
"one-byte buffer overwrite has happened");
}
fail_unless(victim.canary2 == 35,
"two-byte buffer overwrite has happened");
fail_unless(victim.canary3 == 41,
"three-byte buffer overwrite has happened");
}
else {
if(d == DOH_OK) {
fail_unless(olen <= sizeof(victim.dohbuffer),
"wrote outside bounds");
fail_unless(olen > strlen(name), "unrealistic low size");
}
}
}
} while(0);
/* run normal cases and try to trigger buffer length related errors */
do {
DNStype dnstype = CURL_DNS_TYPE_A;
unsigned char buffer[128];
const size_t buflen = sizeof(buffer);
const size_t magic1 = 9765;
size_t olen1 = magic1;
static const char *sunshine1 = "a.com";
static const char *dotshine1 = "a.com.";
static const char *sunshine2 = "aa.com";
size_t olen2;
DOHcode ret2;
size_t olen;
DOHcode ret = doh_req_encode(sunshine1, dnstype, buffer, buflen, &olen1);
fail_unless(ret == DOH_OK, "sunshine case 1 should pass fine");
fail_if(olen1 == magic1, "olen has not been assigned properly");
fail_unless(olen1 > strlen(sunshine1), "bad out length");
/* with a trailing dot, the response should have the same length */
olen2 = magic1;
ret2 = doh_req_encode(dotshine1, dnstype, buffer, buflen, &olen2);
fail_unless(ret2 == DOH_OK, "dotshine case should pass fine");
fail_if(olen2 == magic1, "olen has not been assigned properly");
fail_unless(olen1 == olen2, "olen should not grow for a trailing dot");
/* add one letter, the response should be one longer */
olen2 = magic1;
ret2 = doh_req_encode(sunshine2, dnstype, buffer, buflen, &olen2);
fail_unless(ret2 == DOH_OK, "sunshine case 2 should pass fine");
fail_if(olen2 == magic1, "olen has not been assigned properly");
fail_unless(olen1 + 1 == olen2, "olen should grow with the hostname");
/* pass a short buffer, should fail */
ret = doh_req_encode(sunshine1, dnstype, buffer, olen1 - 1, &olen);
fail_if(ret == DOH_OK, "short buffer should have been noticed");
/* pass a minimum buffer, should succeed */
ret = doh_req_encode(sunshine1, dnstype, buffer, olen1, &olen);
fail_unless(ret == DOH_OK, "minimal length buffer should be long enough");
fail_unless(olen == olen1, "bad buffer length");
} while(0);
#endif /* CURL_DISABLE_DOH */
UNITTEST_END_SIMPLE
}
+124
View File
@@ -0,0 +1,124 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "vtls/x509asn1.h"
#if defined(USE_GNUTLS) || defined(USE_SCHANNEL) || defined(USE_MBEDTLS)
struct test_spec {
const char *input;
const char *exp_output;
CURLcode exp_result;
};
static bool do_test(const struct test_spec *spec, size_t i,
struct dynbuf *dbuf)
{
CURLcode result;
const char *in = spec->input;
curlx_dyn_reset(dbuf);
result = Curl_x509_GTime2str(dbuf, in, in + strlen(in));
if(result != spec->exp_result) {
curl_mfprintf(stderr, "test %zu: expect result %d, got %d\n",
i, spec->exp_result, result);
return FALSE;
}
else if(!result && strcmp(spec->exp_output, curlx_dyn_ptr(dbuf))) {
curl_mfprintf(stderr,
"test %zu: input '%s', expected output '%s', got '%s'\n",
i, in, spec->exp_output, curlx_dyn_ptr(dbuf));
return FALSE;
}
return TRUE;
}
static CURLcode test_unit1656(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
static const struct test_spec test_specs[] = {
{ "190321134340", "1903-21-13 43:40:00", CURLE_OK },
{ "", NULL, CURLE_BAD_FUNCTION_ARGUMENT },
{ "WTF", NULL, CURLE_BAD_FUNCTION_ARGUMENT },
{ "0WTF", NULL, CURLE_BAD_FUNCTION_ARGUMENT },
{ "19032113434", NULL, CURLE_BAD_FUNCTION_ARGUMENT },
{ "19032113434WTF", NULL, CURLE_BAD_FUNCTION_ARGUMENT },
{ "190321134340.", NULL, CURLE_BAD_FUNCTION_ARGUMENT },
{ "190321134340.1", "1903-21-13 43:40:00.1", CURLE_OK },
{ "19032113434017.0", "1903-21-13 43:40:17", CURLE_OK },
{ "19032113434017.01", "1903-21-13 43:40:17.01", CURLE_OK },
{ "19032113434003.001", "1903-21-13 43:40:03.001", CURLE_OK },
{ "19032113434003.090", "1903-21-13 43:40:03.09", CURLE_OK },
{ "190321134340Z", "1903-21-13 43:40:00 GMT", CURLE_OK },
{ "19032113434017.0Z", "1903-21-13 43:40:17 GMT", CURLE_OK },
{ "19032113434017.01Z", "1903-21-13 43:40:17.01 GMT", CURLE_OK },
{ "19032113434003.001Z", "1903-21-13 43:40:03.001 GMT", CURLE_OK },
{ "19032113434003.090Z", "1903-21-13 43:40:03.09 GMT", CURLE_OK },
{ "190321134340CET", "1903-21-13 43:40:00 CET", CURLE_OK },
{ "19032113434017.0CET", "1903-21-13 43:40:17 CET", CURLE_OK },
{ "19032113434017.01CET", "1903-21-13 43:40:17.01 CET", CURLE_OK },
{ "190321134340+02:30", "1903-21-13 43:40:00 UTC+02:30", CURLE_OK },
{ "19032113434017.0+02:30", "1903-21-13 43:40:17 UTC+02:30", CURLE_OK },
{ "19032113434017.01+02:30", "1903-21-13 43:40:17.01 UTC+02:30", CURLE_OK },
{ "190321134340-3", "1903-21-13 43:40:00 UTC-3", CURLE_OK },
{ "19032113434017.0-04", "1903-21-13 43:40:17 UTC-04", CURLE_OK },
{ "19032113434017.01-01:10", "1903-21-13 43:40:17.01 UTC-01:10", CURLE_OK },
};
size_t i;
struct dynbuf dbuf;
bool all_ok = TRUE;
curlx_dyn_init(&dbuf, 32*1024);
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
for(i = 0; i < CURL_ARRAYSIZE(test_specs); ++i) {
if(!do_test(&test_specs[i], i, &dbuf))
all_ok = FALSE;
}
fail_unless(all_ok, "some tests of Curl_x509_GTime2str() fails");
curlx_dyn_free(&dbuf);
curl_global_cleanup();
UNITTEST_END_SIMPLE
}
#else
static CURLcode test_unit1656(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
puts("not tested since Curl_x509_GTime2str() is not built in");
UNITTEST_END_SIMPLE
}
#endif
+124
View File
@@ -0,0 +1,124 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "vtls/x509asn1.h"
#if defined(USE_GNUTLS) || defined(USE_SCHANNEL) || defined(USE_MBEDTLS)
struct test1657_spec {
CURLcode (*setbuf)(const struct test1657_spec *spec, struct dynbuf *buf);
size_t n;
CURLcode exp_result;
};
static CURLcode make1657_nested(const struct test1657_spec *spec,
struct dynbuf *buf)
{
CURLcode r;
size_t i;
unsigned char open_undef[] = { 0x32, 0x80 };
unsigned char close_undef[] = { 0x00, 0x00 };
for(i = 0; i < spec->n; ++i) {
r = curlx_dyn_addn(buf, open_undef, sizeof(open_undef));
if(r)
return r;
}
for(i = 0; i < spec->n; ++i) {
r = curlx_dyn_addn(buf, close_undef, sizeof(close_undef));
if(r)
return r;
}
return CURLE_OK;
}
static const struct test1657_spec test1657_specs[] = {
{ make1657_nested, 3, CURLE_OK },
{ make1657_nested, 16, CURLE_OK },
{ make1657_nested, 17, CURLE_BAD_FUNCTION_ARGUMENT },
{ make1657_nested, 1024, CURLE_BAD_FUNCTION_ARGUMENT },
};
static bool do_test1657(const struct test1657_spec *spec, size_t i,
struct dynbuf *buf)
{
CURLcode result;
struct Curl_asn1Element elem;
const char *in;
memset(&elem, 0, sizeof(elem));
curlx_dyn_reset(buf);
result = spec->setbuf(spec, buf);
if(result) {
curl_mfprintf(stderr, "test %zu: error setting buf %d\n", i, result);
return FALSE;
}
in = curlx_dyn_ptr(buf);
result = Curl_x509_getASN1Element(&elem, in, in + curlx_dyn_len(buf));
if(result != spec->exp_result) {
curl_mfprintf(stderr, "test %zu: expect result %d, got %d\n",
i, spec->exp_result, result);
return FALSE;
}
return TRUE;
}
static CURLcode test_unit1657(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
size_t i;
bool all_ok = TRUE;
struct dynbuf dbuf;
curlx_dyn_init(&dbuf, 32*1024);
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
curl_mfprintf(stderr, "curl_global_init() failed\n");
return TEST_ERR_MAJOR_BAD;
}
for(i = 0; i < CURL_ARRAYSIZE(test1657_specs); ++i) {
if(!do_test1657(&test1657_specs[i], i, &dbuf))
all_ok = FALSE;
}
fail_unless(all_ok, "some tests of Curl_x509_getASN1Element() fails");
curlx_dyn_free(&dbuf);
curl_global_cleanup();
UNITTEST_END_SIMPLE
}
#else
static CURLcode test_unit1657(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
puts("not tested since Curl_x509_getASN1Element() is not built in");
UNITTEST_END_SIMPLE
}
#endif
+552
View File
@@ -0,0 +1,552 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "doh.h" /* from the lib dir */
/* DoH + HTTPSRR are required */
#if !defined(CURL_DISABLE_DOH) && defined(USE_HTTPSRR)
static CURLcode t1658_setup(void)
{
/* whatever you want done first */
curl_global_init(CURL_GLOBAL_ALL);
return CURLE_OK;
}
extern CURLcode doh_resp_decode_httpsrr(struct Curl_easy *data,
const unsigned char *cp, size_t len,
struct Curl_https_rrinfo **hrr);
extern void doh_print_httpsrr(struct Curl_easy *data,
struct Curl_https_rrinfo *hrr);
/*
* The idea here is that we pass one DNS packet at the time to the decoder. we
* then generate a string output with the results and compare if it matches
* the expected. One by one.
*/
static char rrbuffer[256];
static void rrresults(struct Curl_https_rrinfo *rr, CURLcode result)
{
char *p = rrbuffer;
char *pend = rrbuffer + sizeof(rrbuffer);
curl_msnprintf(rrbuffer, sizeof(rrbuffer), "r:%d|", (int)result);
p += strlen(rrbuffer);
if(rr) {
unsigned int i;
curl_msnprintf(p, pend - p, "p:%d|", rr->priority);
p += strlen(p);
curl_msnprintf(p, pend - p, "%s|", rr->target ? rr->target : "-");
p += strlen(p);
for(i = 0; i < MAX_HTTPSRR_ALPNS && rr->alpns[i] != ALPN_none; i++) {
curl_msnprintf(p, pend - p, "alpn:%x|", rr->alpns[i]);
p += strlen(p);
}
if(rr->no_def_alpn) {
curl_msnprintf(p, pend - p, "no-def-alpn|");
p += strlen(p);
}
if(rr->port >= 0) {
curl_msnprintf(p, pend - p, "port:%d|", rr->port);
p += strlen(p);
}
if(rr->ipv4hints) {
for(i = 0; i < rr->ipv4hints_len; i += 4) {
curl_msnprintf(p, pend - p, "ipv4:%d.%d.%d.%d|",
rr->ipv4hints[i],
rr->ipv4hints[i + 1],
rr->ipv4hints[i + 2],
rr->ipv4hints[i + 3]);
p += strlen(p);
}
}
if(rr->echconfiglist) {
curl_msnprintf(p, pend - p, "ech:");
p += strlen(p);
for(i = 0; i < rr->echconfiglist_len; i++) {
curl_msnprintf(p, pend - p, "%02x", rr->echconfiglist[i]);
p += strlen(p);
}
curl_msnprintf(p, pend - p, "|");
p += strlen(p);
}
if(rr->ipv6hints) {
for(i = 0; i < rr->ipv6hints_len; i += 16) {
int x;
curl_msnprintf(p, pend - p, "ipv6:");
p += strlen(p);
for(x = 0; x < 16; x += 2) {
curl_msnprintf(p, pend - p, "%s%02x%02x",
x ? ":" : "",
rr->ipv6hints[i + x],
rr->ipv6hints[i + x + 1]);
p += strlen(p);
}
curl_msnprintf(p, pend - p, "|");
p += strlen(p);
}
}
}
}
static CURLcode test_unit1658(const char *arg)
{
UNITTEST_BEGIN(t1658_setup())
/* The "SvcParamKeys" specified within the HTTPS RR packet *must* be
provided in numerical order. */
struct test {
const char *name;
const unsigned char *dns;
size_t len; /* size of the dns packet */
const char *expect;
};
static const struct test t[] = {
{
"single h2 alpn",
(const unsigned char *)"\x00\x00" /* 16-bit prio */
"\x04name\x00" /* RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x03" /* data size */
"\x02" /* length byte */
"h2",
15,
"r:0|p:0|name.|alpn:10|"
},
{
"single h2 alpn missing last byte",
(const unsigned char *)"\x00\x00" /* 16-bit prio */
"\x04name\x00" /* RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x03" /* data size */
"\x02" /* length byte */
"h", /* missing byte */
14,
"r:8|"
},
{
"two alpns",
(const unsigned char *)"\x00\x00" /* 16-bit prio */
"\x04name\x04some\x00" /* RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x06" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x02" /* APLN length byte */
"h3",
23,
"r:0|p:0|name.some.|alpn:10|alpn:20|"
},
{
"wrong syntax alpns",
(const unsigned char *)"\x00\x00" /* 16-bit prio */
"\x04name\x04some\x00" /* RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x06" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x03" /* APLN length byte (WRONG) */
"h3",
23,
"r:61|"
},
{
"five alpns (ignore dupes)", /* we only support four */
(const unsigned char *)"\x00\x00" /* 16-bit prio */
"\x04name\x04some\x00" /* RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x0f" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x02" /* ALPN length byte */
"h2"
"\x02" /* ALPN length byte */
"h2"
"\x02" /* ALPN length byte */
"h2"
"\x02" /* APLN length byte */
"h3",
32,
"r:0|p:0|name.some.|alpn:10|alpn:20|"
},
{
"rname only",
(const unsigned char *)"\x00\x00" /* 16-bit prio */
"\x04name\x04some\x00", /* RNAME */
13,
"r:0|p:0|name.some.|"
},
{
"rname with low ascii byte",
(const unsigned char *)"\x00\x00" /* 16-bit prio */
"\x04name\x04som\x03\x00", /* RNAME */
13,
"r:8|"
},
{
"rname with null byte",
(const unsigned char *)"\x00\x00" /* 16-bit prio */
"\x04sa\x00e\x04some\x00", /* RNAME */
13,
"r:27|"
},
{
"rname only (missing byte)",
(const unsigned char *)"\x00\x00" /* 16-bit prio */
"\x04name\x05some\x00", /* RNAME */
/* it lacks a byte */
13,
"r:27|"
},
{
"unrecognized alpn",
(const unsigned char *)"\x00\x00" /* 16-bit prio */
"\x04name\x04some\x00" /* RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x06" /* data size */
"\x02" /* ALPN length byte */
"h8" /* unrecognized */
"\x02" /* APLN length byte */
"h1",
23,
"r:0|p:0|name.some.|alpn:8|"
},
{
"alnt + no-default-alpn",
(const unsigned char *)"\x00\x00" /* 16-bit prio */
"\x04name\x04some\x00" /* RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x03" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x00\x02" /* RR (2 == NO DEFAULT ALPN) */
"\x00\x00", /* must be zero */
24,
"r:0|p:0|name.some.|alpn:10|no-def-alpn|"
},
{
"alnt + no-default-alpn with size",
(const unsigned char *)"\x00\x00" /* 16-bit prio */
"\x04name\x04some\x00" /* RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x03" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x00\x02" /* RR (2 == NO DEFAULT ALPN) */
"\x00\x01" /* must be zero */
"\xff",
25,
"r:43|"
},
{
"alnt + no-default-alpn with size too short package",
(const unsigned char *)"\x00\x00" /* 16-bit prio */
"\x04name\x04some\x00" /* RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x03" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x00\x02" /* RR (2 == NO DEFAULT ALPN) */
"\x00\x01", /* must be zero */
/* missing last byte in the packet */
24,
"r:8|"
},
{
"rname + blank alpn field",
(const unsigned char *)"\x11\x11" /* 16-bit prio */
"\x04name\x04some\x00" /* RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x00", /* data size, strictly speaking this is illegal:
"one or more alpn-ids" */
17,
"r:0|p:4369|name.some.|"
},
{
"no rname + blank alpn",
(const unsigned char *)"\x00\x11" /* 16-bit prio */
"\x00" /* no RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x00", /* data size */
7,
"r:0|p:17|.|"
},
{
"unsupported field",
(const unsigned char *)"\xff\xff" /* 16-bit prio */
"\x00" /* no RNAME */
"\x00\x07" /* RR (7 == not a supported data) */
"\x00\x02" /* data size */
"FF", /* unknown to curl */
9,
"r:0|p:65535|.|"
},
{
"unsupported field (wrong size)",
(const unsigned char *)"\xff\xff" /* 16-bit prio */
"\x00" /* no RNAME */
"\x00\x07" /* RR (7 == not a supported data) */
"\x00\x02" /* data size */
"F", /* unknown to curl */
8,
"r:8|"
},
{
"port number",
(const unsigned char *)"\x00\x10" /* 16-bit prio */
"\x00" /* no RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x03" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x00\x03" /* RR (3 == PORT) */
"\x00\x02" /* data size */
"\x12\x34", /* port number */
16,
"r:0|p:16|.|alpn:10|port:4660|"
},
{
"port number with wrong size (3 bytes)",
(const unsigned char *)"\x00\x10" /* 16-bit prio */
"\x00" /* no RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x03" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x00\x03" /* RR (3 == PORT) */
"\x00\x03" /* data size */
"\x12\x34\x00", /* 24 bit port number! */
17,
"r:43|"
},
{
"port number with wrong size (1 byte)",
(const unsigned char *)"\x00\x10" /* 16-bit prio */
"\x00" /* no RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x03" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x00\x03" /* RR (3 == PORT) */
"\x00\x01" /* data size */
"\x12", /* 8 bit port number! */
15,
"r:43|"
},
{
"alpn + two ipv4 addresses",
(const unsigned char *)"\x00\x10" /* 16-bit prio */
"\x00" /* no RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x03" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x00\x04" /* RR (4 == Ipv4hints) */
"\x00\x08" /* data size */
"\xc0\xa8\x00\x01" /* 32 bits */
"\xc0\xa8\x00\x02", /* 32 bits */
22,
"r:0|p:16|.|alpn:10|ipv4:192.168.0.1|ipv4:192.168.0.2|"
},
{
"alpn + two ipv4 addresses in wrong order",
(const unsigned char *)"\x00\x10" /* 16-bit prio */
"\x00" /* no RNAME */
"\x00\x04" /* RR (4 == Ipv4hints) */
"\x00\x08" /* data size */
"\xc0\xa8\x00\x01" /* 32 bits */
"\xc0\xa8\x00\x02" /* 32 bits */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x03" /* data size */
"\x02" /* ALPN length byte */
"h2",
22,
"r:8|"
},
{
"alpn + ipv4 address with wrong size",
(const unsigned char *)"\x00\x10" /* 16-bit prio */
"\x00" /* no RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x03" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x00\x04" /* RR (4 == Ipv4hints) */
"\x00\x05" /* data size */
"\xc0\xa8\x00\x01\xff", /* 32 + 8 bits */
19,
"r:43|"
},
{
"alpn + one ipv6 address",
(const unsigned char *)"\x00\x10" /* 16-bit prio */
"\x00" /* no RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x03" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x00\x06" /* RR (6 == Ipv6hints) */
"\x00\x10" /* data size */
"\xfe\x80\xda\xbb\xc1\xff\xfe\xa3\x8a\x22\x12\x34\x56\x78\x91\x23",
30,
"r:0|p:16|.|alpn:10|ipv6:fe80:dabb:c1ff:fea3:8a22:1234:5678:9123|"
},
{
"alpn + one ipv6 address with wrong size",
(const unsigned char *)"\x00\x10" /* 16-bit prio */
"\x00" /* no RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x03" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x00\x06" /* RR (6 == Ipv6hints) */
"\x00\x11" /* data size */
"\xfe\x80\xda\xbb\xc1\xff\xfe\xa3\x8a\x22\x12\x34\x56\x78\x91\x23\x45",
31,
"r:43|"
},
{
"alpn + two ipv6 addresses",
(const unsigned char *)"\x00\x10" /* 16-bit prio */
"\x00" /* no RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x03" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x00\x06" /* RR (6 == Ipv6hints) */
"\x00\x20" /* data size */
"\xfe\x80\xda\xbb\xc1\xff\xfe\xa3\x8a\x22\x12\x34\x56\x78\x91\x23"
"\xee\x80\xda\xbb\xc1\xff\xfe\xa3\x8a\x22\x12\x34\x56\x78\x91\x25",
46,
"r:0|p:16|.|alpn:10|ipv6:fe80:dabb:c1ff:fea3:8a22:1234:5678:9123|"
"ipv6:ee80:dabb:c1ff:fea3:8a22:1234:5678:9125|"
},
{
"alpn + ech",
(const unsigned char *)"\x00\x10" /* 16-bit prio */
"\x00" /* no RNAME */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x03" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x00\x05" /* RR (5 == ECH) */
"\x00\x10" /* data size */
"\xfe\x80\xda\xbb\xc1\xff\xfe\xa3\x8a\x22\x12\x34\x56\x78\x91\x23",
30,
"r:0|p:16|.|alpn:10|ech:fe80dabbc1fffea38a22123456789123|"
},
{
"fully packed",
(const unsigned char *)"\xa0\x0b" /* 16-bit prio */
"\x00" /* no RNAME */
"\x00\x00" /* RR (0 == MANDATORY) */
"\x00\x00" /* data size */
"\x00\x01" /* RR (1 == ALPN) */
"\x00\x06" /* data size */
"\x02" /* ALPN length byte */
"h2"
"\x02" /* ALPN length byte */
"h1"
"\x00\x02" /* RR (2 == NO DEFAULT ALPN) */
"\x00\x00" /* must be zero */
"\x00\x03" /* RR (3 == PORT) */
"\x00\x02" /* data size */
"\xbc\x71" /* port number */
"\x00\x04" /* RR (4 == Ipv4hints) */
"\x00\x08" /* data size */
"\xc0\xa8\x00\x01" /* 32 bits */
"\xc0\xa8\x00\x02" /* 32 bits */
"\x00\x05" /* RR (5 == ECH) */
"\x00\x10" /* data size */
"\xfe\x80\xda\xbb\xc1\xff\x7e\xb3\x8a\x22\x12\x34\x56\x78\x91\x23"
"\x00\x06" /* RR (6 == Ipv6hints) */
"\x00\x20" /* data size */
"\xfe\x80\xda\xbb\xc1\xff\xfe\xa3\x8a\x22\x12\x34\x56\x78\x91\x23"
"\xee\x80\xda\xbb\xc1\xff\xfe\xa3\x8a\x22\x12\x34\x56\x78\x91\x25"
"\x01\x07" /* RR (263 == not supported) */
"\x00\x04" /* data size */
"FFAA", /* unknown to the world */
103,
"r:0|p:40971|.|alpn:10|alpn:8|no-def-alpn|port:48241|"
"ipv4:192.168.0.1|ipv4:192.168.0.2|"
"ech:fe80dabbc1ff7eb38a22123456789123|"
"ipv6:fe80:dabb:c1ff:fea3:8a22:1234:5678:9123|"
"ipv6:ee80:dabb:c1ff:fea3:8a22:1234:5678:9125|"
}
};
CURLcode result = CURLE_OUT_OF_MEMORY;
CURL *easy;
easy = curl_easy_init();
/* so that we get the log output: */
curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
if(easy) {
unsigned int i;
for(i = 0; i < CURL_ARRAYSIZE(t); i++) {
struct Curl_https_rrinfo *hrr;
curl_mprintf("test %u: %s\n", i, t[i].name);
result = doh_resp_decode_httpsrr(easy, t[i].dns, t[i].len, &hrr);
/* create an output */
rrresults(hrr, result);
/* is the output the expected? */
if(strcmp(rrbuffer, t[i].expect)) {
curl_mfprintf(stderr, "Test %s (%u) failed\n"
"Expected: %s\n"
"Received: %s\n", t[i].name, i, t[i].expect, rrbuffer);
unitfail++;
}
/* free the generated struct */
if(hrr) {
Curl_httpsrr_cleanup(hrr);
curl_free(hrr);
}
}
curl_easy_cleanup(easy);
}
UNITTEST_END(curl_global_cleanup())
}
#else /* CURL_DISABLE_DOH or not HTTPSRR enabled */
static CURLcode test_unit1658(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
UNITTEST_END_SIMPLE
}
#endif
+172
View File
@@ -0,0 +1,172 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "hsts.h"
#if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_HSTS)
static CURLcode test_unit1660(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
puts("nothing to do when HTTP or HSTS are disabled");
UNITTEST_END_SIMPLE
}
#else
static void showsts(struct stsentry *e, const char *chost)
{
if(!e)
curl_mprintf("'%s' is not HSTS\n", chost);
else {
curl_mprintf("%s [%s]: %" CURL_FORMAT_CURL_OFF_T "%s\n",
chost, e->host, e->expires,
e->includeSubDomains ? " includeSubDomains" : "");
}
}
static CURLcode test_unit1660(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
struct testit {
const char *host;
const char *chost; /* if non-NULL, use to lookup with */
const char *hdr; /* if NULL, just do the lookup */
const CURLcode result; /* parse result */
};
static const struct testit headers[] = {
/* two entries read from disk cache, verify first */
{ "-", "readfrom.example", NULL, CURLE_OK},
{ "-", "old.example", NULL, CURLE_OK},
/* delete the remaining one read from disk */
{ "readfrom.example", NULL, "max-age=\"0\"", CURLE_OK},
{ "example.com", NULL, "max-age=\"31536000\"\r\n", CURLE_OK },
{ "example.com", NULL, "max-age=\"21536000\"\r\n", CURLE_OK },
{ "example.com", NULL, "max-age=\"21536000\"; \r\n", CURLE_OK },
{ "example.com", NULL, "max-age=\"21536000\"; includeSubDomains\r\n",
CURLE_OK },
{ "example.org", NULL, "max-age=\"31536000\"\r\n", CURLE_OK },
{ "this.example", NULL, "max=\"31536\";", CURLE_BAD_FUNCTION_ARGUMENT },
{ "this.example", NULL, "max-age=\"31536", CURLE_BAD_FUNCTION_ARGUMENT },
{ "this.example", NULL, "max-age=31536\"", CURLE_OK },
/* max-age=0 removes the entry */
{ "this.example", NULL, "max-age=0", CURLE_OK },
{ "another.example", NULL, "includeSubDomains; ",
CURLE_BAD_FUNCTION_ARGUMENT },
/* Two max-age is illegal */
{ "example.com", NULL,
"max-age=\"21536000\"; includeSubDomains; max-age=\"3\";",
CURLE_BAD_FUNCTION_ARGUMENT },
/* Two includeSubDomains is illegal */
{ "2.example.com", NULL,
"max-age=\"21536000\"; includeSubDomains; includeSubDomains;",
CURLE_BAD_FUNCTION_ARGUMENT },
/* use an unknown directive "include" that should be ignored */
{ "3.example.com", NULL, "max-age=\"21536000\"; include; includeSubDomains;",
CURLE_OK },
/* remove the "3.example.com" one, should still match the example.com */
{ "3.example.com", NULL, "max-age=\"0\"; includeSubDomains;",
CURLE_OK },
{ "-", "foo.example.com", NULL, CURLE_OK},
{ "-", "foo.xample.com", NULL, CURLE_OK},
/* should not match */
{ "example.net", "forexample.net", "max-age=\"31536000\"\r\n", CURLE_OK },
/* should not match either, since forexample.net is not in the example.net
domain */
{ "example.net", "forexample.net",
"max-age=\"31536000\"; includeSubDomains\r\n", CURLE_OK },
/* remove example.net again */
{ "example.net", NULL, "max-age=\"0\"; includeSubDomains\r\n", CURLE_OK },
/* make this live for 7 seconds */
{ "expire.example", NULL, "max-age=\"7\"\r\n", CURLE_OK },
{ NULL, NULL, NULL, CURLE_OK }
};
CURLcode result;
struct stsentry *e;
struct hsts *h = Curl_hsts_init();
int i;
const char *chost;
CURL *easy;
char savename[256];
abort_unless(h, "Curl_hsts_init()");
curl_global_init(CURL_GLOBAL_ALL);
easy = curl_easy_init();
if(!easy) {
Curl_hsts_cleanup(&h);
curl_global_cleanup();
abort_unless(easy, "curl_easy_init()");
}
Curl_hsts_loadfile(easy, h, arg);
for(i = 0; headers[i].host ; i++) {
if(headers[i].hdr) {
result = Curl_hsts_parse(h, headers[i].host, headers[i].hdr);
if(result != headers[i].result) {
curl_mfprintf(stderr, "Curl_hsts_parse(%s) failed: %d\n",
headers[i].hdr, result);
unitfail++;
continue;
}
else if(result) {
curl_mprintf("Input %u: error %d\n", i, (int) result);
continue;
}
}
chost = headers[i].chost ? headers[i].chost : headers[i].host;
e = Curl_hsts(h, chost, strlen(chost), TRUE);
showsts(e, chost);
}
curl_mprintf("Number of entries: %zu\n", Curl_llist_count(&h->list));
/* verify that it is exists for 7 seconds */
chost = "expire.example";
for(i = 100; i < 110; i++) {
e = Curl_hsts(h, chost, strlen(chost), TRUE);
showsts(e, chost);
deltatime++; /* another second passed */
}
curl_msnprintf(savename, sizeof(savename), "%s.save", arg);
(void)Curl_hsts_save(easy, h, savename);
Curl_hsts_cleanup(&h);
curl_easy_cleanup(easy);
curl_global_cleanup();
UNITTEST_END(curl_global_cleanup())
}
#endif
+115
View File
@@ -0,0 +1,115 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "bufref.h"
#include "memdebug.h"
static int freecount = 0;
static void test_free(void *p)
{
fail_unless(p, "pointer to free may not be NULL");
freecount++;
free(p);
}
static CURLcode t1661_setup(struct bufref *bufref)
{
Curl_bufref_init(bufref);
return CURLE_OK;
}
static void t1661_stop(struct bufref *bufref)
{
Curl_bufref_free(bufref);
}
static CURLcode test_unit1661(const char *arg)
{
struct bufref bufref;
UNITTEST_BEGIN(t1661_setup(&bufref))
const char *buffer = NULL;
CURLcode result = CURLE_OK;
/**
* testing Curl_bufref_init.
* @assumptions:
* 1: data size will be 0
* 2: reference will be NULL
* 3: destructor will be NULL
*/
fail_unless(!bufref.ptr, "Initial reference must be NULL");
fail_unless(!bufref.len, "Initial length must be NULL");
fail_unless(!bufref.dtor, "Destructor must be NULL");
/**
* testing Curl_bufref_set
*/
buffer = malloc(13);
abort_unless(buffer, "Out of memory");
Curl_bufref_set(&bufref, buffer, 13, test_free);
fail_unless((const char *)bufref.ptr == buffer, "Referenced data badly set");
fail_unless(bufref.len == 13, "Data size badly set");
fail_unless(bufref.dtor == test_free, "Destructor badly set");
/**
* testing Curl_bufref_ptr
*/
fail_unless((const char *) Curl_bufref_ptr(&bufref) == buffer,
"Wrong pointer value returned");
/**
* testing Curl_bufref_len
*/
fail_unless(Curl_bufref_len(&bufref) == 13, "Wrong data size returned");
/**
* testing Curl_bufref_memdup
*/
result = Curl_bufref_memdup(&bufref, "1661", 3);
abort_unless(result == CURLE_OK, curl_easy_strerror(result));
fail_unless(freecount == 1, "Destructor not called");
fail_unless((const char *)bufref.ptr != buffer, "Returned pointer not set");
buffer = (const char *)Curl_bufref_ptr(&bufref);
fail_unless(buffer, "Allocated pointer is NULL");
fail_unless(bufref.len == 3, "Wrong data size stored");
if(buffer) {
fail_unless(!buffer[3], "Duplicated data should have been truncated");
fail_unless(!strcmp(buffer, "166"), "Bad duplicated data");
}
/**
* testing Curl_bufref_free
*/
Curl_bufref_free(&bufref);
fail_unless(freecount == 1, "Wrong destructor called");
fail_unless(!bufref.ptr, "Initial reference must be NULL");
fail_unless(!bufref.len, "Initial length must be NULL");
fail_unless(!bufref.dtor, "Destructor must be NULL");
UNITTEST_END(t1661_stop(&bufref))
}
+93
View File
@@ -0,0 +1,93 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_NETINET_IN6_H
#include <netinet/in6.h>
#endif
#include "cf-socket.h"
#include "memdebug.h" /* LAST include file */
static CURLcode t1663_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
return res;
}
static void t1663_parse(
const char *input_data,
const char *exp_dev,
const char *exp_iface,
const char *exp_host,
CURLcode exp_rc)
{
char *dev = NULL;
char *iface = NULL;
char *host = NULL;
CURLcode rc = Curl_parse_interface(input_data, &dev, &iface, &host);
fail_unless(rc == exp_rc, "Curl_parse_interface() failed");
fail_unless(!!exp_dev == !!dev, "dev expectation failed.");
fail_unless(!!exp_iface == !!iface, "iface expectation failed");
fail_unless(!!exp_host == !!host, "host expectation failed");
if(!unitfail) {
fail_unless(!dev || !exp_dev || strcmp(dev, exp_dev) == 0,
"dev should be equal to exp_dev");
fail_unless(!iface || !exp_iface || strcmp(iface, exp_iface) == 0,
"iface should be equal to exp_iface");
fail_unless(!host || !exp_host || strcmp(host, exp_host) == 0,
"host should be equal to exp_host");
}
free(dev);
free(iface);
free(host);
}
static CURLcode test_unit1663(const char *arg)
{
UNITTEST_BEGIN(t1663_setup())
t1663_parse("dev", "dev", NULL, NULL, CURLE_OK);
t1663_parse("if!eth0", NULL, "eth0", NULL, CURLE_OK);
t1663_parse("host!myname", NULL, NULL, "myname", CURLE_OK);
t1663_parse("ifhost!eth0!myname", NULL, "eth0", "myname", CURLE_OK);
t1663_parse("", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
t1663_parse("!", "!", NULL, NULL, CURLE_OK);
t1663_parse("if!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
t1663_parse("if!eth0!blubb", NULL, "eth0!blubb", NULL, CURLE_OK);
t1663_parse("host!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
t1663_parse("ifhost!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
t1663_parse("ifhost!eth0", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
t1663_parse("ifhost!eth0!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
UNITTEST_END(curl_global_cleanup())
}
+484
View File
@@ -0,0 +1,484 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_NETINET_IN6_H
#include <netinet/in6.h>
#endif
#include "memdebug.h" /* LAST include file */
static CURLcode t1664_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
return res;
}
static CURLcode test_unit1664(const char *arg)
{
UNITTEST_BEGIN(t1664_setup())
static const char *wordparse[] = {
"word",
"word ",
" word ",
"wo rd",
"word(",
"wor(d",
"perfect",
"",
"longerth",
NULL
};
int i;
curl_mprintf("curlx_str_word\n");
for(i = 0; wordparse[i]; i++) {
struct Curl_str out;
const char *line = wordparse[i];
const char *orgline = line;
int rc = curlx_str_word(&line, &out, 7);
curl_mprintf("%u: (\"%s\") %d, \"%.*s\" [%d], line %d\n",
i, orgline, rc, (int)out.len, out.str, (int)out.len,
(int)(line - orgline));
}
curl_mprintf("curlx_str_until\n");
for(i = 0; wordparse[i]; i++) {
struct Curl_str out;
const char *line = wordparse[i];
const char *orgline = line;
int rc = curlx_str_until(&line, &out, 7, 'd');
curl_mprintf("%u: (\"%s\") %d, \"%.*s\" [%d], line %d\n",
i, orgline, rc, (int)out.len, out.str, (int)out.len,
(int)(line - orgline));
}
{
static const char *qwords[] = {
"\"word\"",
"\"word",
"word\"",
"\"word\"\"",
"\"word\" ",
" \"word\"",
"\"perfect\"",
"\"p r e t\"",
"\"perfec\\\"",
"\"\"",
"",
"\"longerth\"",
NULL
};
curl_mprintf("curlx_str_quotedword\n");
for(i = 0; qwords[i]; i++) {
struct Curl_str out;
const char *line = qwords[i];
const char *orgline = line;
int rc = curlx_str_quotedword(&line, &out, 7);
curl_mprintf("%u: (\"%s\") %d, \"%.*s\" [%d], line %d\n",
i, orgline, rc, (int)out.len, out.str, (int)out.len,
(int)(line - orgline));
}
}
{
static const char *single[] = {
"a",
"aa",
"A",
"b",
"\\",
" ",
"",
NULL
};
curl_mprintf("curlx_str_single\n");
for(i = 0; single[i]; i++) {
const char *line = single[i];
const char *orgline = line;
int rc = curlx_str_single(&line, 'a');
curl_mprintf("%u: (\"%s\") %d, line %d\n",
i, orgline, rc, (int)(line - orgline));
}
}
{
static const char *single[] = {
"a",
"aa",
"A",
"b",
"\\",
" ",
"\t",
"\n",
"",
NULL
};
curl_mprintf("curlx_str_singlespace\n");
for(i = 0; single[i]; i++) {
const char *line = single[i];
const char *orgline = line;
int rc = curlx_str_singlespace(&line);
curl_mprintf("%u: (\"%s\") %d, line %d\n",
i, orgline, rc, (int)(line - orgline));
}
}
{
static const char *single[] = {
"a",
"aa",
"A",
"b",
"\\",
" ",
"",
NULL
};
curl_mprintf("curlx_str_single\n");
for(i = 0; single[i]; i++) {
const char *line = single[i];
const char *orgline = line;
int rc = curlx_str_single(&line, 'a');
curl_mprintf("%u: (\"%s\") %d, line %d\n",
i, orgline, rc, (int)(line - orgline));
}
}
{
static const char *nums[] = {
"1",
"10000",
"1234",
"1235",
"1236",
"01234",
"00000000000000000000000000001234",
"0123 345",
"0123O345",
"-12",
" 123",
"",
NULL
};
curl_mprintf("curlx_str_number\n");
for(i = 0; nums[i]; i++) {
curl_off_t num;
const char *line = nums[i];
const char *orgline = line;
int rc = curlx_str_number(&line, &num, 1235);
curl_mprintf("%u: (\"%s\") %d, [%" CURL_FORMAT_CURL_OFF_T "] line %d\n",
i, orgline, rc, num, (int)(line - orgline));
}
}
{
struct t {
const char *str;
curl_off_t max;
};
static struct t nums[] = {
{ "00", 8},
{ "1", 8},
{ "1", 1},
{ "2", 1},
{ "2", 2},
{ "5", 6},
{ "000000000000000000000006", 6},
{ "7", 6},
{ "8", 6},
{ "9", 8},
{ "10", 10},
{ "11", 10},
{ "12", 10},
{NULL, 0}
};
curl_mprintf("curlx_str_number varying max\n");
for(i = 0; nums[i].str; i++) {
curl_off_t num;
const char *line = nums[i].str;
const char *orgline = line;
int rc = curlx_str_number(&line, &num, nums[i].max);
curl_mprintf("%u: (\"%s\") max %" CURL_FORMAT_CURL_OFF_T
" == %d, [%" CURL_FORMAT_CURL_OFF_T "]\n",
i, orgline, nums[i].max, rc, num);
}
}
{
struct t {
const char *str;
curl_off_t max;
};
static struct t nums[] = {
{ "00", 8},
{ "1", 8},
{ "1", 1},
{ "2", 1},
{ "2", 2},
{ "5", 6},
{ "000000000000000000000006", 6},
{ "7", 6},
{ "8", 6},
{ "9", 8},
{ "a", 14},
{ "b", 14},
{ "c", 14},
{ "d", 14},
{ "e", 14},
{ "f", 14},
{ "f", 15},
{ "10", 16},
{ "11", 16},
{ "12", 16},
{NULL, 0}
};
curl_mprintf("curlx_str_hex varying max\n");
for(i = 0; nums[i].str; i++) {
curl_off_t num;
const char *line = nums[i].str;
const char *orgline = line;
int rc = curlx_str_hex(&line, &num, nums[i].max);
curl_mprintf("%u: (\"%s\") max %" CURL_FORMAT_CURL_OFF_T
" == %d, [%" CURL_FORMAT_CURL_OFF_T "]\n",
i, orgline, nums[i].max, rc, num);
}
}
{
struct t {
const char *str;
curl_off_t max;
};
static struct t nums[] = {
{ "00", 4},
{ "1", 4},
{ "1", 4},
{ "2", 4},
{ "3", 4},
{ "4", 4},
{ "5", 4},
{ "000000000000000000000006", 6},
{ "7", 7},
{ "10", 8},
{ "11", 8},
{ "11", 9},
{ "12", 9},
{ "13", 9},
{ "8", 10},
{NULL, 0}
};
curl_mprintf("curlx_str_octal varying max\n");
for(i = 0; nums[i].str; i++) {
curl_off_t num;
const char *line = nums[i].str;
const char *orgline = line;
int rc = curlx_str_octal(&line, &num, nums[i].max);
curl_mprintf("%u: (\"%s\") max %" CURL_FORMAT_CURL_OFF_T
" == %d, [%" CURL_FORMAT_CURL_OFF_T "]\n",
i, orgline, nums[i].max, rc, num);
}
}
{
/* CURL_OFF_T is typically 9223372036854775807 */
static const char *nums[] = {
"9223372036854775807", /* 2^63 -1 */
"9223372036854775808", /* 2^63 */
"18446744073709551615", /* 2^64 - 1 */
"18446744073709551616", /* 2^64 */
"18446744073709551617", /* 2^64 + 1 */
"0123456799a",
"0123456789",
"123498760b",
"1234987607611298232",
"1111111111111111111",
"2222222222222222222",
"00000000000000000000000000000009223372036854775807",
"3333333333333333333",
"4444444444444444444",
"5555555555555555555",
"6666666666666666666",
"7777777777777777777",
"8888888888888888888",
"999999999999999999",
NULL
};
curl_mprintf("curlx_str_number / max\n");
for(i = 0; nums[i]; i++) {
curl_off_t num;
const char *line = nums[i];
const char *orgline = line;
int rc = curlx_str_number(&line, &num, CURL_OFF_T_MAX);
curl_mprintf("%u: (\"%s\") %d, [%" CURL_FORMAT_CURL_OFF_T "] line %d\n",
i, orgline, rc, num, (int)(line - orgline));
}
}
{
static const char *newl[] = {
"a",
"aa",
"A",
"b",
"\\",
" ",
"\n",
"\r",
"\r\n",
"\x0c",
"",
NULL
};
curl_mprintf("curlx_str_newline\n");
for(i = 0; newl[i]; i++) {
const char *line = newl[i];
const char *orgline = line;
int rc = curlx_str_newline(&line);
curl_mprintf("%u: (%%%02x) %d, line %d\n",
i, *orgline, rc, (int)(line - orgline));
}
}
{
static const char *nums[] = {
"1",
"1000",
"1234",
"1235",
"1236",
"01234",
"00000000000000000000000000001234",
"0123 345",
"0123O345",
"-12",
" 123",
"",
NULL
};
curl_mprintf("curlx_str_hex\n");
for(i = 0; nums[i]; i++) {
curl_off_t num;
const char *line = nums[i];
const char *orgline = line;
int rc = curlx_str_hex(&line, &num, 0x1235);
curl_mprintf("%u: (\"%s\") %d, [%" CURL_FORMAT_CURL_OFF_T "] line %d\n",
i, orgline, rc, num, (int)(line - orgline));
}
}
{
static const char *nums[] = {
"1",
"1000",
"1234",
"1235",
"1236",
"01234",
"00000000000000000000000000001234",
"0123 345",
"0123O345",
"-12",
" 123",
"",
NULL
};
curl_mprintf("curlx_str_octal\n");
for(i = 0; nums[i]; i++) {
curl_off_t num;
const char *line = nums[i];
const char *orgline = line;
int rc = curlx_str_octal(&line, &num, 01235);
curl_mprintf("%u: (\"%s\") %d, [%" CURL_FORMAT_CURL_OFF_T "] line %d\n",
i, orgline, rc, num, (int)(line - orgline));
}
}
{
/* CURL_OFF_T is typically 2^63-1 */
static const char *nums[] = {
"777777777777777777777", /* 2^63 -1 */
"1000000000000000000000", /* 2^63 */
"111111111111111111111",
"222222222222222222222",
"333333333333333333333",
"444444444444444444444",
"555555555555555555555",
"666666666666666666666",
NULL
};
curl_mprintf("curlx_str_octal / max\n");
for(i = 0; nums[i]; i++) {
curl_off_t num;
const char *line = nums[i];
const char *orgline = line;
int rc = curlx_str_octal(&line, &num, CURL_OFF_T_MAX);
curl_mprintf("%u: (\"%s\") %d, [%" CURL_FORMAT_CURL_OFF_T "] line %d\n",
i, orgline, rc, num, (int)(line - orgline));
}
}
{
/* CURL_OFF_T is typically 2^63-1 */
static const char *nums[] = {
"7FFFFFFFFFFFFFFF", /* 2^63 -1 */
"8000000000000000", /* 2^63 */
"1111111111111111",
"2222222222222222",
"3333333333333333",
"4444444444444444",
"5555555555555555",
"6666666666666666",
"7777777777777777",
"888888888888888",
"999999999999999",
"aaaaaaaaAAAAAAA",
"bbbbbbbbBBBBBBB",
"BBBBBBBBbbbbbbb",
"ccccccccCCCCCCC",
"ddddddddDDDDDDD",
"eeeeeeeeEEEEEEE",
"ffffffffFFFFFFF",
"abcdef",
"ABCDEF",
NULL
};
curl_mprintf("curlx_str_hex / max\n");
for(i = 0; nums[i]; i++) {
curl_off_t num;
const char *line = nums[i];
const char *orgline = line;
int rc = curlx_str_hex(&line, &num, CURL_OFF_T_MAX);
curl_mprintf("%u: (\"%s\") %d, [%" CURL_FORMAT_CURL_OFF_T "] line %d\n",
i, orgline, rc, num, (int)(line - orgline));
}
}
UNITTEST_END(curl_global_cleanup())
}
+137
View File
@@ -0,0 +1,137 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "http_aws_sigv4.h"
static CURLcode test_unit1979(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS)
struct testcase {
const char *testname;
const bool normalize;
const char *url_part;
const char *canonical_url;
};
static const struct testcase testcases[] = {
{
"test-equals-encode",
true,
"/a=b",
"/a%3Db"
},
{
"test-equals-noencode",
false,
"/a=b",
"/a=b"
},
{
"test-s3-tables",
true,
"/tables/arn%3Aaws%3As3tables%3Aus-east-1%3A022954301426%3Abucket%2Fja"
"soehartablebucket/jasoeharnamespace/jasoehartable/encryption",
"/tables/arn%253Aaws%253As3tables%253Aus-east-1%253A022954301426%253Ab"
"ucket%252Fjasoehartablebucket/jasoeharnamespace/jasoehartable/encrypt"
"ion"
},
{
"get-vanilla",
true,
"/",
"/"
},
{
"get-unreserved",
true,
"/-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
"/-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
},
{
"get-slashes-unnormalized",
false,
"//example//",
"//example//"
},
{
"get-space-normalized",
true,
"/example space/",
"/example%20space/"
},
{
"get-slash-dot-slash-unnormalized",
false,
"/./",
"/./"
},
{
"get-slash-unnormalized",
false,
"//",
"//"
},
{
"get-relative-relative-unnormalized",
false,
"/example1/example2/../..",
"/example1/example2/../.."
}
};
size_t i;
for(i = 0; i < CURL_ARRAYSIZE(testcases); i++) {
struct dynbuf canonical_path;
char buffer[1024];
char *canonical_path_string;
int result;
int msnprintf_result;
curlx_dyn_init(&canonical_path, CURL_MAX_HTTP_HEADER);
result = canon_path(testcases[i].url_part, strlen(testcases[i].url_part),
&canonical_path, testcases[i].normalize);
canonical_path_string = curlx_dyn_ptr(&canonical_path);
msnprintf_result = curl_msnprintf(buffer, sizeof(buffer),
"%s: Received \"%s\" "
"and should be \"%s\", normalize (%d)",
testcases[i].testname,
curlx_dyn_ptr(&canonical_path),
testcases[i].canonical_url,
testcases[i].normalize);
fail_unless(msnprintf_result >= 0, "curl_msnprintf fails");
fail_unless(!result && canonical_path_string &&
!strcmp(canonical_path_string, testcases[i].canonical_url),
buffer);
curlx_dyn_free(&canonical_path);
}
#endif /* !CURL_DISABLE_HTTP && !CURL_DISABLE_AWS */
UNITTEST_END_SIMPLE
}
+108
View File
@@ -0,0 +1,108 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "http_aws_sigv4.h"
static CURLcode test_unit1980(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS)
struct testcase {
const char *testname;
const char *query_part;
const char *canonical_query;
};
static const struct testcase testcases[] = {
{
"no-value",
"Param1=",
"Param1="
},
{
"test-439",
"name=me&noval&aim=b%aad&weirdo=*.//-",
"aim=b%AAd&name=me&noval=&weirdo=%2A.%2F%2F-"
},
{
"blank-query-params",
"hello=a&b&c=&d",
"b=&c=&d=&hello=a"
},
{
"get-vanilla-query-order-key-case",
"Param2=value2&Param1=value1",
"Param1=value1&Param2=value2"
},
{
"get-vanilla-query-unreserved",
"-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz="
"-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
"-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz="
"-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
},
{
"get-vanilla-empty-query-key",
"Param1=value1",
"Param1=value1"
},
{
"get-vanilla-query-order-encoded",
"Param-3=Value3&Param=Value2&%E1%88%B4=Value1",
"%E1%88%B4=Value1&Param=Value2&Param-3=Value3"
},
};
size_t i;
for(i = 0; i < CURL_ARRAYSIZE(testcases); i++) {
struct dynbuf canonical_query;
char buffer[1024];
char *canonical_query_ptr;
int result;
int msnprintf_result;
curlx_dyn_init(&canonical_query, CURL_MAX_HTTP_HEADER);
result = canon_query(testcases[i].query_part, &canonical_query);
canonical_query_ptr = curlx_dyn_ptr(&canonical_query);
msnprintf_result = curl_msnprintf(buffer, sizeof(buffer),
"%s: Received \"%s\" "
"and should be \"%s\"",
testcases[i].testname,
canonical_query_ptr,
testcases[i].canonical_query);
fail_unless(msnprintf_result >= 0, "curl_msnprintf fails");
fail_unless(!result && canonical_query_ptr &&
!strcmp(canonical_query_ptr, testcases[i].canonical_query),
buffer);
curlx_dyn_free(&canonical_query);
}
#endif /* !CURL_DISABLE_HTTP && !CURL_DISABLE_AWS */
UNITTEST_END_SIMPLE
}
+409
View File
@@ -0,0 +1,409 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_NETINET_IN6_H
#include <netinet/in6.h>
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef __VMS
#include <in.h>
#include <inet.h>
#endif
#include "urldata.h"
#include "connect.h"
#include "cfilters.h"
#include "cf-ip-happy.h"
#include "multiif.h"
#include "select.h"
#include "curl_trc.h"
#include "memdebug.h"
static CURLcode t2600_setup(CURL **easy)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
*easy = curl_easy_init();
if(!*easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
curl_global_trace("all");
curl_easy_setopt(*easy, CURLOPT_VERBOSE, 1L);
return res;
}
static void t2600_stop(CURL *easy)
{
curl_easy_cleanup(easy);
curl_global_cleanup();
}
struct test_case {
int id;
const char *url;
const char *resolve_info;
long ip_version;
timediff_t connect_timeout_ms;
timediff_t he_timeout_ms;
timediff_t cf4_fail_delay_ms;
timediff_t cf6_fail_delay_ms;
int exp_cf4_creations;
int exp_cf6_creations;
timediff_t min_duration_ms;
timediff_t max_duration_ms;
CURLcode exp_result;
const char *pref_family;
};
struct ai_family_stats {
const char *family;
int creations;
timediff_t first_created;
timediff_t last_created;
};
struct test_result {
CURLcode result;
struct curltime started;
struct curltime ended;
struct ai_family_stats cf4;
struct ai_family_stats cf6;
};
static const struct test_case *current_tc;
static struct test_result *current_tr;
static int test_idx;
struct cf_test_ctx {
int idx;
int ai_family;
int transport;
char id[16];
struct curltime started;
timediff_t fail_delay_ms;
struct ai_family_stats *stats;
};
static void cf_test_destroy(struct Curl_cfilter *cf, struct Curl_easy *data)
{
struct cf_test_ctx *ctx = cf->ctx;
#ifndef CURL_DISABLE_VERBOSE_STRINGS
infof(data, "%04dms: cf[%s] destroyed",
(int)curlx_timediff(curlx_now(), current_tr->started), ctx->id);
#else
(void)data;
#endif
free(ctx);
cf->ctx = NULL;
}
static CURLcode cf_test_connect(struct Curl_cfilter *cf,
struct Curl_easy *data,
bool *done)
{
struct cf_test_ctx *ctx = cf->ctx;
timediff_t duration_ms;
(void)data;
*done = FALSE;
duration_ms = curlx_timediff(curlx_now(), ctx->started);
if(duration_ms >= ctx->fail_delay_ms) {
infof(data, "%04dms: cf[%s] fail delay reached",
(int)duration_ms, ctx->id);
return CURLE_COULDNT_CONNECT;
}
if(duration_ms) {
infof(data, "%04dms: cf[%s] continuing", (int)duration_ms, ctx->id);
curlx_wait_ms(10);
}
Curl_expire(data, ctx->fail_delay_ms - duration_ms, EXPIRE_TIMEOUT);
return CURLE_OK;
}
static CURLcode cf_test_adjust_pollset(struct Curl_cfilter *cf,
struct Curl_easy *data,
struct easy_pollset *ps)
{
struct cf_test_ctx *ctx = cf->ctx;
/* just for testing, give one socket with events back */
return Curl_pollset_set(data, ps, ctx->idx, TRUE, TRUE);
}
static CURLcode cf_test_create(struct Curl_cfilter **pcf,
struct Curl_easy *data,
struct connectdata *conn,
const struct Curl_addrinfo *ai,
int transport)
{
static const struct Curl_cftype cft_test = {
"TEST",
CF_TYPE_IP_CONNECT,
CURL_LOG_LVL_NONE,
cf_test_destroy,
cf_test_connect,
Curl_cf_def_close,
Curl_cf_def_shutdown,
cf_test_adjust_pollset,
Curl_cf_def_data_pending,
Curl_cf_def_send,
Curl_cf_def_recv,
Curl_cf_def_cntrl,
Curl_cf_def_conn_is_alive,
Curl_cf_def_conn_keep_alive,
Curl_cf_def_query,
};
struct cf_test_ctx *ctx = NULL;
struct Curl_cfilter *cf = NULL;
timediff_t created_at;
CURLcode result;
(void)data;
(void)conn;
ctx = calloc(1, sizeof(*ctx));
if(!ctx) {
result = CURLE_OUT_OF_MEMORY;
goto out;
}
ctx->idx = test_idx++;
ctx->ai_family = ai->ai_family;
ctx->transport = transport;
ctx->started = curlx_now();
#ifdef USE_IPV6
if(ctx->ai_family == AF_INET6) {
ctx->stats = &current_tr->cf6;
ctx->fail_delay_ms = current_tc->cf6_fail_delay_ms;
curl_msprintf(ctx->id, "v6-%d", ctx->stats->creations);
ctx->stats->creations++;
}
else
#endif
{
ctx->stats = &current_tr->cf4;
ctx->fail_delay_ms = current_tc->cf4_fail_delay_ms;
curl_msprintf(ctx->id, "v4-%d", ctx->stats->creations);
ctx->stats->creations++;
}
created_at = curlx_timediff(ctx->started, current_tr->started);
if(ctx->stats->creations == 1)
ctx->stats->first_created = created_at;
ctx->stats->last_created = created_at;
infof(data, "%04dms: cf[%s] created", (int)created_at, ctx->id);
result = Curl_cf_create(&cf, &cft_test, ctx);
if(result)
goto out;
Curl_expire(data, ctx->fail_delay_ms, EXPIRE_TIMEOUT);
out:
*pcf = (!result) ? cf : NULL;
if(result) {
free(cf);
free(ctx);
}
return result;
}
static void check_result(const struct test_case *tc,
struct test_result *tr)
{
char msg[256];
timediff_t duration_ms;
duration_ms = curlx_timediff(tr->ended, tr->started);
curl_mfprintf(stderr, "%d: test case took %dms\n", tc->id, (int)duration_ms);
if(tr->result != tc->exp_result
&& CURLE_OPERATION_TIMEDOUT != tr->result) {
/* on CI we encounter the TIMEOUT result, since images get less CPU
* and events are not as sharply timed. */
curl_msprintf(msg, "%d: expected result %d but got %d",
tc->id, tc->exp_result, tr->result);
fail(msg);
}
if(tr->cf4.creations != tc->exp_cf4_creations) {
curl_msprintf(msg, "%d: expected %d ipv4 creations, but got %d",
tc->id, tc->exp_cf4_creations, tr->cf4.creations);
fail(msg);
}
if(tr->cf6.creations != tc->exp_cf6_creations) {
curl_msprintf(msg, "%d: expected %d ipv6 creations, but got %d",
tc->id, tc->exp_cf6_creations, tr->cf6.creations);
fail(msg);
}
duration_ms = curlx_timediff(tr->ended, tr->started);
if(duration_ms < tc->min_duration_ms) {
curl_msprintf(msg, "%d: expected min duration of %dms, but took %dms",
tc->id, (int)tc->min_duration_ms, (int)duration_ms);
fail(msg);
}
if(duration_ms > tc->max_duration_ms) {
curl_msprintf(msg, "%d: expected max duration of %dms, but took %dms",
tc->id, (int)tc->max_duration_ms, (int)duration_ms);
fail(msg);
}
if(tr->cf6.creations && tr->cf4.creations && tc->pref_family) {
/* did ipv4 and ipv6 both, expect the preferred family to start right arway
* with the other being delayed by the happy_eyeball_timeout */
struct ai_family_stats *stats1 = !strcmp(tc->pref_family, "v6") ?
&tr->cf6 : &tr->cf4;
struct ai_family_stats *stats2 = !strcmp(tc->pref_family, "v6") ?
&tr->cf4 : &tr->cf6;
if(stats1->first_created > 100) {
curl_msprintf(msg, "%d: expected ip%s to start right away, instead "
"first attempt made after %dms",
tc->id, stats1->family, (int)stats1->first_created);
fail(msg);
}
if(stats2->first_created < tc->he_timeout_ms) {
curl_msprintf(msg, "%d: expected ip%s to start delayed after %dms, "
"instead first attempt made after %dms",
tc->id, stats2->family, (int)tc->he_timeout_ms,
(int)stats2->first_created);
fail(msg);
}
}
}
static void test_connect(CURL *easy, const struct test_case *tc)
{
struct test_result tr;
struct curl_slist *list = NULL;
Curl_debug_set_transport_provider(TRNSPRT_TCP, cf_test_create);
current_tc = tc;
current_tr = &tr;
list = curl_slist_append(NULL, tc->resolve_info);
fail_unless(list, "error allocating resolve list entry");
curl_easy_setopt(easy, CURLOPT_RESOLVE, list);
curl_easy_setopt(easy, CURLOPT_IPRESOLVE, tc->ip_version);
curl_easy_setopt(easy, CURLOPT_CONNECTTIMEOUT_MS,
(long)tc->connect_timeout_ms);
curl_easy_setopt(easy, CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS,
(long)tc->he_timeout_ms);
curl_easy_setopt(easy, CURLOPT_URL, tc->url);
memset(&tr, 0, sizeof(tr));
tr.cf6.family = "v6";
tr.cf4.family = "v4";
tr.started = curlx_now();
tr.result = curl_easy_perform(easy);
tr.ended = curlx_now();
curl_easy_setopt(easy, CURLOPT_RESOLVE, NULL);
curl_slist_free_all(list);
list = NULL;
current_tc = NULL;
current_tr = NULL;
check_result(tc, &tr);
}
/*
* How these test cases work:
* - replace the creation of the TCP socket filter with our test filter
* - test filter does nothing and reports failure after configured delay
* - we feed addresses into the resolve cache to simulate different cases
* - we monitor how many instances of ipv4/v6 attempts are made and when
* - for mixed families, we expect HAPPY_EYEBALLS_TIMEOUT to trigger
*
* Max Duration checks needs to be conservative since CI jobs are not
* as sharp.
*/
#define TURL "http://test.com:123"
#define R_FAIL CURLE_COULDNT_CONNECT
/* timeout values accounting for low cpu resources in CI */
#define TC_TMOT 90000 /* 90 sec max test duration */
#define CNCT_TMOT 60000 /* 60sec connect timeout */
static CURLcode test_unit2600(const char *arg)
{
CURL *easy;
UNITTEST_BEGIN(t2600_setup(&easy))
static const struct test_case TEST_CASES[] = {
/* TIMEOUT_MS, FAIL_MS CREATED DURATION Result, HE_PREF */
/* CNCT HE v4 v6 v4 v6 MIN MAX */
{ 1, TURL, "test.com:123:192.0.2.1", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 250, 250, 1, 0, 200, TC_TMOT, R_FAIL, NULL },
/* 1 ipv4, fails after ~200ms, reports COULDNT_CONNECT */
{ 2, TURL, "test.com:123:192.0.2.1,192.0.2.2", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 250, 250, 2, 0, 400, TC_TMOT, R_FAIL, NULL },
/* 2 ipv4, fails after ~400ms, reports COULDNT_CONNECT */
#ifdef USE_IPV6
{ 3, TURL, "test.com:123:::1", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 250, 250, 0, 1, 200, TC_TMOT, R_FAIL, NULL },
/* 1 ipv6, fails after ~200ms, reports COULDNT_CONNECT */
{ 4, TURL, "test.com:123:::1,::2", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 250, 250, 0, 2, 400, TC_TMOT, R_FAIL, NULL },
/* 2 ipv6, fails after ~400ms, reports COULDNT_CONNECT */
{ 5, TURL, "test.com:123:192.0.2.1,::1", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 250, 250, 1, 1, 350, TC_TMOT, R_FAIL, "v6" },
/* mixed ip4+6, v6 always first, v4 kicks in on HE, fails after ~350ms */
{ 6, TURL, "test.com:123:::1,192.0.2.1", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 250, 250, 1, 1, 350, TC_TMOT, R_FAIL, "v6" },
/* mixed ip6+4, v6 starts, v4 never starts due to high HE, TIMEOUT */
{ 7, TURL, "test.com:123:192.0.2.1,::1", CURL_IPRESOLVE_V4,
CNCT_TMOT, 150, 500, 500, 1, 0, 400, TC_TMOT, R_FAIL, NULL },
/* mixed ip4+6, but only use v4, check it uses full connect timeout,
although another address of the 'wrong' family is available */
{ 8, TURL, "test.com:123:::1,192.0.2.1", CURL_IPRESOLVE_V6,
CNCT_TMOT, 150, 500, 500, 0, 1, 400, TC_TMOT, R_FAIL, NULL },
/* mixed ip4+6, but only use v6, check it uses full connect timeout,
although another address of the 'wrong' family is available */
{ 9, TURL, "test.com:123:::1,192.0.2.1,::2,::3", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 50, 400, 400, 1, 3, 550, TC_TMOT, R_FAIL, NULL },
/* 1 v4, 3 v6, fails after (3*HE)+400ms, ~550ms, COULDNT_CONNECT */
#endif
};
size_t i;
for(i = 0; i < CURL_ARRAYSIZE(TEST_CASES); ++i) {
test_connect(easy, &TEST_CASES[i]);
}
UNITTEST_END(t2600_stop(easy))
}
+240
View File
@@ -0,0 +1,240 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "bufq.h"
#include "curl_trc.h"
static const char *tail_err(struct bufq *q)
{
struct buf_chunk *chunk;
if(!q->tail) {
return q->head ? "tail is NULL, but head is not" : NULL;
}
chunk = q->head;
while(chunk) {
if(chunk == q->tail) {
if(chunk->next) {
return "tail points to queue, but not at the end";
}
return NULL;
}
chunk = chunk->next;
}
return "tail not part of queue";
}
static void dump_bufq(struct bufq *q, const char *msg)
{
struct buf_chunk *chunk;
const char *terr;
size_t n;
curl_mfprintf(stderr, "bufq[chunk_size=%zu, max_chunks=%zu] %s\n",
q->chunk_size, q->max_chunks, msg);
curl_mfprintf(stderr, "- queue[\n");
chunk = q->head;
while(chunk) {
curl_mfprintf(stderr, " chunk[len=%zu, roff=%zu, woff=%zu]\n",
chunk->dlen, chunk->r_offset, chunk->w_offset);
chunk = chunk->next;
}
curl_mfprintf(stderr, " ]\n");
terr = tail_err(q);
curl_mfprintf(stderr, "- tail: %s\n", terr ? terr : "ok");
n = 0;
chunk = q->spare;
while(chunk) {
++n;
chunk = chunk->next;
}
curl_mfprintf(stderr, "- chunks: %zu\n", q->chunk_count);
curl_mfprintf(stderr, "- spares: %zu\n", n);
}
static void check_bufq(size_t pool_spares,
size_t chunk_size, size_t max_chunks,
size_t wsize, size_t rsize, int opts)
{
static unsigned char test_data[32*1024];
struct bufq q;
struct bufc_pool pool;
size_t max_len = chunk_size * max_chunks;
CURLcode result;
ssize_t i;
size_t n2;
size_t nwritten, nread;
if(pool_spares > 0) {
Curl_bufcp_init(&pool, chunk_size, pool_spares);
Curl_bufq_initp(&q, &pool, max_chunks, opts);
}
else {
Curl_bufq_init2(&q, chunk_size, max_chunks, opts);
}
fail_unless(q.chunk_size == chunk_size, "chunk_size init wrong");
fail_unless(q.max_chunks == max_chunks, "max_chunks init wrong");
fail_unless(q.head == NULL, "init: head not NULL");
fail_unless(q.tail == NULL, "init: tail not NULL");
fail_unless(q.spare == NULL, "init: spare not NULL");
fail_unless(Curl_bufq_len(&q) == 0, "init: bufq length != 0");
result = Curl_bufq_write(&q, test_data, wsize, &n2);
fail_unless(n2 <= wsize, "write: wrong size returned");
fail_unless(result == CURLE_OK, "write: wrong result returned");
/* write empty bufq full */
nwritten = 0;
Curl_bufq_reset(&q);
while(!Curl_bufq_is_full(&q)) {
result = Curl_bufq_write(&q, test_data, wsize, &n2);
if(!result) {
nwritten += n2;
}
else if(result != CURLE_AGAIN) {
fail_unless(result == CURLE_AGAIN, "write-loop: unexpected result");
break;
}
}
if(nwritten != max_len) {
curl_mfprintf(stderr, "%zu bytes written, but max_len=%zu\n",
nwritten, max_len);
dump_bufq(&q, "after writing full");
fail_if(TRUE, "write: bufq full but nwritten wrong");
}
/* read full bufq empty */
nread = 0;
while(!Curl_bufq_is_empty(&q)) {
result = Curl_bufq_read(&q, test_data, rsize, &n2);
if(!result) {
nread += n2;
}
else if(result != CURLE_AGAIN) {
fail_unless(result == CURLE_AGAIN, "read-loop: unexpected result");
break;
}
}
if(nread != max_len) {
curl_mfprintf(stderr, "%zu bytes read, but max_len=%zu\n",
nwritten, max_len);
dump_bufq(&q, "after reading empty");
fail_if(TRUE, "read: bufq empty but nread wrong");
}
if(q.tail) {
dump_bufq(&q, "after reading empty");
fail_if(TRUE, "read empty, but tail is not NULL");
}
for(i = 0; i < 1000; ++i) {
result = Curl_bufq_write(&q, test_data, wsize, &n2);
if(result && result != CURLE_AGAIN) {
fail_unless(result == CURLE_AGAIN, "rw-loop: unexpected write result");
break;
}
result = Curl_bufq_read(&q, test_data, rsize, &n2);
if(result && result != CURLE_AGAIN) {
fail_unless(result == CURLE_AGAIN, "rw-loop: unexpected read result");
break;
}
}
/* Test SOFT_LIMIT option */
Curl_bufq_free(&q);
Curl_bufq_init2(&q, chunk_size, max_chunks, (opts|BUFQ_OPT_SOFT_LIMIT));
nwritten = 0;
while(!Curl_bufq_is_full(&q)) {
result = Curl_bufq_write(&q, test_data, wsize, &n2);
if(result || n2 != wsize) {
fail_unless(!result && n2 == wsize, "write should be complete");
break;
}
nwritten += n2;
}
if(nwritten < max_len) {
curl_mfprintf(stderr, "%zu bytes written, but max_len=%zu\n",
nwritten, max_len);
dump_bufq(&q, "after writing full");
fail_if(TRUE, "write: bufq full but nwritten wrong");
}
/* do one more write on a full bufq, should work */
result = Curl_bufq_write(&q, test_data, wsize, &n2);
fail_unless(!result && n2 == wsize, "write should be complete");
nwritten += n2;
/* see that we get all out again */
nread = 0;
while(!Curl_bufq_is_empty(&q)) {
result = Curl_bufq_read(&q, test_data, rsize, &n2);
if(result) {
fail_unless(result, "read-loop: unexpected fail");
break;
}
nread += n2;
}
fail_unless(nread == nwritten, "did not get the same out as put in");
dump_bufq(&q, "at end of test");
Curl_bufq_free(&q);
if(pool_spares > 0)
Curl_bufcp_free(&pool);
}
static CURLcode test_unit2601(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
struct bufq q;
size_t n;
CURLcode result;
unsigned char buf[16*1024];
Curl_bufq_init(&q, 8*1024, 12);
result = Curl_bufq_read(&q, buf, 128, &n);
fail_unless(result && result == CURLE_AGAIN, "read empty fail");
Curl_bufq_free(&q);
check_bufq(0, 1024, 4, 128, 128, BUFQ_OPT_NONE);
check_bufq(0, 1024, 4, 129, 127, BUFQ_OPT_NONE);
check_bufq(0, 1024, 4, 2000, 16000, BUFQ_OPT_NONE);
check_bufq(0, 1024, 4, 16000, 3000, BUFQ_OPT_NONE);
check_bufq(0, 8000, 10, 1234, 1234, BUFQ_OPT_NONE);
check_bufq(0, 8000, 10, 8*1024, 4*1024, BUFQ_OPT_NONE);
check_bufq(0, 1024, 4, 128, 128, BUFQ_OPT_NO_SPARES);
check_bufq(0, 1024, 4, 129, 127, BUFQ_OPT_NO_SPARES);
check_bufq(0, 1024, 4, 2000, 16000, BUFQ_OPT_NO_SPARES);
check_bufq(0, 1024, 4, 16000, 3000, BUFQ_OPT_NO_SPARES);
check_bufq(8, 1024, 4, 128, 128, BUFQ_OPT_NONE);
check_bufq(8, 8000, 10, 1234, 1234, BUFQ_OPT_NONE);
check_bufq(8, 1024, 4, 129, 127, BUFQ_OPT_NO_SPARES);
UNITTEST_END_SIMPLE
}
+140
View File
@@ -0,0 +1,140 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "dynhds.h"
#include "curl_trc.h"
static CURLcode test_unit2602(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
struct dynhds hds;
struct dynbuf dbuf;
CURLcode result;
size_t i;
/* add 1 more header than allowed */
Curl_dynhds_init(&hds, 2, 128);
fail_if(Curl_dynhds_count(&hds), "should be empty");
fail_if(Curl_dynhds_add(&hds, "test1", 5, "123", 3), "add failed");
fail_if(Curl_dynhds_add(&hds, "test2", 5, "456", 3), "add failed");
/* remove and add without exceeding limits */
for(i = 0; i < 100; ++i) {
if(Curl_dynhds_remove(&hds, "test2", 5) != 1) {
fail_if(TRUE, "should");
break;
}
if(Curl_dynhds_add(&hds, "test2", 5, "456", 3)) {
fail_if(TRUE, "add failed");
break;
}
}
fail_unless(Curl_dynhds_count(&hds) == 2, "should hold 2");
/* set, replacing previous entry without exceeding limits */
for(i = 0; i < 100; ++i) {
if(Curl_dynhds_set(&hds, "test2", 5, "456", 3)) {
fail_if(TRUE, "add failed");
break;
}
}
fail_unless(Curl_dynhds_count(&hds) == 2, "should hold 2");
/* exceed limit on # of entries */
result = Curl_dynhds_add(&hds, "test3", 5, "789", 3);
fail_unless(result, "add should have failed");
fail_unless(Curl_dynhds_count_name(&hds, "test", 4) == 0, "false positive");
fail_unless(Curl_dynhds_count_name(&hds, "test1", 4) == 0, "false positive");
fail_if(Curl_dynhds_get(&hds, "test1", 4), "false positive");
fail_unless(Curl_dynhds_get(&hds, "test1", 5), "false negative");
fail_unless(Curl_dynhds_count_name(&hds, "test1", 5) == 1, "should");
fail_unless(Curl_dynhds_ccount_name(&hds, "test2") == 1, "should");
fail_unless(Curl_dynhds_cget(&hds, "test2"), "should");
fail_unless(Curl_dynhds_ccount_name(&hds, "TEST2") == 1, "should");
fail_unless(Curl_dynhds_ccontains(&hds, "TesT2"), "should");
fail_unless(Curl_dynhds_contains(&hds, "TeSt2", 5), "should");
Curl_dynhds_free(&hds);
/* add header exceeding max overall length */
Curl_dynhds_init(&hds, 128, 10);
fail_if(Curl_dynhds_add(&hds, "test1", 5, "123", 3), "add failed");
fail_unless(Curl_dynhds_add(&hds, "test2", 5, "456", 3), "should fail");
fail_if(Curl_dynhds_add(&hds, "t", 1, "1", 1), "add failed");
Curl_dynhds_reset(&hds);
Curl_dynhds_free(&hds);
Curl_dynhds_init(&hds, 128, 4*1024);
fail_if(Curl_dynhds_add(&hds, "test1", 5, "123", 3), "add failed");
fail_if(Curl_dynhds_add(&hds, "test1", 5, "123", 3), "add failed");
fail_if(Curl_dynhds_cadd(&hds, "blablabla", "thingies"), "add failed");
fail_if(Curl_dynhds_h1_cadd_line(&hds, "blablabla: thingies"), "add failed");
fail_unless(Curl_dynhds_ccount_name(&hds, "blablabla") == 2, "should");
fail_unless(Curl_dynhds_cremove(&hds, "blablabla") == 2, "should");
fail_if(Curl_dynhds_ccontains(&hds, "blablabla"), "should not");
result = Curl_dynhds_h1_cadd_line(&hds, "blablabla thingies");
fail_unless(result, "add should have failed");
if(!result) {
fail_unless(Curl_dynhds_ccount_name(&hds, "bLABlaBlA") == 0, "should");
fail_if(Curl_dynhds_cadd(&hds, "Bla-Bla", "thingies"), "add failed");
curlx_dyn_init(&dbuf, 32*1024);
fail_if(Curl_dynhds_h1_dprint(&hds, &dbuf), "h1 print failed");
if(curlx_dyn_ptr(&dbuf)) {
fail_if(strcmp(curlx_dyn_ptr(&dbuf),
"test1: 123\r\ntest1: 123\r\nBla-Bla: thingies\r\n"),
"h1 format differs");
}
curlx_dyn_free(&dbuf);
}
Curl_dynhds_free(&hds);
Curl_dynhds_init(&hds, 128, 4*1024);
/* continuation without previous header fails */
result = Curl_dynhds_h1_cadd_line(&hds, " indented value");
fail_unless(result, "add should have failed");
/* continuation with previous header must succeed */
fail_if(Curl_dynhds_h1_cadd_line(&hds, "ti1: val1"), "add");
fail_if(Curl_dynhds_h1_cadd_line(&hds, " val2"), "add indent");
fail_if(Curl_dynhds_h1_cadd_line(&hds, "ti2: val1"), "add");
fail_if(Curl_dynhds_h1_cadd_line(&hds, "\tval2"), "add indent");
fail_if(Curl_dynhds_h1_cadd_line(&hds, "ti3: val1"), "add");
fail_if(Curl_dynhds_h1_cadd_line(&hds, " val2"), "add indent");
curlx_dyn_init(&dbuf, 32*1024);
fail_if(Curl_dynhds_h1_dprint(&hds, &dbuf), "h1 print failed");
if(curlx_dyn_ptr(&dbuf)) {
curl_mfprintf(stderr, "indent concat: %s\n", curlx_dyn_ptr(&dbuf));
fail_if(strcmp(curlx_dyn_ptr(&dbuf),
"ti1: val1 val2\r\nti2: val1 val2\r\nti3: val1 val2\r\n"),
"wrong format");
}
curlx_dyn_free(&dbuf);
Curl_dynhds_free(&hds);
UNITTEST_END_SIMPLE
}
+189
View File
@@ -0,0 +1,189 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "http.h"
#include "http1.h"
#include "curl_trc.h"
#ifndef CURL_DISABLE_HTTP
static void check_eq(const char *s, const char *exp_s, const char *name)
{
if(s && exp_s) {
if(strcmp(s, exp_s)) {
curl_mfprintf(stderr, "expected %s: '%s' but got '%s'\n",
name, exp_s, s);
fail("unexpected req component");
}
}
else if(!s && exp_s) {
curl_mfprintf(stderr, "expected %s: '%s' but got NULL\n", name, exp_s);
fail("unexpected req component");
}
else if(s && !exp_s) {
curl_mfprintf(stderr, "expected %s: NULL but got '%s'\n", name, s);
fail("unexpected req component");
}
}
struct tcase {
const char **input;
const char *default_scheme;
const char *method;
const char *scheme;
const char *authority;
const char *path;
size_t header_count;
size_t input_remain;
};
static void parse_success(const struct tcase *t)
{
struct h1_req_parser p;
const char *buf;
size_t buflen, i, in_len, in_consumed;
CURLcode err;
ssize_t nread;
Curl_h1_req_parse_init(&p, 1024);
in_len = in_consumed = 0;
for(i = 0; t->input[i]; ++i) {
buf = t->input[i];
buflen = strlen(buf);
in_len += buflen;
nread = Curl_h1_req_parse_read(&p, buf, buflen, t->default_scheme,
0, &err);
if(nread < 0) {
curl_mfprintf(stderr, "got err %d parsing: '%s'\n", err, buf);
fail("error consuming");
}
in_consumed += (size_t)nread;
if((size_t)nread != buflen) {
if(!p.done) {
curl_mfprintf(stderr, "only %zd/%zu consumed for: '%s'\n",
nread, buflen, buf);
fail("not all consumed");
}
}
}
fail_if(!p.done, "end not detected");
fail_if(!p.req, "not request created");
if(t->input_remain != (in_len - in_consumed)) {
curl_mfprintf(stderr, "expected %zu input bytes to remain, but got %zu\n",
t->input_remain, in_len - in_consumed);
fail("unexpected input consumption");
}
if(p.req) {
check_eq(p.req->method, t->method, "method");
check_eq(p.req->scheme, t->scheme, "scheme");
check_eq(p.req->authority, t->authority, "authority");
check_eq(p.req->path, t->path, "path");
if(Curl_dynhds_count(&p.req->headers) != t->header_count) {
curl_mfprintf(stderr, "expected %zu headers but got %zu\n",
t->header_count, Curl_dynhds_count(&p.req->headers));
fail("unexpected req header count");
}
}
Curl_h1_req_parse_free(&p);
}
#endif
static CURLcode test_unit2603(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#ifndef CURL_DISABLE_HTTP
static const char *T1_INPUT[] = {
"GET /path HTTP/1.1\r\nHost: test.curl.se\r\n\r\n",
NULL,
};
static const struct tcase TEST1a = {
T1_INPUT, NULL, "GET", NULL, NULL, "/path", 1, 0
};
static const struct tcase TEST1b = {
T1_INPUT, "https", "GET", "https", NULL, "/path", 1, 0
};
static const char *T2_INPUT[] = {
"GET /path HTT",
"P/1.1\r\nHost: te",
"st.curl.se\r\n\r",
"\n12345678",
NULL,
};
static const struct tcase TEST2 = {
T2_INPUT, NULL, "GET", NULL, NULL, "/path", 1, 8
};
static const char *T3_INPUT[] = {
"GET ftp://ftp.curl.se/xxx?a=2 HTTP/1.1\r\nContent-Length: 0\r",
"\nUser-Agent: xxx\r\n\r\n",
NULL,
};
static const struct tcase TEST3a = {
T3_INPUT, NULL, "GET", "ftp", "ftp.curl.se", "/xxx?a=2", 2, 0
};
static const char *T4_INPUT[] = {
"CONNECT ftp.curl.se:123 HTTP/1.1\r\nContent-Length: 0\r\n",
"User-Agent: xxx\r\n",
"nothing: \r\n\r\n\n\n",
NULL,
};
static const struct tcase TEST4a = {
T4_INPUT, NULL, "CONNECT", NULL, "ftp.curl.se:123", NULL, 3, 2
};
static const char *T5_INPUT[] = {
"OPTIONS * HTTP/1.1\r\nContent-Length: 0\r\nBlabla: xxx.yyy\r",
"\n\tzzzzzz\r\n\r\n",
"123",
NULL,
};
static const struct tcase TEST5a = {
T5_INPUT, NULL, "OPTIONS", NULL, NULL, "*", 2, 3
};
static const char *T6_INPUT[] = {
"PUT /path HTTP/1.1\nHost: test.curl.se\n\n123",
NULL,
};
static const struct tcase TEST6a = {
T6_INPUT, NULL, "PUT", NULL, NULL, "/path", 1, 3
};
parse_success(&TEST1a);
parse_success(&TEST1b);
parse_success(&TEST2);
parse_success(&TEST3a);
parse_success(&TEST4a);
parse_success(&TEST5a);
parse_success(&TEST6a);
#endif
UNITTEST_END_SIMPLE
}
+116
View File
@@ -0,0 +1,116 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "vssh/curl_path.h"
#include "memdebug.h"
static CURLcode test_unit2604(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#ifdef USE_SSH
struct set {
const char *cp;
const char *expect; /* the returned content */
const char *next; /* what cp points to after the call */
const char *home;
CURLcode result;
};
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverlength-strings"
#endif
/* 60 a's */
#define SA60 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
/* 540 a's */
#define SA540 SA60 SA60 SA60 SA60 SA60 SA60 SA60 SA60 SA60
int i;
const size_t too_long = 90720;
struct set list[] = {
{ "-too-long-", "", "", "", CURLE_TOO_LARGE},
{ SA540 " c", SA540, "c", "/", CURLE_OK},
{ "\" " SA540 "\" c", " " SA540, "c", "/", CURLE_OK},
{ "a a", "a", "a", "/home/", CURLE_OK},
{ "b a", "b", "a", "/", CURLE_OK},
{ "a", "a", "", "/home/", CURLE_OK},
{ "b", "b", "", "/", CURLE_OK},
{ "\"foo bar\"\tb", "foo bar", "b", "/", CURLE_OK},
{ "/~/hej", "/home/user/hej", "", "/home/user", CURLE_OK},
{ "\"foo bar", "", "", "/", CURLE_QUOTE_ERROR},
{ "\"foo\\\"bar\" a", "foo\"bar", "a", "/", CURLE_OK},
{ "\"foo\\\'bar\" b", "foo\'bar", "b", "/", CURLE_OK},
{ "\"foo\\\\bar\" c", "foo\\bar", "c", "/", CURLE_OK},
{ "\"foo\\pbar\" c", "foo\\bar", "", "/", CURLE_QUOTE_ERROR},
{ "\"\" c", "", "", "", CURLE_QUOTE_ERROR},
{ "foo\"", "foo\"", "", "/", CURLE_OK},
{ "foo \"", "foo", "\"", "/", CURLE_OK},
{ " \t\t \t ", "", "", "/", CURLE_QUOTE_ERROR},
{ " ", "", "", "/", CURLE_QUOTE_ERROR},
{ "", "", "", "/", CURLE_QUOTE_ERROR},
{ " \r \n ", "\r", "\n ", "/", CURLE_OK},
{ NULL, NULL, NULL, NULL, CURLE_OK }
};
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
char *cp0 = calloc(1, too_long + 1);
fail_unless(cp0, "could not alloc too long value");
memset(cp0, 'a', too_long);
for(i = 0; list[i].home; i++) {
char *path;
const char *cp = i == 0 ? cp0 : list[i].cp;
CURLcode result = Curl_get_pathname(&cp, &path, list[i].home);
curl_mprintf("%u - Curl_get_pathname(\"%s\", ... \"%s\") == %u\n", i,
list[i].cp, list[i].home, list[i].result);
if(result != list[i].result) {
curl_mprintf("... returned %d\n", result);
unitfail++;
}
if(!result) {
if(cp && strcmp(cp, list[i].next)) {
curl_mprintf("... cp points to '%s', not '%s' as expected \n",
cp, list[i].next);
unitfail++;
}
if(path && strcmp(path, list[i].expect)) {
curl_mprintf("... gave '%s', not '%s' as expected \n",
path, list[i].expect);
unitfail++;
}
curl_free(path);
}
}
free(cp0);
#endif
UNITTEST_END_SIMPLE
}
+170
View File
@@ -0,0 +1,170 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "curl_get_line.h"
#include "memdebug.h"
static CURLcode test_unit3200(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#if !defined(CURL_DISABLE_COOKIES) || !defined(CURL_DISABLE_ALTSVC) || \
!defined(CURL_DISABLE_HSTS) || !defined(CURL_DISABLE_NETRC)
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverlength-strings"
#endif
/* The test XML does not supply a way to write files without newlines
* so we write our own
*/
#define C64 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
#define C256 C64 C64 C64 C64
#define C1024 C256 C256 C256 C256
#define C4096 C1024 C1024 C1024 C1024
static const char *filecontents[] = {
/* Both should be read */
"LINE1\n"
"LINE2 NEWLINE\n",
/* Both should be read */
"LINE1\n"
"LINE2 NONEWLINE",
/* Only first should be read */
"LINE1\n"
C4096,
/* First line should be read */
"LINE1\n"
C4096 "SOME EXTRA TEXT",
/* Only first should be read */
"LINE1\n"
C4096 "SOME EXTRA TEXT\n"
"LINE3\n",
"LINE1\x1aTEST"
};
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
size_t i;
CURLcode result = CURLE_OK;
for(i = 0; i < CURL_ARRAYSIZE(filecontents); i++) {
FILE *fp;
struct dynbuf buf;
size_t len = 4096;
char *line;
bool eof;
curlx_dyn_init(&buf, len);
fp = curlx_fopen(arg, "wb");
abort_unless(fp != NULL, "Cannot open testfile");
fwrite(filecontents[i], 1, strlen(filecontents[i]), fp);
curlx_fclose(fp);
fp = curlx_fopen(arg, "rb");
abort_unless(fp != NULL, "Cannot open testfile");
curl_mfprintf(stderr, "Test %zd...", i);
switch(i) {
case 0:
result = Curl_get_line(&buf, fp, &eof);
line = curlx_dyn_ptr(&buf);
fail_unless(!result && line && !strcmp("LINE1\n", line),
"First line failed (1)");
result = Curl_get_line(&buf, fp, &eof);
line = curlx_dyn_ptr(&buf);
fail_unless(!result && line && !strcmp("LINE2 NEWLINE\n", line),
"Second line failed (1)");
result = Curl_get_line(&buf, fp, &eof);
abort_unless(eof, "Missed EOF (1)");
break;
case 1:
result = Curl_get_line(&buf, fp, &eof);
line = curlx_dyn_ptr(&buf);
fail_unless(!result && line && !strcmp("LINE1\n", line),
"First line failed (2)");
result = Curl_get_line(&buf, fp, &eof);
line = curlx_dyn_ptr(&buf);
fail_unless(!result && line && !strcmp("LINE2 NONEWLINE\n", line),
"Second line failed (2)");
result = Curl_get_line(&buf, fp, &eof);
abort_unless(eof, "Missed EOF (2)");
break;
case 2:
result = Curl_get_line(&buf, fp, &eof);
line = curlx_dyn_ptr(&buf);
fail_unless(!result && line && !strcmp("LINE1\n", line),
"First line failed (3)");
result = Curl_get_line(&buf, fp, &eof);
fail_unless(!curlx_dyn_len(&buf),
"Did not detect max read on EOF (3)");
break;
case 3:
result = Curl_get_line(&buf, fp, &eof);
line = curlx_dyn_ptr(&buf);
fail_unless(!result && line && !strcmp("LINE1\n", line),
"First line failed (4)");
result = Curl_get_line(&buf, fp, &eof);
fail_unless(!curlx_dyn_len(&buf),
"Did not ignore partial on EOF (4)");
break;
case 4:
result = Curl_get_line(&buf, fp, &eof);
line = curlx_dyn_ptr(&buf);
fail_unless(!result && line && !strcmp("LINE1\n", line),
"First line failed (5)");
result = Curl_get_line(&buf, fp, &eof);
fail_unless(!curlx_dyn_len(&buf),
"Did not bail out on too long line");
break;
case 5:
result = Curl_get_line(&buf, fp, &eof);
line = curlx_dyn_ptr(&buf);
fail_unless(!result && line && !strcmp("LINE1\x1aTEST\n", line),
"Missed/Misinterpreted ^Z (6)");
result = Curl_get_line(&buf, fp, &eof);
abort_unless(eof, "Missed EOF (6)");
break;
default:
abort_unless(1, "Unknown case");
break;
}
curlx_dyn_free(&buf);
curlx_fclose(fp);
curl_mfprintf(stderr, "OK\n");
}
return result;
#endif
UNITTEST_END_SIMPLE
}
+611
View File
@@ -0,0 +1,611 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Jan Venekamp, <jan@venekamp.net>
*
* 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "vtls/cipher_suite.h"
static CURLcode test_unit3205(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
#if defined(USE_MBEDTLS) || defined(USE_RUSTLS)
struct test_cs_entry {
uint16_t id;
const char *rfc;
const char *openssl;
};
static const struct test_cs_entry test_cs_list[] = {
{ 0x1301, "TLS_AES_128_GCM_SHA256",
NULL },
{ 0x1302, "TLS_AES_256_GCM_SHA384",
NULL },
{ 0x1303, "TLS_CHACHA20_POLY1305_SHA256",
NULL },
{ 0x1304, "TLS_AES_128_CCM_SHA256",
NULL },
{ 0x1305, "TLS_AES_128_CCM_8_SHA256",
NULL },
{ 0xC02B, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
"ECDHE-ECDSA-AES128-GCM-SHA256" },
{ 0xC02C, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
"ECDHE-ECDSA-AES256-GCM-SHA384" },
{ 0xC02F, "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
"ECDHE-RSA-AES128-GCM-SHA256" },
{ 0xC030, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
"ECDHE-RSA-AES256-GCM-SHA384" },
{ 0xCCA8, "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256",
"ECDHE-RSA-CHACHA20-POLY1305" },
{ 0xCCA9, "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256",
"ECDHE-ECDSA-CHACHA20-POLY1305" },
#ifdef USE_MBEDTLS
{ 0x002F, "TLS_RSA_WITH_AES_128_CBC_SHA",
"AES128-SHA" },
{ 0x0035, "TLS_RSA_WITH_AES_256_CBC_SHA",
"AES256-SHA" },
{ 0x003C, "TLS_RSA_WITH_AES_128_CBC_SHA256",
"AES128-SHA256" },
{ 0x003D, "TLS_RSA_WITH_AES_256_CBC_SHA256",
"AES256-SHA256" },
{ 0x009C, "TLS_RSA_WITH_AES_128_GCM_SHA256",
"AES128-GCM-SHA256" },
{ 0x009D, "TLS_RSA_WITH_AES_256_GCM_SHA384",
"AES256-GCM-SHA384" },
{ 0xC004, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA",
"ECDH-ECDSA-AES128-SHA" },
{ 0xC005, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA",
"ECDH-ECDSA-AES256-SHA" },
{ 0xC009, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
"ECDHE-ECDSA-AES128-SHA" },
{ 0xC00A, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
"ECDHE-ECDSA-AES256-SHA" },
{ 0xC00E, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA",
"ECDH-RSA-AES128-SHA" },
{ 0xC00F, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA",
"ECDH-RSA-AES256-SHA" },
{ 0xC013, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
"ECDHE-RSA-AES128-SHA" },
{ 0xC014, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
"ECDHE-RSA-AES256-SHA" },
{ 0xC023, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
"ECDHE-ECDSA-AES128-SHA256" },
{ 0xC024, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384",
"ECDHE-ECDSA-AES256-SHA384" },
{ 0xC025, "TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256",
"ECDH-ECDSA-AES128-SHA256" },
{ 0xC026, "TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384",
"ECDH-ECDSA-AES256-SHA384" },
{ 0xC027, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
"ECDHE-RSA-AES128-SHA256" },
{ 0xC028, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384",
"ECDHE-RSA-AES256-SHA384" },
{ 0xC029, "TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256",
"ECDH-RSA-AES128-SHA256" },
{ 0xC02A, "TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384",
"ECDH-RSA-AES256-SHA384" },
{ 0xC02D, "TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256",
"ECDH-ECDSA-AES128-GCM-SHA256" },
{ 0xC02E, "TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384",
"ECDH-ECDSA-AES256-GCM-SHA384" },
{ 0xC031, "TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256",
"ECDH-RSA-AES128-GCM-SHA256" },
{ 0xC032, "TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384",
"ECDH-RSA-AES256-GCM-SHA384" },
{ 0x0001, "TLS_RSA_WITH_NULL_MD5",
"NULL-MD5" },
{ 0x0002, "TLS_RSA_WITH_NULL_SHA",
"NULL-SHA" },
{ 0x002C, "TLS_PSK_WITH_NULL_SHA",
"PSK-NULL-SHA" },
{ 0x002D, "TLS_DHE_PSK_WITH_NULL_SHA",
"DHE-PSK-NULL-SHA" },
{ 0x002E, "TLS_RSA_PSK_WITH_NULL_SHA",
"RSA-PSK-NULL-SHA" },
{ 0x0033, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
"DHE-RSA-AES128-SHA" },
{ 0x0039, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA",
"DHE-RSA-AES256-SHA" },
{ 0x003B, "TLS_RSA_WITH_NULL_SHA256",
"NULL-SHA256" },
{ 0x0067, "TLS_DHE_RSA_WITH_AES_128_CBC_SHA256",
"DHE-RSA-AES128-SHA256" },
{ 0x006B, "TLS_DHE_RSA_WITH_AES_256_CBC_SHA256",
"DHE-RSA-AES256-SHA256" },
{ 0x008C, "TLS_PSK_WITH_AES_128_CBC_SHA",
"PSK-AES128-CBC-SHA" },
{ 0x008D, "TLS_PSK_WITH_AES_256_CBC_SHA",
"PSK-AES256-CBC-SHA" },
{ 0x0090, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA",
"DHE-PSK-AES128-CBC-SHA" },
{ 0x0091, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA",
"DHE-PSK-AES256-CBC-SHA" },
{ 0x0094, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA",
"RSA-PSK-AES128-CBC-SHA" },
{ 0x0095, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA",
"RSA-PSK-AES256-CBC-SHA" },
{ 0x009E, "TLS_DHE_RSA_WITH_AES_128_GCM_SHA256",
"DHE-RSA-AES128-GCM-SHA256" },
{ 0x009F, "TLS_DHE_RSA_WITH_AES_256_GCM_SHA384",
"DHE-RSA-AES256-GCM-SHA384" },
{ 0x00A8, "TLS_PSK_WITH_AES_128_GCM_SHA256",
"PSK-AES128-GCM-SHA256" },
{ 0x00A9, "TLS_PSK_WITH_AES_256_GCM_SHA384",
"PSK-AES256-GCM-SHA384" },
{ 0x00AA, "TLS_DHE_PSK_WITH_AES_128_GCM_SHA256",
"DHE-PSK-AES128-GCM-SHA256" },
{ 0x00AB, "TLS_DHE_PSK_WITH_AES_256_GCM_SHA384",
"DHE-PSK-AES256-GCM-SHA384" },
{ 0x00AC, "TLS_RSA_PSK_WITH_AES_128_GCM_SHA256",
"RSA-PSK-AES128-GCM-SHA256" },
{ 0x00AD, "TLS_RSA_PSK_WITH_AES_256_GCM_SHA384",
"RSA-PSK-AES256-GCM-SHA384" },
{ 0x00AE, "TLS_PSK_WITH_AES_128_CBC_SHA256",
"PSK-AES128-CBC-SHA256" },
{ 0x00AF, "TLS_PSK_WITH_AES_256_CBC_SHA384",
"PSK-AES256-CBC-SHA384" },
{ 0x00B0, "TLS_PSK_WITH_NULL_SHA256",
"PSK-NULL-SHA256" },
{ 0x00B1, "TLS_PSK_WITH_NULL_SHA384",
"PSK-NULL-SHA384" },
{ 0x00B2, "TLS_DHE_PSK_WITH_AES_128_CBC_SHA256",
"DHE-PSK-AES128-CBC-SHA256" },
{ 0x00B3, "TLS_DHE_PSK_WITH_AES_256_CBC_SHA384",
"DHE-PSK-AES256-CBC-SHA384" },
{ 0x00B4, "TLS_DHE_PSK_WITH_NULL_SHA256",
"DHE-PSK-NULL-SHA256" },
{ 0x00B5, "TLS_DHE_PSK_WITH_NULL_SHA384",
"DHE-PSK-NULL-SHA384" },
{ 0x00B6, "TLS_RSA_PSK_WITH_AES_128_CBC_SHA256",
"RSA-PSK-AES128-CBC-SHA256" },
{ 0x00B7, "TLS_RSA_PSK_WITH_AES_256_CBC_SHA384",
"RSA-PSK-AES256-CBC-SHA384" },
{ 0x00B8, "TLS_RSA_PSK_WITH_NULL_SHA256",
"RSA-PSK-NULL-SHA256" },
{ 0x00B9, "TLS_RSA_PSK_WITH_NULL_SHA384",
"RSA-PSK-NULL-SHA384" },
{ 0xC001, "TLS_ECDH_ECDSA_WITH_NULL_SHA",
"ECDH-ECDSA-NULL-SHA" },
{ 0xC006, "TLS_ECDHE_ECDSA_WITH_NULL_SHA",
"ECDHE-ECDSA-NULL-SHA" },
{ 0xC00B, "TLS_ECDH_RSA_WITH_NULL_SHA",
"ECDH-RSA-NULL-SHA" },
{ 0xC010, "TLS_ECDHE_RSA_WITH_NULL_SHA",
"ECDHE-RSA-NULL-SHA" },
{ 0xC035, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA",
"ECDHE-PSK-AES128-CBC-SHA" },
{ 0xC036, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA",
"ECDHE-PSK-AES256-CBC-SHA" },
{ 0xCCAB, "TLS_PSK_WITH_CHACHA20_POLY1305_SHA256",
"PSK-CHACHA20-POLY1305" },
{ 0xC09C, "TLS_RSA_WITH_AES_128_CCM",
"AES128-CCM" },
{ 0xC09D, "TLS_RSA_WITH_AES_256_CCM",
"AES256-CCM" },
{ 0xC0A0, "TLS_RSA_WITH_AES_128_CCM_8",
"AES128-CCM8" },
{ 0xC0A1, "TLS_RSA_WITH_AES_256_CCM_8",
"AES256-CCM8" },
{ 0xC0AC, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM",
"ECDHE-ECDSA-AES128-CCM" },
{ 0xC0AD, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM",
"ECDHE-ECDSA-AES256-CCM" },
{ 0xC0AE, "TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8",
"ECDHE-ECDSA-AES128-CCM8" },
{ 0xC0AF, "TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8",
"ECDHE-ECDSA-AES256-CCM8" },
/* entries marked ns are non-"standard", they are not in OpenSSL */
{ 0x0041, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA",
"CAMELLIA128-SHA" },
{ 0x0045, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA",
"DHE-RSA-CAMELLIA128-SHA" },
{ 0x0084, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA",
"CAMELLIA256-SHA" },
{ 0x0088, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA",
"DHE-RSA-CAMELLIA256-SHA" },
{ 0x00BA, "TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256",
"CAMELLIA128-SHA256" },
{ 0x00BE, "TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256",
"DHE-RSA-CAMELLIA128-SHA256" },
{ 0x00C0, "TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256",
"CAMELLIA256-SHA256" },
{ 0x00C4, "TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256",
"DHE-RSA-CAMELLIA256-SHA256" },
{ 0xC037, "TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256",
"ECDHE-PSK-AES128-CBC-SHA256" },
{ 0xC038, "TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA384",
"ECDHE-PSK-AES256-CBC-SHA384" },
{ 0xC039, "TLS_ECDHE_PSK_WITH_NULL_SHA",
"ECDHE-PSK-NULL-SHA" },
{ 0xC03A, "TLS_ECDHE_PSK_WITH_NULL_SHA256",
"ECDHE-PSK-NULL-SHA256" },
{ 0xC03B, "TLS_ECDHE_PSK_WITH_NULL_SHA384",
"ECDHE-PSK-NULL-SHA384" },
{ 0xC03C, "TLS_RSA_WITH_ARIA_128_CBC_SHA256",
"ARIA128-SHA256" /* ns */ },
{ 0xC03D, "TLS_RSA_WITH_ARIA_256_CBC_SHA384",
"ARIA256-SHA384" /* ns */ },
{ 0xC044, "TLS_DHE_RSA_WITH_ARIA_128_CBC_SHA256",
"DHE-RSA-ARIA128-SHA256" /* ns */ },
{ 0xC045, "TLS_DHE_RSA_WITH_ARIA_256_CBC_SHA384",
"DHE-RSA-ARIA256-SHA384" /* ns */ },
{ 0xC048, "TLS_ECDHE_ECDSA_WITH_ARIA_128_CBC_SHA256",
"ECDHE-ECDSA-ARIA128-SHA256" /* ns */ },
{ 0xC049, "TLS_ECDHE_ECDSA_WITH_ARIA_256_CBC_SHA384",
"ECDHE-ECDSA-ARIA256-SHA384" /* ns */ },
{ 0xC04A, "TLS_ECDH_ECDSA_WITH_ARIA_128_CBC_SHA256",
"ECDH-ECDSA-ARIA128-SHA256" /* ns */ },
{ 0xC04B, "TLS_ECDH_ECDSA_WITH_ARIA_256_CBC_SHA384",
"ECDH-ECDSA-ARIA256-SHA384" /* ns */ },
{ 0xC04C, "TLS_ECDHE_RSA_WITH_ARIA_128_CBC_SHA256",
"ECDHE-ARIA128-SHA256" /* ns */ },
{ 0xC04D, "TLS_ECDHE_RSA_WITH_ARIA_256_CBC_SHA384",
"ECDHE-ARIA256-SHA384" /* ns */ },
{ 0xC04E, "TLS_ECDH_RSA_WITH_ARIA_128_CBC_SHA256",
"ECDH-ARIA128-SHA256" /* ns */ },
{ 0xC04F, "TLS_ECDH_RSA_WITH_ARIA_256_CBC_SHA384",
"ECDH-ARIA256-SHA384" /* ns */ },
{ 0xC050, "TLS_RSA_WITH_ARIA_128_GCM_SHA256",
"ARIA128-GCM-SHA256" },
{ 0xC051, "TLS_RSA_WITH_ARIA_256_GCM_SHA384",
"ARIA256-GCM-SHA384" },
{ 0xC052, "TLS_DHE_RSA_WITH_ARIA_128_GCM_SHA256",
"DHE-RSA-ARIA128-GCM-SHA256" },
{ 0xC053, "TLS_DHE_RSA_WITH_ARIA_256_GCM_SHA384",
"DHE-RSA-ARIA256-GCM-SHA384" },
{ 0xC05C, "TLS_ECDHE_ECDSA_WITH_ARIA_128_GCM_SHA256",
"ECDHE-ECDSA-ARIA128-GCM-SHA256" },
{ 0xC05D, "TLS_ECDHE_ECDSA_WITH_ARIA_256_GCM_SHA384",
"ECDHE-ECDSA-ARIA256-GCM-SHA384" },
{ 0xC05E, "TLS_ECDH_ECDSA_WITH_ARIA_128_GCM_SHA256",
"ECDH-ECDSA-ARIA128-GCM-SHA256" /* ns */ },
{ 0xC05F, "TLS_ECDH_ECDSA_WITH_ARIA_256_GCM_SHA384",
"ECDH-ECDSA-ARIA256-GCM-SHA384" /* ns */ },
{ 0xC060, "TLS_ECDHE_RSA_WITH_ARIA_128_GCM_SHA256",
"ECDHE-ARIA128-GCM-SHA256" },
{ 0xC061, "TLS_ECDHE_RSA_WITH_ARIA_256_GCM_SHA384",
"ECDHE-ARIA256-GCM-SHA384" },
{ 0xC062, "TLS_ECDH_RSA_WITH_ARIA_128_GCM_SHA256",
"ECDH-ARIA128-GCM-SHA256" /* ns */ },
{ 0xC063, "TLS_ECDH_RSA_WITH_ARIA_256_GCM_SHA384",
"ECDH-ARIA256-GCM-SHA384" /* ns */ },
{ 0xC064, "TLS_PSK_WITH_ARIA_128_CBC_SHA256",
"PSK-ARIA128-SHA256" /* ns */ },
{ 0xC065, "TLS_PSK_WITH_ARIA_256_CBC_SHA384",
"PSK-ARIA256-SHA384" /* ns */ },
{ 0xC066, "TLS_DHE_PSK_WITH_ARIA_128_CBC_SHA256",
"DHE-PSK-ARIA128-SHA256" /* ns */ },
{ 0xC067, "TLS_DHE_PSK_WITH_ARIA_256_CBC_SHA384",
"DHE-PSK-ARIA256-SHA384" /* ns */ },
{ 0xC068, "TLS_RSA_PSK_WITH_ARIA_128_CBC_SHA256",
"RSA-PSK-ARIA128-SHA256" /* ns */ },
{ 0xC069, "TLS_RSA_PSK_WITH_ARIA_256_CBC_SHA384",
"RSA-PSK-ARIA256-SHA384" /* ns */ },
{ 0xC06A, "TLS_PSK_WITH_ARIA_128_GCM_SHA256",
"PSK-ARIA128-GCM-SHA256" },
{ 0xC06B, "TLS_PSK_WITH_ARIA_256_GCM_SHA384",
"PSK-ARIA256-GCM-SHA384" },
{ 0xC06C, "TLS_DHE_PSK_WITH_ARIA_128_GCM_SHA256",
"DHE-PSK-ARIA128-GCM-SHA256" },
{ 0xC06D, "TLS_DHE_PSK_WITH_ARIA_256_GCM_SHA384",
"DHE-PSK-ARIA256-GCM-SHA384" },
{ 0xC06E, "TLS_RSA_PSK_WITH_ARIA_128_GCM_SHA256",
"RSA-PSK-ARIA128-GCM-SHA256" },
{ 0xC06F, "TLS_RSA_PSK_WITH_ARIA_256_GCM_SHA384",
"RSA-PSK-ARIA256-GCM-SHA384" },
{ 0xC070, "TLS_ECDHE_PSK_WITH_ARIA_128_CBC_SHA256",
"ECDHE-PSK-ARIA128-SHA256" /* ns */ },
{ 0xC071, "TLS_ECDHE_PSK_WITH_ARIA_256_CBC_SHA384",
"ECDHE-PSK-ARIA256-SHA384" /* ns */ },
{ 0xC072, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_CBC_SHA256",
"ECDHE-ECDSA-CAMELLIA128-SHA256" },
{ 0xC073, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_CBC_SHA384",
"ECDHE-ECDSA-CAMELLIA256-SHA384" },
{ 0xC074, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_CBC_SHA256",
"ECDH-ECDSA-CAMELLIA128-SHA256" /* ns */ },
{ 0xC075, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_CBC_SHA384",
"ECDH-ECDSA-CAMELLIA256-SHA384" /* ns */ },
{ 0xC076, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_CBC_SHA256",
"ECDHE-RSA-CAMELLIA128-SHA256" },
{ 0xC077, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_CBC_SHA384",
"ECDHE-RSA-CAMELLIA256-SHA384" },
{ 0xC078, "TLS_ECDH_RSA_WITH_CAMELLIA_128_CBC_SHA256",
"ECDH-CAMELLIA128-SHA256" /* ns */ },
{ 0xC079, "TLS_ECDH_RSA_WITH_CAMELLIA_256_CBC_SHA384",
"ECDH-CAMELLIA256-SHA384" /* ns */ },
{ 0xC07A, "TLS_RSA_WITH_CAMELLIA_128_GCM_SHA256",
"CAMELLIA128-GCM-SHA256" /* ns */ },
{ 0xC07B, "TLS_RSA_WITH_CAMELLIA_256_GCM_SHA384",
"CAMELLIA256-GCM-SHA384" /* ns */ },
{ 0xC07C, "TLS_DHE_RSA_WITH_CAMELLIA_128_GCM_SHA256",
"DHE-RSA-CAMELLIA128-GCM-SHA256" /* ns */ },
{ 0xC07D, "TLS_DHE_RSA_WITH_CAMELLIA_256_GCM_SHA384",
"DHE-RSA-CAMELLIA256-GCM-SHA384" /* ns */ },
{ 0xC086, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_128_GCM_SHA256",
"ECDHE-ECDSA-CAMELLIA128-GCM-SHA256" /* ns */ },
{ 0xC087, "TLS_ECDHE_ECDSA_WITH_CAMELLIA_256_GCM_SHA384",
"ECDHE-ECDSA-CAMELLIA256-GCM-SHA384" /* ns */ },
{ 0xC088, "TLS_ECDH_ECDSA_WITH_CAMELLIA_128_GCM_SHA256",
"ECDH-ECDSA-CAMELLIA128-GCM-SHA256" /* ns */ },
{ 0xC089, "TLS_ECDH_ECDSA_WITH_CAMELLIA_256_GCM_SHA384",
"ECDH-ECDSA-CAMELLIA256-GCM-SHA384" /* ns */ },
{ 0xC08A, "TLS_ECDHE_RSA_WITH_CAMELLIA_128_GCM_SHA256",
"ECDHE-CAMELLIA128-GCM-SHA256" /* ns */ },
{ 0xC08B, "TLS_ECDHE_RSA_WITH_CAMELLIA_256_GCM_SHA384",
"ECDHE-CAMELLIA256-GCM-SHA384" /* ns */ },
{ 0xC08C, "TLS_ECDH_RSA_WITH_CAMELLIA_128_GCM_SHA256",
"ECDH-CAMELLIA128-GCM-SHA256" /* ns */ },
{ 0xC08D, "TLS_ECDH_RSA_WITH_CAMELLIA_256_GCM_SHA384",
"ECDH-CAMELLIA256-GCM-SHA384" /* ns */ },
{ 0xC08E, "TLS_PSK_WITH_CAMELLIA_128_GCM_SHA256",
"PSK-CAMELLIA128-GCM-SHA256" /* ns */ },
{ 0xC08F, "TLS_PSK_WITH_CAMELLIA_256_GCM_SHA384",
"PSK-CAMELLIA256-GCM-SHA384" /* ns */ },
{ 0xC090, "TLS_DHE_PSK_WITH_CAMELLIA_128_GCM_SHA256",
"DHE-PSK-CAMELLIA128-GCM-SHA256" /* ns */ },
{ 0xC091, "TLS_DHE_PSK_WITH_CAMELLIA_256_GCM_SHA384",
"DHE-PSK-CAMELLIA256-GCM-SHA384" /* ns */ },
{ 0xC092, "TLS_RSA_PSK_WITH_CAMELLIA_128_GCM_SHA256",
"RSA-PSK-CAMELLIA128-GCM-SHA256" /* ns */ },
{ 0xC093, "TLS_RSA_PSK_WITH_CAMELLIA_256_GCM_SHA384",
"RSA-PSK-CAMELLIA256-GCM-SHA384" /* ns */ },
{ 0xC094, "TLS_PSK_WITH_CAMELLIA_128_CBC_SHA256",
"PSK-CAMELLIA128-SHA256" },
{ 0xC095, "TLS_PSK_WITH_CAMELLIA_256_CBC_SHA384",
"PSK-CAMELLIA256-SHA384" },
{ 0xC096, "TLS_DHE_PSK_WITH_CAMELLIA_128_CBC_SHA256",
"DHE-PSK-CAMELLIA128-SHA256" },
{ 0xC097, "TLS_DHE_PSK_WITH_CAMELLIA_256_CBC_SHA384",
"DHE-PSK-CAMELLIA256-SHA384" },
{ 0xC098, "TLS_RSA_PSK_WITH_CAMELLIA_128_CBC_SHA256",
"RSA-PSK-CAMELLIA128-SHA256" },
{ 0xC099, "TLS_RSA_PSK_WITH_CAMELLIA_256_CBC_SHA384",
"RSA-PSK-CAMELLIA256-SHA384" },
{ 0xC09A, "TLS_ECDHE_PSK_WITH_CAMELLIA_128_CBC_SHA256",
"ECDHE-PSK-CAMELLIA128-SHA256" },
{ 0xC09B, "TLS_ECDHE_PSK_WITH_CAMELLIA_256_CBC_SHA384",
"ECDHE-PSK-CAMELLIA256-SHA384" },
{ 0xC09E, "TLS_DHE_RSA_WITH_AES_128_CCM",
"DHE-RSA-AES128-CCM" },
{ 0xC09F, "TLS_DHE_RSA_WITH_AES_256_CCM",
"DHE-RSA-AES256-CCM" },
{ 0xC0A2, "TLS_DHE_RSA_WITH_AES_128_CCM_8",
"DHE-RSA-AES128-CCM8" },
{ 0xC0A3, "TLS_DHE_RSA_WITH_AES_256_CCM_8",
"DHE-RSA-AES256-CCM8" },
{ 0xC0A4, "TLS_PSK_WITH_AES_128_CCM",
"PSK-AES128-CCM" },
{ 0xC0A5, "TLS_PSK_WITH_AES_256_CCM",
"PSK-AES256-CCM" },
{ 0xC0A6, "TLS_DHE_PSK_WITH_AES_128_CCM",
"DHE-PSK-AES128-CCM" },
{ 0xC0A7, "TLS_DHE_PSK_WITH_AES_256_CCM",
"DHE-PSK-AES256-CCM" },
{ 0xC0A8, "TLS_PSK_WITH_AES_128_CCM_8",
"PSK-AES128-CCM8" },
{ 0xC0A9, "TLS_PSK_WITH_AES_256_CCM_8",
"PSK-AES256-CCM8" },
{ 0xC0AA, "TLS_PSK_DHE_WITH_AES_128_CCM_8",
"DHE-PSK-AES128-CCM8" },
{ 0xC0AB, "TLS_PSK_DHE_WITH_AES_256_CCM_8",
"DHE-PSK-AES256-CCM8" },
{ 0xCCAA, "TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256",
"DHE-RSA-CHACHA20-POLY1305" },
{ 0xCCAC, "TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256",
"ECDHE-PSK-CHACHA20-POLY1305" },
{ 0xCCAD, "TLS_DHE_PSK_WITH_CHACHA20_POLY1305_SHA256",
"DHE-PSK-CHACHA20-POLY1305" },
{ 0xCCAE, "TLS_RSA_PSK_WITH_CHACHA20_POLY1305_SHA256",
"RSA-PSK-CHACHA20-POLY1305" },
#endif
};
static const char *cs_test_string =
"TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:"
"TLS_CHACHA20_POLY1305_SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:"
"ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:"
"ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:"
"ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:"
"DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:"
"ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:"
"ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:"
"ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:"
"DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:"
"AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:"
"DES-CBC3-SHA:"
":: GIBBERISH ::"
;
struct test_str_entry {
uint16_t id;
const char *str;
};
static const struct test_str_entry test_str_list[] = {
{ 0x1301, "TLS_AES_128_GCM_SHA256"},
{ 0x1302, "TLS_AES_256_GCM_SHA384"},
{ 0x1303, "TLS_CHACHA20_POLY1305_SHA256"},
{ 0xC02B, "ECDHE-ECDSA-AES128-GCM-SHA256"},
{ 0xC02F, "ECDHE-RSA-AES128-GCM-SHA256"},
{ 0xC02C, "ECDHE-ECDSA-AES256-GCM-SHA384"},
{ 0xC030, "ECDHE-RSA-AES256-GCM-SHA384"},
{ 0xCCA9, "ECDHE-ECDSA-CHACHA20-POLY1305"},
{ 0xCCA8, "ECDHE-RSA-CHACHA20-POLY1305"},
#ifdef USE_MBEDTLS
{ 0x009E, "DHE-RSA-AES128-GCM-SHA256"},
{ 0x009F, "DHE-RSA-AES256-GCM-SHA384"},
#else
{ 0x0000, "DHE-RSA-AES128-GCM-SHA256"},
{ 0x0000, "DHE-RSA-AES256-GCM-SHA384"},
#endif
#ifdef USE_MBEDTLS
{ 0xCCAA, "DHE-RSA-CHACHA20-POLY1305"},
#else
{ 0x0000, "DHE-RSA-CHACHA20-POLY1305"},
#endif
#ifdef USE_MBEDTLS
{ 0xC023, "ECDHE-ECDSA-AES128-SHA256" },
{ 0xC027, "ECDHE-RSA-AES128-SHA256" },
{ 0xC009, "ECDHE-ECDSA-AES128-SHA" },
{ 0xC013, "ECDHE-RSA-AES128-SHA" },
{ 0xC024, "ECDHE-ECDSA-AES256-SHA384" },
{ 0xC028, "ECDHE-RSA-AES256-SHA384" },
{ 0xC00A, "ECDHE-ECDSA-AES256-SHA" },
{ 0xC014, "ECDHE-RSA-AES256-SHA" },
#else
{ 0x0000, "ECDHE-ECDSA-AES128-SHA256" },
{ 0x0000, "ECDHE-RSA-AES128-SHA256" },
{ 0x0000, "ECDHE-ECDSA-AES128-SHA" },
{ 0x0000, "ECDHE-RSA-AES128-SHA" },
{ 0x0000, "ECDHE-ECDSA-AES256-SHA384" },
{ 0x0000, "ECDHE-RSA-AES256-SHA384" },
{ 0x0000, "ECDHE-ECDSA-AES256-SHA" },
{ 0x0000, "ECDHE-RSA-AES256-SHA" },
#endif
#ifdef USE_MBEDTLS
{ 0x0067, "DHE-RSA-AES128-SHA256" },
{ 0x006B, "DHE-RSA-AES256-SHA256" },
#else
{ 0x0000, "DHE-RSA-AES128-SHA256" },
{ 0x0000, "DHE-RSA-AES256-SHA256" },
#endif
#ifdef USE_MBEDTLS
{ 0x009C, "AES128-GCM-SHA256" },
{ 0x009D, "AES256-GCM-SHA384" },
{ 0x003C, "AES128-SHA256" },
{ 0x003D, "AES256-SHA256" },
{ 0x002F, "AES128-SHA" },
{ 0x0035, "AES256-SHA" },
#else
{ 0x0000, "AES128-GCM-SHA256" },
{ 0x0000, "AES256-GCM-SHA384" },
{ 0x0000, "AES128-SHA256" },
{ 0x0000, "AES256-SHA256" },
{ 0x0000, "AES128-SHA" },
{ 0x0000, "AES256-SHA" },
#endif
{ 0x0000, "DES-CBC3-SHA" },
{ 0x0000, "GIBBERISH" },
{ 0x0000, "" },
};
size_t i;
for(i = 0; i < CURL_ARRAYSIZE(test_cs_list); i++) {
const struct test_cs_entry *test = &test_cs_list[i];
const char *expect;
char buf[64] = "";
char alt[64] = "";
uint16_t id;
/* test Curl_cipher_suite_lookup_id() for rfc name */
if(test->rfc) {
id = Curl_cipher_suite_lookup_id(test->rfc, strlen(test->rfc));
if(id != test->id) {
curl_mfprintf(stderr, "Curl_cipher_suite_lookup_id FAILED for \"%s\", "
"result = 0x%04x, expected = 0x%04x\n",
test->rfc, id, test->id);
unitfail++;
}
}
/* test Curl_cipher_suite_lookup_id() for OpenSSL name */
if(test->openssl) {
id = Curl_cipher_suite_lookup_id(test->openssl, strlen(test->openssl));
if(id != test->id) {
curl_mfprintf(stderr, "Curl_cipher_suite_lookup_id FAILED for \"%s\", "
"result = 0x%04x, expected = 0x%04x\n",
test->openssl, id, test->id);
unitfail++;
}
}
/* test Curl_cipher_suite_get_str() prefer rfc name */
buf[0] = '\0';
expect = test->rfc ? test->rfc : test->openssl;
Curl_cipher_suite_get_str(test->id, buf, sizeof(buf), true);
if(expect && strcmp(buf, expect) != 0) {
curl_mfprintf(stderr, "Curl_cipher_suite_get_str FAILED for 0x%04x, "
"result = \"%s\", expected = \"%s\"\n",
test->id, buf, expect);
unitfail++;
}
/* test Curl_cipher_suite_get_str() prefer OpenSSL name */
buf[0] = '\0';
expect = test->openssl ? test->openssl : test->rfc;
Curl_cipher_suite_get_str(test->id, buf, sizeof(buf), false);
/* suites matched by EDH alias will return the DHE name */
if(test->id >= 0x0011 && test->id < 0x0017) {
if(expect && memcmp(expect, "EDH-", 4) == 0)
expect = (char *) memcpy(strcpy(alt, expect), "DHE-", 4);
if(expect && memcmp(expect + 4, "EDH-", 4) == 0)
expect = (char *) memcpy(strcpy(alt, expect) + 4, "DHE-", 4) - 4;
}
if(expect && strcmp(buf, expect) != 0) {
curl_mfprintf(stderr, "Curl_cipher_suite_get_str FAILED for 0x%04x, "
"result = \"%s\", expected = \"%s\"\n",
test->id, buf, expect);
unitfail++;
}
}
/* test Curl_cipher_suite_walk_str() */
{
const char *ptr, *end = cs_test_string;
int j = 0;
uint16_t id;
size_t len;
for(ptr = cs_test_string; ptr[0] != '\0'; ptr = end) {
const struct test_str_entry *test = &test_str_list[j];
abort_if(j == CURL_ARRAYSIZE(test_str_list), "should have been done");
id = Curl_cipher_suite_walk_str(&ptr, &end);
len = end - ptr;
if(id != test->id) {
curl_mfprintf(stderr, "Curl_cipher_suite_walk_str FAILED for \"%s\" "
"unexpected cipher, "
"result = 0x%04x, expected = 0x%04x\n",
test->str, id, test->id);
unitfail++;
}
if(len > 64 || strncmp(ptr, test->str, len) != 0) {
curl_mfprintf(stderr, "Curl_cipher_suite_walk_str ABORT for \"%s\" "
"unexpected pointers\n",
test->str);
unitfail++;
goto unit_test_abort;
}
j++;
}
}
#endif /* USE_MBEDTLS || USE_RUSTLS */
UNITTEST_END_SIMPLE
}
+146
View File
@@ -0,0 +1,146 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "uint-bset.h"
#include "curl_trc.h"
static void check_set(const char *name, unsigned int capacity,
const unsigned int *s, size_t slen)
{
struct uint_bset bset;
size_t i, j;
unsigned int n, c;
curl_mfprintf(stderr, "test %s, capacity=%u, %zu numbers\n",
name, capacity, slen);
Curl_uint_bset_init(&bset);
fail_unless(!Curl_uint_bset_resize(&bset, capacity), "bset resize failed");
c = Curl_uint_bset_capacity(&bset);
fail_unless(c == (((capacity + 63) / 64) * 64), "wrong capacity");
Curl_uint_bset_clear(&bset);
c = Curl_uint_bset_count(&bset);
fail_unless(c == 0, "set count is not 0");
for(i = 0; i < slen; ++i) { /* add all */
fail_unless(Curl_uint_bset_add(&bset, s[i]), "failed to add");
for(j = i + 1; j < slen; ++j)
fail_unless(!Curl_uint_bset_contains(&bset, s[j]), "unexpectedly found");
}
for(i = 0; i < slen; ++i) { /* all present */
fail_unless(Curl_uint_bset_contains(&bset, s[i]), "failed presence check");
}
/* iterator over all numbers */
fail_unless(Curl_uint_bset_first(&bset, &n), "first failed");
fail_unless(n == s[0], "first not correct number");
for(i = 1; i < slen; ++i) {
fail_unless(Curl_uint_bset_next(&bset, n, &n), "next failed");
if(n != s[i]) {
curl_mfprintf(stderr, "expected next to be %u, not %u\n", s[i], n);
fail_unless(n == s[i], "next not correct number");
}
}
/* Adding capacity number does not work (0 - capacity-1) */
c = Curl_uint_bset_capacity(&bset);
fail_unless(!Curl_uint_bset_add(&bset, c), "add out of range worked");
/* The count it correct */
c = Curl_uint_bset_count(&bset);
fail_unless(c == slen, "set count is wrong");
for(i = 0; i < slen; i += 2) { /* remove every 2nd */
Curl_uint_bset_remove(&bset, s[i]);
fail_unless(!Curl_uint_bset_contains(&bset, s[i]), "unexpectedly found");
}
for(i = 1; i < slen; i += 2) { /* others still there */
fail_unless(Curl_uint_bset_contains(&bset, s[i]), "unexpectedly gone");
}
/* The count is half */
c = Curl_uint_bset_count(&bset);
fail_unless(c == slen/2, "set count is wrong");
Curl_uint_bset_clear(&bset);
c = Curl_uint_bset_count(&bset);
fail_unless(c == 0, "set count is not 0");
for(i = 0; i < slen; i++) { /* none present any longer */
fail_unless(!Curl_uint_bset_contains(&bset, s[i]), "unexpectedly there");
}
for(i = 0; i < slen; ++i) { /* add all again */
fail_unless(Curl_uint_bset_add(&bset, s[i]), "failed to add");
}
fail_unless(!Curl_uint_bset_resize(&bset, capacity * 2),
"resize double failed");
for(i = 0; i < slen; i++) { /* all still present after resize */
fail_unless(Curl_uint_bset_contains(&bset, s[i]), "unexpectedly lost");
}
fail_unless(!Curl_uint_bset_resize(&bset, capacity), "resize back failed");
for(i = 0; i < slen; i++) /* all still present after resize back */
fail_unless(Curl_uint_bset_contains(&bset, s[i]), "unexpectedly lost");
fail_unless(!Curl_uint_bset_resize(&bset, capacity/2), "resize half failed");
/* halved the size, what numbers remain in set? */
c = Curl_uint_bset_capacity(&bset);
n = 0;
for(i = 0; i < slen; ++i) {
if(s[i] < c)
++n;
}
fail_unless(n == Curl_uint_bset_count(&bset), "set count(halved) wrong");
for(i = 0; i < n; i++) /* still present after resize half */
fail_unless(Curl_uint_bset_contains(&bset, s[i]), "unexpectedly lost");
Curl_uint_bset_destroy(&bset);
}
static CURLcode test_unit3211(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
static const unsigned int s1[] = { /* spread numbers, some at slot edges */
0, 1, 4, 17, 63, 64, 65, 66,
90, 99,
};
static const unsigned int s2[] = { /* set with all bits in slot1 set */
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127,
};
check_set("s1", 100, s1, CURL_ARRAYSIZE(s1));
check_set("s2", 1000, s2, CURL_ARRAYSIZE(s2));
UNITTEST_END_SIMPLE
}
+134
View File
@@ -0,0 +1,134 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "uint-table.h"
#include "curl_trc.h"
#include "unitprotos.h"
#define TBL_SIZE 100
static CURLcode t3212_setup(struct uint_tbl *tbl)
{
Curl_uint_tbl_init(tbl, NULL);
return Curl_uint_tbl_resize(tbl, TBL_SIZE);
}
static void t3212_stop(struct uint_tbl *tbl)
{
Curl_uint_tbl_destroy(tbl);
}
static CURLcode test_unit3212(const char *arg)
{
struct uint_tbl tbl;
int dummy;
UNITTEST_BEGIN(t3212_setup(&tbl))
unsigned int i, key, n;
void *entry;
fail_unless(Curl_uint_tbl_capacity(&tbl) == TBL_SIZE, "wrong capacity");
for(i = 0; i < TBL_SIZE; ++i) {
fail_unless(Curl_uint_tbl_add(&tbl, &dummy, &key), "failed to add");
fail_unless(key == i, "unexpected key assigned");
}
/* table should be full now */
fail_unless(Curl_uint_tbl_count(&tbl) == TBL_SIZE, "wrong count");
fail_unless(!Curl_uint_tbl_add(&tbl, &dummy, &key), "could add more");
/* remove every 2nd entry, from full table */
n = TBL_SIZE;
for(i = 0; i < TBL_SIZE; i += 2) {
Curl_uint_tbl_remove(&tbl, i);
--n;
fail_unless(Curl_uint_tbl_count(&tbl) == n, "wrong count after remove");
}
/* remove same again, should not change count */
for(i = 0; i < TBL_SIZE; i += 2) {
Curl_uint_tbl_remove(&tbl, i);
fail_unless(Curl_uint_tbl_count(&tbl) == n, "wrong count after remove");
}
/* still contains all odd entries */
for(i = 1; i < TBL_SIZE; i += 2) {
fail_unless(Curl_uint_tbl_contains(&tbl, i), "does not contain");
fail_unless(Curl_uint_tbl_get(&tbl, i) == &dummy,
"does not contain dummy");
}
/* get the first key */
fail_unless(Curl_uint_tbl_first(&tbl, &key, &entry), "first failed");
fail_unless(key == 1, "unexpected first key");
fail_unless(entry == &dummy, "unexpected first entry");
/* get the second key */
fail_unless(Curl_uint_tbl_next(&tbl, 1, &key, &entry), "next1 failed");
fail_unless(key == 3, "unexpected second key");
fail_unless(entry == &dummy, "unexpected second entry");
/* get the key after 42 */
fail_unless(Curl_uint_tbl_next(&tbl, 42, &key, &entry), "next42 failed");
fail_unless(key == 43, "unexpected next42 key");
fail_unless(entry == &dummy, "unexpected next42 entry");
/* double capacity */
n = Curl_uint_tbl_count(&tbl);
fail_unless(!Curl_uint_tbl_resize(&tbl, TBL_SIZE * 2),
"error doubling size");
fail_unless(Curl_uint_tbl_count(&tbl) == n, "wrong resize count");
/* resize to half of original */
fail_unless(!Curl_uint_tbl_resize(&tbl, TBL_SIZE / 2), "error halving size");
fail_unless(Curl_uint_tbl_count(&tbl) == n / 2, "wrong half size count");
for(i = 1; i < TBL_SIZE / 2; i += 2) {
fail_unless(Curl_uint_tbl_contains(&tbl, i), "does not contain");
fail_unless(Curl_uint_tbl_get(&tbl, i) == &dummy,
"does not contain dummy");
}
/* clear */
Curl_uint_tbl_clear(&tbl);
fail_unless(!Curl_uint_tbl_count(&tbl), "count not 0 after clear");
for(i = 0; i < TBL_SIZE / 2; ++i) {
fail_unless(!Curl_uint_tbl_contains(&tbl, i), "does contain, should not");
}
/* add after clear gets key 0 again */
fail_unless(Curl_uint_tbl_add(&tbl, &dummy, &key), "failed to add");
fail_unless(key == 0, "unexpected key assigned");
/* remove it again and add, should get key 1 */
Curl_uint_tbl_remove(&tbl, key);
fail_unless(Curl_uint_tbl_add(&tbl, &dummy, &key), "failed to add");
fail_unless(key == 1, "unexpected key assigned");
/* clear, fill, remove one, add, should get the removed key again */
Curl_uint_tbl_clear(&tbl);
for(i = 0; i < Curl_uint_tbl_capacity(&tbl); ++i)
fail_unless(Curl_uint_tbl_add(&tbl, &dummy, &key), "failed to add");
fail_unless(!Curl_uint_tbl_add(&tbl, &dummy, &key), "add on full");
Curl_uint_tbl_remove(&tbl, 17);
fail_unless(Curl_uint_tbl_add(&tbl, &dummy, &key), "failed to add again");
fail_unless(key == 17, "unexpected key assigned");
/* and again, triggering key search wrap around */
Curl_uint_tbl_remove(&tbl, 17);
fail_unless(Curl_uint_tbl_add(&tbl, &dummy, &key), "failed to add again");
fail_unless(key == 17, "unexpected key assigned");
UNITTEST_END(t3212_stop(&tbl))
}
+121
View File
@@ -0,0 +1,121 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
#include "uint-spbset.h"
#include "curl_trc.h"
#include "unitprotos.h"
static void check_spbset(const char *name, const unsigned int *s, size_t slen)
{
struct uint_spbset bset;
size_t i, j;
unsigned int n, c;
curl_mfprintf(stderr, "test %s, %zu numbers\n", name, slen);
Curl_uint_spbset_init(&bset);
Curl_uint_spbset_clear(&bset);
c = Curl_uint_spbset_count(&bset);
fail_unless(c == 0, "set count is not 0");
for(i = 0; i < slen; ++i) { /* add all */
fail_unless(Curl_uint_spbset_add(&bset, s[i]), "failed to add");
for(j = i + 1; j < slen; ++j)
fail_unless(!Curl_uint_spbset_contains(&bset, s[j]),
"unexpectedly found");
}
for(i = 0; i < slen; ++i) { /* all present */
fail_unless(Curl_uint_spbset_contains(&bset, s[i]),
"failed presence check");
}
/* iterator over all numbers */
fail_unless(Curl_uint_spbset_first(&bset, &n), "first failed");
fail_unless(n == s[0], "first not correct number");
for(i = 1; i < slen; ++i) {
fail_unless(Curl_uint_spbset_next(&bset, n, &n), "next failed");
if(n != s[i]) {
curl_mfprintf(stderr, "expected next to be %u, not %u\n", s[i], n);
fail_unless(n == s[i], "next not correct number");
}
}
for(i = 0; i < slen; i += 2) { /* remove every 2nd */
Curl_uint_spbset_remove(&bset, s[i]);
fail_unless(!Curl_uint_spbset_contains(&bset, s[i]), "unexpectedly found");
}
for(i = 1; i < slen; i += 2) { /* others still there */
fail_unless(Curl_uint_spbset_contains(&bset, s[i]), "unexpectedly gone");
}
/* The count is half */
c = Curl_uint_spbset_count(&bset);
fail_unless(c == slen/2, "set count is wrong");
Curl_uint_spbset_clear(&bset);
c = Curl_uint_spbset_count(&bset);
fail_unless(c == 0, "set count is not 0");
for(i = 0; i < slen; i++) { /* none present any longer */
fail_unless(!Curl_uint_spbset_contains(&bset, s[i]), "unexpectedly there");
}
for(i = 0; i < slen; ++i) { /* add all again */
fail_unless(Curl_uint_spbset_add(&bset, s[i]), "failed to add");
}
Curl_uint_spbset_destroy(&bset);
}
static CURLcode test_unit3213(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
static const unsigned int s1[] = { /* spread numbers, some at slot edges */
0, 1, 4, 17, 63, 64, 65, 66,
90, 99,
};
static const unsigned int s2[] = { /* set with all bits in slot1 set */
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127,
};
static const unsigned int s3[] = { /* very spread numbers */
2232, 5167, 8204, 8526, 8641, 10056, 10140, 10611,
10998, 11626, 13735, 15539, 17947, 24295, 27833, 30318,
};
check_spbset("s1", s1, CURL_ARRAYSIZE(s1));
check_spbset("s2", s2, CURL_ARRAYSIZE(s2));
check_spbset("s3", s3, CURL_ARRAYSIZE(s3));
UNITTEST_END_SIMPLE
}
+86
View File
@@ -0,0 +1,86 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, 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.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.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "unitcheck.h"
#include "urldata.h"
static void checksize(const char *name, size_t size, size_t allowed)
{
if(size > allowed) {
curl_mfprintf(stderr, "BAD: struct %s is %zu bytes, "
"allowed to be %zu: %zu bytes too big\n",
name, size, allowed, size - allowed);
unitfail++;
}
else {
curl_mprintf("FINE: struct %s is %zu bytes, "
"allowed %zu (margin: %zu bytes)\n",
name, size, allowed, allowed - size);
}
}
/* the maximum sizes we allow specific structs to grow to */
#define MAX_CURL_EASY 5800
#define MAX_CONNECTDATA 1300
#define MAX_CURL_MULTI 850
#define MAX_CURL_HTTPPOST 112
#define MAX_CURL_SLIST 16
#define MAX_CURL_KHKEY 24
#define MAX_CURL_HSTSENTRY 40
#define MAX_CURL_INDEX 16
#define MAX_CURL_MIME 96
#define MAX_CURL_MIMEPART 440
#define MAX_CURL_CERTINFO 16
#define MAX_CURL_TLSSESSIONINFO 16
#define MAX_CURL_BLOB 24
#define MAX_CURLMSG 24
#define MAX_CURL_HEADER 48
static CURLcode test_unit3214(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
checksize("Curl_easy", sizeof(struct Curl_easy), MAX_CURL_EASY);
checksize("connectdata", sizeof(struct connectdata), MAX_CONNECTDATA);
checksize("Curl_multi", sizeof(struct Curl_multi), MAX_CURL_MULTI);
/* public structs MUST NOT change (unless controlled), but exact sizes
depend on architecture */
checksize("curl_httppost", sizeof(struct curl_httppost), MAX_CURL_HTTPPOST);
checksize("curl_slist", sizeof(struct curl_slist), MAX_CURL_SLIST);
checksize("curl_khkey", sizeof(struct curl_khkey), MAX_CURL_KHKEY);
checksize("curl_hstsentry", sizeof(struct curl_hstsentry),
MAX_CURL_HSTSENTRY);
checksize("curl_index", sizeof(struct curl_index), MAX_CURL_INDEX);
checksize("curl_mime", sizeof(struct curl_mime), MAX_CURL_MIME);
checksize("curl_mimepart", sizeof(struct curl_mimepart), MAX_CURL_MIMEPART);
checksize("curl_certinfo", sizeof(struct curl_certinfo), MAX_CURL_CERTINFO);
checksize("curl_tlssessioninfo", sizeof(struct curl_tlssessioninfo),
MAX_CURL_TLSSESSIONINFO);
checksize("curl_blob", sizeof(struct curl_blob), MAX_CURL_BLOB);
checksize("CURLMsg", sizeof(struct CURLMsg), MAX_CURLMSG);
checksize("curl_header", sizeof(struct curl_header), MAX_CURL_HEADER);
UNITTEST_END_SIMPLE
}
+122
View File
@@ -0,0 +1,122 @@
/* !checksrc! disable COPYRIGHT all */
#include "first.h"
#include "unit1300.c"
#include "unit1302.c"
#include "unit1303.c"
#include "unit1304.c"
#include "unit1305.c"
#include "unit1307.c"
#include "unit1309.c"
#include "unit1323.c"
#include "unit1330.c"
#include "unit1395.c"
#include "unit1396.c"
#include "unit1397.c"
#include "unit1398.c"
#include "unit1399.c"
#include "unit1600.c"
#include "unit1601.c"
#include "unit1602.c"
#include "unit1603.c"
#include "unit1605.c"
#include "unit1606.c"
#include "unit1607.c"
#include "unit1608.c"
#include "unit1609.c"
#include "unit1610.c"
#include "unit1611.c"
#include "unit1612.c"
#include "unit1614.c"
#include "unit1615.c"
#include "unit1616.c"
#include "unit1620.c"
#include "unit1650.c"
#include "unit1651.c"
#include "unit1652.c"
#include "unit1653.c"
#include "unit1654.c"
#include "unit1655.c"
#include "unit1656.c"
#include "unit1657.c"
#include "unit1658.c"
#include "unit1660.c"
#include "unit1661.c"
#include "unit1663.c"
#include "unit1664.c"
#include "unit1979.c"
#include "unit1980.c"
#include "unit2600.c"
#include "unit2601.c"
#include "unit2602.c"
#include "unit2603.c"
#include "unit2604.c"
#include "unit3200.c"
#include "unit3205.c"
#include "unit3211.c"
#include "unit3212.c"
#include "unit3213.c"
#include "unit3214.c"
const struct entry_s s_entries[] = {
{"unit1300", test_unit1300},
{"unit1302", test_unit1302},
{"unit1303", test_unit1303},
{"unit1304", test_unit1304},
{"unit1305", test_unit1305},
{"unit1307", test_unit1307},
{"unit1309", test_unit1309},
{"unit1323", test_unit1323},
{"unit1330", test_unit1330},
{"unit1395", test_unit1395},
{"unit1396", test_unit1396},
{"unit1397", test_unit1397},
{"unit1398", test_unit1398},
{"unit1399", test_unit1399},
{"unit1600", test_unit1600},
{"unit1601", test_unit1601},
{"unit1602", test_unit1602},
{"unit1603", test_unit1603},
{"unit1605", test_unit1605},
{"unit1606", test_unit1606},
{"unit1607", test_unit1607},
{"unit1608", test_unit1608},
{"unit1609", test_unit1609},
{"unit1610", test_unit1610},
{"unit1611", test_unit1611},
{"unit1612", test_unit1612},
{"unit1614", test_unit1614},
{"unit1615", test_unit1615},
{"unit1616", test_unit1616},
{"unit1620", test_unit1620},
{"unit1650", test_unit1650},
{"unit1651", test_unit1651},
{"unit1652", test_unit1652},
{"unit1653", test_unit1653},
{"unit1654", test_unit1654},
{"unit1655", test_unit1655},
{"unit1656", test_unit1656},
{"unit1657", test_unit1657},
{"unit1658", test_unit1658},
{"unit1660", test_unit1660},
{"unit1661", test_unit1661},
{"unit1663", test_unit1663},
{"unit1664", test_unit1664},
{"unit1979", test_unit1979},
{"unit1980", test_unit1980},
{"unit2600", test_unit2600},
{"unit2601", test_unit2601},
{"unit2602", test_unit2602},
{"unit2603", test_unit2603},
{"unit2604", test_unit2604},
{"unit3200", test_unit3200},
{"unit3205", test_unit3205},
{"unit3211", test_unit3211},
{"unit3212", test_unit3212},
{"unit3213", test_unit3213},
{"unit3214", test_unit3214},
{NULL, NULL}
};
#include "first.c"