Files
wget2/tests/libtest.h
Neil Locketz 39dfeec1ae Fixed problems pointed out in MR. Added tests and doxygen documentation.
* bootstrap.conf: Add canonicalize module.
* cfg.mk: Added exclusions to no new line at EOF for binary files used in tests.
* configure.ac: Check for libgpgme
* docs/wget2_manual.md: Added manual entries for --verify-sig, --gnupg-homedir, and new exit codes.
* fuzz/Makefile.am: Amend linker options
* include/wget/wget.h: Add error codes for GPG signature verification.
* po/POTFILES.in: Add new files.
* src/Makefile.am: Add src/gpgme.c and src/wget_gpgme.h
* src/gpgme.c: Using new error codes, and better signature verification failure detection.
* src/job.c (job_free): Free sig_filename
* src/options.c: Add new options --gnupg-homedir and --verify-sig
* src/wget.c: Verify the signature if possible, exit with the proper status code,
  print error messages
* src/wget_gpgme.h: Add documentation.
* src/wget_job.h: Extend struct JOB
* src/wget_options.h: Add new status codes, add new members to struct config
* tests/Makefile.am: Added new tests.
* tests/gpg-test-util.h: Common GPG testing functionality (tries to verify a signature, expects exit code ... etc).
* tests/gpg/helloworld.txt: Text that has been signed in the .sig files.
* tests/gpg/helloworld.txt.{invalid,no-pub,missing,trusted}.sig: Signatures on helloworld.txt with properties described by their names.
* tests/gpg/openpgp-revocs.d/*: Revocation certs for the fake "homedir"
* tests/gpg/private-keys-v1.d/*: The not-so-private private keys used to sign the test file.
* tests/gpg/pubring.kbx: Fake gnupg homedir public key ring.
* tests/gpg/test-gpg-*.c: Tests.
* tests/valgrind-supressions: Supress failures due to oddness with GPGME.
* unit-tests/Makefile.am: Add src/gpgme.o to BASE_OBJS
2018-01-01 13:28:43 +01:00

150 lines
3.7 KiB
C

/*
* Copyright(c) 2013-2014 Tim Ruehsen
* Copyright(c) 2015-2016 Free Software Foundation, Inc.
*
* This file is part of libwget.
*
* Libwget is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Libwget is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libwget. If not, see <https://www.gnu.org/licenses/>.
*
*
* Test suite function library header
*
* Changelog
* 10.03.2013 Tim Ruehsen created
*
* Test suite function library
*
* To create the X.509 stuff, I followed the instructions at
* gnutls.org/manual/html_node/gnutls_002dserv-Invocation.html
*
*/
#ifndef _LIBWGET_LIBTEST_H
#define _LIBWGET_LIBTEST_H
#include <wget.h>
// gnulib convenience header for libintl.h, turn of annoying warnings
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wundef"
#include <gettext.h>
#pragma GCC diagnostic pop
#ifdef ENABLE_NLS
# define _(STRING) gettext(STRING)
#else
# define _(STRING) STRING
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define WGET_TEST_EXIT_SKIP 77
// defines for wget_test_start_http_server()
#define WGET_TEST_EXPECTED_REQUEST_HEADER 1001
#define WGET_TEST_RESPONSE_URLS 1002
#define WGET_TEST_FEATURE_MHD 1101
#define WGET_TEST_FEATURE_TLS 1102
#define WGET_TEST_FEATURE_IDN 1103
#define WGET_TEST_FEATURE_PLUGIN 1104
// defines for wget_test()
#define WGET_TEST_REQUEST_URL 2001
#define WGET_TEST_OPTIONS 2002
#define WGET_TEST_EXPECTED_ERROR_CODE 2003
#define WGET_TEST_EXPECTED_FILES 2004
#define WGET_TEST_EXISTING_FILES 2005
#define WGET_TEST_KEEP_TMPFILES 2006
#define WGET_TEST_REQUEST_URLS 2007
#define WGET_TEST_EXECUTABLE 2008
#define WGET_TEST_SERVER_SEND_CONTENT_LENGTH 2009
// defines for wget_test_check_file_system()
#define WGET_TEST_FS_CASEMATTERS 3001 // file system is case-sensitive
#define countof(a) (sizeof(a)/sizeof(*(a)))
#define TEST_OPAQUE_STR "11733b200778ce33060f31c9af70a870ba96ddd4"
G_GNUC_WGET_UNUSED static const char *WGET_TEST_SOME_HTML_BODY = "\
<html>\n\
<head>\n\
<title>The Title</title>\n\
</head>\n\
<body>\n\
<p>\n\
Some text\n\
</p>\n\
</body>\n\
</html>\n";
typedef struct {
const char *
name;
const char *
content;
time_t
timestamp;
char
restricted_mode;
} wget_test_file_t;
typedef struct {
const char *
name;
const char *
code;
const char *
body;
const char *
headers[10];
const char *
request_headers[10];
time_t
modified;
char
body_alloc; // if body has been allocated internally (and need to be freed on exit)
char
header_alloc[10]; // if header[n] has been allocated internally (and need to be freed on exit)
// auth fields
const char *
auth_method;
const char *
auth_username;
const char *
auth_password;
size_t
body_len; // The length of the body in bytes. 0 means use strlen(body)
} wget_test_url_t;
WGETAPI void wget_test_stop_server(void);
WGETAPI void wget_test_start_server(int first_key, ...);
WGETAPI void wget_test(int first_key, ...);
WGETAPI int wget_test_check_file_system(void);
WGETAPI int wget_test_get_http_server_port(void) G_GNUC_WGET_PURE;
WGETAPI int wget_test_get_https_server_port(void) G_GNUC_WGET_PURE;
#if defined __clang__ || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
# pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif
#ifdef __cplusplus
}
#endif
#endif /* _LIBWGET_LIBTEST_H */