libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 6bf4168dfef7a679d4ef11c9e8a6c170ce050db1
parent 82d864759c08796d36139336df070b62b1a0e077
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sat, 30 Jul 2022 22:28:25 +0300

gen_auth: added support for two authorization headers in request

Diffstat:
Msrc/microhttpd/basicauth.c | 23+----------------------
Msrc/microhttpd/connection.c | 3---
Msrc/microhttpd/digestauth.c | 22++++------------------
Msrc/microhttpd/gen_auth.c | 398+++++++++++++++++++++++++++++++++++++++++--------------------------------------
Msrc/microhttpd/gen_auth.h | 68+++++++++++++++++++++++++-------------------------------------------
Msrc/microhttpd/internal.h | 41+++++++++++++++++++++++++++++++----------
Msrc/microhttpd/test_auth_parse.c | 1188+++++++++++++++++++++++++++++++++++++++++--------------------------------------
7 files changed, 889 insertions(+), 854 deletions(-)

diff --git a/src/microhttpd/basicauth.c b/src/microhttpd/basicauth.c @@ -34,27 +34,6 @@ /** - * Get request's Basic Authorisation parameters. - * @param connection the connection to process - * @return pointer to request Basic Authorisation parameters structure if - * request has such header (allocated in connection's pool), - * NULL otherwise. - */ -static const struct MHD_RqBAuth * -get_rq_bauth_params (struct MHD_Connection *connection) -{ - const struct MHD_AuthRqHeader *rq_params; - - rq_params = MHD_get_auth_rq_params_ (connection); - if ( (NULL == rq_params) || - (MHD_AUTHTYPE_BASIC != rq_params->auth_type) ) - return NULL; - - return rq_params->params.bauth; -} - - -/** * Get the username and password from the Basic Authorisation header * sent by the client * @@ -73,7 +52,7 @@ MHD_basic_auth_get_username_password3 (struct MHD_Connection *connection) size_t decoded_max_len; struct MHD_BasicAuthInfo *ret; - params = get_rq_bauth_params (connection); + params = MHD_get_rq_bauth_params_ (connection); if (NULL == params) return NULL; diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c @@ -4737,9 +4737,6 @@ connection_reset (struct MHD_Connection *connection, c->state = MHD_CONNECTION_INIT; memset (&c->rq, 0, sizeof(c->rq)); -#if defined(BAUTH_SUPPORT) || defined(DAUTH_SUPPORT) - c->rq_auth = NULL; -#endif /* iov (if any) will be deallocated by MHD_pool_reset */ memset (&c->rp, 0, sizeof(c->rp)); diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c @@ -479,20 +479,6 @@ digest_calc_hash (struct DigestAlgorithm *da, uint8_t *digest) } -static const struct MHD_RqDAuth * -get_rq_dauth_params (struct MHD_Connection *connection) -{ - const struct MHD_AuthRqHeader *rq_params; - - rq_params = MHD_get_auth_rq_params_ (connection); - if ( (NULL == rq_params) || - (MHD_AUTHTYPE_DIGEST != rq_params->auth_type) ) - return NULL; - - return rq_params->params.dauth; -} - - /** * Extract timestamp from the given nonce. * @param nonce the nonce to check @@ -1141,7 +1127,7 @@ MHD_digest_auth_get_request_info3 (struct MHD_Connection *connection) size_t unif_buf_used; enum MHD_GetRqNCResult nc_res; - params = get_rq_dauth_params (connection); + params = MHD_get_rq_dauth_params_ (connection); if (NULL == params) return NULL; @@ -1234,7 +1220,7 @@ MHD_digest_auth_get_username3 (struct MHD_Connection *connection) uint8_t *unif_buf_ptr; size_t unif_buf_used; - params = get_rq_dauth_params (connection); + params = MHD_get_rq_dauth_params_ (connection); if (NULL == params) return NULL; @@ -1288,7 +1274,7 @@ MHD_digest_auth_get_username (struct MHD_Connection *connection) size_t buf_size; enum MHD_DigestAuthUsernameType uname_type; - params = get_rq_dauth_params (connection); + params = MHD_get_rq_dauth_params_ (connection); if (NULL == params) return NULL; @@ -2050,7 +2036,7 @@ digest_auth_check_all_inner (struct MHD_Connection *connection, tmp2_size = 0; - params = get_rq_dauth_params (connection); + params = MHD_get_rq_dauth_params_ (connection); if (NULL == params) return MHD_DAUTH_WRONG_HEADER; diff --git a/src/microhttpd/gen_auth.c b/src/microhttpd/gen_auth.c @@ -40,7 +40,104 @@ #error This file requires Basic or Digest authentication support #endif +/** + * Type of authorisation + */ +enum MHD_AuthType +{ + MHD_AUTHTYPE_NONE = 0,/**< No authorisation, unused */ + MHD_AUTHTYPE_BASIC, /**< Basic Authorisation, RFC 7617 */ + MHD_AUTHTYPE_DIGEST, /**< Digest Authorisation, RFC 7616 */ + MHD_AUTHTYPE_UNKNOWN, /**< Unknown/Unsupported authorisation type, unused */ + MHD_AUTHTYPE_INVALID /**< Wrong/broken authorisation header, unused */ +}; + +/** + * Find required "Authorization" request header + * @param c the connection with request + * @param type the type of the authorisation: basic or digest + * @param[out] auth_value will be set to the remaining of header value after + * authorisation token (after "Basic " or "Digest ") + * @return true if requested header is found, + * false otherwise + */ +static bool +find_auth_rq_header_ (const struct MHD_Connection *c, enum MHD_AuthType type, + struct _MHD_str_w_len *auth_value) +{ + const struct MHD_HTTP_Req_Header *h; + const char *token; + size_t token_len; + + mhd_assert (MHD_CONNECTION_HEADERS_PROCESSED <= c->state); + if (MHD_CONNECTION_HEADERS_PROCESSED > c->state) + return false; + +#ifdef DAUTH_SUPPORT + if (MHD_AUTHTYPE_DIGEST == type) + { + token = _MHD_AUTH_DIGEST_BASE; + token_len = MHD_STATICSTR_LEN_ (_MHD_AUTH_DIGEST_BASE); + } + else /* combined with the next line */ +#endif /* DAUTH_SUPPORT */ +#ifdef BAUTH_SUPPORT + if (MHD_AUTHTYPE_BASIC == type) + { + token = _MHD_AUTH_BASIC_BASE; + token_len = MHD_STATICSTR_LEN_ (_MHD_AUTH_BASIC_BASE); + } + else /* combined with the next line */ +#endif /* BAUTH_SUPPORT */ + { + assert (0); + return false; + } + + for (h = c->rq.headers_received; NULL != h; h = h->next) + { + if (MHD_HEADER_KIND != h->kind) + continue; + if (MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_AUTHORIZATION) != h->header_size) + continue; + if (token_len > h->value_size) + continue; + if (! MHD_str_equal_caseless_bin_n_ (MHD_HTTP_HEADER_AUTHORIZATION, + h->header, + MHD_STATICSTR_LEN_ ( \ + MHD_HTTP_HEADER_AUTHORIZATION))) + continue; + if (! MHD_str_equal_caseless_bin_n_ (h->value, token, token_len)) + continue; + /* Match only if token string is full header value or token is + * followed by space or tab + * Note: RFC 9110 (and RFC 7234) allows only space character, but + * tab is supported here as well for additional flexibility and uniformity + * as tabs are supported as separators between parameters. + */ + if ((token_len == h->value_size) || + (' ' == h->value[token_len]) || ('\t' == h->value[token_len])) + { + if (token_len != h->value_size) + { /* Skip whitespace */ + auth_value->str = h->value + token_len + 1; + auth_value->len = h->value_size - (token_len + 1); + } + else + { /* No whitespace to skip */ + auth_value->str = h->value + token_len; + auth_value->len = h->value_size - token_len; + } + return true; /* Found a match */ + } + } + return false; /* No matching header has been found */ +} + + #ifdef BAUTH_SUPPORT + + /** * Parse request Authorization header parameters for Basic Authentication * @param str the header string, everything after "Basic " substring @@ -99,6 +196,71 @@ parse_bauth_params (const char *str, } +/** + * Return request's Basic Authorisation parameters. + * + * Function return result of parsing of the request's "Authorization" header or + * returns cached parsing result if the header was already parsed for + * the current request. + * @param connection the connection to process + * @return the pointer to structure with Authentication parameters, + * NULL if no memory in memory pool, if called too early (before + * header has been received) or if no valid Basic Authorisation header + * found. + */ +const struct MHD_RqBAuth * +MHD_get_rq_bauth_params_ (struct MHD_Connection *connection) +{ + struct _MHD_str_w_len h_auth_value; + struct MHD_RqBAuth *bauth; + + mhd_assert (MHD_CONNECTION_HEADERS_PROCESSED <= connection->state); + + if (connection->rq.bauth_tried) + return connection->rq.bauth; + + if (MHD_CONNECTION_HEADERS_PROCESSED > connection->state) + return NULL; + + if (! find_auth_rq_header_ (connection, MHD_AUTHTYPE_BASIC, &h_auth_value)) + { + connection->rq.bauth_tried = true; + connection->rq.bauth = NULL; + return NULL; + } + + bauth = + (struct MHD_RqBAuth *) + MHD_connection_alloc_memory_ (connection, sizeof (struct MHD_RqBAuth)); + + if (NULL == bauth) + { +#ifdef HAVE_MESSAGES + MHD_DLOG (connection->daemon, + _ ("Not enough memory in the connection's pool to allocate " \ + "for Basic Authorization header parsing.\n")); +#endif /* HAVE_MESSAGES */ + return NULL; + } + + memset (bauth, 0, sizeof(struct MHD_RqBAuth)); + if (parse_bauth_params (h_auth_value.str, h_auth_value.len, bauth)) + connection->rq.bauth = bauth; + else + { +#ifdef HAVE_MESSAGES + MHD_DLOG (connection->daemon, + _ ("The Basic Authorization client's header has " + "incorrect format.\n")); +#endif /* HAVE_MESSAGES */ + connection->rq.bauth = NULL; + /* Memory in the pool remains allocated until next request */ + } + connection->rq.bauth_tried = true; + return connection->rq.bauth; +} + + #endif /* BAUTH_SUPPORT */ #ifdef DAUTH_SUPPORT @@ -312,213 +474,69 @@ parse_dauth_params (const char *str, } -#endif /* DAUTH_SUPPORT */ - - /** - * Parse request "Authorization" header - * @param c the connection to process - * @return true if any supported Authorisation scheme were found, - * false if no "Authorization" header found, no supported scheme found, - * or an error occurred. + * Return request's Digest Authorisation parameters. + * + * Function return result of parsing of the request's "Authorization" header or + * returns cached parsing result if the header was already parsed for + * the current request. + * @param connection the connection to process + * @return the pointer to structure with Authentication parameters, + * NULL if no memory in memory pool, if called too early (before + * header has been received) or if no valid Basic Authorisation header + * found. */ -_MHD_static_inline bool -parse_auth_rq_header_ (struct MHD_Connection *c) +const struct MHD_RqDAuth * +MHD_get_rq_dauth_params_ (struct MHD_Connection *connection) { - const char *h; /**< The "Authorization" header */ - size_t h_len; - struct MHD_AuthRqHeader *rq_auth; - size_t i; + struct _MHD_str_w_len h_auth_value; + struct MHD_RqDAuth *dauth; - mhd_assert (NULL == c->rq_auth); - mhd_assert (MHD_CONNECTION_HEADERS_PROCESSED <= c->state); - if (MHD_CONNECTION_HEADERS_PROCESSED > c->state) - return false; + mhd_assert (MHD_CONNECTION_HEADERS_PROCESSED <= connection->state); - if (MHD_NO == - MHD_lookup_connection_value_n (c, MHD_HEADER_KIND, - MHD_HTTP_HEADER_AUTHORIZATION, - MHD_STATICSTR_LEN_ ( \ - MHD_HTTP_HEADER_AUTHORIZATION), &h, - &h_len)) - { - rq_auth = (struct MHD_AuthRqHeader *) - MHD_connection_alloc_memory_ (c, - sizeof (struct MHD_AuthRqHeader)); - c->rq_auth = rq_auth; - if (NULL != rq_auth) - { - memset (rq_auth, 0, sizeof(struct MHD_AuthRqHeader)); - rq_auth->auth_type = MHD_AUTHTYPE_NONE; - } - return false; - } + if (connection->rq.dauth_tried) + return connection->rq.dauth; - rq_auth = NULL; - i = 0; - /* Skip the leading whitespace */ - while (i < h_len) - { - const char ch = h[i]; - if ((' ' != ch) && ('\t' != ch)) - break; - i++; - } - h += i; - h_len -= i; - - if (0 == h_len) - { /* The header is an empty string */ - rq_auth = (struct MHD_AuthRqHeader *) - MHD_connection_alloc_memory_ (c, - sizeof (struct MHD_AuthRqHeader)); - c->rq_auth = rq_auth; - if (NULL != rq_auth) - { - memset (rq_auth, 0, sizeof(struct MHD_AuthRqHeader)); - rq_auth->auth_type = MHD_AUTHTYPE_INVALID; - } - return false; - } + if (MHD_CONNECTION_HEADERS_PROCESSED > connection->state) + return NULL; -#ifdef DAUTH_SUPPORT - if (1) + if (! find_auth_rq_header_ (connection, MHD_AUTHTYPE_DIGEST, &h_auth_value)) { - static const struct _MHD_cstr_w_len scheme_token = - _MHD_S_STR_W_LEN (_MHD_AUTH_DIGEST_BASE); - - if ((scheme_token.len <= h_len) && - MHD_str_equal_caseless_bin_n_ (h, scheme_token.str, scheme_token.len)) - { - i = scheme_token.len; - /* RFC 7235 require only space after scheme token */ - if ( (h_len <= i) || - ((' ' == h[i]) || ('\t' == h[i])) ) /* Actually tab should NOT be allowed */ - { /* Matched Digest authorisation scheme */ - i++; /* Advance to the next char (even if it is beyond the end of the string) */ - - rq_auth = (struct MHD_AuthRqHeader *) - MHD_connection_alloc_memory_ (c, - sizeof (struct MHD_AuthRqHeader) - + sizeof (struct MHD_RqDAuth)); - c->rq_auth = rq_auth; - if (NULL == rq_auth) - { -#ifdef HAVE_MESSAGES - MHD_DLOG (c->daemon, - _ ("Failed to allocate memory in connection pool to " \ - "process \"" MHD_HTTP_HEADER_AUTHORIZATION "\" " \ - "header.\n")); -#endif /* HAVE_MESSAGES */ - return false; - } - memset (rq_auth, 0, sizeof (struct MHD_AuthRqHeader) - + sizeof (struct MHD_RqDAuth)); - rq_auth->params.dauth = (struct MHD_RqDAuth *) (rq_auth + 1); + connection->rq.dauth_tried = true; + connection->rq.dauth = NULL; + return NULL; + } - if (h_len > i) - { - if (! parse_dauth_params (h + i, h_len - i, rq_auth->params.dauth)) - { - rq_auth->auth_type = MHD_AUTHTYPE_INVALID; - return false; - } - } + dauth = + (struct MHD_RqDAuth *) + MHD_connection_alloc_memory_ (connection, sizeof (struct MHD_RqDAuth)); - rq_auth->auth_type = MHD_AUTHTYPE_DIGEST; - return true; - } - } - } -#endif /* DAUTH_SUPPORT */ -#ifdef BAUTH_SUPPORT - if (1) + if (NULL == dauth) { - static const struct _MHD_cstr_w_len scheme_token = - _MHD_S_STR_W_LEN (_MHD_AUTH_BASIC_BASE); - - if ((scheme_token.len <= h_len) && - MHD_str_equal_caseless_bin_n_ (h, scheme_token.str, scheme_token.len)) - { - i = scheme_token.len; - /* RFC 7235 require only space after scheme token */ - if ( (h_len <= i) || - ((' ' == h[i]) || ('\t' == h[i])) ) /* Actually tab should NOT be allowed */ - { /* Matched Basic authorisation scheme */ - i++; /* Advance to the next char (even if it is beyond the end of the string) */ - - rq_auth = (struct MHD_AuthRqHeader *) - MHD_connection_alloc_memory_ (c, - sizeof (struct MHD_AuthRqHeader) - + sizeof (struct MHD_RqBAuth)); - c->rq_auth = rq_auth; - if (NULL == rq_auth) - { #ifdef HAVE_MESSAGES - MHD_DLOG (c->daemon, - _ ("Failed to allocate memory in connection pool to " \ - "process \"" MHD_HTTP_HEADER_AUTHORIZATION "\" " \ - "header.\n")); + MHD_DLOG (connection->daemon, + _ ("Not enough memory in the connection's pool to allocate " \ + "for Digest Authorization header parsing.\n")); #endif /* HAVE_MESSAGES */ - return false; - } - memset (rq_auth, 0, sizeof (struct MHD_AuthRqHeader) - + sizeof (struct MHD_RqBAuth)); - rq_auth->params.bauth = (struct MHD_RqBAuth *) (rq_auth + 1); - - if (h_len > i) - { - if (! parse_bauth_params (h + i, h_len - i, rq_auth->params.bauth)) - { - rq_auth->auth_type = MHD_AUTHTYPE_INVALID; - return false; - } - } - - rq_auth->auth_type = MHD_AUTHTYPE_BASIC; - return true; - } - } + return NULL; } -#endif /* BAUTH_SUPPORT */ - if (NULL == rq_auth) - rq_auth = (struct MHD_AuthRqHeader *) - MHD_connection_alloc_memory_ (c, - sizeof (struct MHD_AuthRqHeader)); - c->rq_auth = rq_auth; - if (NULL != rq_auth) + memset (dauth, 0, sizeof(struct MHD_RqDAuth)); + if (parse_dauth_params (h_auth_value.str, h_auth_value.len, dauth)) + connection->rq.dauth = dauth; + else { - memset (rq_auth, 0, sizeof(struct MHD_AuthRqHeader)); - rq_auth->auth_type = MHD_AUTHTYPE_UNKNOWN; +#ifdef HAVE_MESSAGES + MHD_DLOG (connection->daemon, + _ ("The Digest Authorization client's header has " + "incorrect format.\n")); +#endif /* HAVE_MESSAGES */ + connection->rq.dauth = NULL; + /* Memory in the pool remains allocated until next request */ } - return false; + connection->rq.dauth_tried = true; + return connection->rq.dauth; } -/** - * Return request's Authentication type and parameters. - * - * Function return result of parsing of the request's "Authorization" header or - * returns cached parsing result if the header was already parsed for - * the current request. - * @param connection the connection to process - * @return the pointer to structure with Authentication type and parameters, - * NULL if no memory in memory pool or if called too early (before - * header has been received). - */ -const struct MHD_AuthRqHeader * -MHD_get_auth_rq_params_ (struct MHD_Connection *connection) -{ - mhd_assert (MHD_CONNECTION_HEADERS_PROCESSED <= connection->state); - - if (NULL != connection->rq_auth) - return connection->rq_auth; - - if (MHD_CONNECTION_HEADERS_PROCESSED > connection->state) - return NULL; - - parse_auth_rq_header_ (connection); - - return connection->rq_auth; -} +#endif /* DAUTH_SUPPORT */ diff --git a/src/microhttpd/gen_auth.h b/src/microhttpd/gen_auth.h @@ -33,62 +33,44 @@ struct MHD_Connection; /* Forward declaration to avoid include of the large headers */ -/** - * Type of authorisation - */ -enum MHD_AuthType -{ - MHD_AUTHTYPE_NONE = 0,/**< No authorisation */ - MHD_AUTHTYPE_BASIC, /**< Basic Authorisation, RFC 7617 */ - MHD_AUTHTYPE_DIGEST, /**< Digest Authorisation, RFC 7616 */ - MHD_AUTHTYPE_UNKNOWN, /**< Unknown/Unsupported authorisation type */ - MHD_AUTHTYPE_INVALID /**< Wrong/broken authorisation header */ -}; - #ifdef BAUTH_SUPPORT + /* Forward declaration to avoid additional headers inclusion */ struct MHD_RqBAuth; -#endif /* BAUTH_SUPPORT */ -#ifdef DAUTH_SUPPORT -/* Forward declaration to avoid additional headers inclusion */ -struct MHD_RqDAuth; -#endif /* DAUTH_SUPPORT */ - /** - * Universal Authorisation Request parameters + * Return request's Basic Authorisation parameters. + * + * Function return result of parsing of the request's "Authorization" header or + * returns cached parsing result if the header was already parsed for + * the current request. + * @param connection the connection to process + * @return the pointer to structure with Authentication parameters, + * NULL if no memory in memory pool, if called too early (before + * header has been received) or if no valid Basic Authorisation header + * found. */ -union MHD_AuthRqParams -{ -#ifdef BAUTH_SUPPORT - struct MHD_RqBAuth *bauth; +const struct MHD_RqBAuth * +MHD_get_rq_bauth_params_ (struct MHD_Connection *connection); + #endif /* BAUTH_SUPPORT */ #ifdef DAUTH_SUPPORT - struct MHD_RqDAuth *dauth; -#endif /* DAUTH_SUPPORT */ -}; - -/** - * Request Authentication type and parameters - */ -struct MHD_AuthRqHeader -{ - enum MHD_AuthType auth_type; - union MHD_AuthRqParams params; -}; - +/* Forward declaration to avoid additional headers inclusion */ +struct MHD_RqDAuth; /** - * Return request's Authentication type and parameters. + * Return request's Digest Authorisation parameters. * * Function return result of parsing of the request's "Authorization" header or * returns cached parsing result if the header was already parsed for * the current request. * @param connection the connection to process - * @return the pointer to structure with Authentication type and parameters, - * NULL if no memory in memory pool or if called too early (before - * header has been received). + * @return the pointer to structure with Authentication parameters, + * NULL if no memory in memory pool, if called too early (before + * header has been received) or if no valid Basic Authorisation header + * found. */ -const struct MHD_AuthRqHeader * -MHD_get_auth_rq_params_ (struct MHD_Connection *connection); +const struct MHD_RqDAuth * +MHD_get_rq_dauth_params_ (struct MHD_Connection *connection); +#endif /* DAUTH_SUPPORT */ -#endif /* ! MHD_GET_AUTH_H */ +#endif /* MHD_GET_AUTH_H */ diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h @@ -62,6 +62,10 @@ #include "mhd_locks.h" #include "mhd_sockets.h" #include "mhd_itc_types.h" +#if defined(BAUTH_SUPPORT) || defined(DAUTH_SUPPORT) +#include "gen_auth.h" +#endif /* BAUTH_SUPPORT || DAUTH_SUPPORT*/ + /** * Macro to drop 'const' qualifier from pointer without compiler warning. @@ -786,8 +790,6 @@ typedef ssize_t size_t max_bytes); -struct MHD_AuthRqHeader; /* Forward declaration only */ - /** * Ability to use same connection for next request */ @@ -1020,6 +1022,33 @@ struct MHD_Request */ bool client_aware; +#ifdef BAUTH_SUPPORT + /** + * Basic Authorization parameters. + * The result of Basic Authorization header parsing. + * Allocated in the connection's pool. + */ + const struct MHD_RqBAuth *bauth; + + /** + * Set to true if current request headers are checked for Basic Authorization + */ + bool bauth_tried; +#endif /* BAUTH_SUPPORT */ +#ifdef DAUTH_SUPPORT + /** + * Digest Authorization parameters. + * The result of Digest Authorization header parsing. + * Allocated in the connection's pool. + */ + const struct MHD_RqDAuth *dauth; + + /** + * Set to true if current request headers are checked for Digest Authorization + */ + bool dauth_tried; +#endif /* DAUTH_SUPPORT */ + /** * Last incomplete header line during parsing of headers. * Allocated in pool. Only valid if state is @@ -1183,14 +1212,6 @@ struct MHD_Connection */ void *socket_context; -#if defined(BAUTH_SUPPORT) || defined(DAUTH_SUPPORT) - /** - * Pointer to request authorization structure. - * Allocated in pool. - */ - const struct MHD_AuthRqHeader *rq_auth; -#endif - /** * Close connection after sending response? * Functions may change value from "Unknown" or "KeepAlive" to "Must close", diff --git a/src/microhttpd/test_auth_parse.c b/src/microhttpd/test_auth_parse.c @@ -120,54 +120,6 @@ _mhdErrorExit_func (const char *errDesc, const char *funcName, int lineNum) /* Local replacements implementations */ -/** - * Parameters for function emulation - */ -struct TestArguments -{ - const char *str; - size_t len; - enum MHD_Result res; -}; - - -_MHD_EXTERN enum MHD_Result -MHD_lookup_connection_value_n (struct MHD_Connection *connection, - enum MHD_ValueKind kind, - const char *key, - size_t key_size, - const char **value_ptr, - size_t *value_size_ptr) -{ - struct TestArguments *args; - if (NULL == connection) - mhdErrorExitDesc ("The 'connection' parameter is NULL"); - if (MHD_HEADER_KIND != kind) - mhdErrorExitDesc ("Wrong 'kind' parameter"); - if (NULL == key) - mhdErrorExitDesc ("The 'key' parameter is NULL"); - if (0 != strcmp (key, MHD_HTTP_HEADER_AUTHORIZATION)) - mhdErrorExitDesc ("Wrong 'key' value"); - if (MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_AUTHORIZATION) != key_size) - mhdErrorExitDesc ("Wrong 'key_size' value"); - if (NULL == value_ptr) - mhdErrorExitDesc ("The 'value_ptr' parameter is NULL"); - if (NULL == value_size_ptr) - mhdErrorExitDesc ("The 'value_size_ptr' parameter is NULL"); - - if (NULL == connection->rq.client_context) - externalErrorExitDesc ("The 'connection->client_context' value is NULL"); - - args = (struct TestArguments *) connection->rq.client_context; - if (MHD_NO == args->res) - return args->res; - - *value_ptr = args->str; - *value_size_ptr = args->len; - return args->res; -} - - void * MHD_connection_alloc_memory_ (struct MHD_Connection *connection, size_t size) @@ -188,118 +140,257 @@ MHD_connection_alloc_memory_ (struct MHD_Connection *connection, } -_MHD_NORETURN void +/** + * Static variable to avoid additional malloc()/free() pairs + */ +static struct MHD_Connection conn; + +void MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...) { (void) daemon; - fprintf (stderr, "Unexpected call of 'MHD_LOG(), format is '%s'.\n", format); - mhdErrorExit (); + if (NULL == conn.rq.last) + { + fprintf (stderr, "Unexpected call of 'MHD_LOG(), format is '%s'.\n", + format); + fprintf (stderr, "'Authorization' header value: '%s'.\n", + (NULL == conn.rq.headers_received) ? + "NULL" : (conn.rq.headers_received->value)); + mhdErrorExit (); + } + conn.rq.last = NULL; /* Clear the flag */ + return; } /** * Static variable to avoid additional malloc()/free() pairs */ -static struct MHD_Connection conn; +static struct MHD_HTTP_Req_Header req_header; + +static void +test_global_init (void) +{ + memset (&conn, 0, sizeof(conn)); + memset (&req_header, 0, sizeof(req_header)); +} + /** - * Create test "Authorization" client header and return result of its parsing. + * Add "Authorization" client test header. * - * Function performs basic checking of the parsing result - * @param use_hdr if set to non-zero value, the test header is added, - * if set to zero value, emulated absence "Authorization" client - * header - * @param hdr the test "Authorization" client header string, must be statically - * allocated. + * @param hdr the pointer to the headr value, must be valid until end of + * checking of this header * @param hdr_len the length of the @a hdr - * @return result of @a hdr parsing (or parsing of header absence if @a use_hdr - * is not set), never NULL. Must be free()'ed. * @note The function is NOT thread-safe */ -static const struct MHD_AuthRqHeader * -get_AuthRqHeader (int use_hdr, const char *hdr, size_t hdr_len) +static void +add_AuthHeader (const char *hdr, size_t hdr_len) +{ + if ((NULL != conn.rq.headers_received) || + (NULL != conn.rq.headers_received_tail)) + externalErrorExitDesc ("Connection's test headers are not empty already"); + if (NULL != hdr) + { + /* Skip initial whitespaces, emulate MHD's headers processing */ + while (' ' == hdr[0] || '\t' == hdr[0]) + { + hdr++; + hdr_len--; + } + req_header.header = MHD_HTTP_HEADER_AUTHORIZATION; /* Static string */ + req_header.header_size = MHD_STATICSTR_LEN_ (MHD_HTTP_HEADER_AUTHORIZATION); + req_header.value = hdr; + req_header.value_size = hdr_len; + req_header.kind = MHD_HEADER_KIND; + req_header.prev = NULL; + req_header.next = NULL; + conn.rq.headers_received = &req_header; + conn.rq.headers_received_tail = &req_header; + } + else + { + conn.rq.headers_received = NULL; + conn.rq.headers_received_tail = NULL; + } + conn.state = MHD_CONNECTION_FULL_REQ_RECEIVED; /* Should be a typical value */ +} + + +#ifdef BAUTH_SUPPORT +/** + * Parse previously added Basic Authorization client header and return + * result of the parsing. + * + * Function performs basic checking of the parsing result + * @return result of header parsing + * @note The function is NOT thread-safe + */ +static const struct MHD_RqBAuth * +get_BAuthRqParams (void) { - const struct MHD_AuthRqHeader *res1; - const struct MHD_AuthRqHeader *res2; - static struct TestArguments test_args; - if (NULL != conn.socket_context) - mhdErrorExitDesc ("Memory was not freed in previous check cycle"); - test_args.res = use_hdr ? MHD_YES : MHD_NO; - test_args.str = hdr; - test_args.len = hdr_len; - memset (&conn, 0, sizeof (conn)); + const struct MHD_RqBAuth *res1; + const struct MHD_RqBAuth *res2; /* Store pointer in some member unused in this test */ - conn.rq.client_context = &test_args; - conn.state = MHD_CONNECTION_FULL_REQ_RECEIVED; /* Should be typical value */ - res1 = MHD_get_auth_rq_params_ (&conn); - if (NULL == res1) - mhdErrorExitDesc ("MHD_get_auth_rq_params_() returned NULL"); - res2 = MHD_get_auth_rq_params_ (&conn); + res1 = MHD_get_rq_bauth_params_ (&conn); + if (! conn.rq.bauth_tried) + mhdErrorExitDesc ("'rq.bauth_tried' is not set"); + res2 = MHD_get_rq_bauth_params_ (&conn); if (res1 != res2) - mhdErrorExitDesc ("MHD_get_auth_rq_params_() returned another pointer when" \ - "called for the second time"); + mhdErrorExitDesc ("MHD_get_rq_bauth_params_() returned another pointer " \ + "when called for the second time"); return res2; } +#endif /* BAUTH_SUPPORT */ + +#ifdef DAUTH_SUPPORT +/** + * Parse previously added Digest Authorization client header and return + * result of the parsing. + * + * Function performs basic checking of the parsing result + * @return result of header parsing + * @note The function is NOT thread-safe + */ +static const struct MHD_RqDAuth * +get_DAuthRqParams (void) +{ + const struct MHD_RqDAuth *res1; + const struct MHD_RqDAuth *res2; + /* Store pointer in some member unused in this test */ + res1 = MHD_get_rq_dauth_params_ (&conn); + if (! conn.rq.dauth_tried) + mhdErrorExitDesc ("'rq.dauth_tried' is not set"); + res2 = MHD_get_rq_dauth_params_ (&conn); + if (res1 != res2) + mhdErrorExitDesc ("MHD_get_rq_bauth_params_() returned another pointer " \ + "when called for the second time"); + return res2; +} + + +#endif /* DAUTH_SUPPORT */ + + static void -free_AuthRqHeader (void) +clean_AuthHeaders (void) { - if (conn.socket_context != conn.rq_auth) + conn.state = MHD_CONNECTION_INIT; + free (conn.socket_context); + +#ifdef BAUTH_SUPPORT + conn.rq.bauth_tried = false; +#endif /* BAUTH_SUPPORT */ +#ifdef DAUTH_SUPPORT + conn.rq.dauth_tried = false; +#endif /* BAUTH_SUPPORT */ + +#ifdef BAUTH_SUPPORT + if ((NULL != conn.rq.bauth) && (conn.socket_context != conn.rq.bauth)) externalErrorExitDesc ("Memory allocation is not tracked as it should be"); + conn.rq.bauth = NULL; +#endif /* BAUTH_SUPPORT */ +#ifdef DAUTH_SUPPORT + if ((NULL != conn.rq.dauth) && (conn.socket_context != conn.rq.dauth)) + externalErrorExitDesc ("Memory allocation is not tracked as it should be"); + conn.rq.dauth = NULL; +#endif /* BAUTH_SUPPORT */ + + conn.rq.headers_received = NULL; + conn.rq.headers_received_tail = NULL; - if (NULL != conn.rq_auth) - free (conn.socket_context); - conn.rq_auth = NULL; conn.socket_context = NULL; + conn.rq.last = NULL; } -static const char * -get_auth_type_str (enum MHD_AuthType type) +enum MHD_TestAuthType { - switch (type) - { - case MHD_AUTHTYPE_NONE: - return "No authorisation"; - case MHD_AUTHTYPE_BASIC: - return "Basic Authorisation"; - case MHD_AUTHTYPE_DIGEST: - return "Digest Authorisation"; - case MHD_AUTHTYPE_UNKNOWN: - return "Unknown/Unsupported authorisation"; - case MHD_AUTHTYPE_INVALID: - return "Wrong/broken authorisation header"; - default: - mhdErrorExitDesc ("Wrong 'enum MHD_AuthType' value"); - } - return "Wrong 'enum MHD_AuthType' value"; /* Unreachable code */ -} + MHD_TEST_AUTHTYPE_NONE, + MHD_TEST_AUTHTYPE_BASIC, + MHD_TEST_AUTHTYPE_DIGEST, +}; -/* return zero if succeed, 1 otherwise */ +/* return zero if succeed, non-zero otherwise */ static unsigned int -expect_result_type_n (int use_hdr, const char *hdr, size_t hdr_len, - const enum MHD_AuthType expected_type, +expect_result_type_n (const char *hdr, size_t hdr_len, + const enum MHD_TestAuthType expected_type, + int expect_log, unsigned int line_num) { - const struct MHD_AuthRqHeader *h; + static char marker1[] = "Expected log call"; unsigned int ret; - h = get_AuthRqHeader (use_hdr, hdr, hdr_len); - mhd_assert (NULL != h); - if (expected_type == h->auth_type) - ret = 0; + ret = 0; + add_AuthHeader (hdr, hdr_len); + if (expect_log) + conn.rq.last = marker1; /* Use like a flag */ else + conn.rq.last = NULL; +#ifdef BAUTH_SUPPORT + if (MHD_TEST_AUTHTYPE_BASIC == expected_type) + { + if (NULL == get_BAuthRqParams ()) + { + fprintf (stderr, + "'Authorization' header parsing FAILED:\n" + "Basic Authorization was not found, while it should be.\n"); + ret++; + } + } + else +#endif /* BAUTH_SUPPORT */ +#ifdef DAUTH_SUPPORT + if (MHD_TEST_AUTHTYPE_DIGEST == expected_type) + { + if (NULL == get_DAuthRqParams ()) + { + fprintf (stderr, + "'Authorization' header parsing FAILED:\n" + "Digest Authorization was not found, while it should be.\n"); + ret++; + } + } + else +#endif /* BAUTH_SUPPORT */ + { +#ifdef BAUTH_SUPPORT + if (NULL != get_BAuthRqParams ()) + { + fprintf (stderr, + "'Authorization' header parsing FAILED:\n" + "Found Basic Authorization, while it should not be.\n"); + ret++; + } +#endif /* BAUTH_SUPPORT */ +#ifdef DAUTH_SUPPORT + if (NULL != get_DAuthRqParams ()) + { + fprintf (stderr, + "'Authorization' header parsing FAILED:\n" + "Found Digest Authorization, while it should not be.\n"); + ret++; + } +#endif /* DAUTH_SUPPORT */ + } +#if defined(BAUTH_SUPPORT) && defined(DAUTH_SUPPORT) + if (conn.rq.last) { fprintf (stderr, - "'Authorization' header parsing FAILED:\n" - "Wrong type:\tRESULT: %s\tEXPECTED: %s\n", - get_auth_type_str (h->auth_type), - get_auth_type_str (expected_type)); - if (! use_hdr) + "'Authorization' header parsing ERROR:\n" + "Log function must be called, but it was not.\n"); + ret++; + } +#endif /* BAUTH_SUPPORT && DAUTH_SUPPORT */ + + if (ret) + { + if (NULL == hdr) fprintf (stderr, "Input: Absence of 'Authorization' header.\n"); else if (0 == hdr_len) @@ -312,30 +403,14 @@ expect_result_type_n (int use_hdr, const char *hdr, size_t hdr_len, "The check is at line: %u\n\n", line_num); ret = 1; } - free_AuthRqHeader (); + clean_AuthHeaders (); return ret; } -#define expect_result_type(u,h,t) \ - expect_result_type_n(u,h,MHD_STATICSTR_LEN_(h),t,__LINE__) - - -#ifdef BAUTH_SUPPORT -#define EXPECT_TYPE_FOR_BASIC_AUTH MHD_AUTHTYPE_BASIC -#define EXPECT_TYPE_FOR_BASIC_INVLD MHD_AUTHTYPE_INVALID -#else /* ! BAUTH_SUPPORT */ -#define EXPECT_TYPE_FOR_BASIC_AUTH MHD_AUTHTYPE_UNKNOWN -#define EXPECT_TYPE_FOR_BASIC_INVLD MHD_AUTHTYPE_UNKNOWN -#endif /* ! BAUTH_SUPPORT */ -#ifdef DAUTH_SUPPORT -#define EXPECT_TYPE_FOR_DIGEST_AUTH MHD_AUTHTYPE_DIGEST -#define EXPECT_TYPE_FOR_DIGEST_INVLD MHD_AUTHTYPE_INVALID -#else /* ! DAUTH_SUPPORT */ -#define EXPECT_TYPE_FOR_DIGEST_AUTH MHD_AUTHTYPE_UNKNOWN -#define EXPECT_TYPE_FOR_DIGEST_INVLD MHD_AUTHTYPE_UNKNOWN -#endif /* ! DAUTH_SUPPORT */ +#define expect_result_type(h,t,l) \ + expect_result_type_n(h,MHD_STATICSTR_LEN_(h),t,l,__LINE__) static unsigned int @@ -343,378 +418,378 @@ check_type (void) { unsigned int r = 0; /**< The number of errors */ - r += expect_result_type (0, "", MHD_AUTHTYPE_NONE); - - r += expect_result_type (1, "", MHD_AUTHTYPE_INVALID); - r += expect_result_type (1, " ", MHD_AUTHTYPE_INVALID); - r += expect_result_type (1, " ", MHD_AUTHTYPE_INVALID); - r += expect_result_type (1, "\t", MHD_AUTHTYPE_INVALID); - r += expect_result_type (1, " \t", MHD_AUTHTYPE_INVALID); - r += expect_result_type (1, "\t ", MHD_AUTHTYPE_INVALID); - r += expect_result_type (1, "\t \t", MHD_AUTHTYPE_INVALID); - r += expect_result_type (1, " \t ", MHD_AUTHTYPE_INVALID); - r += expect_result_type (1, " \t \t", MHD_AUTHTYPE_INVALID); - r += expect_result_type (1, "\t \t ", MHD_AUTHTYPE_INVALID); - - r += expect_result_type (1, "Basic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, " Basic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\tBasic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t Basic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, " \tBasic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, " Basic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t\t\tBasic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t\t \tBasic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t\t \t Basic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "Basic ", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "Basic \t", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "Basic \t ", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "Basic 123", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "Basic \t123", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "Basic abc ", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "bAsIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, " bAsIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\tbAsIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t bAsIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, " \tbAsIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, " bAsIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t\t\tbAsIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t\t \tbAsIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t\t \t bAsIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "bAsIC ", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "bAsIC \t", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "bAsIC \t ", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "bAsIC 123", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "bAsIC \t123", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "bAsIC abc ", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "basic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, " basic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\tbasic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t basic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, " \tbasic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, " basic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t\t\tbasic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t\t \tbasic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t\t \t basic", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "basic ", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "basic \t", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "basic \t ", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "basic 123", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "basic \t123", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "basic abc ", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "BASIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, " BASIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\tBASIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t BASIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, " \tBASIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, " BASIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t\t\tBASIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t\t \tBASIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "\t\t \t BASIC", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "BASIC ", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "BASIC \t", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "BASIC \t ", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "BASIC 123", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "BASIC \t123", EXPECT_TYPE_FOR_BASIC_AUTH); - r += expect_result_type (1, "BASIC abc ", EXPECT_TYPE_FOR_BASIC_AUTH); + r += expect_result_type_n (NULL, 0, MHD_TEST_AUTHTYPE_NONE, 0, __LINE__); + + r += expect_result_type ("", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" ", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" ", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("\t", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" \t", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("\t ", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("\t \t", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" \t ", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" \t \t", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("\t \t ", MHD_TEST_AUTHTYPE_NONE, 0); + + r += expect_result_type ("Basic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type (" Basic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\tBasic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t Basic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type (" \tBasic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type (" Basic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t\t\tBasic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t\t \tBasic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t\t \t Basic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("Basic ", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("Basic \t", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("Basic \t ", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("Basic 123", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("Basic \t123", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("Basic abc ", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("bAsIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type (" bAsIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\tbAsIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t bAsIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type (" \tbAsIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type (" bAsIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t\t\tbAsIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t\t \tbAsIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t\t \t bAsIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("bAsIC ", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("bAsIC \t", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("bAsIC \t ", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("bAsIC 123", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("bAsIC \t123", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("bAsIC abc ", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("basic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type (" basic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\tbasic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t basic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type (" \tbasic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type (" basic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t\t\tbasic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t\t \tbasic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t\t \t basic", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("basic ", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("basic \t", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("basic \t ", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("basic 123", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("basic \t123", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("basic abc ", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("BASIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type (" BASIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\tBASIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t BASIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type (" \tBASIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type (" BASIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t\t\tBASIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t\t \tBASIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("\t\t \t BASIC", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("BASIC ", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("BASIC \t", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("BASIC \t ", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("BASIC 123", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("BASIC \t123", MHD_TEST_AUTHTYPE_BASIC, 0); + r += expect_result_type ("BASIC abc ", MHD_TEST_AUTHTYPE_BASIC, 0); /* Only single token is allowed for 'Basic' Authorization */ - r += expect_result_type (1, "Basic a b", EXPECT_TYPE_FOR_BASIC_INVLD); - r += expect_result_type (1, "Basic a\tb", EXPECT_TYPE_FOR_BASIC_INVLD); - r += expect_result_type (1, "Basic a\tb", EXPECT_TYPE_FOR_BASIC_INVLD); - r += expect_result_type (1, "Basic abc1 b", EXPECT_TYPE_FOR_BASIC_INVLD); - r += expect_result_type (1, "Basic c abc1", EXPECT_TYPE_FOR_BASIC_INVLD); - r += expect_result_type (1, "Basic c abc1 ", EXPECT_TYPE_FOR_BASIC_INVLD); - r += expect_result_type (1, "Basic c abc1\t", EXPECT_TYPE_FOR_BASIC_INVLD); - r += expect_result_type (1, "Basic c\tabc1\t", EXPECT_TYPE_FOR_BASIC_INVLD); - r += expect_result_type (1, "Basic c abc1 b", EXPECT_TYPE_FOR_BASIC_INVLD); - r += expect_result_type (1, "Basic zyx, b", EXPECT_TYPE_FOR_BASIC_INVLD); - r += expect_result_type (1, "Basic zyx,b", EXPECT_TYPE_FOR_BASIC_INVLD); - r += expect_result_type (1, "Basic zyx ,b", EXPECT_TYPE_FOR_BASIC_INVLD); - r += expect_result_type (1, "Basic zyx;b", EXPECT_TYPE_FOR_BASIC_INVLD); - r += expect_result_type (1, "Basic zyx; b", EXPECT_TYPE_FOR_BASIC_INVLD); - - r += expect_result_type (1, "Basic2", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, " Basic2", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, " Basic2 ", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "\tBasic2", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "\t Basic2", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, " \tBasic2", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, " Basic2", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "\t\t\tBasic2", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "\t\t \tBasic2", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "\t\t \t Basic2", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "Basic2 ", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "Basic2 \t", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "Basic2 \t ", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "Basic2 123", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "Basic2 \t123", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "Basic2 abc ", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "BasicBasic", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, " BasicBasic", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "\tBasicBasic", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "\t BasicBasic", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, " \tBasicBasic", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "BasicBasic ", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "BasicBasic \t", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "BasicBasic \t\t", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "BasicDigest", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, " BasicDigest", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "BasicDigest ", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "Basic\0", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "\0" "Basic", MHD_AUTHTYPE_UNKNOWN); - - r += expect_result_type (1, "Digest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " Digest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\tDigest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t Digest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " \tDigest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " Digest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t\t\tDigest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t\t \tDigest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t\t \t Digest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest \t", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest \t ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\tDigest ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " Digest \t", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t \tDigest \t ", EXPECT_TYPE_FOR_DIGEST_AUTH); - - r += expect_result_type (1, "digEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " digEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\tdigEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t digEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " \tdigEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " digEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t\t\tdigEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t\t \tdigEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t\t \t digEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "digEST ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "digEST \t", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "digEST \t ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\tdigEST ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " digEST \t", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t \tdigEST \t ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "digest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " digest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\tdigest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t digest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " \tdigest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " digest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t\t\tdigest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t\t \tdigest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t\t \t digest", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "digest ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "digest \t", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "digest \t ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\tdigest ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " digest \t", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t \tdigest \t ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "DIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " DIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\tDIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t DIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " \tDIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " DIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t\t\tDIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t\t \tDIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t\t \t DIGEST", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "DIGEST ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "DIGEST \t", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "DIGEST \t ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\tDIGEST ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, " DIGEST \t", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "\t \tDIGEST \t ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest ,", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest ,\t", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest , ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest , ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest ,\t, ,\t, ,\t, ,", \ - EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest ,\t,\t,\t,\t,\t,\t,", \ - EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest a=b", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest a=\"b\"", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest nc=1", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest nc=\"1\"", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest a=b ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest a=\"b\" ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest nc=1 ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest nc=\"1\" ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest a = b", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest a\t=\t\"b\"", \ - EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest nc =1", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest nc= \"1\"", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest a=\tb ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest a = \"b\" ", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest nc\t\t\t= 1 ", \ - EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest nc =\t\t\t\"1\" ", \ - EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest nc =1,,,,", EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest nc =1 ,,,,", \ - EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest ,,,,nc= \"1 \"", \ - EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest ,,,, nc= \" 1\"", \ - EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest ,,,, nc= \"1\",,,,", \ - EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest ,,,, nc= \"1\" ,,,,", \ - EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest ,,,, nc= \"1\" ,,,,", \ - EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest ,,,, nc= \"1\" ,,,,", \ - EXPECT_TYPE_FOR_DIGEST_AUTH); - r += expect_result_type (1, "Digest ,,,, nc= \"1\" ,,,,,", \ - EXPECT_TYPE_FOR_DIGEST_AUTH); - - r += expect_result_type (1, "Digest nc", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc ", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc ,", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc , ", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest \tnc\t ", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest \tnc\t ", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc,", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc,uri", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=1,uri", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=1,uri ", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=1,uri,", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=1, uri,", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=1,uri ,", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=1,uri , ", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); + r += expect_result_type ("Basic a b", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Basic a\tb", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Basic a\tb", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Basic abc1 b", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Basic c abc1", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Basic c abc1 ", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Basic c abc1\t", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Basic c\tabc1\t", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Basic c abc1 b", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Basic zyx, b", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Basic zyx,b", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Basic zyx ,b", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Basic zyx;b", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Basic zyx; b", MHD_TEST_AUTHTYPE_NONE, 1); + + r += expect_result_type ("Basic2", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" Basic2", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" Basic2 ", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("\tBasic2", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("\t Basic2", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" \tBasic2", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" Basic2", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("\t\t\tBasic2", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("\t\t \tBasic2", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("\t\t \t Basic2", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("Basic2 ", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("Basic2 \t", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("Basic2 \t ", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("Basic2 123", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("Basic2 \t123", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("Basic2 abc ", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("BasicBasic", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" BasicBasic", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("\tBasicBasic", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("\t BasicBasic", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" \tBasicBasic", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("BasicBasic ", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("BasicBasic \t", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("BasicBasic \t\t", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("BasicDigest", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" BasicDigest", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("BasicDigest ", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("Basic\0", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("\0" "Basic", MHD_TEST_AUTHTYPE_NONE, 0); + + r += expect_result_type ("Digest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" Digest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\tDigest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t Digest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" \tDigest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" Digest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t\t\tDigest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t\t \tDigest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t\t \t Digest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest \t", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest \t ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\tDigest ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" Digest \t", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t \tDigest \t ", MHD_TEST_AUTHTYPE_DIGEST, 0); + + r += expect_result_type ("digEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" digEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\tdigEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t digEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" \tdigEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" digEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t\t\tdigEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t\t \tdigEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t\t \t digEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("digEST ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("digEST \t", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("digEST \t ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\tdigEST ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" digEST \t", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t \tdigEST \t ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("digest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" digest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\tdigest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t digest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" \tdigest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" digest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t\t\tdigest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t\t \tdigest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t\t \t digest", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("digest ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("digest \t", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("digest \t ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\tdigest ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" digest \t", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t \tdigest \t ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("DIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" DIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\tDIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t DIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" \tDIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" DIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t\t\tDIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t\t \tDIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t\t \t DIGEST", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("DIGEST ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("DIGEST \t", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("DIGEST \t ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\tDIGEST ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type (" DIGEST \t", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("\t \tDIGEST \t ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest ,", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest ,\t", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest , ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest , ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest ,\t, ,\t, ,\t, ,", \ + MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest ,\t,\t,\t,\t,\t,\t,", \ + MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest a=b", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest a=\"b\"", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest nc=1", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest nc=\"1\"", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest a=b ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest a=\"b\" ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest nc=1 ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest nc=\"1\" ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest a = b", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest a\t=\t\"b\"", \ + MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest nc =1", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest nc= \"1\"", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest a=\tb ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest a = \"b\" ", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest nc\t\t\t= 1 ", \ + MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest nc =\t\t\t\"1\" ", \ + MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest nc =1,,,,", MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest nc =1 ,,,,", \ + MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest ,,,,nc= \"1 \"", \ + MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest ,,,, nc= \" 1\"", \ + MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest ,,,, nc= \"1\",,,,", \ + MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest ,,,, nc= \"1\" ,,,,", \ + MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest ,,,, nc= \"1\" ,,,,", \ + MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest ,,,, nc= \"1\" ,,,,", \ + MHD_TEST_AUTHTYPE_DIGEST, 0); + r += expect_result_type ("Digest ,,,, nc= \"1\" ,,,,,", \ + MHD_TEST_AUTHTYPE_DIGEST, 0); + + r += expect_result_type ("Digest nc", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc ", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc ,", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc , ", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest \tnc\t ", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest \tnc\t ", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc,", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc,uri", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=1,uri", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=1,uri ", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=1,uri,", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=1, uri,", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=1,uri ,", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=1,uri , ", \ + MHD_TEST_AUTHTYPE_NONE, 1); /* Binary zero */ - r += expect_result_type (1, "Digest nc=1\0", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=1\0" " ", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=1\t\0", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=\0" "1", EXPECT_TYPE_FOR_DIGEST_INVLD); + r += expect_result_type ("Digest nc=1\0", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=1\0" " ", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=1\t\0", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=\0" "1", MHD_TEST_AUTHTYPE_NONE, 1); /* Semicolon */ - r += expect_result_type (1, "Digest nc=1;", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=1; ", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=;1", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc;=1", EXPECT_TYPE_FOR_DIGEST_INVLD); + r += expect_result_type ("Digest nc=1;", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=1; ", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=;1", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc;=1", MHD_TEST_AUTHTYPE_NONE, 1); /* The equal sign alone */ - r += expect_result_type (1, "Digest =", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest =", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest = ", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest ,=", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest , =", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest ,= ", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest , = ", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=1,=", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=1, =", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo=bar,=", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo=bar, =", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); + r += expect_result_type ("Digest =", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest =", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest = ", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest ,=", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest , =", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest ,= ", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest , = ", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=1,=", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=1, =", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo=bar,=", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo=bar, =", \ + MHD_TEST_AUTHTYPE_NONE, 1); /* Unclosed quotation */ - r += expect_result_type (1, "Digest nc=\"", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=\"abc", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=\" ", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=\"abc ", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=\" abc", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=\" abc", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=\"\\", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=\"\\\"", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=\" \\\"", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=\"\\\" ", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=\" \\\" ", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc=\"\\\"\\\"\\\"\\\"", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc= \"", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc= \"abc", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc= \" ", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc= \"abc ", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc= \" abc", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc= \" abc", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc= \"\\", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc= \"\\\"", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc= \" \\\"", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc= \"\\\" ", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc= \" \\\" ", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest nc= \"\\\"\\\"\\\"\\\"", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo=\"", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo=\"bar", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo=\" ", EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo=\"bar ", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo=\" bar", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo=\" bar", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo= \" bar", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo=\", bar", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo=\" bar,", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo=\"\\\"", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo=\" \\\"", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo=\"\\\" ", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo=\" \\\" ", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest foo=\"\\\"\\\"\\\"\\\"", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); + r += expect_result_type ("Digest nc=\"", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=\"abc", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=\" ", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=\"abc ", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=\" abc", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=\" abc", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=\"\\", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=\"\\\"", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=\" \\\"", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=\"\\\" ", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=\" \\\" ", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc=\"\\\"\\\"\\\"\\\"", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc= \"", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc= \"abc", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc= \" ", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc= \"abc ", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc= \" abc", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc= \" abc", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc= \"\\", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc= \"\\\"", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc= \" \\\"", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc= \"\\\" ", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc= \" \\\" ", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest nc= \"\\\"\\\"\\\"\\\"", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo=\"", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo=\"bar", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo=\" ", MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo=\"bar ", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo=\" bar", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo=\" bar", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo= \" bar", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo=\", bar", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo=\" bar,", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo=\"\\\"", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo=\" \\\"", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo=\"\\\" ", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo=\" \\\" ", \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest foo=\"\\\"\\\"\\\"\\\"", \ + MHD_TEST_AUTHTYPE_NONE, 1); /* Full set of parameters with semicolon inside */ - r += expect_result_type (1, "Digest username=\"test@example.com\", " \ + r += expect_result_type ("Digest username=\"test@example.com\", " \ "realm=\"users@example.com\", nonce=\"32141232413abcde\", " \ "uri=\"/example\", qop=auth, nc=00000001; cnonce=\"0a4f113b\", " \ "response=\"6629fae49393a05397450978507c4ef1\", " \ "opaque=\"sadfljk32sdaf\"", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest username=\"test@example.com\", " \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest username=\"test@example.com\", " \ "realm=\"users@example.com\", nonce=\"32141232413abcde\", " \ "uri=\"/example\", qop=auth, nc=00000001;cnonce=\"0a4f113b\", " \ "response=\"6629fae49393a05397450978507c4ef1\", " \ "opaque=\"sadfljk32sdaf\"", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - r += expect_result_type (1, "Digest username;=\"test@example.com\", " \ + MHD_TEST_AUTHTYPE_NONE, 1); + r += expect_result_type ("Digest username;=\"test@example.com\", " \ "realm=\"users@example.com\", nonce=\"32141232413abcde\", " \ "uri=\"/example\", qop=auth, nc=00000001, cnonce=\"0a4f113b\", " \ "response=\"6629fae49393a05397450978507c4ef1\", " \ "opaque=\"sadfljk32sdaf\"", \ - EXPECT_TYPE_FOR_DIGEST_INVLD); - - r += expect_result_type (1, "Digest2", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "2Digest", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "Digest" "a", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "a" "Digest", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, " Digest2", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, " 2Digest", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, " Digest" "a", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, " a" "Digest", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "Digest2 ", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "2Digest ", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "Digest" "a", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "a" "Digest ", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "DigestBasic", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "DigestBasic ", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, " DigestBasic", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "DigestBasic" "a", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "Digest" "\0", MHD_AUTHTYPE_UNKNOWN); - r += expect_result_type (1, "\0" "Digest", MHD_AUTHTYPE_UNKNOWN); + MHD_TEST_AUTHTYPE_NONE, 1); + + r += expect_result_type ("Digest2", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("2Digest", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("Digest" "a", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("a" "Digest", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" Digest2", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" 2Digest", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" Digest" "a", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" a" "Digest", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("Digest2 ", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("2Digest ", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("Digest" "a", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("a" "Digest ", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("DigestBasic", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("DigestBasic ", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type (" DigestBasic", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("DigestBasic" "a", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("Digest" "\0", MHD_TEST_AUTHTYPE_NONE, 0); + r += expect_result_type ("\0" "Digest", MHD_TEST_AUTHTYPE_NONE, 0); return r; } @@ -727,51 +802,39 @@ expect_basic_n (const char *hdr, size_t hdr_len, const char *tkn, size_t tkn_len, unsigned int line_num) { - const struct MHD_AuthRqHeader *h; + const struct MHD_RqBAuth *h; unsigned int ret; mhd_assert (NULL != hdr); mhd_assert (0 != hdr_len); - h = get_AuthRqHeader (1, hdr, hdr_len); - mhd_assert (NULL != h); - if (MHD_AUTHTYPE_BASIC != h->auth_type) - { + add_AuthHeader (hdr, hdr_len); + h = get_BAuthRqParams (); + if (NULL == h) + mhdErrorExitDesc ("'MHD_get_rq_bauth_params_()' returned NULL"); + ret = 1; + if (tkn_len != h->token68.len) fprintf (stderr, "'Authorization' header parsing FAILED:\n" - "Wrong type:\tRESULT: %s\tEXPECTED: %s\n", - get_auth_type_str (h->auth_type), - get_auth_type_str (MHD_AUTHTYPE_BASIC)); - ret = 1; - } + "Wrong token length:\tRESULT[%u]: %.*s\tEXPECTED[%u]: %.*s\n", + (unsigned) h->token68.len, + (int) h->token68.len, + h->token68.str ? + h->token68.str : "(NULL)", + (unsigned) tkn_len, (int) tkn_len, tkn ? tkn : "(NULL)"); + else if ( ((NULL == tkn) != (NULL == h->token68.str)) || + ((NULL != tkn) && + (0 != memcmp (tkn, h->token68.str, tkn_len))) ) + fprintf (stderr, + "'Authorization' header parsing FAILED:\n" + "Wrong token string:\tRESULT[%u]: %.*s\tEXPECTED[%u]: %.*s\n", + (unsigned) h->token68.len, + (int) h->token68.len, + h->token68.str ? + h->token68.str : "(NULL)", + (unsigned) tkn_len, (int) tkn_len, tkn ? tkn : "(NULL)"); else - { - if (NULL == h->params.bauth) - mhdErrorExitDesc ("'params.bauth' pointer is NULL"); - ret = 1; - if (tkn_len != h->params.bauth->token68.len) - fprintf (stderr, - "'Authorization' header parsing FAILED:\n" - "Wrong token length:\tRESULT[%u]: %.*s\tEXPECTED[%u]: %.*s\n", - (unsigned) h->params.bauth->token68.len, - (int) h->params.bauth->token68.len, - h->params.bauth->token68.str ? - h->params.bauth->token68.str : "(NULL)", - (unsigned) tkn_len, (int) tkn_len, tkn ? tkn : "(NULL)"); - else if ( ((NULL == tkn) != (NULL == h->params.bauth->token68.str)) || - ((NULL != tkn) && - (0 != memcmp (tkn, h->params.bauth->token68.str, tkn_len))) ) - fprintf (stderr, - "'Authorization' header parsing FAILED:\n" - "Wrong token string:\tRESULT[%u]: %.*s\tEXPECTED[%u]: %.*s\n", - (unsigned) h->params.bauth->token68.len, - (int) h->params.bauth->token68.len, - h->params.bauth->token68.str ? - h->params.bauth->token68.str : "(NULL)", - (unsigned) tkn_len, (int) tkn_len, tkn ? tkn : "(NULL)"); - else - ret = 0; - } + ret = 0; if (0 != ret) { fprintf (stderr, @@ -779,7 +842,7 @@ expect_basic_n (const char *hdr, size_t hdr_len, fprintf (stderr, "The check is at line: %u\n\n", line_num); } - free_AuthRqHeader (); + clean_AuthHeaders (); return ret; } @@ -911,51 +974,38 @@ expect_digest_n (const char *hdr, size_t hdr_len, int userhash, unsigned int line_num) { - const struct MHD_AuthRqHeader *h; + const struct MHD_RqDAuth *h; unsigned int ret; mhd_assert (NULL != hdr); mhd_assert (0 != hdr_len); - h = get_AuthRqHeader (1, hdr, hdr_len); - mhd_assert (NULL != h); - if (MHD_AUTHTYPE_DIGEST != h->auth_type) - { - fprintf (stderr, - "'Authorization' header parsing FAILED:\n" - "Wrong type:\tRESULT: %s\tEXPECTED: %s\n", - get_auth_type_str (h->auth_type), - get_auth_type_str (MHD_AUTHTYPE_DIGEST)); - ret = 1; - } - else - { - const struct MHD_RqDAuth *params; - if (NULL == h->params.dauth) - mhdErrorExitDesc ("'params.dauth' pointer is NULL"); - params = h->params.dauth; - ret = 0; + add_AuthHeader (hdr, hdr_len); - ret += cmp_dauth_param ("nonce", &params->nonce, nonce); - ret += cmp_dauth_param ("algorithm", &params->algorithm, algorithm); - ret += cmp_dauth_param ("response", &params->response, response); - ret += cmp_dauth_param ("username", &params->username, username); - ret += cmp_dauth_param ("username_ext", &params->username_ext, - username_ext); - ret += cmp_dauth_param ("realm", &params->realm, realm); - ret += cmp_dauth_param ("uri", &params->uri, uri); - ret += cmp_dauth_param ("qop", &params->qop, qop); - ret += cmp_dauth_param ("cnonce", &params->cnonce, cnonce); - ret += cmp_dauth_param ("nc", &params->nc, nc); - if (params->userhash != ! (! userhash)) - { - ret += 1; - fprintf (stderr, "Parameter 'userhash' parsed incorrectly:\n"); - fprintf (stderr, "\tRESULT :\t%s\n", - params->userhash ? "true" : "false"); - fprintf (stderr, "\tEXPECTED:\t%s\n", - userhash ? "true" : "false"); - } + h = get_DAuthRqParams (); + if (NULL == h) + mhdErrorExitDesc ("'MHD_get_rq_dauth_params_()' returned NULL"); + ret = 0; + + ret += cmp_dauth_param ("nonce", &h->nonce, nonce); + ret += cmp_dauth_param ("algorithm", &h->algorithm, algorithm); + ret += cmp_dauth_param ("response", &h->response, response); + ret += cmp_dauth_param ("username", &h->username, username); + ret += cmp_dauth_param ("username_ext", &h->username_ext, + username_ext); + ret += cmp_dauth_param ("realm", &h->realm, realm); + ret += cmp_dauth_param ("uri", &h->uri, uri); + ret += cmp_dauth_param ("qop", &h->qop, qop); + ret += cmp_dauth_param ("cnonce", &h->cnonce, cnonce); + ret += cmp_dauth_param ("nc", &h->nc, nc); + if (h->userhash != ! (! userhash)) + { + ret += 1; + fprintf (stderr, "Parameter 'userhash' parsed incorrectly:\n"); + fprintf (stderr, "\tRESULT :\t%s\n", + h->userhash ? "true" : "false"); + fprintf (stderr, "\tEXPECTED:\t%s\n", + userhash ? "true" : "false"); } if (0 != ret) { @@ -964,7 +1014,7 @@ expect_digest_n (const char *hdr, size_t hdr_len, fprintf (stderr, "The check is at line: %u\n\n", line_num); } - free_AuthRqHeader (); + clean_AuthHeaders (); return ret; } @@ -1214,6 +1264,8 @@ main (int argc, char *argv[]) { unsigned int errcount = 0; (void) argc; (void) argv; /* Unused. Silent compiler warning. */ + test_global_init (); + errcount += check_type (); #ifdef BAUTH_SUPPORT errcount += check_basic ();