2 * Copyright 2005-2006 Jacek Caban for CodeWeavers
3 * Copyright 2009-2010 Detlef Riekenberg
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define NONAMELESSUNION
24 /* needed for IInternetZoneManagerEx2 */
25 #define _WIN32_IE 0x0700
27 #include <wine/test.h>
39 static HRESULT (WINAPI *pCoInternetCreateSecurityManager)(IServiceProvider *, IInternetSecurityManager**, DWORD);
40 static HRESULT (WINAPI *pCoInternetCreateZoneManager)(IServiceProvider *, IInternetZoneManager**, DWORD);
41 static HRESULT (WINAPI *pCoInternetGetSecurityUrl)(LPCWSTR, LPWSTR*, PSUACTION, DWORD);
43 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
44 '/','b','l','a','n','k','.','h','t','m',0};
45 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
46 static const WCHAR url3[] = {'f','i','l','e',':','/','/','c',':','\\','I','n','d','e','x','.','h','t','m',0};
47 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
48 '%','2','e','j','p','g',0};
49 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','z','o','n','e','3',
50 '.','w','i','n','e','t','e','s','t',0};
51 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
52 static const WCHAR url7[] = {'f','t','p',':','/','/','z','o','n','e','3',
53 '.','w','i','n','e','t','e','s','t','/','f','i','l','e','.','t','e','s','t',0};
54 static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
55 static const WCHAR url9[] = {'h','t','t','p',':','/','/','w','w','w','.','z','o','n','e','3',
56 '.','w','i','n','e','t','e','s','t', '/','s','i','t','e','/','a','b','o','u','t',0};
57 static const WCHAR url10[] = {'f','i','l','e',':','/','/','s','o','m','e','%','2','0','f','i','l','e',
60 static const WCHAR url4e[] = {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e',
64 static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
65 static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','z','o','n','e','3',
66 '.','w','i','n','e','t','e','s','t',3,0,0,0};
67 static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
68 static const BYTE secid7[] = {'f','t','p',':','z','o','n','e','3',
69 '.','w','i','n','e','t','e','s','t',3,0,0,0};
70 static const BYTE secid10[] =
71 {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e','.','j','p','g',3,0,0,0};
72 static const BYTE secid10_2[] =
73 {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e','.','j','p','g',3,0,0,0};
75 static const GUID CLSID_TestActiveX =
76 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
78 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
79 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
80 {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
82 static struct secmgr_test {
90 {url1, 0, S_OK, sizeof(secid1), secid1, S_OK},
91 {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
92 {url3, 0, S_OK, sizeof(secid1), secid1, S_OK},
93 {url5, 3, S_OK, sizeof(secid5), secid5, S_OK},
94 {url6, 3, S_OK, sizeof(secid6), secid6, S_OK},
95 {url7, 3, S_OK, sizeof(secid7), secid7, S_OK}
98 static int strcmp_w(const WCHAR *str1, const WCHAR *str2)
100 DWORD len1 = lstrlenW(str1);
101 DWORD len2 = lstrlenW(str2);
103 if(len1!=len2) return 1;
104 return memcmp(str1, str2, len1*sizeof(WCHAR));
107 static void test_SecurityManager(void)
110 IInternetSecurityManager *secmgr = NULL;
112 DWORD zone, size, policy;
115 if(!pCoInternetCreateSecurityManager) {
119 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
120 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
124 for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
126 hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
128 ok(hres == secmgr_tests[i].zone_hres /* IE <=6 */
129 || (FAILED(secmgr_tests[i].zone_hres) && hres == E_INVALIDARG), /* IE7 */
130 "[%d] MapUrlToZone failed: %08x, expected %08x\n",
131 i, hres, secmgr_tests[i].zone_hres);
133 ok(zone == secmgr_tests[i].zone, "[%d] zone=%d, expected %d\n", i, zone,
134 secmgr_tests[i].zone);
136 ok(zone == secmgr_tests[i].zone || zone == -1, "[%d] zone=%d\n", i, zone);
139 memset(buf, 0xf0, sizeof(buf));
140 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
142 ok(hres == secmgr_tests[i].secid_hres,
143 "[%d] GetSecurityId failed: %08x, expected %08x\n",
144 i, hres, secmgr_tests[i].secid_hres);
145 if(secmgr_tests[i].secid) {
146 ok(size == secmgr_tests[i].secid_size, "[%d] size=%d, expected %d\n",
147 i, size, secmgr_tests[i].secid_size);
148 ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
153 hres = IInternetSecurityManager_MapUrlToZone(secmgr, url10, &zone, 0);
154 ok(hres == S_OK, "MapUrlToZone failed: %08x, expected S_OK\n", hres);
155 ok(zone == 3, "zone=%d, expected 3\n", zone);
157 /* win2k3 translates %20 into a space */
159 memset(buf, 0xf0, sizeof(buf));
160 hres = IInternetSecurityManager_GetSecurityId(secmgr, url10, buf, &size, 0);
161 ok(hres == S_OK, "GetSecurityId failed: %08x, expected S_OK\n", hres);
162 ok(size == sizeof(secid10) ||
163 size == sizeof(secid10_2), /* win2k3 */
165 ok(!memcmp(buf, secid10, size) ||
166 !memcmp(buf, secid10_2, size), /* win2k3 */
170 hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
171 ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08x, expected E_INVALIDARG\n", hres);
172 ok(zone == 100 || zone == -1, "zone=%d\n", zone);
175 hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
176 ok(hres == E_INVALIDARG,
177 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
178 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
180 ok(hres == E_INVALIDARG,
181 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
182 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
184 ok(hres == E_INVALIDARG,
185 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
187 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, NULL, URLACTION_SCRIPT_RUN, (BYTE*)&policy,
188 sizeof(WCHAR), NULL, 0, 0, 0);
189 ok(hres == E_INVALIDARG, "ProcessUrlAction failed: %08x, expected E_INVALIDARG\n", hres);
191 IInternetSecurityManager_Release(secmgr);
194 /* Check if Internet Explorer is configured to run in "Enhanced Security Configuration" (aka hardened mode) */
195 /* Note: this code is duplicated in dlls/mshtml/tests/mshtml_test.h and dlls/urlmon/tests/sec_mgr.c */
196 static BOOL is_ie_hardened(void)
199 DWORD ie_harden, type, size;
202 if(RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap",
203 0, KEY_QUERY_VALUE, &zone_map) == ERROR_SUCCESS) {
204 size = sizeof(DWORD);
205 if (RegQueryValueExA(zone_map, "IEHarden", NULL, &type, (LPBYTE) &ie_harden, &size) != ERROR_SUCCESS ||
209 RegCloseKey(zone_map);
212 return ie_harden != 0;
215 static void test_url_action(IInternetSecurityManager *secmgr, IInternetZoneManager *zonemgr, DWORD action)
217 DWORD res, size, policy, reg_policy;
222 /* FIXME: HKEY_CURRENT_USER is most of the time the default but this can be changed on a system.
223 * The test should be changed to cope with that, if need be.
225 res = RegOpenKeyA(HKEY_CURRENT_USER,
226 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3", &hkey);
227 if(res != ERROR_SUCCESS) {
228 ok(0, "Could not open zone key\n");
232 wsprintf(buf, "%X", action);
233 size = sizeof(DWORD);
234 res = RegQueryValueExA(hkey, buf, NULL, NULL, (BYTE*)®_policy, &size);
236 if(res != ERROR_SUCCESS || size != sizeof(DWORD)) {
238 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
239 sizeof(WCHAR), NULL, 0, 0, 0);
240 ok(hres == E_FAIL || broken(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
241 "(0x%x) got 0x%x (expected E_FAIL)\n", action, hres);
242 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
245 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
246 sizeof(DWORD), URLZONEREG_DEFAULT);
247 ok(hres == E_FAIL || broken(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
248 "(0x%x) got 0x%x (expected E_FAIL)\n", action, hres);
249 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
254 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
255 sizeof(DWORD), URLZONEREG_DEFAULT);
256 ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
257 ok(policy == reg_policy, "(%x) policy=%x, expected %x\n", action, policy, reg_policy);
259 if(policy != URLPOLICY_QUERY) {
260 if(winetest_interactive || ! is_ie_hardened()) {
262 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
263 sizeof(WCHAR), NULL, 0, 0, 0);
264 if(reg_policy == URLPOLICY_DISALLOW)
265 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
267 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
268 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
271 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
273 if(reg_policy == URLPOLICY_DISALLOW)
274 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
276 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
277 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
280 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
281 sizeof(DWORD), NULL, 0, 0, 0);
282 if(reg_policy == URLPOLICY_DISALLOW)
283 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
285 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
286 ok(policy == reg_policy, "(%x) policy=%x\n", action, policy);
289 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
290 sizeof(WCHAR), (BYTE*)0xdeadbeef, 16, 0, 0);
291 if(reg_policy == URLPOLICY_DISALLOW)
292 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
294 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
295 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
297 skip("IE running in Enhanced Security Configuration\n");
302 static void test_special_url_action(IInternetSecurityManager *secmgr, IInternetZoneManager *zonemgr, DWORD action)
308 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
309 sizeof(DWORD), URLZONEREG_DEFAULT);
310 ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
311 ok(policy == URLPOLICY_DISALLOW, "(%x) policy=%x, expected URLPOLICY_DISALLOW\n", action, policy);
314 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, action, (BYTE*)&policy,
315 sizeof(WCHAR), NULL, 0, 0, 0);
316 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
319 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, action, (BYTE*)&policy,
320 sizeof(DWORD), NULL, 0, 0, 0);
321 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
322 ok(policy == URLPOLICY_DISALLOW, "policy = %x\n", policy);
325 static void test_activex(IInternetSecurityManager *secmgr)
327 DWORD policy, policy_size;
328 struct CONFIRMSAFETY cs;
333 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, URLACTION_ACTIVEX_RUN, (BYTE*)&policy,
334 sizeof(DWORD), (BYTE*)&CLSID_TestActiveX, sizeof(CLSID), 0, 0);
335 ok(hres == S_OK, "ProcessUrlAction(URLACTION_ACTIVEX_RUN) failed: %08x\n", hres);
336 ok(policy == URLPOLICY_ALLOW || policy == URLPOLICY_DISALLOW, "policy = %x\n", policy);
338 cs.clsid = CLSID_TestActiveX;
339 cs.pUnk = (IUnknown*)0xdeadbeef;
341 hres = IInternetSecurityManager_QueryCustomPolicy(secmgr, url1, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
342 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
343 ok(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), "QueryCusromPolicy failed: %08x\n", hres);
346 static void test_polices(void)
348 IInternetZoneManager *zonemgr = NULL;
349 IInternetSecurityManager *secmgr = NULL;
352 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
353 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
354 hres = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
355 ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
357 test_url_action(secmgr, zonemgr, URLACTION_SCRIPT_RUN);
358 test_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_RUN);
359 test_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_OVERRIDE_OBJECT_SAFETY);
360 test_url_action(secmgr, zonemgr, URLACTION_CHANNEL_SOFTDIST_PERMISSIONS);
361 test_url_action(secmgr, zonemgr, 0xdeadbeef);
363 test_special_url_action(secmgr, zonemgr, URLACTION_SCRIPT_OVERRIDE_SAFETY);
364 test_special_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY);
366 test_activex(secmgr);
368 IInternetSecurityManager_Release(secmgr);
369 IInternetZoneManager_Release(zonemgr);
372 static void test_CoInternetCreateZoneManager(void)
374 IInternetZoneManager *zonemgr = NULL;
375 IUnknown *punk = NULL;
378 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
379 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
383 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IUnknown, (void **) &punk);
384 ok(SUCCEEDED(hr), "got 0x%x with %p (expected Success)\n", hr, punk);
386 IUnknown_Release(punk);
388 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IInternetZoneManager, (void **) &punk);
389 ok(SUCCEEDED(hr), "got 0x%x with %p (expected Success)\n", hr, punk);
391 IUnknown_Release(punk);
394 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IInternetZoneManagerEx, (void **) &punk);
396 IUnknown_Release(punk);
398 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IInternetZoneManagerEx2, (void **) &punk);
400 IUnknown_Release(punk);
402 win_skip("InternetZoneManagerEx2 not supported\n");
406 win_skip("InternetZoneManagerEx not supported\n");
408 hr = IInternetZoneManager_Release(zonemgr);
409 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
413 static void test_CreateZoneEnumerator(void)
415 IInternetZoneManager *zonemgr = NULL;
422 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
423 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
428 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, NULL, 0);
429 ok((hr == E_INVALIDARG) && (dwEnum == 0xdeadbeef),
430 "got 0x%x with 0x%x (expected E_INVALIDARG with 0xdeadbeef)\n", hr, dwEnum);
433 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, NULL, &dwCount, 0);
434 ok((hr == E_INVALIDARG) && (dwCount == 0xdeadbeef),
435 "got 0x%x and 0x%x (expected E_INVALIDARG and 0xdeadbeef)\n", hr, dwCount);
439 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 0xffffffff);
440 ok((hr == E_INVALIDARG) && (dwEnum == 0xdeadbeef) && (dwCount == 0xdeadbeef),
441 "got 0x%x with 0x%x and 0x%x (expected E_INVALIDARG with 0xdeadbeef and 0xdeadbeef)\n",
442 hr, dwEnum, dwCount);
446 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 1);
447 ok((hr == E_INVALIDARG) && (dwEnum == 0xdeadbeef) && (dwCount == 0xdeadbeef),
448 "got 0x%x with 0x%x and 0x%x (expected E_INVALIDARG with 0xdeadbeef and 0xdeadbeef)\n",
449 hr, dwEnum, dwCount);
454 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 0);
455 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
460 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum2, &dwCount2, 0);
461 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
463 /* native urlmon has an incrementing counter for dwEnum */
464 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum2);
465 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
468 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum);
469 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
471 /* Destroy the Enumerator twice is detected and handled in native urlmon */
472 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum);
473 ok((hr == E_INVALIDARG), "got 0x%x (expected E_INVALIDARG)\n", hr);
476 /* ::Release succeed also, when a ::DestroyZoneEnumerator is missing */
477 hr = IInternetZoneManager_Release(zonemgr);
478 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
481 static void test_GetZoneActionPolicy(void)
483 IInternetZoneManager *zonemgr = NULL;
486 DWORD action = URLACTION_CREDENTIALS_USE; /* Implemented on all IE versions */
488 hres = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
489 ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
493 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, buf,
494 sizeof(DWORD), URLZONEREG_DEFAULT);
495 ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
496 ok(*(DWORD*)buf == URLPOLICY_CREDENTIALS_SILENT_LOGON_OK ||
497 *(DWORD*)buf == URLPOLICY_CREDENTIALS_MUST_PROMPT_USER ||
498 *(DWORD*)buf == URLPOLICY_CREDENTIALS_CONDITIONAL_PROMPT ||
499 *(DWORD*)buf == URLPOLICY_CREDENTIALS_ANONYMOUS_ONLY,
500 "unexpected policy=%d\n", *(DWORD*)buf);
502 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, NULL,
503 sizeof(DWORD), URLZONEREG_DEFAULT);
504 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
506 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, buf,
507 2, URLZONEREG_DEFAULT);
508 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
510 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
511 sizeof(DWORD), URLZONEREG_DEFAULT);
512 ok(hres == E_FAIL || broken(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
513 "(0x%x) got 0x%x (expected E_FAIL)\n", action, hres);
515 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, action, buf,
516 sizeof(DWORD), URLZONEREG_DEFAULT);
517 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
519 IInternetZoneManager_Release(zonemgr);
522 static void test_GetZoneAt(void)
524 IInternetZoneManager *zonemgr = NULL;
531 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
532 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
536 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 0);
541 /* this crashes with native urlmon */
542 hr = IInternetZoneManager_GetZoneAt(zonemgr, dwEnum, 0, NULL);
546 hr = IInternetZoneManager_GetZoneAt(zonemgr, 0xdeadbeef, 0, &dwZone);
547 ok(hr == E_INVALIDARG,
548 "got 0x%x with 0x%x (expected E_INVALIDARG)\n", hr, dwZone);
550 for (i = 0; i < dwCount; i++)
553 hr = IInternetZoneManager_GetZoneAt(zonemgr, dwEnum, i, &dwZone);
554 ok(hr == S_OK, "#%d: got x%x with %d (expected S_OK)\n", i, hr, dwZone);
558 /* MSDN (index .. must be .. less than or equal to) is wrong */
559 hr = IInternetZoneManager_GetZoneAt(zonemgr, dwEnum, dwCount, &dwZone);
560 ok(hr == E_INVALIDARG,
561 "got 0x%x with 0x%x (expected E_INVALIDARG)\n", hr, dwZone);
563 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum);
564 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
567 hr = IInternetZoneManager_Release(zonemgr);
568 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
571 static void test_GetZoneAttributes(void)
573 IInternetZoneManager *zonemgr = NULL;
574 CHAR buffer [sizeof(ZONEATTRIBUTES) + 32];
575 ZONEATTRIBUTES* pZA = (ZONEATTRIBUTES*) buffer;
579 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
580 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
584 /* native urlmon has Zone "0" up to Zone "4" since IE4 */
585 for (i = 0; i < 5; i++) {
586 memset(buffer, -1, sizeof(buffer));
587 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, i, pZA);
588 ok(hr == S_OK, "#%d: got 0x%x (expected S_OK)\n", i, hr);
591 /* IE8 no longer set cbSize */
592 memset(buffer, -1, sizeof(buffer));
594 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, pZA);
595 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
596 ok((pZA->cbSize == 0) || (pZA->cbSize == sizeof(ZONEATTRIBUTES)),
597 "got cbSize = %d (expected 0)\n", pZA->cbSize);
599 memset(buffer, -1, sizeof(buffer));
601 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, pZA);
602 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
603 ok((pZA->cbSize == 64) || (pZA->cbSize == sizeof(ZONEATTRIBUTES)),
604 "got cbSize = %d (expected 64)\n", pZA->cbSize);
606 memset(buffer, -1, sizeof(buffer));
607 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, pZA);
608 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
609 ok((pZA->cbSize == 0xffffffff) || (pZA->cbSize == sizeof(ZONEATTRIBUTES)),
610 "got cbSize = 0x%x (expected 0xffffffff)\n", pZA->cbSize);
612 /* IE8 no longer fail on invalid zones */
613 memset(buffer, -1, sizeof(buffer));
614 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0xdeadbeef, pZA);
615 ok(hr == S_OK || (hr == E_FAIL),
616 "got 0x%x (expected S_OK or E_FAIL)\n", hr);
618 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, NULL);
619 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
621 hr = IInternetZoneManager_Release(zonemgr);
622 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
625 static void test_InternetSecurityMarshalling(void)
627 IInternetSecurityManager *secmgr = NULL;
632 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
633 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
637 hres = IInternetSecurityManager_QueryInterface(secmgr, &IID_IUnknown, (void**)&unk);
638 ok(hres == S_OK, "QueryInterface returned: %08x\n", hres);
640 hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
641 ok(hres == S_OK, "CreateStreamOnHGlobal returned: %08x\n", hres);
643 hres = CoMarshalInterface(stream, &IID_IInternetSecurityManager, unk, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
644 /* Not supported in W98 */
645 ok(hres == S_OK || broken(hres == REGDB_E_IIDNOTREG),
646 "CoMarshalInterface returned: %08x\n", hres);
648 IStream_Release(stream);
649 IUnknown_Release(unk);
650 IInternetSecurityManager_Release(secmgr);
653 static void test_InternetGetSecurityUrl(void)
655 const WCHAR url5_out[] = {'h','t','t','p',':','w','w','w','.','z','o','n','e','3',
656 '.','w','i','n','e','t','e','s','t',0};
657 const WCHAR url7_out[] = {'f','t','p',':','z','o','n','e','3','.','w','i','n','e','t','e','s','t',0};
659 const WCHAR *in[] = {url2, url3, url4, url5, url7, url8, url9, url10};
660 const WCHAR *out_default[] = {url2, url3, url4, url5_out, url7_out, url8, url5_out, url10};
661 const WCHAR *out_securl[] = {url2, url3, url4, url5, url7, url8, url9, url10};
667 for(i=0; i<sizeof(in)/sizeof(WCHAR*); i++) {
668 hres = pCoInternetGetSecurityUrl(in[i], &sec, PSU_DEFAULT, 0);
669 ok(hres == S_OK, "(%d) CoInternetGetSecurityUrl returned: %08x\n", i, hres);
671 ok(!strcmp_w(sec, out_default[i]), "(%d) Got %s, expected %s\n",
672 i, wine_dbgstr_w(sec), wine_dbgstr_w(out_default[i]));
676 hres = pCoInternetGetSecurityUrl(in[i], &sec, PSU_SECURITY_URL_ONLY, 0);
677 ok(hres == S_OK, "(%d) CoInternetGetSecurityUrl returned: %08x\n", i, hres);
679 ok(!strcmp_w(sec, out_securl[i]), "(%d) Got %s, expected %s\n",
680 i, wine_dbgstr_w(sec), wine_dbgstr_w(out_securl[i]));
691 hurlmon = GetModuleHandle("urlmon.dll");
692 pCoInternetCreateSecurityManager = (void*) GetProcAddress(hurlmon, "CoInternetCreateSecurityManager");
693 pCoInternetCreateZoneManager = (void*) GetProcAddress(hurlmon, "CoInternetCreateZoneManager");
694 pCoInternetGetSecurityUrl = (void*) GetProcAddress(hurlmon, "CoInternetGetSecurityUrl");
696 if (!pCoInternetCreateSecurityManager || !pCoInternetCreateZoneManager ||
697 !pCoInternetGetSecurityUrl) {
698 win_skip("Various CoInternet* functions not present in IE 4.0\n");
704 test_InternetGetSecurityUrl();
705 test_SecurityManager();
707 test_CoInternetCreateZoneManager();
708 test_CreateZoneEnumerator();
709 test_GetZoneActionPolicy();
711 test_GetZoneAttributes();
712 test_InternetSecurityMarshalling();