From de495dbb3cf5ae296774bae2beddc82e2e5faf4c Mon Sep 17 00:00:00 2001
From: Ghennadi Procopciuc <gprococpiuc@ixiacom.com>
Date: Mon, 18 Jun 2012 16:00:43 +0300
Subject: [PATCH] New test for IPv6 cookies in libcurl.

---
 tests/data/Makefile.am     |    1 +
 tests/data/test1500        |   88 ++++++++++++++++++++++++++++++++++++++++++++
 tests/libtest/Makefile.inc |    4 +-
 tests/libtest/lib1500.c    |   70 +++++++++++++++++++++++++++++++++++
 4 files changed, 162 insertions(+), 1 deletion(-)
 create mode 100755 tests/data/test1500
 create mode 100755 tests/libtest/lib1500.c

diff --git a/tests/data/Makefile.am b/tests/data/Makefile.am
index a0e7ac5..42ef361 100644
--- a/tests/data/Makefile.am
+++ b/tests/data/Makefile.am
@@ -84,6 +84,7 @@ test1306 test1307 test1308 test1309 test1310 test1311 test1312 test1313 \
 test1314 test1315 test1316 test1317 test1318 test1319 test1320 test1321 \
 test1322 test1323 test1324 test1325 test1326 test1327 test1328 test1329 \
 test1400 test1401 test1402 test1403 test1404 test1405 test1406 test1407 \
+test1500 \
 test2000 test2001 test2002 test2003 test2004
 
 EXTRA_DIST = $(TESTCASES) DISABLED
diff --git a/tests/data/test1500 b/tests/data/test1500
new file mode 100664
index 0000000..1e2fff3
--- /dev/null
+++ b/tests/data/test1500
@@ -0,0 +1,88 @@
+<testcase>
+<info>
+<keywords>
+HTTP
+HTTP GET
+IPV6
+</keywords>
+</info>
+#
+# Server-side
+<reply>
+<data1>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Content-Length: 6
+Connection: close
+Content-Type: text/html
+Set-Cookie: time=1
+
+-foo-
+</data1>
+<data2>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Content-Length: 6
+Connection: close
+Content-Type: text/html
+Set-Cookie: time=2
+
+-foo-
+</data2>
+
+# since the request runs twice
+<datacheck>
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Content-Length: 6
+Connection: close
+Content-Type: text/html
+Set-Cookie: time=1
+
+-foo-
+HTTP/1.1 200 OK
+Date: Thu, 09 Nov 2010 14:49:00 GMT
+Content-Length: 6
+Connection: close
+Content-Type: text/html
+Set-Cookie: time=2
+
+-foo-
+</datacheck>
+
+</reply>
+
+# Client-side
+<client>
+<server>
+http-ipv6
+</server>
+# tool is what to use instead of 'curl'
+<tool>
+lib1500
+</tool>
+
+ <name>
+HTTP, receive cookies over IPV6
+ </name>
+ <command>
+http://%HOST6IP:%HTTP6PORT/path/1500
+</command>
+</client>
+
+#
+# Verify data after the test has been "shot"
+<verify>
+<protocol>
+GET /path/15000001 HTTP/1.1
+Host: %HOST6IP:%HTTP6PORT
+Accept: */*
+
+GET /path/15000002 HTTP/1.1
+Host: %HOST6IP:%HTTP6PORT
+Accept: */*
+Cookie: time=1
+
+</protocol>
+</verify>
+</testcase>
diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc
index e24d742..252b34e 100644
--- a/tests/libtest/Makefile.inc
+++ b/tests/libtest/Makefile.inc
@@ -19,7 +19,7 @@ noinst_PROGRAMS = chkhostname \
   lib543 lib544 lib545 lib547 lib548 lib549 lib552 lib553 lib554 lib555	\
   lib556 lib539 lib557 lib560 lib562 lib564 lib565 lib566 lib567 lib568	\
   lib569 lib570 lib571 lib572 lib573 lib582 lib583 lib585 lib586 lib587 \
-  lib590 lib591 lib597 lib598
+  lib590 lib591 lib597 lib598 lib1500
 
 chkhostname_SOURCES = chkhostname.c $(top_srcdir)/lib/curl_gethostname.c
 chkhostname_LDADD = @CURL_NETWORK_LIBS@
@@ -183,3 +183,5 @@ lib591_SOURCES = lib591.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
 lib597_SOURCES = lib597.c $(SUPPORTFILES) $(TESTUTIL) $(WARNLESS)
 
 lib598_SOURCES = lib598.c $(SUPPORTFILES)
+
+lib1500_SOURCES = lib1500.c $(SUPPORTFILES)
diff --git a/tests/libtest/lib1500.c b/tests/libtest/lib1500.c
new file mode 100664
index 0000000..eee4e36
--- /dev/null
+++ b/tests/libtest/lib1500.c
@@ -0,0 +1,70 @@
+/***************************************************************************
+ *                                  _   _ ____  _
+ *  Project                     ___| | | |  _ \| |
+ *                             / __| | | | |_) | |
+ *                            | (__| |_| |  _ <| |___
+ *                             \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+#include "test.h"
+
+#include "memdebug.h"
+
+#define REQN    2
+
+int test(char *URL)
+{
+  CURLcode res;
+  CURL *curl;
+  char target_url[256];
+  int i;
+  
+  if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
+    fprintf(stderr, "curl_global_init() failed\n");
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  if ((curl = curl_easy_init()) == NULL) {
+    fprintf(stderr, "curl_easy_init() failed\n");
+    curl_global_cleanup();
+    return TEST_ERR_MAJOR_BAD;
+  }
+
+  test_setopt(curl, CURLOPT_COOKIEFILE, ""); /* just to start the cookie engine */
+
+  for(i = 0; i < REQN; i++){
+    sprintf(target_url, "%s%04i", URL, i + 1);
+    target_url[sizeof(target_url) - 1] = '\0';
+
+    test_setopt(curl, CURLOPT_URL, target_url);	
+    test_setopt(curl, CURLOPT_HEADER, 1L);
+    test_setopt(curl, CURLOPT_VERBOSE, 1L);
+
+    res = curl_easy_perform(curl);
+
+    if(res) {
+      fprintf(stderr, "retrieve 1 failed\n");
+      goto test_cleanup;
+    }
+  }
+
+test_cleanup:
+
+  curl_easy_cleanup(curl);
+  curl_global_cleanup();
+
+  return (int)res;
+}
-- 
1.7.9.5

