diff options
author | Daniel Stenberg <daniel@haxx.se> | 2020-11-02 23:17:01 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2020-11-03 16:08:48 +0100 |
commit | 2cfc4ed98347047249b8f7f91ad513a4b0b84e45 (patch) | |
tree | 6e69f05aeeb76db0a7f15f9c8314f1e983ed42e8 /tests/libtest | |
parent | 7385610d0c74c6a254fea5e4cd6e1d559d848c8c (diff) | |
download | curl-2cfc4ed98347047249b8f7f91ad513a4b0b84e45.tar.gz |
hsts: add read/write callbacks
- read/write callback options
- man pages for the 4 new setopts
- test 1915 verifies the callbacks
Closes #5896
Diffstat (limited to 'tests/libtest')
-rw-r--r-- | tests/libtest/Makefile.inc | 5 | ||||
-rw-r--r-- | tests/libtest/lib1915.c | 95 | ||||
-rwxr-xr-x | tests/libtest/mk-lib1521.pl | 2 |
3 files changed, 102 insertions, 0 deletions
diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index 98fd2ee9f..b18d6e58e 100644 --- a/tests/libtest/Makefile.inc +++ b/tests/libtest/Makefile.inc @@ -59,6 +59,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect \ lib1558 lib1559 lib1560 lib1564 lib1565 lib1567 \ lib1591 lib1592 lib1593 lib1594 lib1596 \ lib1905 lib1906 lib1907 lib1908 lib1910 lib1911 lib1912 lib1913 \ + lib1915 \ lib3010 chkdecimalpoint_SOURCES = chkdecimalpoint.c ../../lib/mprintf.c \ @@ -649,6 +650,10 @@ lib1913_SOURCES = lib1913.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS) lib1913_LDADD = $(TESTUTIL_LIBS) lib1913_CPPFLAGS = $(AM_CPPFLAGS) +lib1915_SOURCES = lib1915.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS) +lib1915_LDADD = $(TESTUTIL_LIBS) +lib1915_CPPFLAGS = $(AM_CPPFLAGS) + lib3010_SOURCES = lib3010.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS) lib3010_LDADD = $(TESTUTIL_LIBS) lib3010_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/tests/libtest/lib1915.c b/tests/libtest/lib1915.c new file mode 100644 index 000000000..25da75d22 --- /dev/null +++ b/tests/libtest/lib1915.c @@ -0,0 +1,95 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 2020, 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.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ +#include "test.h" + +#include "testutil.h" +#include "warnless.h" +#include "memdebug.h" + +static const char *preload_hosts[] = { + "1.example.com", + "2.example.com", + "3.example.com", + "4.example.com", + NULL /* end of list marker */ +}; + +struct state { + int index; +}; + +/* "read" is from the point of the library, it wants data from us */ +static CURLSTScode hstsread(CURL *easy, struct curl_hstsentry *e, + void *userp) +{ + const char *host; + struct state *s = (struct state *)userp; + (void)easy; + host = preload_hosts[s->index++]; + + if(host && (strlen(host) < e->namelen)) { + strcpy(e->name, host); + e->includeSubDomains = FALSE; + strcpy(e->expire, "20300320 01:02:03"); /* curl turns 32 that day */ + fprintf(stderr, "add '%s'\n", host); + } + else + return CURLSTS_DONE; + return CURLSTS_OK; +} + +/* check that we get the hosts back in the save */ +static CURLSTScode hstswrite(CURL *easy, struct curl_hstsentry *e, + struct curl_index *i, void *userp) +{ + (void)easy; + (void)userp; + printf("[%u/%u] %s %s\n", i->index, i->total, e->name, e->expire); + return CURLSTS_OK; +} + +/* + * Read/write HSTS cache entries via callback. + */ + +int test(char *URL) +{ + CURLcode ret = CURLE_OK; + CURL *hnd; + struct state st = {0}; + + curl_global_init(CURL_GLOBAL_ALL); + + hnd = curl_easy_init(); + if(hnd) { + curl_easy_setopt(hnd, CURLOPT_URL, URL); + curl_easy_setopt(hnd, CURLOPT_HSTSREADFUNCTION, hstsread); + curl_easy_setopt(hnd, CURLOPT_HSTSREADDATA, &st); + curl_easy_setopt(hnd, CURLOPT_HSTSWRITEFUNCTION, hstswrite); + curl_easy_setopt(hnd, CURLOPT_HSTSWRITEDATA, &st); + curl_easy_setopt(hnd, CURLOPT_HSTS_CTRL, CURLHSTS_ENABLE); + ret = curl_easy_perform(hnd); + curl_easy_cleanup(hnd); + } + curl_global_cleanup(); + return (int)ret; +} diff --git a/tests/libtest/mk-lib1521.pl b/tests/libtest/mk-lib1521.pl index 9b57b64ee..fa2d38c9a 100755 --- a/tests/libtest/mk-lib1521.pl +++ b/tests/libtest/mk-lib1521.pl @@ -133,6 +133,8 @@ static curl_chunk_end_callback chunk_end_cb; static curl_fnmatch_callback fnmatch_cb; static curl_closesocket_callback closesocketcb; static curl_xferinfo_callback xferinfocb; +static curl_hstsread_callback hstsreadcb; +static curl_hstswrite_callback hstswritecb; static curl_resolver_start_callback resolver_start_cb; int test(char *URL) |