Add test for blanks in URL path
[yaz-moved-to-github.git] / test / test_solr.c
index 27eafc8..6ea884c 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2012 Index Data
+ * Copyright (C) 1995-2013 Index Data
  * See the file LICENSE for details.
  */
 #if HAVE_CONFIG_H
@@ -8,6 +8,7 @@
 
 #include <stdlib.h>
 #include <yaz/srw.h>
+#include <yaz/log.h>
 #if YAZ_HAVE_XML2
 #include <libxml/parser.h>
 #endif
@@ -39,7 +40,7 @@ int compare_solr_req(ODR odr, Z_SRW_PDU *sr,
     {
         int len = 0;
         char *buf = odr_getbuf(odr, &len, 0);
-        
+
         if (buf)
         {
             if (len == strlen(expect) && !memcmp(buf, expect, len))
@@ -64,10 +65,11 @@ void tst_encoding(void)
     {
         Z_SRW_PDU *sr = yaz_srw_get_pdu(odr, Z_SRW_searchRetrieve_request,
                                         "1.2");
-        
+
+        sr->u.request->query = "title:solr";
         YAZ_CHECK(compare_solr_req(
                       odr, sr, 0,
-                      "GET Default/select? HTTP/1.1\r\n"
+                      "GET Default/select?q=title%3Asolr HTTP/1.1\r\n"
                       "User-Agent: YAZ/" YAZ_VERSION "\r\n"
                       "Host: localhost\r\n"
                       "Content-Type: text/xml\r\n\r\n"));
@@ -76,9 +78,10 @@ void tst_encoding(void)
     {
         Z_SRW_PDU *sr = yaz_srw_get_pdu(odr, Z_SRW_searchRetrieve_request,
                                         "1.2");
+        sr->u.request->query = "title:solr";
         YAZ_CHECK(compare_solr_req(
                       odr, sr, "utf-8",
-                      "GET Default/select? HTTP/1.1\r\n"
+                      "GET Default/select?q=title%3Asolr HTTP/1.1\r\n"
                       "User-Agent: YAZ/" YAZ_VERSION "\r\n"
                       "Host: localhost\r\n"
                       "Content-Type: text/xml; charset=utf-8\r\n\r\n"));
@@ -87,9 +90,8 @@ void tst_encoding(void)
     {
         Z_SRW_PDU *sr = yaz_srw_get_pdu(odr, Z_SRW_searchRetrieve_request,
                                         "1.2");
-        
-        sr->u.request->query_type = Z_SRW_query_type_cql;
-        sr->u.request->query.cql = "title:solr";
+
+        sr->u.request->query = "title:solr";
         sr->u.request->startRecord = odr_intdup(odr, 3);
         sr->u.request->maximumRecords = odr_intdup(odr, 10);
 
@@ -105,9 +107,8 @@ void tst_encoding(void)
     {
         Z_SRW_PDU *sr = yaz_srw_get_pdu(odr, Z_SRW_searchRetrieve_request,
                                         "1.2");
-        
-        sr->u.request->query_type = Z_SRW_query_type_cql;
-        sr->u.request->query.cql = "title:solr";
+
+        sr->u.request->query = "title:solr";
         sr->u.request->startRecord = odr_intdup(odr, 3);
         sr->u.request->maximumRecords = odr_intdup(odr, 10);
         sr->u.request->facetList = yaz_pqf_parse_facet_list(
@@ -137,7 +138,7 @@ int check_response(ODR o, const char *content, Z_SRW_searchRetrieveResponse **p)
     Z_SRW_PDU *sr_p;
     char *http_response = odr_malloc(o, strlen(content) + 300);
 
-    strcpy(http_response, 
+    strcpy(http_response,
            "HTTP/1.1 200 OK\r\n"
            "Last-Modified: Wed, 13 Apr 2011 08:30:59 GMT\r\n"
            "ETag: \"MjcyMWE5M2JiNDgwMDAwMFNvbHI=\"\r\n"
@@ -167,7 +168,7 @@ void tst_decoding(void)
     Z_SRW_searchRetrieveResponse *response;
 
     YAZ_CHECK(check_response(
-                  odr, 
+                  odr,
                   "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                   "<response>\n"
                   "<lst name=\"responseHeader\"><int name=\"status\">0</int>"
@@ -188,7 +189,7 @@ void tst_decoding(void)
 
     YAZ_CHECK(
         check_response(
-            odr, 
+            odr,
             "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
             "<response><lst name=\"responseHeader\">"
             "<int name=\"status\">0</int><int name=\"QTime\">2</int>"
@@ -269,7 +270,7 @@ void tst_decoding(void)
             "</doc>";
 
         Z_SRW_record *record = response->records;
-        
+
         YAZ_CHECK(record->recordData_len == strlen(doc) &&
                   !memcmp(record->recordData_buf, doc, record->recordData_len));
     }
@@ -329,6 +330,42 @@ void tst_decoding(void)
     odr_destroy(odr);
 #endif
 }
+
+void tst_yaz_700(void)
+{
+    ODR odr = odr_createmem(ODR_ENCODE);
+    int r;
+    const char *url =
+        "http://localhost:9036/XXX/cproxydebug-7/node102/p/105/c=content_connector"
+        "a=usr/pw#&? r=cfusr/cfpw p=1.2.3.4:80/www.indexdata.com/staff/";
+    int use_full_host = 0;
+    Z_GDU *gdu_req = z_get_HTTP_Request_uri(odr, url, 0, use_full_host);
+    Z_HTTP_Request *hreq = gdu_req->u.HTTP_Request;
+    hreq->method = "GET";
+
+    hreq->content_buf = odr_strdup(odr, "");
+    hreq->content_len = 0;
+
+    r = z_GDU(odr, &gdu_req, 0, 0);
+    YAZ_CHECK(r);
+    if (r)
+    {
+        int len;
+        char *buf = odr_getbuf(odr, &len, 0);
+        ODR decode = odr_createmem(ODR_DECODE);
+        YAZ_CHECK(buf);
+        if (buf)
+        {
+            odr_setbuf(decode, buf, len, 0);
+            r = z_GDU(decode, &gdu_req, 0, 0);
+            YAZ_CHECK(r);
+        }
+        odr_destroy(decode);
+    }
+    odr_destroy(odr);
+}
+
+
 int main(int argc, char **argv)
 {
     YAZ_CHECK_INIT(argc, argv);
@@ -337,6 +374,7 @@ int main(int argc, char **argv)
 #endif
     tst_encoding();
     tst_decoding();
+    tst_yaz_700();
     YAZ_CHECK_TERM;
 }