diff options
author | Kamil Dudka <kdudka@redhat.com> | 2010-07-30 00:47:49 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2010-07-30 00:51:24 +0200 |
commit | b5c3feda1788301bea7f1dd4f9bb240d13862bd0 (patch) | |
tree | 50e6cbe63ec308b53d3bec11456b80832f94f634 /tests/libtest/sethostname.c | |
parent | 01c309e186b3f1055d56211d4074f451bf5282bf (diff) | |
download | gnurl-b5c3feda1788301bea7f1dd4f9bb240d13862bd0.tar.gz gnurl-b5c3feda1788301bea7f1dd4f9bb240d13862bd0.tar.bz2 gnurl-b5c3feda1788301bea7f1dd4f9bb240d13862bd0.zip |
NTLM tests: boost coverage by forcing the hostname
A shared library tests/libtest/.libs/lihostname.so is preloaded in NTLM
test-cases to override the system implementation of gethostname(). It
makes it possible to test the NTLM authentication for exact match, and
this way test the implementation of MD4 and DES.
If LD_PRELOAD doesn't work, a debug build willl also workk as debug
builds are now made to prefer a specific environment variable and will
then return that content as host name instead of the actual one.
Kamil wrote the bulk of this, Daniel Stenberg polished it.
Diffstat (limited to 'tests/libtest/sethostname.c')
-rw-r--r-- | tests/libtest/sethostname.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/libtest/sethostname.c b/tests/libtest/sethostname.c new file mode 100644 index 000000000..667f689ae --- /dev/null +++ b/tests/libtest/sethostname.c @@ -0,0 +1,28 @@ +/***************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + */ + +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#define GETHOSTNAME_ENV_VAR "CURL_GETHOSTNAME" + +/* + * we force our own host name, in order to make some tests machine independent + */ +int gethostname(char *name, size_t namelen) { + const char *force_hostname = getenv(GETHOSTNAME_ENV_VAR); + if(force_hostname) { + strncpy(name, force_hostname, namelen); + return 0; + } + + /* LD_PRELOAD used, but no hostname set, we'll just return a failure */ + return -1; +}; |