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 if(!pCoInternetCreateSecurityManager
|| !pCoInternetCreateZoneManager
) {
356 hres
= pCoInternetCreateSecurityManager(NULL
, &secmgr
, 0);
357 ok(hres
== S_OK
, "CoInternetCreateSecurityManager failed: %08x\n", hres
);
358 hres
= pCoInternetCreateZoneManager(NULL
, &zonemgr
, 0);
359 ok(hres
== S_OK
, "CoInternetCreateZoneManager failed: %08x\n", hres
);
361 test_url_action(secmgr
, zonemgr
, URLACTION_SCRIPT_RUN
);
362 test_url_action(secmgr
, zonemgr
, URLACTION_ACTIVEX_RUN
);
363 test_url_action(secmgr
, zonemgr
, URLACTION_ACTIVEX_OVERRIDE_OBJECT_SAFETY
);
364 test_url_action(secmgr
, zonemgr
, URLACTION_CHANNEL_SOFTDIST_PERMISSIONS
);
365 test_url_action(secmgr
, zonemgr
, 0xdeadbeef);
367 test_special_url_action(secmgr
, zonemgr
, URLACTION_SCRIPT_OVERRIDE_SAFETY
);
368 test_special_url_action(secmgr
, zonemgr
, URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY
);
370 test_activex(secmgr
);
372 IInternetSecurityManager_Release(secmgr
);
373 IInternetZoneManager_Release(zonemgr
);
376 static void test_CoInternetCreateZoneManager(void)
378 IInternetZoneManager
*zonemgr
= NULL
;
379 IUnknown
*punk
= NULL
;
382 if(!pCoInternetCreateZoneManager
) {
386 hr
= pCoInternetCreateZoneManager(NULL
, &zonemgr
, 0);
387 ok(hr
== S_OK
, "CoInternetCreateZoneManager result: 0x%x\n", hr
);
391 hr
= IInternetZoneManager_QueryInterface(zonemgr
, &IID_IUnknown
, (void **) &punk
);
392 ok(SUCCEEDED(hr
), "got 0x%x with %p (expected Success)\n", hr
, punk
);
394 IUnknown_Release(punk
);
396 hr
= IInternetZoneManager_QueryInterface(zonemgr
, &IID_IInternetZoneManager
, (void **) &punk
);
397 ok(SUCCEEDED(hr
), "got 0x%x with %p (expected Success)\n", hr
, punk
);
399 IUnknown_Release(punk
);
402 hr
= IInternetZoneManager_QueryInterface(zonemgr
, &IID_IInternetZoneManagerEx
, (void **) &punk
);
404 IUnknown_Release(punk
);
406 hr
= IInternetZoneManager_QueryInterface(zonemgr
, &IID_IInternetZoneManagerEx2
, (void **) &punk
);
408 IUnknown_Release(punk
);
410 win_skip("InternetZoneManagerEx2 not supported\n");
414 win_skip("InternetZoneManagerEx not supported\n");
416 hr
= IInternetZoneManager_Release(zonemgr
);
417 ok(hr
== S_OK
, "got 0x%x (expected S_OK)\n", hr
);
421 static void test_CreateZoneEnumerator(void)
423 IInternetZoneManager
*zonemgr
= NULL
;
430 if (!pCoInternetCreateZoneManager
) {
434 hr
= pCoInternetCreateZoneManager(NULL
, &zonemgr
, 0);
435 ok(hr
== S_OK
, "CoInternetCreateZoneManager result: 0x%x\n", hr
);
440 hr
= IInternetZoneManager_CreateZoneEnumerator(zonemgr
, &dwEnum
, NULL
, 0);
441 ok((hr
== E_INVALIDARG
) && (dwEnum
== 0xdeadbeef),
442 "got 0x%x with 0x%x (expected E_INVALIDARG with 0xdeadbeef)\n", hr
, dwEnum
);
445 hr
= IInternetZoneManager_CreateZoneEnumerator(zonemgr
, NULL
, &dwCount
, 0);
446 ok((hr
== E_INVALIDARG
) && (dwCount
== 0xdeadbeef),
447 "got 0x%x and 0x%x (expected E_INVALIDARG and 0xdeadbeef)\n", hr
, dwCount
);
451 hr
= IInternetZoneManager_CreateZoneEnumerator(zonemgr
, &dwEnum
, &dwCount
, 0xffffffff);
452 ok((hr
== E_INVALIDARG
) && (dwEnum
== 0xdeadbeef) && (dwCount
== 0xdeadbeef),
453 "got 0x%x with 0x%x and 0x%x (expected E_INVALIDARG with 0xdeadbeef and 0xdeadbeef)\n",
454 hr
, dwEnum
, dwCount
);
458 hr
= IInternetZoneManager_CreateZoneEnumerator(zonemgr
, &dwEnum
, &dwCount
, 1);
459 ok((hr
== E_INVALIDARG
) && (dwEnum
== 0xdeadbeef) && (dwCount
== 0xdeadbeef),
460 "got 0x%x with 0x%x and 0x%x (expected E_INVALIDARG with 0xdeadbeef and 0xdeadbeef)\n",
461 hr
, dwEnum
, dwCount
);
466 hr
= IInternetZoneManager_CreateZoneEnumerator(zonemgr
, &dwEnum
, &dwCount
, 0);
467 ok(hr
== S_OK
, "got 0x%x (expected S_OK)\n", hr
);
472 hr
= IInternetZoneManager_CreateZoneEnumerator(zonemgr
, &dwEnum2
, &dwCount2
, 0);
473 ok(hr
== S_OK
, "got 0x%x (expected S_OK)\n", hr
);
475 /* native urlmon has an incrementing counter for dwEnum */
476 hr
= IInternetZoneManager_DestroyZoneEnumerator(zonemgr
, dwEnum2
);
477 ok(hr
== S_OK
, "got 0x%x (expected S_OK)\n", hr
);
480 hr
= IInternetZoneManager_DestroyZoneEnumerator(zonemgr
, dwEnum
);
481 ok(hr
== S_OK
, "got 0x%x (expected S_OK)\n", hr
);
483 /* Destroy the Enumerator twice is detected and handled in native urlmon */
484 hr
= IInternetZoneManager_DestroyZoneEnumerator(zonemgr
, dwEnum
);
485 ok((hr
== E_INVALIDARG
), "got 0x%x (expected E_INVALIDARG)\n", hr
);
488 /* ::Release succeed also, when a ::DestroyZoneEnumerator is missing */
489 hr
= IInternetZoneManager_Release(zonemgr
);
490 ok(hr
== S_OK
, "got 0x%x (expected S_OK)\n", hr
);
493 static void test_GetZoneActionPolicy(void)
495 IInternetZoneManager
*zonemgr
= NULL
;
498 DWORD action
= URLACTION_CREDENTIALS_USE
; /* Implemented on all IE versions */
500 hres
= pCoInternetCreateZoneManager(NULL
, &zonemgr
, 0);
501 ok(hres
== S_OK
, "CoInternetCreateZoneManager failed: %08x\n", hres
);
505 hres
= IInternetZoneManager_GetZoneActionPolicy(zonemgr
, 3, action
, buf
,
506 sizeof(DWORD
), URLZONEREG_DEFAULT
);
507 ok(hres
== S_OK
, "GetZoneActionPolicy failed: %08x\n", hres
);
508 ok(*(DWORD
*)buf
== URLPOLICY_CREDENTIALS_SILENT_LOGON_OK
||
509 *(DWORD
*)buf
== URLPOLICY_CREDENTIALS_MUST_PROMPT_USER
||
510 *(DWORD
*)buf
== URLPOLICY_CREDENTIALS_CONDITIONAL_PROMPT
||
511 *(DWORD
*)buf
== URLPOLICY_CREDENTIALS_ANONYMOUS_ONLY
,
512 "unexpected policy=%d\n", *(DWORD
*)buf
);
514 hres
= IInternetZoneManager_GetZoneActionPolicy(zonemgr
, 3, action
, NULL
,
515 sizeof(DWORD
), URLZONEREG_DEFAULT
);
516 ok(hres
== E_INVALIDARG
, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres
);
518 hres
= IInternetZoneManager_GetZoneActionPolicy(zonemgr
, 3, action
, buf
,
519 2, URLZONEREG_DEFAULT
);
520 ok(hres
== E_INVALIDARG
, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres
);
522 hres
= IInternetZoneManager_GetZoneActionPolicy(zonemgr
, 3, 0x1fff, buf
,
523 sizeof(DWORD
), URLZONEREG_DEFAULT
);
524 ok(hres
== E_FAIL
|| broken(hres
== HRESULT_FROM_WIN32(ERROR_NOT_FOUND
)),
525 "(0x%x) got 0x%x (expected E_FAIL)\n", action
, hres
);
527 hres
= IInternetZoneManager_GetZoneActionPolicy(zonemgr
, 13, action
, buf
,
528 sizeof(DWORD
), URLZONEREG_DEFAULT
);
529 ok(hres
== E_INVALIDARG
, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres
);
531 IInternetZoneManager_Release(zonemgr
);
534 static void test_GetZoneAt(void)
536 IInternetZoneManager
*zonemgr
= NULL
;
543 hr
= pCoInternetCreateZoneManager(NULL
, &zonemgr
, 0);
544 ok(hr
== S_OK
, "CoInternetCreateZoneManager result: 0x%x\n", hr
);
548 hr
= IInternetZoneManager_CreateZoneEnumerator(zonemgr
, &dwEnum
, &dwCount
, 0);
553 /* this crashes with native urlmon */
554 hr
= IInternetZoneManager_GetZoneAt(zonemgr
, dwEnum
, 0, NULL
);
558 hr
= IInternetZoneManager_GetZoneAt(zonemgr
, 0xdeadbeef, 0, &dwZone
);
559 ok(hr
== E_INVALIDARG
,
560 "got 0x%x with 0x%x (expected E_INVALIDARG)\n", hr
, dwZone
);
562 for (i
= 0; i
< dwCount
; i
++)
565 hr
= IInternetZoneManager_GetZoneAt(zonemgr
, dwEnum
, i
, &dwZone
);
566 ok(hr
== S_OK
, "#%d: got x%x with %d (expected S_OK)\n", i
, hr
, dwZone
);
570 /* MSDN (index .. must be .. less than or equal to) is wrong */
571 hr
= IInternetZoneManager_GetZoneAt(zonemgr
, dwEnum
, dwCount
, &dwZone
);
572 ok(hr
== E_INVALIDARG
,
573 "got 0x%x with 0x%x (expected E_INVALIDARG)\n", hr
, dwZone
);
575 hr
= IInternetZoneManager_DestroyZoneEnumerator(zonemgr
, dwEnum
);
576 ok(hr
== S_OK
, "got 0x%x (expected S_OK)\n", hr
);
579 hr
= IInternetZoneManager_Release(zonemgr
);
580 ok(hr
== S_OK
, "got 0x%x (expected S_OK)\n", hr
);
583 static void test_GetZoneAttributes(void)
585 IInternetZoneManager
*zonemgr
= NULL
;
586 CHAR buffer
[sizeof(ZONEATTRIBUTES
) + 32];
587 ZONEATTRIBUTES
* pZA
= (ZONEATTRIBUTES
*) buffer
;
591 hr
= pCoInternetCreateZoneManager(NULL
, &zonemgr
, 0);
592 ok(hr
== S_OK
, "CoInternetCreateZoneManager result: 0x%x\n", hr
);
596 /* native urlmon has Zone "0" up to Zone "4" since IE4 */
597 for (i
= 0; i
< 5; i
++) {
598 memset(buffer
, -1, sizeof(buffer
));
599 hr
= IInternetZoneManager_GetZoneAttributes(zonemgr
, i
, pZA
);
600 ok(hr
== S_OK
, "#%d: got 0x%x (expected S_OK)\n", i
, hr
);
603 /* IE8 no longer set cbSize */
604 memset(buffer
, -1, sizeof(buffer
));
606 hr
= IInternetZoneManager_GetZoneAttributes(zonemgr
, 0, pZA
);
607 ok(hr
== S_OK
, "got 0x%x (expected S_OK)\n", hr
);
608 ok((pZA
->cbSize
== 0) || (pZA
->cbSize
== sizeof(ZONEATTRIBUTES
)),
609 "got cbSize = %d (expected 0)\n", pZA
->cbSize
);
611 memset(buffer
, -1, sizeof(buffer
));
613 hr
= IInternetZoneManager_GetZoneAttributes(zonemgr
, 0, pZA
);
614 ok(hr
== S_OK
, "got 0x%x (expected S_OK)\n", hr
);
615 ok((pZA
->cbSize
== 64) || (pZA
->cbSize
== sizeof(ZONEATTRIBUTES
)),
616 "got cbSize = %d (expected 64)\n", pZA
->cbSize
);
618 memset(buffer
, -1, sizeof(buffer
));
619 hr
= IInternetZoneManager_GetZoneAttributes(zonemgr
, 0, pZA
);
620 ok(hr
== S_OK
, "got 0x%x (expected S_OK)\n", hr
);
621 ok((pZA
->cbSize
== 0xffffffff) || (pZA
->cbSize
== sizeof(ZONEATTRIBUTES
)),
622 "got cbSize = 0x%x (expected 0xffffffff)\n", pZA
->cbSize
);
624 /* IE8 no longer fail on invalid zones */
625 memset(buffer
, -1, sizeof(buffer
));
626 hr
= IInternetZoneManager_GetZoneAttributes(zonemgr
, 0xdeadbeef, pZA
);
627 ok(hr
== S_OK
|| (hr
== E_FAIL
),
628 "got 0x%x (expected S_OK or E_FAIL)\n", hr
);
630 hr
= IInternetZoneManager_GetZoneAttributes(zonemgr
, 0, NULL
);
631 ok(hr
== E_INVALIDARG
, "got 0x%x (expected E_INVALIDARG)\n", hr
);
633 hr
= IInternetZoneManager_Release(zonemgr
);
634 ok(hr
== S_OK
, "got 0x%x (expected S_OK)\n", hr
);
637 static void test_InternetSecurityMarshalling(void)
639 IInternetSecurityManager
*secmgr
= NULL
;
644 if(!pCoInternetCreateSecurityManager
) {
648 hres
= pCoInternetCreateSecurityManager(NULL
, &secmgr
, 0);
649 ok(hres
== S_OK
, "CoInternetCreateSecurityManager failed: %08x\n", hres
);
653 hres
= IInternetSecurityManager_QueryInterface(secmgr
, &IID_IUnknown
, (void**)&unk
);
654 ok(hres
== S_OK
, "QueryInterface returned: %08x\n", hres
);
656 hres
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
657 ok(hres
== S_OK
, "CreateStreamOnHGlobal returned: %08x\n", hres
);
659 hres
= CoMarshalInterface(stream
, &IID_IInternetSecurityManager
, unk
, MSHCTX_INPROC
, NULL
, MSHLFLAGS_NORMAL
);
660 /* Not supported in W98 */
661 ok(hres
== S_OK
|| broken(hres
== REGDB_E_IIDNOTREG
),
662 "CoMarshalInterface returned: %08x\n", hres
);
664 IStream_Release(stream
);
665 IUnknown_Release(unk
);
666 IInternetSecurityManager_Release(secmgr
);
669 static void test_InternetGetSecurityUrl(void)
671 const WCHAR url5_out
[] = {'h','t','t','p',':','w','w','w','.','z','o','n','e','3',
672 '.','w','i','n','e','t','e','s','t',0};
673 const WCHAR url7_out
[] = {'f','t','p',':','z','o','n','e','3','.','w','i','n','e','t','e','s','t',0};
675 const WCHAR
*in
[] = {url2
, url3
, url4
, url5
, url7
, url8
, url9
, url10
};
676 const WCHAR
*out_default
[] = {url2
, url3
, url4
, url5_out
, url7_out
, url8
, url5_out
, url10
};
677 const WCHAR
*out_securl
[] = {url2
, url3
, url4
, url5
, url7
, url8
, url9
, url10
};
683 if (!pCoInternetGetSecurityUrl
) {
687 for(i
=0; i
<sizeof(in
)/sizeof(WCHAR
*); i
++) {
688 hres
= pCoInternetGetSecurityUrl(in
[i
], &sec
, PSU_DEFAULT
, 0);
689 ok(hres
== S_OK
, "(%d) CoInternetGetSecurityUrl returned: %08x\n", i
, hres
);
691 ok(!strcmp_w(sec
, out_default
[i
]), "(%d) Got %s, expected %s\n",
692 i
, wine_dbgstr_w(sec
), wine_dbgstr_w(out_default
[i
]));
696 hres
= pCoInternetGetSecurityUrl(in
[i
], &sec
, PSU_SECURITY_URL_ONLY
, 0);
697 ok(hres
== S_OK
, "(%d) CoInternetGetSecurityUrl returned: %08x\n", i
, hres
);
699 ok(!strcmp_w(sec
, out_securl
[i
]), "(%d) Got %s, expected %s\n",
700 i
, wine_dbgstr_w(sec
), wine_dbgstr_w(out_securl
[i
]));
713 hurlmon
= GetModuleHandle("urlmon.dll");
714 pCoInternetCreateSecurityManager
= (void*) GetProcAddress(hurlmon
, "CoInternetCreateSecurityManager");
715 pCoInternetCreateZoneManager
= (void*) GetProcAddress(hurlmon
, "CoInternetCreateZoneManager");
716 pCoInternetGetSecurityUrl
= (void*) GetProcAddress(hurlmon
, "CoInternetGetSecurityUrl");
718 if (!pCoInternetCreateSecurityManager
|| !pCoInternetCreateZoneManager
||
719 !pCoInternetGetSecurityUrl
) {
720 win_skip("Various CoInternet* functions not present in IE 4.0\n");
723 test_InternetGetSecurityUrl();
724 test_SecurityManager();
726 test_CoInternetCreateZoneManager();
727 test_CreateZoneEnumerator();
728 test_GetZoneActionPolicy();
730 test_GetZoneAttributes();
731 test_InternetSecurityMarshalling();