2 * Copyright 2005-2006 Jacek Caban for CodeWeavers
3 * Copyright 2009-2010 Detlef Riekenberg
4 * Copyright 2011 Thomas Mullaly for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #define NONAMELESSUNION
25 /* needed for IInternetZoneManagerEx2 */
26 #define _WIN32_IE 0x0700
28 #include <wine/test.h>
40 #define URLZONE_CUSTOM URLZONE_USER_MIN+1
41 #define URLZONE_CUSTOM2 URLZONE_CUSTOM+1
43 #define DEFINE_EXPECT(func) \
44 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
46 #define SET_EXPECT(func) \
47 expect_ ## func = TRUE
49 #define CHECK_EXPECT(func) \
51 ok(expect_ ##func, "unexpected call " #func "\n"); \
52 expect_ ## func = FALSE; \
53 called_ ## func = TRUE; \
56 #define CHECK_EXPECT2(func) \
58 ok(expect_ ##func, "unexpected call " #func "\n"); \
59 called_ ## func = TRUE; \
62 #define CHECK_CALLED(func) \
64 ok(called_ ## func, "expected " #func "\n"); \
65 expect_ ## func = called_ ## func = FALSE; \
68 DEFINE_EXPECT(ParseUrl_SECURITY_URL_input);
69 DEFINE_EXPECT(ParseUrl_SECURITY_URL_input2);
70 DEFINE_EXPECT(ParseUrl_SECURITY_URL_expected);
71 DEFINE_EXPECT(ParseUrl_SECURITY_URL_http);
72 DEFINE_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
74 static HRESULT (WINAPI *pCoInternetCreateSecurityManager)(IServiceProvider *, IInternetSecurityManager**, DWORD);
75 static HRESULT (WINAPI *pCoInternetCreateZoneManager)(IServiceProvider *, IInternetZoneManager**, DWORD);
76 static HRESULT (WINAPI *pCoInternetGetSecurityUrl)(LPCWSTR, LPWSTR*, PSUACTION, DWORD);
77 static HRESULT (WINAPI *pCoInternetGetSecurityUrlEx)(IUri*, IUri**, PSUACTION, DWORD_PTR);
78 static HRESULT (WINAPI *pCreateUri)(LPCWSTR, DWORD, DWORD_PTR, IUri**);
79 static HRESULT (WINAPI *pCoInternetGetSession)(DWORD, IInternetSession**, DWORD);
81 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
82 '/','b','l','a','n','k','.','h','t','m',0};
83 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
84 static const WCHAR url3[] = {'f','i','l','e',':','/','/','c',':','\\','I','n','d','e','x','.','h','t','m',0};
85 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
86 '%','2','e','j','p','g',0};
87 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','z','o','n','e','3',
88 '.','w','i','n','e','t','e','s','t',0};
89 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
90 static const WCHAR url7[] = {'f','t','p',':','/','/','z','o','n','e','3',
91 '.','w','i','n','e','t','e','s','t','/','f','i','l','e','.','t','e','s','t',0};
92 static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
93 static const WCHAR url9[] = {'h','t','t','p',':','/','/','w','w','w','.','z','o','n','e','3',
94 '.','w','i','n','e','t','e','s','t', '/','s','i','t','e','/','a','b','o','u','t',0};
95 static const WCHAR url10[] = {'f','i','l','e',':','/','/','s','o','m','e','%','2','0','f','i','l','e',
98 static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
101 static const WCHAR winetestW[] = {'w','i','n','e','t','e','s','t',0};
102 static const WCHAR security_urlW[] = {'w','i','n','e','t','e','s','t',':','t','e','s','t','i','n','g',0};
103 static const WCHAR security_url2W[] = {'w','i','n','e','t','e','s','t',':','t','e','s','t','i','n','g','2',0};
104 static const WCHAR security_expectedW[] = {'w','i','n','e','t','e','s','t',':','z','i','p',0};
105 static const WCHAR winetest_to_httpW[] = {'w','i','n','e','t','e','s','t',':','h',0};
107 static const char *szZoneMapDomainsKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains";
109 static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
110 static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','z','o','n','e','3',
111 '.','w','i','n','e','t','e','s','t',3,0,0,0};
112 static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
113 static const BYTE secid7[] = {'f','t','p',':','z','o','n','e','3',
114 '.','w','i','n','e','t','e','s','t',3,0,0,0};
115 static const BYTE secid10[] =
116 {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e','.','j','p','g',3,0,0,0};
117 static const BYTE secid10_2[] =
118 {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e','.','j','p','g',3,0,0,0};
120 static const GUID CLSID_TestActiveX =
121 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
123 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
124 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
125 {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
127 static int called_securl_http;
129 static struct secmgr_test {
137 {url1, 0, S_OK, sizeof(secid1), secid1, S_OK},
138 {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
139 {url3, 0, S_OK, sizeof(secid1), secid1, S_OK},
140 {url5, 3, S_OK, sizeof(secid5), secid5, S_OK},
141 {url6, 3, S_OK, sizeof(secid6), secid6, S_OK},
142 {url7, 3, S_OK, sizeof(secid7), secid7, S_OK}
145 static int strcmp_w(const WCHAR *str1, const WCHAR *str2)
147 DWORD len1 = lstrlenW(str1);
148 DWORD len2 = lstrlenW(str2);
150 if(len1!=len2) return 1;
151 return memcmp(str1, str2, len1*sizeof(WCHAR));
154 static inline void heap_free(void *mem)
156 HeapFree(GetProcessHeap(), 0, mem);
159 static inline LPWSTR a2w(LPCSTR str)
164 DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
165 ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
166 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
172 static inline DWORD strcmp_aw(LPCSTR strA, LPCWSTR strB) {
173 LPWSTR strAW = a2w(strA);
174 DWORD ret = lstrcmpW(strAW, strB);
179 static void test_SecurityManager(void)
182 IInternetSecurityManager *secmgr = NULL;
184 DWORD zone, size, policy;
187 if(!pCoInternetCreateSecurityManager) {
191 trace("Testing security manager...\n");
193 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
194 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
198 for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
200 hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
202 ok(hres == secmgr_tests[i].zone_hres /* IE <=6 */
203 || (FAILED(secmgr_tests[i].zone_hres) && hres == E_INVALIDARG), /* IE7 */
204 "[%d] MapUrlToZone failed: %08x, expected %08x\n",
205 i, hres, secmgr_tests[i].zone_hres);
207 ok(zone == secmgr_tests[i].zone, "[%d] zone=%d, expected %d\n", i, zone,
208 secmgr_tests[i].zone);
210 ok(zone == secmgr_tests[i].zone || zone == -1, "[%d] zone=%d\n", i, zone);
213 memset(buf, 0xf0, sizeof(buf));
214 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
216 ok(hres == secmgr_tests[i].secid_hres,
217 "[%d] GetSecurityId failed: %08x, expected %08x\n",
218 i, hres, secmgr_tests[i].secid_hres);
219 if(secmgr_tests[i].secid) {
220 ok(size == secmgr_tests[i].secid_size, "[%d] size=%d, expected %d\n",
221 i, size, secmgr_tests[i].secid_size);
222 ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
227 hres = IInternetSecurityManager_MapUrlToZone(secmgr, url10, &zone, 0);
228 ok(hres == S_OK, "MapUrlToZone failed: %08x, expected S_OK\n", hres);
229 ok(zone == 3, "zone=%d, expected 3\n", zone);
231 /* win2k3 translates %20 into a space */
233 memset(buf, 0xf0, sizeof(buf));
234 hres = IInternetSecurityManager_GetSecurityId(secmgr, url10, buf, &size, 0);
235 ok(hres == S_OK, "GetSecurityId failed: %08x, expected S_OK\n", hres);
236 ok(size == sizeof(secid10) ||
237 size == sizeof(secid10_2), /* win2k3 */
239 ok(!memcmp(buf, secid10, size) ||
240 !memcmp(buf, secid10_2, size), /* win2k3 */
244 hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
245 ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08x, expected E_INVALIDARG\n", hres);
246 ok(zone == 100 || zone == -1, "zone=%d\n", zone);
249 hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
250 ok(hres == E_INVALIDARG,
251 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
252 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
254 ok(hres == E_INVALIDARG,
255 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
256 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
258 ok(hres == E_INVALIDARG,
259 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
261 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, NULL, URLACTION_SCRIPT_RUN, (BYTE*)&policy,
262 sizeof(WCHAR), NULL, 0, 0, 0);
263 ok(hres == E_INVALIDARG, "ProcessUrlAction failed: %08x, expected E_INVALIDARG\n", hres);
265 IInternetSecurityManager_Release(secmgr);
268 /* Check if Internet Explorer is configured to run in "Enhanced Security Configuration" (aka hardened mode) */
269 /* Note: this code is duplicated in dlls/mshtml/tests/mshtml_test.h and dlls/urlmon/tests/sec_mgr.c */
270 static BOOL is_ie_hardened(void)
273 DWORD ie_harden, type, size;
276 if(RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap",
277 0, KEY_QUERY_VALUE, &zone_map) == ERROR_SUCCESS) {
278 size = sizeof(DWORD);
279 if (RegQueryValueExA(zone_map, "IEHarden", NULL, &type, (LPBYTE) &ie_harden, &size) != ERROR_SUCCESS ||
283 RegCloseKey(zone_map);
286 return ie_harden != 0;
289 static void test_url_action(IInternetSecurityManager *secmgr, IInternetZoneManager *zonemgr, DWORD action)
291 DWORD res, size, policy, reg_policy;
296 /* FIXME: HKEY_CURRENT_USER is most of the time the default but this can be changed on a system.
297 * The test should be changed to cope with that, if need be.
299 res = RegOpenKeyA(HKEY_CURRENT_USER,
300 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3", &hkey);
301 if(res != ERROR_SUCCESS) {
302 ok(0, "Could not open zone key\n");
306 wsprintf(buf, "%X", action);
307 size = sizeof(DWORD);
308 res = RegQueryValueExA(hkey, buf, NULL, NULL, (BYTE*)®_policy, &size);
310 if(res != ERROR_SUCCESS || size != sizeof(DWORD)) {
312 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
313 sizeof(WCHAR), NULL, 0, 0, 0);
314 ok(hres == E_FAIL || broken(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
315 "(0x%x) got 0x%x (expected E_FAIL)\n", action, hres);
316 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
319 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
320 sizeof(DWORD), URLZONEREG_DEFAULT);
321 ok(hres == E_FAIL || broken(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
322 "(0x%x) got 0x%x (expected E_FAIL)\n", action, hres);
323 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
328 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
329 sizeof(DWORD), URLZONEREG_DEFAULT);
330 ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
331 ok(policy == reg_policy, "(%x) policy=%x, expected %x\n", action, policy, reg_policy);
333 if(policy != URLPOLICY_QUERY) {
334 if(winetest_interactive || ! is_ie_hardened()) {
335 BOOL expect_parse_call = !called_securl_http;
338 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
339 sizeof(WCHAR), NULL, 0, 0, 0);
340 if(reg_policy == URLPOLICY_DISALLOW)
341 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
343 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
344 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
347 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
349 if(reg_policy == URLPOLICY_DISALLOW)
350 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
352 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
353 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
356 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
357 sizeof(DWORD), NULL, 0, 0, 0);
358 if(reg_policy == URLPOLICY_DISALLOW)
359 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
361 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
362 ok(policy == reg_policy, "(%x) policy=%x\n", action, policy);
365 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
366 sizeof(WCHAR), (BYTE*)0xdeadbeef, 16, 0, 0);
367 if(reg_policy == URLPOLICY_DISALLOW)
368 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
370 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
371 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
374 if(expect_parse_call)
375 SET_EXPECT(ParseUrl_SECURITY_URL_http);
376 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, winetest_to_httpW, action, (BYTE*)&policy,
377 sizeof(DWORD), NULL, 0, 0, 0);
378 if(expect_parse_call)
379 CHECK_CALLED(ParseUrl_SECURITY_URL_http);
380 if(reg_policy == URLPOLICY_DISALLOW)
381 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
383 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
384 ok(policy == reg_policy, "(%x) policy=%x\n", action, policy);
386 skip("IE running in Enhanced Security Configuration\n");
391 static void test_special_url_action(IInternetSecurityManager *secmgr, IInternetZoneManager *zonemgr, DWORD action)
397 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
398 sizeof(DWORD), URLZONEREG_DEFAULT);
399 ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
400 ok(policy == URLPOLICY_DISALLOW, "(%x) policy=%x, expected URLPOLICY_DISALLOW\n", action, policy);
403 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, action, (BYTE*)&policy,
404 sizeof(WCHAR), NULL, 0, 0, 0);
405 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
408 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, action, (BYTE*)&policy,
409 sizeof(DWORD), NULL, 0, 0, 0);
410 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
411 ok(policy == URLPOLICY_DISALLOW, "policy = %x\n", policy);
414 static void test_activex(IInternetSecurityManager *secmgr)
416 DWORD policy, policy_size;
417 struct CONFIRMSAFETY cs;
422 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, URLACTION_ACTIVEX_RUN, (BYTE*)&policy,
423 sizeof(DWORD), (BYTE*)&CLSID_TestActiveX, sizeof(CLSID), 0, 0);
424 ok(hres == S_OK, "ProcessUrlAction(URLACTION_ACTIVEX_RUN) failed: %08x\n", hres);
425 ok(policy == URLPOLICY_ALLOW || policy == URLPOLICY_DISALLOW, "policy = %x\n", policy);
427 cs.clsid = CLSID_TestActiveX;
428 cs.pUnk = (IUnknown*)0xdeadbeef;
430 hres = IInternetSecurityManager_QueryCustomPolicy(secmgr, url1, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
431 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
432 ok(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), "QueryCusromPolicy failed: %08x\n", hres);
435 static void test_polices(void)
437 IInternetZoneManager *zonemgr = NULL;
438 IInternetSecurityManager *secmgr = NULL;
441 trace("testing polices...\n");
443 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
444 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
445 hres = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
446 ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
448 test_url_action(secmgr, zonemgr, URLACTION_SCRIPT_RUN);
449 test_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_RUN);
450 test_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_OVERRIDE_OBJECT_SAFETY);
451 test_url_action(secmgr, zonemgr, URLACTION_CHANNEL_SOFTDIST_PERMISSIONS);
452 test_url_action(secmgr, zonemgr, 0xdeadbeef);
454 test_special_url_action(secmgr, zonemgr, URLACTION_SCRIPT_OVERRIDE_SAFETY);
455 test_special_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY);
457 test_activex(secmgr);
459 IInternetSecurityManager_Release(secmgr);
460 IInternetZoneManager_Release(zonemgr);
463 /* IE (or at least newer versions of it) seem to cache the keys in ZoneMap
464 * when urlmon.dll is loaded and it doesn't seem to update its cache, unless
465 * SetZoneMapping is used.
467 static void test_zone_domain_cache(void)
471 IInternetSecurityManager *secmgr = NULL;
472 HKEY domains, domain;
474 static const WCHAR testing_domain_urlW[] = {'h','t','t','p',':','/','/','t','e','s','t','i','n','g','.',
475 'd','o','m','a','i','n','/',0};
477 res = RegOpenKeyA(HKEY_CURRENT_USER, szZoneMapDomainsKey, &domains);
478 ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
479 if(res != ERROR_SUCCESS)
482 res = RegCreateKeyA(domains, "testing.domain", &domain);
483 ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
484 if(res != ERROR_SUCCESS) {
485 RegCloseKey(domains);
489 zone = URLZONE_CUSTOM;
490 res = RegSetValueExA(domain, "http", 0, REG_DWORD, (BYTE*)&zone, sizeof(DWORD));
491 ok(res == ERROR_SUCCESS, "RegSetValueEx failed: %d\n", res);
495 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
496 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
498 zone = URLZONE_INVALID;
499 hres = IInternetSecurityManager_MapUrlToZone(secmgr, testing_domain_urlW, &zone, 0);
500 ok(hres == S_OK, "MapUrlToZone failed: %08x\n", hres);
501 todo_wine ok(zone == URLZONE_INTERNET, "Got %d, expected URLZONE_INTERNET\n", zone);
503 /* FIXME: Play nice with ZoneMaps that existed before the test is run. */
504 res = RegDeleteKeyA(domains, "testing.domain");
505 ok(res == ERROR_SUCCESS, "RegDeleteKey failed: %d\n", res);
507 RegCloseKey(domains);
508 IInternetSecurityManager_Release(secmgr);
513 const char *subdomain;
516 } zone_domain_mapping;
518 /* FIXME: Move these into SetZoneMapping tests when the day comes... */
519 static const zone_domain_mapping zone_domain_mappings[] = {
520 /* Implicitly means "*.yabadaba.do". */
521 {"yabadaba.do",NULL,"http",URLZONE_CUSTOM},
522 /* The '*' doesn't count as a wildcard, since its not the first component of the subdomain. */
523 {"super.cool","testing.*","ftp",URLZONE_CUSTOM2},
524 /* The '*' counts since it's the first component of the subdomain. */
525 {"super.cool","*.testing","ftp",URLZONE_CUSTOM2},
526 /* All known scheme types apply to wildcard schemes. */
527 {"tests.test",NULL,"*",URLZONE_CUSTOM},
528 /* Due to a defect with how windows checks the mappings, unknown scheme types
529 * never seem to get mapped properly. */
530 {"tests.test",NULL,"zip",URLZONE_CUSTOM},
531 {"www.testing.com",NULL,"http",URLZONE_CUSTOM},
532 {"www.testing.com","testing","http",URLZONE_CUSTOM2},
533 {"org",NULL,"http",URLZONE_CUSTOM},
534 {"org","testing","http",URLZONE_CUSTOM2}
537 static void register_zone_domains(void)
542 /* Some Windows versions don't seem to have a "Domains" key in their HKLM. */
543 res = RegOpenKeyA(HKEY_LOCAL_MACHINE, szZoneMapDomainsKey, &domains);
544 ok(res == ERROR_SUCCESS || broken(res == ERROR_FILE_NOT_FOUND), "RegOpenKey failed: %d\n", res);
545 if(res == ERROR_SUCCESS) {
547 DWORD zone = URLZONE_CUSTOM;
549 res = RegCreateKeyA(domains, "local.machine", &domain);
550 ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
552 res = RegSetValueExA(domain, "http", 0, REG_DWORD, (BYTE*)&zone, sizeof(DWORD));
553 ok(res == ERROR_SUCCESS, "RegSetValueEx failed: %d\n", res);
556 RegCloseKey(domains);
559 res = RegOpenKeyA(HKEY_CURRENT_USER, szZoneMapDomainsKey, &domains);
560 ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
562 for(i = 0; i < sizeof(zone_domain_mappings)/sizeof(zone_domain_mappings[0]); ++i) {
563 const zone_domain_mapping *test = zone_domain_mappings+i;
566 res = RegCreateKeyA(domains, test->domain, &domain);
567 ok(res == ERROR_SUCCESS, "RegCreateKey failed with %d on test %d\n", res, i);
569 /* Only set the value if there's no subdomain. */
570 if(!test->subdomain) {
571 res = RegSetValueExA(domain, test->scheme, 0, REG_DWORD, (BYTE*)&test->zone, sizeof(DWORD));
572 ok(res == ERROR_SUCCESS, "RegSetValueEx failed with %d on test %d\n", res, i);
576 res = RegCreateKeyA(domain, test->subdomain, &subdomain);
577 ok(res == ERROR_SUCCESS, "RegCreateKey failed with %d on test %d\n", res, i);
579 res = RegSetValueExA(subdomain, test->scheme, 0, REG_DWORD, (BYTE*)&test->zone, sizeof(DWORD));
580 ok(res == ERROR_SUCCESS, "RegSetValueEx failed with %d on test %d\n", res, i);
582 RegCloseKey(subdomain);
588 RegCloseKey(domains);
591 static void unregister_zone_domains(void)
596 res = RegOpenKeyA(HKEY_LOCAL_MACHINE, szZoneMapDomainsKey, &domains);
597 ok(res == ERROR_SUCCESS || broken(res == ERROR_FILE_NOT_FOUND), "RegOpenKey failed: %d\n", res);
598 if(res == ERROR_SUCCESS) {
599 RegDeleteKeyA(domains, "local.machine");
600 RegCloseKey(domains);
603 res = RegOpenKeyA(HKEY_CURRENT_USER, szZoneMapDomainsKey, &domains);
604 ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
606 for(i = 0; i < sizeof(zone_domain_mappings)/sizeof(zone_domain_mappings[0]); ++i) {
607 const zone_domain_mapping *test = zone_domain_mappings+i;
609 /* FIXME: Uses the "cludge" approach to remove the test data from the registry!
610 * Although, if domain names are... unique, this shouldn't cause any harm
611 * to keys (if any) that existed before the tests.
613 if(test->subdomain) {
616 res = RegOpenKeyA(domains, test->domain, &domain);
617 if(res == ERROR_SUCCESS) {
618 RegDeleteKeyA(domain, test->subdomain);
622 RegDeleteKeyA(domains, test->domain);
625 RegCloseKey(domains);
628 static void run_child_process(void)
630 char cmdline[MAX_PATH];
633 PROCESS_INFORMATION pi;
634 STARTUPINFO si = { 0 };
637 GetModuleFileNameA(NULL, path, MAX_PATH);
640 winetest_get_mainargs(&argv);
641 sprintf(cmdline, "\"%s\" %s domain_tests", argv[0], argv[1]);
642 ret = CreateProcess(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
643 ok(ret, "Failed to spawn child process: %u\n", GetLastError());
644 winetest_wait_child_process(pi.hProcess);
645 CloseHandle(pi.hThread);
646 CloseHandle(pi.hProcess);
656 static const zone_mapping_test zone_mapping_tests[] = {
657 /* Tests for "yabadaba.do" zone mappings. */
658 {"http://yabadaba.do/",URLZONE_CUSTOM},
659 {"http://google.yabadaba.do/",URLZONE_CUSTOM},
660 {"zip://yabadaba.do/",URLZONE_INTERNET},
661 /* Tests for "super.cool" zone mappings. */
662 {"ftp://testing.google.super.cool/",URLZONE_INTERNET},
663 {"ftp://testing.*.super.cool/",URLZONE_CUSTOM2},
664 {"ftp://google.testing.super.cool/",URLZONE_CUSTOM2},
665 /* Tests for "tests.test" zone mappings. */
666 {"http://tests.test/",URLZONE_CUSTOM},
667 {"http://www.tests.test/",URLZONE_CUSTOM},
668 {"ftp://tests.test/",URLZONE_CUSTOM},
669 {"ftp://www.tests.test/",URLZONE_CUSTOM},
670 {"test://www.tests.test/",URLZONE_INTERNET},
671 {"test://tests.test/",URLZONE_INTERNET},
672 {"zip://www.tests.test/",URLZONE_INTERNET},
673 {"zip://tests.test/",URLZONE_INTERNET},
674 /* Tests for "www.testing.com" zone mappings. */
675 {"http://google.www.testing.com/",URLZONE_INTERNET},
676 {"http://www.testing.com/",URLZONE_CUSTOM,FALSE,URLZONE_INTERNET},
677 {"http://testing.www.testing.com/",URLZONE_CUSTOM2,FALSE,URLZONE_INTERNET},
678 /* Tests for "org" zone mappings. */
679 {"http://google.org/",URLZONE_INTERNET,FALSE,URLZONE_CUSTOM},
680 {"http://org/",URLZONE_CUSTOM},
681 {"http://testing.org/",URLZONE_CUSTOM2}
684 static void test_zone_domain_mappings(void)
688 IInternetSecurityManager *secmgr = NULL;
690 DWORD zone = URLZONE_INVALID;
692 trace("testing zone domain mappings...\n");
694 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
695 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
697 res = RegOpenKeyA(HKEY_LOCAL_MACHINE, szZoneMapDomainsKey, &domains);
698 if(res == ERROR_SUCCESS) {
699 static const WCHAR local_machineW[] = {'h','t','t','p',':','/','/','t','e','s','t','.','l','o','c','a','l',
700 '.','m','a','c','h','i','n','e','/',0};
702 hres = IInternetSecurityManager_MapUrlToZone(secmgr, local_machineW, &zone, 0);
703 ok(hres == S_OK, "MapUrlToZone failed: %08x\n", hres);
704 ok(zone == URLZONE_CUSTOM, "Expected URLZONE_CUSTOM, but got %d\n", zone);
706 RegCloseKey(domains);
709 for(i = 0; i < sizeof(zone_mapping_tests)/sizeof(zone_mapping_tests[0]); ++i) {
710 const zone_mapping_test *test = zone_mapping_tests+i;
711 LPWSTR urlW = a2w(test->url);
712 zone = URLZONE_INVALID;
714 hres = IInternetSecurityManager_MapUrlToZone(secmgr, urlW, &zone, 0);
715 ok(hres == S_OK, "MapUrlToZone failed: %08x\n", hres);
718 ok(zone == test->zone || broken(test->broken_zone == zone),
719 "Expected %d, but got %d on test %d\n", test->zone, zone, i);
721 ok(zone == test->zone || broken(test->broken_zone == zone),
722 "Expected %d, but got %d on test %d\n", test->zone, zone, i);
727 IInternetSecurityManager_Release(secmgr);
730 static void test_zone_domains(void)
732 if(is_ie_hardened()) {
733 skip("IE running in Enhanced Security Configuration\n");
735 } else if(!pCreateUri) {
736 win_skip("Skipping zone domain tests, IE too old\n");
740 trace("testing zone domains...\n");
742 test_zone_domain_cache();
744 register_zone_domains();
746 unregister_zone_domains();
749 static void test_CoInternetCreateZoneManager(void)
751 IInternetZoneManager *zonemgr = NULL;
752 IUnknown *punk = NULL;
755 trace("simple zone manager tests...\n");
757 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
758 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
762 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IUnknown, (void **) &punk);
763 ok(SUCCEEDED(hr), "got 0x%x with %p (expected Success)\n", hr, punk);
765 IUnknown_Release(punk);
767 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IInternetZoneManager, (void **) &punk);
768 ok(SUCCEEDED(hr), "got 0x%x with %p (expected Success)\n", hr, punk);
770 IUnknown_Release(punk);
773 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IInternetZoneManagerEx, (void **) &punk);
775 IUnknown_Release(punk);
777 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IInternetZoneManagerEx2, (void **) &punk);
778 ok(hr == S_OK || broken(hr == E_NOINTERFACE /* some W2K3 */),
779 "got 0x%x (expected S_OK)\n", hr);
781 IUnknown_Release(punk);
783 win_skip("InternetZoneManagerEx2 not supported\n");
787 win_skip("InternetZoneManagerEx not supported\n");
789 hr = IInternetZoneManager_Release(zonemgr);
790 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
794 static void test_CreateZoneEnumerator(void)
796 IInternetZoneManager *zonemgr = NULL;
803 trace("testing zone enumerator...\n");
805 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
806 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
811 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, NULL, 0);
812 ok((hr == E_INVALIDARG) && (dwEnum == 0xdeadbeef),
813 "got 0x%x with 0x%x (expected E_INVALIDARG with 0xdeadbeef)\n", hr, dwEnum);
816 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, NULL, &dwCount, 0);
817 ok((hr == E_INVALIDARG) && (dwCount == 0xdeadbeef),
818 "got 0x%x and 0x%x (expected E_INVALIDARG and 0xdeadbeef)\n", hr, dwCount);
822 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 0xffffffff);
823 ok((hr == E_INVALIDARG) && (dwEnum == 0xdeadbeef) && (dwCount == 0xdeadbeef),
824 "got 0x%x with 0x%x and 0x%x (expected E_INVALIDARG with 0xdeadbeef and 0xdeadbeef)\n",
825 hr, dwEnum, dwCount);
829 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 1);
830 ok((hr == E_INVALIDARG) && (dwEnum == 0xdeadbeef) && (dwCount == 0xdeadbeef),
831 "got 0x%x with 0x%x and 0x%x (expected E_INVALIDARG with 0xdeadbeef and 0xdeadbeef)\n",
832 hr, dwEnum, dwCount);
837 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 0);
838 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
843 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum2, &dwCount2, 0);
844 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
846 /* native urlmon has an incrementing counter for dwEnum */
847 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum2);
848 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
851 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum);
852 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
854 /* Destroy the Enumerator twice is detected and handled in native urlmon */
855 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum);
856 ok((hr == E_INVALIDARG), "got 0x%x (expected E_INVALIDARG)\n", hr);
859 /* ::Release succeed also, when a ::DestroyZoneEnumerator is missing */
860 hr = IInternetZoneManager_Release(zonemgr);
861 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
864 static void test_GetZoneActionPolicy(void)
866 IInternetZoneManager *zonemgr = NULL;
869 DWORD action = URLACTION_CREDENTIALS_USE; /* Implemented on all IE versions */
871 trace("testing GetZoneActionPolixy...\n");
873 hres = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
874 ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
878 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, buf,
879 sizeof(DWORD), URLZONEREG_DEFAULT);
880 ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
881 ok(*(DWORD*)buf == URLPOLICY_CREDENTIALS_SILENT_LOGON_OK ||
882 *(DWORD*)buf == URLPOLICY_CREDENTIALS_MUST_PROMPT_USER ||
883 *(DWORD*)buf == URLPOLICY_CREDENTIALS_CONDITIONAL_PROMPT ||
884 *(DWORD*)buf == URLPOLICY_CREDENTIALS_ANONYMOUS_ONLY,
885 "unexpected policy=%d\n", *(DWORD*)buf);
887 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, NULL,
888 sizeof(DWORD), URLZONEREG_DEFAULT);
889 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
891 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, buf,
892 2, URLZONEREG_DEFAULT);
893 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
895 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
896 sizeof(DWORD), URLZONEREG_DEFAULT);
897 ok(hres == E_FAIL || broken(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
898 "(0x%x) got 0x%x (expected E_FAIL)\n", action, hres);
900 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, action, buf,
901 sizeof(DWORD), URLZONEREG_DEFAULT);
902 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
904 IInternetZoneManager_Release(zonemgr);
907 static void test_GetZoneAt(void)
909 IInternetZoneManager *zonemgr = NULL;
916 trace("testing GetZoneAt...\n");
918 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
919 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
923 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 0);
928 /* this crashes with native urlmon */
929 IInternetZoneManager_GetZoneAt(zonemgr, dwEnum, 0, NULL);
933 hr = IInternetZoneManager_GetZoneAt(zonemgr, 0xdeadbeef, 0, &dwZone);
934 ok(hr == E_INVALIDARG,
935 "got 0x%x with 0x%x (expected E_INVALIDARG)\n", hr, dwZone);
937 for (i = 0; i < dwCount; i++)
940 hr = IInternetZoneManager_GetZoneAt(zonemgr, dwEnum, i, &dwZone);
941 ok(hr == S_OK, "#%d: got x%x with %d (expected S_OK)\n", i, hr, dwZone);
945 /* MSDN (index .. must be .. less than or equal to) is wrong */
946 hr = IInternetZoneManager_GetZoneAt(zonemgr, dwEnum, dwCount, &dwZone);
947 ok(hr == E_INVALIDARG,
948 "got 0x%x with 0x%x (expected E_INVALIDARG)\n", hr, dwZone);
950 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum);
951 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
954 hr = IInternetZoneManager_Release(zonemgr);
955 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
958 static void test_GetZoneAttributes(void)
960 IInternetZoneManager *zonemgr = NULL;
961 CHAR buffer [sizeof(ZONEATTRIBUTES) + 32];
962 ZONEATTRIBUTES* pZA = (ZONEATTRIBUTES*) buffer;
966 trace("testing GetZoneAttributes...\n");
968 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
969 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
973 /* native urlmon has Zone "0" up to Zone "4" since IE4 */
974 for (i = 0; i < 5; i++) {
975 memset(buffer, -1, sizeof(buffer));
976 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, i, pZA);
977 ok(hr == S_OK, "#%d: got 0x%x (expected S_OK)\n", i, hr);
980 /* IE8 no longer set cbSize */
981 memset(buffer, -1, sizeof(buffer));
983 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, pZA);
984 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
985 ok((pZA->cbSize == 0) || (pZA->cbSize == sizeof(ZONEATTRIBUTES)),
986 "got cbSize = %d (expected 0)\n", pZA->cbSize);
988 memset(buffer, -1, sizeof(buffer));
990 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, pZA);
991 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
992 ok((pZA->cbSize == 64) || (pZA->cbSize == sizeof(ZONEATTRIBUTES)),
993 "got cbSize = %d (expected 64)\n", pZA->cbSize);
995 memset(buffer, -1, sizeof(buffer));
996 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, pZA);
997 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
998 ok((pZA->cbSize == 0xffffffff) || (pZA->cbSize == sizeof(ZONEATTRIBUTES)),
999 "got cbSize = 0x%x (expected 0xffffffff)\n", pZA->cbSize);
1001 /* IE8 no longer fail on invalid zones */
1002 memset(buffer, -1, sizeof(buffer));
1003 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0xdeadbeef, pZA);
1004 ok(hr == S_OK || (hr == E_FAIL),
1005 "got 0x%x (expected S_OK or E_FAIL)\n", hr);
1007 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, NULL);
1008 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1010 hr = IInternetZoneManager_Release(zonemgr);
1011 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1014 static void test_InternetSecurityMarshalling(void)
1016 IInternetSecurityManager *secmgr = NULL;
1021 trace("testing marshalling...\n");
1023 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
1024 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
1028 hres = IInternetSecurityManager_QueryInterface(secmgr, &IID_IUnknown, (void**)&unk);
1029 ok(hres == S_OK, "QueryInterface returned: %08x\n", hres);
1031 hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1032 ok(hres == S_OK, "CreateStreamOnHGlobal returned: %08x\n", hres);
1034 hres = CoMarshalInterface(stream, &IID_IInternetSecurityManager, unk, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
1035 /* Not supported in W98 */
1036 ok(hres == S_OK || broken(hres == REGDB_E_IIDNOTREG),
1037 "CoMarshalInterface returned: %08x\n", hres);
1039 IStream_Release(stream);
1040 IUnknown_Release(unk);
1041 IInternetSecurityManager_Release(secmgr);
1044 static void test_InternetGetSecurityUrl(void)
1046 const WCHAR url5_out[] = {'h','t','t','p',':','w','w','w','.','z','o','n','e','3',
1047 '.','w','i','n','e','t','e','s','t',0};
1048 const WCHAR url7_out[] = {'f','t','p',':','z','o','n','e','3','.','w','i','n','e','t','e','s','t',0};
1050 const WCHAR *in[] = {url2, url3, url4, url5, url7, url8, url9, url10};
1051 const WCHAR *out_default[] = {url2, url3, url4, url5_out, url7_out, url8, url5_out, url10};
1052 const WCHAR *out_securl[] = {url2, url3, url4, url5, url7, url8, url9, url10};
1058 trace("testing CoInternetGetSecurityUrl...\n");
1060 for(i=0; i<sizeof(in)/sizeof(WCHAR*); i++) {
1061 hres = pCoInternetGetSecurityUrl(in[i], &sec, PSU_DEFAULT, 0);
1062 ok(hres == S_OK, "(%d) CoInternetGetSecurityUrl returned: %08x\n", i, hres);
1064 ok(!strcmp_w(sec, out_default[i]), "(%d) Got %s, expected %s\n",
1065 i, wine_dbgstr_w(sec), wine_dbgstr_w(out_default[i]));
1069 hres = pCoInternetGetSecurityUrl(in[i], &sec, PSU_SECURITY_URL_ONLY, 0);
1070 ok(hres == S_OK, "(%d) CoInternetGetSecurityUrl returned: %08x\n", i, hres);
1072 ok(!strcmp_w(sec, out_securl[i]), "(%d) Got %s, expected %s\n",
1073 i, wine_dbgstr_w(sec), wine_dbgstr_w(out_securl[i]));
1078 SET_EXPECT(ParseUrl_SECURITY_URL_input2);
1079 SET_EXPECT(ParseUrl_SECURITY_URL_expected);
1080 SET_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
1082 hres = pCoInternetGetSecurityUrl(security_url2W, &sec, PSU_DEFAULT, 0);
1083 ok(hres == S_OK, "CoInternetGetSecurityUrl returned 0x%08x, expected S_OK\n", hres);
1085 CHECK_CALLED(ParseUrl_SECURITY_URL_input2);
1086 CHECK_CALLED(ParseUrl_SECURITY_URL_expected);
1087 CHECK_CALLED(ParseUrl_SECURITY_DOMAIN_expected);
1089 ok(!lstrcmpW(security_expectedW, sec), "Expected %s but got %s\n",
1090 wine_dbgstr_w(security_expectedW), wine_dbgstr_w(sec));
1094 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
1095 REFIID riid, void **ppv)
1097 ok(0, "unexpected call\n");
1098 return E_NOINTERFACE;
1101 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
1106 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
1111 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
1112 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
1113 DWORD *pcchResult, DWORD dwReserved)
1115 const WCHAR *ret = NULL;
1117 ok(pwzResult != NULL, "pwzResult == NULL\n");
1118 ok(pcchResult != NULL, "pcchResult == NULL\n");
1119 ok(!dwParseFlags, "Expected 0, but got 0x%08x\n", dwParseFlags);
1121 switch(ParseAction) {
1122 case PARSE_SECURITY_URL:
1123 if(!strcmp_w(pwzUrl, security_urlW)) {
1124 CHECK_EXPECT(ParseUrl_SECURITY_URL_input);
1125 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1126 ret = security_expectedW;
1127 } else if(!strcmp_w(pwzUrl, security_url2W)) {
1128 CHECK_EXPECT(ParseUrl_SECURITY_URL_input2);
1129 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1130 ret = security_expectedW;
1131 } else if(!strcmp_w(pwzUrl, security_expectedW)) {
1132 CHECK_EXPECT(ParseUrl_SECURITY_URL_expected);
1133 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1134 ret = security_expectedW;
1135 } else if(!strcmp_w(pwzUrl, winetest_to_httpW)) {
1136 switch(++called_securl_http) {
1138 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1141 CHECK_EXPECT(ParseUrl_SECURITY_URL_http);
1142 ok(cchResult == lstrlenW(url9)+1, "Got %d\n", cchResult);
1145 todo_wine CHECK_EXPECT(ParseUrl_SECURITY_URL_http);
1149 ok(0, "Unexpected call, pwzUrl=%s\n", wine_dbgstr_w(pwzUrl));
1152 case PARSE_SECURITY_DOMAIN:
1154 CHECK_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
1156 ok(!strcmp_w(pwzUrl, security_expectedW), "Expected %s but got %s\n",
1157 wine_dbgstr_w(security_expectedW), wine_dbgstr_w(pwzUrl));
1158 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1159 ret = security_expectedW;
1162 ok(0, "Unexpected call, ParseAction=%d pwzUrl=%s\n", ParseAction,
1163 wine_dbgstr_w(pwzUrl));
1169 *pcchResult = lstrlenW(ret)+1;
1170 if(*pcchResult > cchResult)
1172 memcpy(pwzResult, ret, (*pcchResult)*sizeof(WCHAR));
1176 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
1177 LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
1178 LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
1180 ok(0, "unexpected call\n");
1184 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
1185 LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
1187 ok(0, "unexpected call\n");
1191 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
1192 LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
1193 DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
1195 ok(0, "unexpected call\n");
1199 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
1200 InternetProtocolInfo_QueryInterface,
1201 InternetProtocolInfo_AddRef,
1202 InternetProtocolInfo_Release,
1203 InternetProtocolInfo_ParseUrl,
1204 InternetProtocolInfo_CombineUrl,
1205 InternetProtocolInfo_CompareUrl,
1206 InternetProtocolInfo_QueryInfo
1209 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
1211 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1213 if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
1214 *ppv = &protocol_info;
1218 ok(0, "unexpected call\n");
1219 return E_NOINTERFACE;
1222 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1227 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1232 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1233 REFIID riid, void **ppv)
1235 ok(0, "unexpected call\n");
1239 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1241 ok(0, "unexpected call\n");
1245 static const IClassFactoryVtbl ClassFactoryVtbl = {
1246 ClassFactory_QueryInterface,
1247 ClassFactory_AddRef,
1248 ClassFactory_Release,
1249 ClassFactory_CreateInstance,
1250 ClassFactory_LockServer
1253 static IClassFactory protocol_cf = { &ClassFactoryVtbl };
1255 static void register_protocols(void)
1257 IInternetSession *session;
1260 hres = pCoInternetGetSession(0, &session, 0);
1261 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1265 hres = IInternetSession_RegisterNameSpace(session, &protocol_cf, &IID_NULL,
1266 winetestW, 0, NULL, 0);
1267 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1269 IInternetSession_Release(session);
1272 static void unregister_protocols(void) {
1273 IInternetSession *session;
1276 hr = pCoInternetGetSession(0, &session, 0);
1277 ok(hr == S_OK, "CoInternetGetSession failed: 0x%08x\n", hr);
1281 hr = IInternetSession_UnregisterNameSpace(session, &protocol_cf, winetestW);
1282 ok(hr == S_OK, "UnregisterNameSpace failed: 0x%08x\n", hr);
1284 IInternetSession_Release(session);
1287 static const struct {
1290 const char *security_uri;
1291 HRESULT security_hres;
1292 const char *default_uri;
1293 HRESULT default_hres;
1295 } sec_url_ex_tests[] = {
1296 {"index.htm",Uri_CREATE_ALLOW_RELATIVE,"*:index.html",S_OK,"*:index.htm",S_OK},
1297 {"file://c:\\Index.htm",Uri_CREATE_FILE_USE_DOS_PATH,"file:///c:/Index.htm",S_OK,"file:///c:/Index.htm",S_OK},
1298 {"file:some%20file%2ejpg",0,NULL,E_INVALIDARG,NULL,E_INVALIDARG},
1299 {"file:some file.jpg",0,NULL,E_INVALIDARG,NULL,E_INVALIDARG},
1300 {"http://www.zone3.winetest/",0,"http://www.zone3.winetest/",S_OK,"http://www.zone3.winetest/",S_OK},
1301 {"about:blank",0,"about:blank",S_OK,"about:blank",S_OK},
1302 {"ftp://zone3.winetest/file.test",0,"ftp://zone3.winetest/file.test",S_OK,"ftp://zone3.winetest/file.test",S_OK},
1303 {"test:123abc",0,"test:123abc",S_OK,"test:123abc",S_OK},
1304 {"http:google.com/test.file",0,"http:google.com/test.file",S_OK,"http:google.com/test.file",S_OK},
1305 {"ftp://test@ftp.winehq.org/",0,"ftp://ftp.winehq.org/",S_OK,"ftp://ftp.winehq.org/",S_OK},
1306 {"test://google@ftp.winehq.org/",0,"test://google@ftp.winehq.org/",S_OK,"test://google@ftp.winehq.org/",S_OK}
1309 static void test_InternetGetSecurityUrlEx(void)
1313 IUri *uri = NULL, *result = NULL;
1315 trace("testing CoInternetGetSecurityUrlEx...\n");
1317 hr = pCoInternetGetSecurityUrlEx(NULL, NULL, PSU_DEFAULT, 0);
1318 ok(hr == E_INVALIDARG, "CoInternetGetSecurityUrlEx returned 0x%08x, expected E_INVALIDARG\n", hr);
1320 result = (void*) 0xdeadbeef;
1321 hr = pCoInternetGetSecurityUrlEx(NULL, &result, PSU_DEFAULT, 0);
1322 ok(hr == E_INVALIDARG, "CoInternetGetSecurityUrlEx returned 0x%08x, expected E_INVALIDARG\n", hr);
1323 ok(result == (void*) 0xdeadbeef, "'result' was %p\n", result);
1325 for(i = 0; i < sizeof(sec_url_ex_tests)/sizeof(sec_url_ex_tests[0]); ++i) {
1326 LPWSTR uriW = a2w(sec_url_ex_tests[i].uri);
1329 hr = pCreateUri(uriW, sec_url_ex_tests[i].create_flags, 0, &uri);
1330 ok(hr == S_OK, "CreateUri returned 0x%08x on test %d\n", hr, i);
1334 hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_DEFAULT, 0);
1335 if(sec_url_ex_tests[i].todo) {
1337 ok(hr == sec_url_ex_tests[i].default_hres,
1338 "CoInternetGetSecurityUrlEx returned 0x%08x, expected 0x%08x on test %d\n",
1339 hr, sec_url_ex_tests[i].default_hres, i);
1341 ok(hr == sec_url_ex_tests[i].default_hres,
1342 "CoInternetGetSecurityUrlEx returned 0x%08x, expected 0x%08x on test %d\n",
1343 hr, sec_url_ex_tests[i].default_hres, i);
1348 hr = IUri_GetDisplayUri(result, &received);
1349 ok(hr == S_OK, "GetDisplayUri returned 0x%08x on test %d\n", hr, i);
1351 if(sec_url_ex_tests[i].todo) {
1353 ok(!strcmp_aw(sec_url_ex_tests[i].default_uri, received),
1354 "Expected %s but got %s on test %d\n", sec_url_ex_tests[i].default_uri,
1355 wine_dbgstr_w(received), i);
1357 ok(!strcmp_aw(sec_url_ex_tests[i].default_uri, received),
1358 "Expected %s but got %s on test %d\n", sec_url_ex_tests[i].default_uri,
1359 wine_dbgstr_w(received), i);
1362 SysFreeString(received);
1364 if(result) IUri_Release(result);
1367 hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_SECURITY_URL_ONLY, 0);
1368 if(sec_url_ex_tests[i].todo) {
1370 ok(hr == sec_url_ex_tests[i].default_hres,
1371 "CoInternetGetSecurityUrlEx returned 0x%08x, expected 0x%08x on test %d\n",
1372 hr, sec_url_ex_tests[i].default_hres, i);
1374 ok(hr == sec_url_ex_tests[i].default_hres,
1375 "CoInternetGetSecurityUrlEx returned 0x%08x, expected 0x%08x on test %d\n",
1376 hr, sec_url_ex_tests[i].default_hres, i);
1381 hr = IUri_GetDisplayUri(result, &received);
1382 ok(hr == S_OK, "GetDisplayUri returned 0x%08x on test %d\n", hr, i);
1384 if(sec_url_ex_tests[i].todo) {
1386 ok(!strcmp_aw(sec_url_ex_tests[i].default_uri, received),
1387 "Expected %s but got %s on test %d\n", sec_url_ex_tests[i].default_uri,
1388 wine_dbgstr_w(received), i);
1390 ok(!strcmp_aw(sec_url_ex_tests[i].default_uri, received),
1391 "Expected %s but got %s on test %d\n", sec_url_ex_tests[i].default_uri,
1392 wine_dbgstr_w(received), i);
1395 SysFreeString(received);
1397 if(result) IUri_Release(result);
1400 if(uri) IUri_Release(uri);
1405 static void test_InternetGetSecurityUrlEx_Pluggable(void)
1408 IUri *uri = NULL, *result;
1410 trace("testing CoInternetGetSecurityUrlEx for plugable protocols...\n");
1412 hr = pCreateUri(security_urlW, 0, 0, &uri);
1413 ok(hr == S_OK, "CreateUri returned 0x%08x\n", hr);
1415 SET_EXPECT(ParseUrl_SECURITY_URL_input);
1416 SET_EXPECT(ParseUrl_SECURITY_URL_expected);
1417 SET_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
1419 hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_DEFAULT, 0);
1420 ok(hr == S_OK, "CoInternetGetSecurityUrlEx returned 0x%08x, expected S_OK\n", hr);
1422 CHECK_CALLED(ParseUrl_SECURITY_URL_input);
1423 CHECK_CALLED(ParseUrl_SECURITY_URL_expected);
1424 CHECK_CALLED(ParseUrl_SECURITY_DOMAIN_expected);
1427 BSTR received = NULL;
1429 hr = IUri_GetAbsoluteUri(result, &received);
1430 ok(hr == S_OK, "GetAbsoluteUri returned 0x%08x\n", hr);
1432 ok(!strcmp_w(security_expectedW, received), "Expected %s but got %s\n",
1433 wine_dbgstr_w(security_expectedW), wine_dbgstr_w(received));
1435 SysFreeString(received);
1437 if(result) IUri_Release(result);
1441 SET_EXPECT(ParseUrl_SECURITY_URL_input);
1442 SET_EXPECT(ParseUrl_SECURITY_URL_expected);
1444 hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_SECURITY_URL_ONLY, 0);
1445 ok(hr == S_OK, "CoInternetGetSecurityUrlEx returned 0x%08x, expected S_OK\n", hr);
1447 CHECK_CALLED(ParseUrl_SECURITY_URL_input);
1448 CHECK_CALLED(ParseUrl_SECURITY_URL_expected);
1451 BSTR received = NULL;
1453 hr = IUri_GetAbsoluteUri(result, &received);
1454 ok(hr == S_OK, "GetAbsoluteUri returned 0x%08x\n", hr);
1456 ok(!strcmp_w(security_expectedW, received), "Expected %s but got %s\n",
1457 wine_dbgstr_w(security_expectedW), wine_dbgstr_w(received));
1459 SysFreeString(received);
1461 if(result) IUri_Release(result);
1463 if(uri) IUri_Release(uri);
1472 hurlmon = GetModuleHandle("urlmon.dll");
1473 pCoInternetCreateSecurityManager = (void*) GetProcAddress(hurlmon, "CoInternetCreateSecurityManager");
1474 pCoInternetCreateZoneManager = (void*) GetProcAddress(hurlmon, "CoInternetCreateZoneManager");
1475 pCoInternetGetSecurityUrl = (void*) GetProcAddress(hurlmon, "CoInternetGetSecurityUrl");
1476 pCoInternetGetSecurityUrlEx = (void*) GetProcAddress(hurlmon, "CoInternetGetSecurityUrlEx");
1477 pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
1478 pCoInternetGetSession = (void*) GetProcAddress(hurlmon, "CoInternetGetSession");
1480 if (!pCoInternetCreateSecurityManager || !pCoInternetCreateZoneManager ||
1481 !pCoInternetGetSecurityUrl) {
1482 win_skip("Various CoInternet* functions not present in IE 4.0\n");
1486 argc = winetest_get_mainargs(&argv);
1487 if(argc > 2 && !strcmp(argv[2], "domain_tests")) {
1488 test_zone_domain_mappings();
1492 OleInitialize(NULL);
1493 register_protocols();
1495 test_InternetGetSecurityUrl();
1497 if(!pCoInternetGetSecurityUrlEx || !pCreateUri)
1498 win_skip("Skipping CoInternetGetSecurityUrlEx tests, IE too old\n");
1500 test_InternetGetSecurityUrlEx();
1501 test_InternetGetSecurityUrlEx_Pluggable();
1504 test_SecurityManager();
1506 test_zone_domains();
1507 test_CoInternetCreateZoneManager();
1508 test_CreateZoneEnumerator();
1509 test_GetZoneActionPolicy();
1511 test_GetZoneAttributes();
1512 test_InternetSecurityMarshalling();
1514 unregister_protocols();