Signed-off-by: Alistair Leslie-Hughes leslie_alistair@hotmail.com --- dlls/wininet/tests/http.c | 171 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+)
diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c index 99ea0ef48f..9c2b949cdd 100644 --- a/dlls/wininet/tests/http.c +++ b/dlls/wininet/tests/http.c @@ -2053,6 +2053,11 @@ static const char okmsg[] = "Server: winetest\r\n" "\r\n";
+static const char okmsg201[] = +"HTTP/1.1 201 OK\r\n" +"Server: winetest\r\n" +"\r\n"; + static const char okmsg2[] = "HTTP/1.1 200 OK\r\n" "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n" @@ -2438,6 +2443,15 @@ static DWORD CALLBACK server_thread(LPVOID param) else send(c, noauthmsg, sizeof noauthmsg-1, 0); } + if (strstr(buffer, "HEAD /upload4.txt")) + { + if (strstr(buffer, "Authorization: Bearer dXNlcjE6cHdkMQ==")) + send(c, okmsg, sizeof okmsg-1, 0); + else if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q=")) + send(c, okmsg201, sizeof okmsg-1, 0); + else + send(c, noauthmsg, sizeof noauthmsg-1, 0); + } if (strstr(buffer, "/test_host_override")) { if (strstr(buffer, host_header_override)) @@ -4677,6 +4691,161 @@ static void test_basic_auth_credentials_different(int port) InternetCloseHandle( ses ); }
+/* + * Manually set the Authorization for both calls. + */ +static void test_basic_auth_credentials_manual(int port) +{ + HINTERNET ses, con, req; + DWORD status, size; + BOOL ret; + + ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); + ok( ses != NULL, "InternetOpenA failed\n" ); + + /* Clear the cached credentials */ + ret = InternetSetOptionA(ses, INTERNET_OPTION_END_BROWSER_SESSION, NULL, 0); + ok(ret, "unexpected failure %u\n", GetLastError()); + + con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0 ); + ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() ); + + req = HttpOpenRequestA( con, "HEAD", "/upload.txt", NULL, NULL, NULL, 0, 0 ); + ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() ); + + /* Set Authorization Header */ + ret = HttpAddRequestHeadersA(req, "Authorization: Basic dXNlcjpwd2Q=\r\n", ~0u, + HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD); + ok(ret, "HttpAddRequestHeaders Failed\n"); + + ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); + ok( ret, "HttpSendRequestA failed %u\n", GetLastError() ); + + status = 0xdeadbeef; + size = sizeof(status); + ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); + ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); + ok( status == 200, "got %u\n", status ); + + InternetCloseHandle( req ); + InternetCloseHandle( con ); + InternetCloseHandle( ses ); + + /* Show manual headers are cached. */ + ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); + ok( ses != NULL, "InternetOpenA failed\n" ); + + con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0 ); + ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() ); + + req = HttpOpenRequestA( con, "HEAD", "/upload.txt", NULL, NULL, NULL, 0, 0 ); + ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() ); + + ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); + ok( ret, "HttpSendRequestA failed %u\n", GetLastError() ); + + status = 0xdeadbeef; + size = sizeof(status); + ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); + ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); + ok( status == 401, "got %u\n", status ); + + InternetCloseHandle( req ); + InternetCloseHandle( con ); + InternetCloseHandle( ses ); + + ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); + ok( ses != NULL, "InternetOpenA failed\n" ); + + con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0 ); + ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() ); + + req = HttpOpenRequestA( con, "HEAD", "/upload4.txt", NULL, NULL, NULL, 0, 0 ); + ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() ); + + /* Set Authorization Header */ + ret = HttpAddRequestHeadersA(req, "Authorization: Bearer dXNlcjE6cHdkMQ==\r\n", ~0u, + HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD); + ok(ret, "HttpAddRequestHeaders Failed\n"); + + ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); + ok( ret, "HttpSendRequestA failed %u\n", GetLastError() ); + + status = 0xdeadbeef; + size = sizeof(status); + ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); + ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); + ok( status == 200, "got %u\n", status ); + + InternetCloseHandle( req ); + InternetCloseHandle( con ); + InternetCloseHandle( ses ); +} + +/* + * Manually set the Authorization for the bearer call, which shows the cached is used. + */ +static void test_basic_auth_credentials_cached_manual(int port) +{ + HINTERNET ses, con, req; + DWORD status, size; + BOOL ret; + + ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); + ok( ses != NULL, "InternetOpenA failed\n" ); + + /* Clear the cached credentials */ + ret = InternetSetOptionA(ses, INTERNET_OPTION_END_BROWSER_SESSION, NULL, 0); + ok(ret, "unexpected failure %u\n", GetLastError()); + + con = InternetConnectA( ses, "localhost", port, "user", "pwd", + INTERNET_SERVICE_HTTP, 0, 0 ); + ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() ); + + req = HttpOpenRequestA( con, "HEAD", "/upload.txt", NULL, NULL, NULL, 0, 0 ); + ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() ); + + ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); + ok( ret, "HttpSendRequestA failed %u\n", GetLastError() ); + + status = 0xdeadbeef; + size = sizeof(status); + ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); + ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); + ok( status == 200, "got %u\n", status ); + + InternetCloseHandle( req ); + InternetCloseHandle( con ); + InternetCloseHandle( ses ); + + ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 ); + ok( ses != NULL, "InternetOpenA failed\n" ); + + con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0 ); + ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() ); + + req = HttpOpenRequestA( con, "HEAD", "/upload4.txt", NULL, NULL, NULL, 0, 0 ); + ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() ); + + /* Setting an Authorization Header doesn't override the cached one. */ + ret = HttpAddRequestHeadersA(req, "Authorization: Bearer dXNlcjE6cHdkMQ==\r\n", ~0u, + HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD); + ok(ret, "HttpAddRequestHeaders Failed\n"); + + ret = HttpSendRequestA( req, NULL, 0, NULL, 0 ); + ok( ret, "HttpSendRequestA failed %u\n", GetLastError() ); + + status = 0xdeadbeef; + size = sizeof(status); + ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); + ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() ); + ok( status == 201, "got %u\n", status ); + + InternetCloseHandle( req ); + InternetCloseHandle( con ); + InternetCloseHandle( ses ); +} + static void test_async_read(int port) { HINTERNET ses, con, req; @@ -5873,6 +6042,8 @@ static void test_http_connection(void) test_basic_auth_credentials_reuse(si.port); test_basic_auth_credentials_end_session(si.port); test_basic_auth_credentials_different(si.port); + test_basic_auth_credentials_manual(si.port); + test_basic_auth_credentials_cached_manual(si.port); test_async_read(si.port); test_http_read(si.port); test_connection_break(si.port);
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=57729
Your paranoid android.
=== w7u (32 bit report) ===
wininet: http.c:7466: Test failed: HttpQueryInfoA failed 6 http.c:7467: Test failed: header missing
=== wvistau64 (64 bit report) ===
wininet: http.c:355: Test failed: unexpected status 30 (INTERNET_STATUS_SENDING_REQUEST) http.c:355: Test failed: unexpected status 31 (INTERNET_STATUS_REQUEST_SENT) http.c:355: Test failed: unexpected status 40 (INTERNET_STATUS_RECEIVING_RESPONSE) http.c:355: Test failed: unexpected status 50 (INTERNET_STATUS_CLOSING_CONNECTION) http.c:355: Test failed: unexpected status 51 (INTERNET_STATUS_CONNECTION_CLOSED) http.c:3296: Test failed: expected status 30 (INTERNET_STATUS_SENDING_REQUEST) 1 times, received 2 times http.c:3297: Test failed: expected status 31 (INTERNET_STATUS_REQUEST_SENT) 1 times, received 2 times http.c:3298: Test failed: expected status 40 (INTERNET_STATUS_RECEIVING_RESPONSE) 1 times, received 2 times http.c:5024: Test failed: expected bytes != 0 http.c:5034: Test failed: expected 1 pending read, got 2
=== debian10 (32 bit Chinese:China report) ===
wininet: http.c:4946: Test failed: expected 1 pending read, got 2
=== debian10 (32 bit WoW report) ===
wininet: http.c:5034: Test failed: expected 1 pending read, got 2