[PATCH] winhttp/tests: Test when large amount of data is returned from a 410

Alistair Leslie-Hughes leslie_alistair at hotmail.com
Tue Apr 11 18:20:08 CDT 2017


v2 - Removed unneed Authenicated request type
   - Use loop to send data.
   - Removed redundant tests

If you only have NTLM authenicatation, the test fail, ref
https://testbot.winehq.org/JobDetails.pl?Key=30134

Returning 10K causes WinHttpSendRequest not to send the Authorization
to the server on the second call.  This is because the data isn't flushed
correctly and when WinHttpReceiveResponse is called it still reading
the data from the sent request.

A typical scenario is when the server returns the login page after
the first 401 error.

Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
---
 dlls/winhttp/tests/winhttp.c | 76 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)

diff --git a/dlls/winhttp/tests/winhttp.c b/dlls/winhttp/tests/winhttp.c
index a5eff115b4..fc2822e4d8 100644
--- a/dlls/winhttp/tests/winhttp.c
+++ b/dlls/winhttp/tests/winhttp.c
@@ -2059,6 +2059,15 @@ static const char multiauth[] =
 "Content-Type: text/plain\r\n"
 "\r\n";
 
+static const char largeauth[] =
+"HTTP/1.1 401 Unauthorized\r\n"
+"Server: winetest\r\n"
+"WWW-Authenticate: Basic realm=\"placebo\"\r\n"
+"WWW-Authenticate: NTLM\r\n"
+"Content-Length: 10240\r\n"
+"Content-Type: text/plain\r\n"
+"\r\n";
+
 static const char unauthorized[] = "Unauthorized";
 static const char hello_world[] = "Hello World";
 
@@ -2172,6 +2181,19 @@ static DWORD CALLBACK server_thread(LPVOID param)
         {
             send(c, multiauth, sizeof multiauth - 1, 0);
         }
+        if(strstr(buffer, "GET /largeauth"))
+        {
+            if (strstr(buffer, "Authorization: NTLM"))
+                send(c, okmsg, sizeof(okmsg) - 1, 0);
+            else
+            {
+                send(c, largeauth, sizeof largeauth - 1, 0);
+                for(i = 0; i < 10240; i++)
+                    send(c, "A", 1, 0);
+
+                continue;
+            }
+        }
         if (strstr(buffer, "GET /cookie4"))
         {
             send(c, cookiemsg2, sizeof(cookiemsg2) - 1, 0);
@@ -2554,6 +2576,59 @@ static void test_multi_authentication(int port)
     WinHttpCloseHandle(ses);
 }
 
+static void test_large_data_authentication(int port)
+{
+    static const WCHAR largeauthW[] = {'/','l','a','r','g','e','a','u','t','h',0};
+    static const WCHAR getW[] = {'G','E','T',0};
+    static WCHAR userW[] = {'u','s','e','r',0};
+    static WCHAR passW[] = {'p','w','d',0};
+    HINTERNET ses, con, req;
+    DWORD status, size;
+    BOOL ret;
+
+    ses = WinHttpOpen(test_useragent, WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0);
+    ok(ses != NULL, "failed to open session %u\n", GetLastError());
+
+    con = WinHttpConnect(ses, localhostW, port, 0);
+    ok(con != NULL, "failed to open a connection %u\n", GetLastError());
+
+    req = WinHttpOpenRequest(con, getW, largeauthW, NULL, NULL, NULL, 0);
+    ok(req != NULL, "failed to open a request %u\n", GetLastError());
+
+    ret = WinHttpSendRequest(req, WINHTTP_NO_ADDITIONAL_HEADERS, 0,
+                             WINHTTP_NO_REQUEST_DATA,0, 0, 0 );
+    ok(ret, "expected success\n");
+
+    ret = WinHttpReceiveResponse(req, NULL);
+    ok(ret, "expected success\n");
+
+    size = sizeof(status);
+    ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, NULL,
+                                  &status,  &size,  NULL);
+    ok(ret, "expected success\n");
+    ok(status == HTTP_STATUS_DENIED, "got %d\n", status);
+
+    ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_NTLM, userW, passW, NULL);
+    ok(ret, "expected success\n");
+
+    ret = WinHttpSendRequest(req, WINHTTP_NO_ADDITIONAL_HEADERS, 0,
+                             WINHTTP_NO_REQUEST_DATA, 0, 0, 0);
+    ok(ret, "expected success %d\n", GetLastError());
+
+    ret = WinHttpReceiveResponse(req, NULL);
+    todo_wine ok(ret, "expected success\n");
+
+    size = sizeof(status);
+    ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, NULL,
+                                  &status,  &size,  NULL);
+    todo_wine ok(ret, "expected success\n");
+    todo_wine ok(status == HTTP_STATUS_OK, "got %d\n", status);
+
+    WinHttpCloseHandle(req);
+    WinHttpCloseHandle(con);
+    WinHttpCloseHandle(ses);
+}
+
 static void test_no_headers(int port)
 {
     static const WCHAR no_headersW[] = {'/','n','o','_','h','e','a','d','e','r','s',0};
@@ -4354,6 +4429,7 @@ START_TEST (winhttp)
     test_not_modified(si.port);
     test_basic_authentication(si.port);
     test_multi_authentication(si.port);
+    test_large_data_authentication(si.port);
     test_bad_header(si.port);
     test_multiple_reads(si.port);
     test_cookies(si.port);
-- 
2.11.0




More information about the wine-patches mailing list