+ size = sizeof(buffer);
+ SetLastError(0xdeadbeef);
+ ret = InternetQueryOptionA(req, INTERNET_OPTION_USERNAME, buffer, &size);
+ ok(ret, "unexpected failure %u\n", GetLastError());
+ ok(!strcmp(buffer, "user"), "got %s\n", buffer);
+ ok(size == 4, "got %u\n", size);
+
+ size = sizeof(buffer);
+ SetLastError(0xdeadbeef);
+ ret = InternetQueryOptionA(req, INTERNET_OPTION_PASSWORD, buffer, &size);
+ ok(ret, "unexpected failure %u\n", GetLastError());
+ ok(!strcmp(buffer, "pwd"), "got %s\n", buffer);
+ ok(size == 3, "got %u\n", size);
+
+ 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 );
+}
+
+static void test_basic_auth_credentials_end_session(int port)
+{
+ HINTERNET ses, con, req;
+ DWORD status, size;
+ BOOL ret;
+ char buffer[0x40];
+
+ ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 );
+ ok( ses != NULL, "InternetOpenA failed\n" );
+
+ 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() );
+
+ size = sizeof(buffer);
+ SetLastError(0xdeadbeef);
+ ret = InternetQueryOptionA(req, INTERNET_OPTION_USERNAME, buffer, &size);
+ ok(ret, "unexpected failure %u\n", GetLastError());
+ ok(!strcmp(buffer, "user"), "got %s\n", buffer);
+ ok(size == 4, "got %u\n", size);
+
+ size = sizeof(buffer);
+ SetLastError(0xdeadbeef);
+ ret = InternetQueryOptionA(req, INTERNET_OPTION_PASSWORD, buffer, &size);
+ ok(ret, "unexpected failure %u\n", GetLastError());
+ ok(!strcmp(buffer, "pwd"), "got %s\n", buffer);
+ ok(size == 3, "got %u\n", size);
+
+ 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 == HTTP_STATUS_OK, "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" );
+
+ /* 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, "PUT", "/upload2.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() );
+
+ size = sizeof(buffer);
+ SetLastError(0xdeadbeef);
+ ret = InternetQueryOptionA(req, INTERNET_OPTION_USERNAME, buffer, &size);
+ ok(ret, "unexpected failure %u\n", GetLastError());
+ ok(!strcmp(buffer, ""), "got %s\n", buffer);
+ ok(size == 0, "got %u\n", size);
+
+ size = sizeof(buffer);
+ SetLastError(0xdeadbeef);
+ ret = InternetQueryOptionA(req, INTERNET_OPTION_PASSWORD, buffer, &size);
+ ok(ret, "unexpected failure %u\n", GetLastError());
+ ok(!strcmp(buffer, ""), "got %s\n", buffer);
+ ok(size == 0, "got %u\n", size);
+
+ 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 == HTTP_STATUS_BAD_REQUEST, "got %u\n", status );
+
+ InternetCloseHandle( req );
+ InternetCloseHandle( con );
+ InternetCloseHandle( ses );
+}
+
+static void test_basic_auth_credentials_different(int port)
+{
+ HINTERNET ses, con, req;
+ DWORD status, size;
+ BOOL ret;
+ char buffer[0x40];
+
+ ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 );
+ ok( ses != NULL, "InternetOpenA failed\n" );
+
+ 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() );
+
+ size = sizeof(buffer);
+ SetLastError(0xdeadbeef);
+ ret = InternetQueryOptionA(req, INTERNET_OPTION_USERNAME, buffer, &size);
+ ok(ret, "unexpected failure %u\n", GetLastError());
+ ok(!strcmp(buffer, "user"), "got %s\n", buffer);
+ ok(size == 4, "got %u\n", size);
+
+ size = sizeof(buffer);
+ SetLastError(0xdeadbeef);
+ ret = InternetQueryOptionA(req, INTERNET_OPTION_PASSWORD, buffer, &size);
+ ok(ret, "unexpected failure %u\n", GetLastError());
+ ok(!strcmp(buffer, "pwd"), "got %s\n", buffer);
+ ok(size == 3, "got %u\n", size);
+
+ 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, "user1", "pwd1",
+ INTERNET_SERVICE_HTTP, 0, 0 );
+ ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
+
+ req = HttpOpenRequestA( con, "HEAD", "/upload3.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() );
+
+ size = sizeof(buffer);
+ SetLastError(0xdeadbeef);
+ ret = InternetQueryOptionA(req, INTERNET_OPTION_USERNAME, buffer, &size);
+ ok(ret, "unexpected failure %u\n", GetLastError());
+ ok(!strcmp(buffer, "user1"), "got %s\n", buffer);
+ ok(size == 5, "got %u\n", size);
+
+ size = sizeof(buffer);
+ SetLastError(0xdeadbeef);
+ ret = InternetQueryOptionA(req, INTERNET_OPTION_PASSWORD, buffer, &size);
+ ok(ret, "unexpected failure %u\n", GetLastError());
+ ok(!strcmp(buffer, "pwd1"), "got %s\n", buffer);
+ ok(size == 4, "got %u\n", size);
+
+ 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 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() );
+