]> granicus.if.org Git - curl/commitdiff
unit1600: unit test for Curl_ntlm_core_mk_nt_hash
authorDaniel Stenberg <daniel@haxx.se>
Tue, 3 Feb 2015 19:59:54 +0000 (20:59 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 3 Feb 2015 20:03:11 +0000 (21:03 +0100)
lib/curl_ntlm_core.c
tests/data/Makefile.inc
tests/libtest/first.c
tests/libtest/test.h
tests/unit/curlcheck.h
tests/unit/unit1600.c

index 1bdc82312e7b1291085d084af5fbe92b2b551911..81575156f22bc6c8b3e4f3ddc33d81d938f84adc 100644 (file)
@@ -510,6 +510,7 @@ static void ascii_uppercase_to_unicode_le(unsigned char *dest,
 
 /*
  * Set up nt hashed passwords
+ * @unittest: 1600
  */
 CURLcode Curl_ntlm_core_mk_nt_hash(struct SessionHandle *data,
                                    const char *password,
index 940182baaf9c08bc68b3beac72f3a0b1af1caa81..15b583ecf192d2f9dffacf08e4808b149dfff353 100644 (file)
@@ -155,6 +155,8 @@ test1520 \
 \
 test1525 test1526 test1527 test1528 test1529 \
 \
+test1600 \
+\
 test1800 test1801 \
 \
 test1900 test1901 test1902 test1903 \
index 5851faf62409f18ef44fc5823e224428b2164fea..0ead39d67cd7d1a4804c8348927fcc3585326d5c 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2015, 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
@@ -111,6 +111,20 @@ static void memory_tracking_init(void)
 #  define memory_tracking_init() Curl_nop_stmt
 #endif
 
+/* returns a hexdump in a static memory area */
+char *hexdump(unsigned char *buffer, size_t len)
+{
+  static char dump[200*3+1];
+  char *p = dump;
+  size_t i;
+  if(len > 200)
+    return NULL;
+  for(i=0; i<len; i++, p += 3)
+    snprintf(p, 4, "%02x ", buffer[i]);
+  return dump;
+}
+
+
 int main(int argc, char **argv)
 {
   char *URL;
index 4186c4f2653c6c2b869f92e201f140f7ac1e6d4f..fb95996aaa45d9a89cf7ba99d85bf982632b05ea 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2015, 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
@@ -63,6 +63,8 @@ extern void wait_ms(int ms); /* wait this many milliseconds */
 extern int test(char *URL); /* the actual test function provided by each
                                individual libXXX.c file */
 
+extern char *hexdump(unsigned char *buffer, size_t len);
+
 #ifdef UNITTESTS
 extern int unitfail;
 #endif
index 96203e075667b9cf8d843155fa9c46f3ee5dd823..2e3746bdcded5164881f7b5985f5119fca68711b 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2015, 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
     unitfail++;                                          \
   }
 
-#define verify_memory(dynamic, check, len)                              \
-  if(dynamic && memcmp(dynamic, check, len)) {                          \
-    fprintf(stderr, "%s:%d The dynamic string didn't match '%s'\n",     \
-            __FILE__, __LINE__, check);                                 \
-    unitfail++;                                                         \
+#define verify_memory(dynamic, check, len)                                  \
+  if(dynamic && memcmp(dynamic, check, len)) {                              \
+    fprintf(stderr, "%s:%d Memory buffer mismatch size %d. '%s' is not\n", \
+            __FILE__, __LINE__, len, hexdump((unsigned char *)check, len));      \
+    fprintf(stderr, "%s:%d the same as '%s'\n",                             \
+            __FILE__, __LINE__, hexdump((unsigned char *)dynamic, len));         \
+    unitfail++;                                                             \
   }
 
 /* fail() is for when the test case figured out by itself that a check
index 3cc0ebd8ed455721a0bda3f279c6cbd7d21ac380..6e14d20ef553c419687d81e9b7108b57e3ecb392 100644 (file)
@@ -44,7 +44,18 @@ UNITTEST_START
   Curl_ntlm_core_mk_nt_hash(easy, "1", output);
 
   verify_memory(testp,
-              "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
-              "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 21);
+              "\x69\x94\x3c\x5e\x63\xb4\xd2\xc1\x04\xdb"
+              "\xbc\xc1\x51\x38\xb7\x2b\x00\x00\x00\x00\x00", 21);
+
+  Curl_ntlm_core_mk_nt_hash(easy, "hello-you-fool", output);
+
+  verify_memory(testp,
+              "\x39\xaf\x87\xa6\x75\x0a\x7a\x00\xba\xa0"
+              "\xd3\x4f\x04\x9e\xc1\xd0\x00\x00\x00\x00\x00", 21);
+
+  Curl_ntlm_core_mk_nt_hash(easy, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", output);
+
+  verify_memory(testp,
+                "\x36\x9d\xae\x06\x84\x7e\xe1\xc1\x4a\x94\x39\xea\x6f\x44\x8c\x65\x00\x00\x00\x00\x00", 21);
 
 UNITTEST_STOP