makefiles: Don't use standard libs for programs that specify -nodefaultlibs.
[wine/zf.git] / dlls / urlmon / tests / sec_mgr.c
blob4d61079ab83a2d50c319379869a2c0350fab3a27
1 /*
2 * Copyright 2005-2006 Jacek Caban for CodeWeavers
3 * Copyright 2009-2011 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
21 #define COBJMACROS
22 #define CONST_VTABLE
24 #include <wine/test.h>
25 #include <stdarg.h>
26 #include <stddef.h>
27 #include <stdio.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "ole2.h"
32 #include "urlmon.h"
34 #include "initguid.h"
35 #include <wine/heap.h>
37 #define URLZONE_CUSTOM URLZONE_USER_MIN+1
38 #define URLZONE_CUSTOM2 URLZONE_CUSTOM+1
40 #define DEFINE_EXPECT(func) \
41 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
43 #define SET_EXPECT(func) \
44 expect_ ## func = TRUE
46 #define CHECK_EXPECT(func) \
47 do { \
48 ok(expect_ ##func, "unexpected call " #func "\n"); \
49 expect_ ## func = FALSE; \
50 called_ ## func = TRUE; \
51 }while(0)
53 #define CHECK_EXPECT2(func) \
54 do { \
55 ok(expect_ ##func, "unexpected call " #func "\n"); \
56 called_ ## func = TRUE; \
57 }while(0)
59 #define CHECK_CALLED(func) \
60 do { \
61 ok(called_ ## func, "expected " #func "\n"); \
62 expect_ ## func = called_ ## func = FALSE; \
63 }while(0)
65 #define SET_CALLED(func) \
66 do { \
67 expect_ ## func = called_ ## func = FALSE; \
68 }while(0)
70 DEFINE_EXPECT(ParseUrl_SECURITY_URL_input);
71 DEFINE_EXPECT(ParseUrl_SECURITY_URL_input2);
72 DEFINE_EXPECT(ParseUrl_SECURITY_URL_expected);
73 DEFINE_EXPECT(ParseUrl_SECURITY_URL_http);
74 DEFINE_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
75 DEFINE_EXPECT(ProcessUrlAction);
77 static HRESULT (WINAPI *pCoInternetCreateSecurityManager)(IServiceProvider *, IInternetSecurityManager**, DWORD);
78 static HRESULT (WINAPI *pCoInternetCreateZoneManager)(IServiceProvider *, IInternetZoneManager**, DWORD);
79 static HRESULT (WINAPI *pCoInternetGetSecurityUrl)(LPCWSTR, LPWSTR*, PSUACTION, DWORD);
80 static HRESULT (WINAPI *pCoInternetGetSecurityUrlEx)(IUri*, IUri**, PSUACTION, DWORD_PTR);
81 static HRESULT (WINAPI *pCreateUri)(LPCWSTR, DWORD, DWORD_PTR, IUri**);
82 static HRESULT (WINAPI *pCoInternetGetSession)(DWORD, IInternetSession**, DWORD);
83 static HRESULT (WINAPI *pCoInternetIsFeatureEnabled)(INTERNETFEATURELIST, DWORD);
84 static HRESULT (WINAPI *pCoInternetIsFeatureEnabledForUrl)(INTERNETFEATURELIST, DWORD, LPCWSTR, IInternetSecurityManager*);
85 static HRESULT (WINAPI *pCoInternetIsFeatureZoneElevationEnabled)(LPCWSTR, LPCWSTR, IInternetSecurityManager*, DWORD);
87 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
88 '/','b','l','a','n','k','.','h','t','m',0};
89 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
90 static const WCHAR url3[] = {'f','i','l','e',':','/','/','c',':','\\','I','n','d','e','x','.','h','t','m',0};
91 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
92 '%','2','e','j','p','g',0};
93 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','z','o','n','e','3',
94 '.','w','i','n','e','t','e','s','t',0};
95 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
96 static const WCHAR url7[] = {'f','t','p',':','/','/','z','o','n','e','3',
97 '.','w','i','n','e','t','e','s','t','/','f','i','l','e','.','t','e','s','t',0};
98 static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
99 static const WCHAR url9[] = {'h','t','t','p',':','/','/','w','w','w','.','z','o','n','e','3',
100 '.','w','i','n','e','t','e','s','t', '/','s','i','t','e','/','a','b','o','u','t',0};
101 static const WCHAR url10[] = {'f','i','l','e',':','/','/','s','o','m','e','%','2','0','f','i','l','e',
102 '.','j','p','g',0};
103 static const WCHAR url11[] = {'f','i','l','e',':','/','/','c',':','/','I','n','d','e','x','.','h','t','m',0};
104 static const WCHAR url12[] = {'f','i','l','e',':','/','/','/','c',':','/','I','n','d','e','x','.','h','t','m',0};
105 static const WCHAR url13[] = {'h','t','t','p',':','g','o','o','g','l','e','.','c','o','m',0};
106 static const WCHAR url14[] = {'z','i','p',':','t','e','s','t','i','n','g','.','c','o','m','/','t','e','s','t','i','n','g',0};
107 static const WCHAR url15[] = {'h','t','t','p',':','/','/','g','o','o','g','l','e','.','c','o','m','.','u','k',0};
108 static const WCHAR url16[] = {'f','i','l','e',':','/','/','/','c',':',0};
109 static const WCHAR url17[] = {'f','i','l','e',':','/','/','/','c',':','c','\\',0};
110 static const WCHAR url18[] = {'c',':','\\','t','e','s','t','.','h','t','m',0};
112 static const WCHAR winetestW[] = {'w','i','n','e','t','e','s','t',0};
113 static const WCHAR security_urlW[] = {'w','i','n','e','t','e','s','t',':','t','e','s','t','i','n','g',0};
114 static const WCHAR security_url2W[] = {'w','i','n','e','t','e','s','t',':','t','e','s','t','i','n','g','2',0};
115 static const WCHAR security_expectedW[] = {'w','i','n','e','t','e','s','t',':','z','i','p',0};
116 static const WCHAR winetest_to_httpW[] = {'w','i','n','e','t','e','s','t',':','h',0};
118 static const char *szZoneMapDomainsKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains";
119 static const char *szInternetSettingsKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
121 static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
122 static const BYTE secid2[] = {'*',':','i','n','d','e','x','.','h','t','m',3,0,0,0};
123 static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','z','o','n','e','3',
124 '.','w','i','n','e','t','e','s','t',3,0,0,0};
125 static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
126 static const BYTE secid7[] = {'f','t','p',':','z','o','n','e','3',
127 '.','w','i','n','e','t','e','s','t',3,0,0,0};
128 static const BYTE secid10[] =
129 {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e','.','j','p','g',3,0,0,0};
130 static const BYTE secid14[] =
131 {'z','i','p',':','t','e','s','t','i','n','g','.','c','o','m','/','t','e','s','t','i','n','g',3,0,0,0};
132 static const BYTE secid10_2[] =
133 {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e','.','j','p','g',3,0,0,0};
134 static const BYTE secid13[] = {'h','t','t','p',':','c','o','m','.','u','k',3,0,0,0};
135 static const BYTE secid13_2[] = {'h','t','t','p',':','g','o','o','g','l','e','.','c','o','m','.','u','k',3,0,0,0};
137 static const GUID CLSID_TestActiveX =
138 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
140 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
141 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
142 {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
144 static int called_securl_http;
145 static DWORD ProcessUrlAction_policy;
147 static struct secmgr_test {
148 LPCWSTR url;
149 DWORD zone;
150 HRESULT zone_hres;
151 DWORD secid_size;
152 const BYTE *secid;
153 HRESULT secid_hres;
154 } secmgr_tests[] = {
155 {url1, 0, S_OK, sizeof(secid1), secid1, S_OK},
156 {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
157 {url3, 0, S_OK, sizeof(secid1), secid1, S_OK},
158 {url5, 3, S_OK, sizeof(secid5), secid5, S_OK},
159 {url6, 3, S_OK, sizeof(secid6), secid6, S_OK},
160 {url7, 3, S_OK, sizeof(secid7), secid7, S_OK},
161 {url11,0, S_OK, sizeof(secid1), secid1, S_OK},
162 {url12,0, S_OK, sizeof(secid1), secid1, S_OK},
163 {url16,0, S_OK, sizeof(secid1), secid1, S_OK},
164 {url17,0, S_OK, sizeof(secid1), secid1, S_OK},
165 {url18,0, S_OK, sizeof(secid1), secid1, S_OK}
168 static int strcmp_w(const WCHAR *str1, const WCHAR *str2)
170 DWORD len1 = lstrlenW(str1);
171 DWORD len2 = lstrlenW(str2);
173 if(len1!=len2) return 1;
174 return memcmp(str1, str2, len1*sizeof(WCHAR));
178 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
179 static LONG myRegDeleteTreeA(HKEY hKey, LPCSTR lpszSubKey)
181 LONG ret;
182 DWORD dwMaxSubkeyLen, dwMaxValueLen;
183 DWORD dwMaxLen, dwSize;
184 CHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
185 HKEY hSubKey = hKey;
187 if(lpszSubKey)
189 ret = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
190 if (ret) return ret;
193 /* Get highest length for keys, values */
194 ret = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, NULL,
195 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
196 if (ret) goto cleanup;
198 dwMaxSubkeyLen++;
199 dwMaxValueLen++;
200 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
201 if (dwMaxLen > ARRAY_SIZE(szNameBuf))
203 /* Name too big: alloc a buffer for it */
204 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(CHAR))))
206 ret = ERROR_NOT_ENOUGH_MEMORY;
207 goto cleanup;
211 /* Recursively delete all the subkeys */
212 while (TRUE)
214 dwSize = dwMaxLen;
215 if (RegEnumKeyExA(hSubKey, 0, lpszName, &dwSize, NULL,
216 NULL, NULL, NULL)) break;
218 ret = myRegDeleteTreeA(hSubKey, lpszName);
219 if (ret) goto cleanup;
222 if (lpszSubKey)
223 ret = RegDeleteKeyA(hKey, lpszSubKey);
224 else
225 while (TRUE)
227 dwSize = dwMaxLen;
228 if (RegEnumValueA(hKey, 0, lpszName, &dwSize,
229 NULL, NULL, NULL, NULL)) break;
231 ret = RegDeleteValueA(hKey, lpszName);
232 if (ret) goto cleanup;
235 cleanup:
236 /* Free buffer if allocated */
237 if (lpszName != szNameBuf)
238 heap_free(lpszName);
239 if(lpszSubKey)
240 RegCloseKey(hSubKey);
241 return ret;
244 static HRESULT WINAPI SecurityManager_QueryInterface(IInternetSecurityManager* This,
245 REFIID riid, void **ppvObject)
247 ok(0, "unexpected call\n");
248 return E_NOTIMPL;
251 static ULONG WINAPI SecurityManager_AddRef(IInternetSecurityManager* This)
253 return 2;
256 static ULONG WINAPI SecurityManager_Release(IInternetSecurityManager* This)
258 return 1;
261 static HRESULT WINAPI SecurityManager_SetSecuritySite(IInternetSecurityManager* This,
262 IInternetSecurityMgrSite *pSite)
264 ok(0, "unexpected call\n");
265 return E_NOTIMPL;
268 static HRESULT WINAPI SecurityManager_GetSecuritySite(IInternetSecurityManager* This,
269 IInternetSecurityMgrSite **ppSite)
271 ok(0, "unexpected call\n");
272 return E_NOTIMPL;
275 static HRESULT WINAPI SecurityManager_MapUrlToZone(IInternetSecurityManager* This,
276 LPCWSTR pwszUrl, DWORD *pdwZone, DWORD dwFlags)
278 ok(0, "unexpected call\n");
279 return E_NOTIMPL;
282 static HRESULT WINAPI SecurityManager_GetSecurityId(IInternetSecurityManager* This,
283 LPCWSTR pwszUrl, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
285 ok(0, "unexpected call\n");
286 return E_NOTIMPL;
289 static HRESULT WINAPI SecurityManager_ProcessUrlAction(IInternetSecurityManager* This,
290 LPCWSTR pwszUrl, DWORD dwAction, BYTE *pPolicy, DWORD cbPolicy,
291 BYTE *pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved)
293 CHECK_EXPECT(ProcessUrlAction);
294 ok(dwAction == URLACTION_FEATURE_ZONE_ELEVATION, "dwAction = %x\n", dwAction);
295 ok(cbPolicy == sizeof(DWORD), "cbPolicy = %d\n", cbPolicy);
296 ok(!pContext, "pContext != NULL\n");
297 ok(dwFlags == PUAF_NOUI, "dwFlags = %x\n", dwFlags);
298 ok(dwReserved == 0, "dwReserved = %x\n", dwReserved);
300 *pPolicy = ProcessUrlAction_policy;
301 return ProcessUrlAction_policy==URLPOLICY_ALLOW ? S_OK : S_FALSE;
304 static HRESULT WINAPI SecurityManager_QueryCustomPolicy(IInternetSecurityManager* This,
305 LPCWSTR pwszUrl, REFGUID guidKey, BYTE **ppPolicy, DWORD *pcbPolicy,
306 BYTE *pContext, DWORD cbContext, DWORD dwReserved)
308 ok(0, "unexpected call\n");
309 return E_NOTIMPL;
312 static HRESULT WINAPI SecurityManager_SetZoneMapping(IInternetSecurityManager* This,
313 DWORD dwZone, LPCWSTR lpszPattern, DWORD dwFlags)
315 ok(0, "unexpected call\n");
316 return E_NOTIMPL;
319 static HRESULT WINAPI SecurityManager_GetZoneMappings(IInternetSecurityManager* This,
320 DWORD dwZone, IEnumString **ppenumString, DWORD dwFlags)
322 ok(0, "unexpected call\n");
323 return E_NOTIMPL;
326 static const IInternetSecurityManagerVtbl SecurityManagerVtbl = {
327 SecurityManager_QueryInterface,
328 SecurityManager_AddRef,
329 SecurityManager_Release,
330 SecurityManager_SetSecuritySite,
331 SecurityManager_GetSecuritySite,
332 SecurityManager_MapUrlToZone,
333 SecurityManager_GetSecurityId,
334 SecurityManager_ProcessUrlAction,
335 SecurityManager_QueryCustomPolicy,
336 SecurityManager_SetZoneMapping,
337 SecurityManager_GetZoneMappings
340 static IInternetSecurityManager security_manager = { &SecurityManagerVtbl };
342 static void test_SecurityManager(void)
344 int i;
345 IInternetSecurityManager *secmgr = NULL;
346 BYTE buf[512];
347 DWORD zone, size, policy;
348 HRESULT hres;
350 if(!pCoInternetCreateSecurityManager) {
351 return;
354 trace("Testing security manager...\n");
356 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
357 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
358 if(FAILED(hres))
359 return;
361 for(i = 0; i < ARRAY_SIZE(secmgr_tests); i++) {
362 zone = 100;
363 hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
364 &zone, 0);
365 ok(hres == secmgr_tests[i].zone_hres /* IE <=6 */
366 || (FAILED(secmgr_tests[i].zone_hres) && hres == E_INVALIDARG), /* IE7 */
367 "[%d] MapUrlToZone failed: %08x, expected %08x\n",
368 i, hres, secmgr_tests[i].zone_hres);
369 if(SUCCEEDED(hres))
370 ok(zone == secmgr_tests[i].zone, "[%d] zone=%d, expected %d\n", i, zone,
371 secmgr_tests[i].zone);
372 else
373 ok(zone == secmgr_tests[i].zone || zone == -1, "[%d] zone=%d\n", i, zone);
375 size = sizeof(buf);
376 memset(buf, 0xf0, sizeof(buf));
377 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
378 buf, &size, 0);
379 ok(hres == secmgr_tests[i].secid_hres,
380 "[%d] GetSecurityId failed: %08x, expected %08x\n",
381 i, hres, secmgr_tests[i].secid_hres);
382 if(secmgr_tests[i].secid) {
383 ok(size == secmgr_tests[i].secid_size, "[%d] size=%d, expected %d\n",
384 i, size, secmgr_tests[i].secid_size);
385 ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
389 zone = 100;
390 hres = IInternetSecurityManager_MapUrlToZone(secmgr, url10, &zone, 0);
391 ok(hres == S_OK, "MapUrlToZone failed: %08x, expected S_OK\n", hres);
392 ok(zone == 3, "zone=%d, expected 3\n", zone);
394 /* win2k3 translates %20 into a space */
395 size = sizeof(buf);
396 memset(buf, 0xf0, sizeof(buf));
397 hres = IInternetSecurityManager_GetSecurityId(secmgr, url10, buf, &size, 0);
398 ok(hres == S_OK, "GetSecurityId failed: %08x, expected S_OK\n", hres);
399 ok(size == sizeof(secid10) ||
400 size == sizeof(secid10_2), /* win2k3 */
401 "size=%d\n", size);
402 ok(!memcmp(buf, secid10, sizeof(secid10)) ||
403 !memcmp(buf, secid10_2, sizeof(secid10_2)), /* win2k3 */
404 "wrong secid\n");
406 zone = 100;
407 hres = IInternetSecurityManager_MapUrlToZone(secmgr, url13, &zone, 0);
408 ok(hres == S_OK, "MapUrlToZone failed: %08x\n", hres);
409 ok(zone == URLZONE_INVALID || broken(zone == URLZONE_INTERNET), "zone=%d\n", zone);
411 size = sizeof(buf);
412 memset(buf, 0xf0, sizeof(buf));
413 hres = IInternetSecurityManager_GetSecurityId(secmgr, url13, buf, &size, 0);
414 ok(hres == E_INVALIDARG || broken(hres == S_OK), "GetSecurityId failed: %08x\n", hres);
416 zone = 100;
417 hres = IInternetSecurityManager_MapUrlToZone(secmgr, url14, &zone, 0);
418 ok(hres == S_OK, "MapUrlToZone failed: %08x, expected S_OK\n", hres);
419 ok(zone == URLZONE_INTERNET, "zone=%d\n", zone);
421 size = sizeof(buf);
422 memset(buf, 0xf0, sizeof(buf));
423 hres = IInternetSecurityManager_GetSecurityId(secmgr, url14, buf, &size, 0);
424 ok(hres == S_OK, "GetSecurityId failed: %08x, expected S_OK\n", hres);
425 ok(size == sizeof(secid14), "size=%d\n", size);
426 ok(!memcmp(buf, secid14, size), "wrong secid\n");
428 zone = 100;
429 hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
430 ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08x, expected E_INVALIDARG\n", hres);
431 ok(zone == 100 || zone == -1, "zone=%d\n", zone);
433 size = sizeof(buf);
434 hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
435 ok(hres == E_INVALIDARG,
436 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
437 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
438 NULL, &size, 0);
439 ok(hres == E_INVALIDARG,
440 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
441 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
442 buf, NULL, 0);
443 ok(hres == E_INVALIDARG,
444 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
446 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, NULL, URLACTION_SCRIPT_RUN, (BYTE*)&policy,
447 sizeof(WCHAR), NULL, 0, 0, 0);
448 ok(hres == E_INVALIDARG, "ProcessUrlAction failed: %08x, expected E_INVALIDARG\n", hres);
450 IInternetSecurityManager_Release(secmgr);
453 /* Check if Internet Explorer is configured to run in "Enhanced Security Configuration" (aka hardened mode) */
454 /* Note: this code is duplicated in dlls/mshtml/tests/mshtml_test.h and dlls/urlmon/tests/sec_mgr.c */
455 static BOOL is_ie_hardened(void)
457 HKEY zone_map;
458 DWORD ie_harden, type, size;
460 ie_harden = 0;
461 if(RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap",
462 0, KEY_QUERY_VALUE, &zone_map) == ERROR_SUCCESS) {
463 size = sizeof(DWORD);
464 if (RegQueryValueExA(zone_map, "IEHarden", NULL, &type, (LPBYTE) &ie_harden, &size) != ERROR_SUCCESS ||
465 type != REG_DWORD) {
466 ie_harden = 0;
468 RegCloseKey(zone_map);
471 return ie_harden != 0;
474 static void test_url_action(IInternetSecurityManager *secmgr, IInternetZoneManager *zonemgr, DWORD action)
476 DWORD res, size, policy, reg_policy;
477 char buf[10];
478 HKEY hkey;
479 HRESULT hres;
481 /* FIXME: HKEY_CURRENT_USER is most of the time the default but this can be changed on a system.
482 * The test should be changed to cope with that, if need be.
484 res = RegOpenKeyA(HKEY_CURRENT_USER,
485 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3", &hkey);
486 ok(res == ERROR_SUCCESS, "Could not open zone key\n");
487 if(res != ERROR_SUCCESS)
488 return;
490 wsprintfA(buf, "%X", action);
491 size = sizeof(DWORD);
492 res = RegQueryValueExA(hkey, buf, NULL, NULL, (BYTE*)&reg_policy, &size);
493 RegCloseKey(hkey);
495 /* Try settings from HKEY_LOCAL_MACHINE. */
496 if(res != ERROR_SUCCESS || size != sizeof(DWORD)) {
497 res = RegOpenKeyA(HKEY_LOCAL_MACHINE,
498 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3", &hkey);
499 ok(res == ERROR_SUCCESS, "Could not open zone key\n");
501 size = sizeof(DWORD);
502 res = RegQueryValueExA(hkey, buf, NULL, NULL, (BYTE*)&reg_policy, &size);
503 RegCloseKey(hkey);
506 if(res != ERROR_SUCCESS || size != sizeof(DWORD)) {
507 policy = 0xdeadbeef;
508 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
509 sizeof(WCHAR), NULL, 0, 0, 0);
510 ok(hres == E_FAIL || broken(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
511 "(0x%x) got 0x%x (expected E_FAIL)\n", action, hres);
512 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
514 policy = 0xdeadbeef;
515 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
516 sizeof(DWORD), URLZONEREG_DEFAULT);
517 ok(hres == E_FAIL || broken(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
518 "(0x%x) got 0x%x (expected E_FAIL)\n", action, hres);
519 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
520 return;
523 policy = 0xdeadbeef;
524 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
525 sizeof(DWORD), URLZONEREG_DEFAULT);
526 ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
527 ok(policy == reg_policy, "(%x) policy=%x, expected %x\n", action, policy, reg_policy);
529 if(policy != URLPOLICY_QUERY) {
530 if(winetest_interactive || ! is_ie_hardened()) {
531 BOOL expect_parse_call = !called_securl_http;
533 policy = 0xdeadbeef;
534 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
535 sizeof(WCHAR), NULL, 0, 0, 0);
536 if(reg_policy == URLPOLICY_DISALLOW)
537 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
538 else
539 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
540 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
542 policy = 0xdeadbeef;
543 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
544 2, NULL, 0, 0, 0);
545 if(reg_policy == URLPOLICY_DISALLOW)
546 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
547 else
548 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
549 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
551 policy = 0xdeadbeef;
552 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
553 sizeof(DWORD), NULL, 0, 0, 0);
554 if(reg_policy == URLPOLICY_DISALLOW)
555 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
556 else
557 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
558 ok(policy == reg_policy, "(%x) policy=%x\n", action, policy);
560 policy = 0xdeadbeef;
561 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
562 sizeof(WCHAR), (BYTE*)0xdeadbeef, 16, 0, 0);
563 if(reg_policy == URLPOLICY_DISALLOW)
564 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
565 else
566 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
567 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
569 policy = 0xdeadbeef;
570 if(expect_parse_call)
571 SET_EXPECT(ParseUrl_SECURITY_URL_http);
572 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, winetest_to_httpW, action, (BYTE*)&policy,
573 sizeof(DWORD), NULL, 0, 0, 0);
574 if(expect_parse_call)
575 CHECK_CALLED(ParseUrl_SECURITY_URL_http);
576 if(reg_policy == URLPOLICY_DISALLOW)
577 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
578 else
579 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
580 ok(policy == reg_policy, "(%x) policy=%x\n", action, policy);
581 }else {
582 skip("IE running in Enhanced Security Configuration\n");
587 static void test_special_url_action(IInternetSecurityManager *secmgr, IInternetZoneManager *zonemgr, DWORD action)
589 DWORD policy;
590 HRESULT hres;
592 policy = 0xdeadbeef;
593 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
594 sizeof(DWORD), URLZONEREG_DEFAULT);
595 ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
596 ok(policy == URLPOLICY_DISALLOW, "(%x) policy=%x, expected URLPOLICY_DISALLOW\n", action, policy);
598 policy = 0xdeadbeef;
599 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, action, (BYTE*)&policy,
600 sizeof(WCHAR), NULL, 0, 0, 0);
601 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
603 policy = 0xdeadbeef;
604 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, action, (BYTE*)&policy,
605 sizeof(DWORD), NULL, 0, 0, 0);
606 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
607 ok(policy == URLPOLICY_DISALLOW, "policy = %x\n", policy);
610 static void test_activex(IInternetSecurityManager *secmgr)
612 DWORD policy, policy_size;
613 struct CONFIRMSAFETY cs;
614 BYTE *ppolicy;
615 HRESULT hres;
617 policy = 0xdeadbeef;
618 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, URLACTION_ACTIVEX_RUN, (BYTE*)&policy,
619 sizeof(DWORD), (BYTE*)&CLSID_TestActiveX, sizeof(CLSID), 0, 0);
620 ok(hres == S_OK, "ProcessUrlAction(URLACTION_ACTIVEX_RUN) failed: %08x\n", hres);
621 ok(policy == URLPOLICY_ALLOW || policy == URLPOLICY_DISALLOW, "policy = %x\n", policy);
623 cs.clsid = CLSID_TestActiveX;
624 cs.pUnk = (IUnknown*)0xdeadbeef;
625 cs.dwFlags = 0;
626 hres = IInternetSecurityManager_QueryCustomPolicy(secmgr, url1, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
627 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
628 ok(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), "QueryCusromPolicy failed: %08x\n", hres);
631 static void test_polices(void)
633 IInternetZoneManager *zonemgr = NULL;
634 IInternetSecurityManager *secmgr = NULL;
635 HRESULT hres;
637 trace("testing polices...\n");
639 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
640 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
641 hres = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
642 ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
644 test_url_action(secmgr, zonemgr, URLACTION_SCRIPT_RUN);
645 test_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_RUN);
646 test_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_OVERRIDE_OBJECT_SAFETY);
647 test_url_action(secmgr, zonemgr, URLACTION_CHANNEL_SOFTDIST_PERMISSIONS);
648 test_url_action(secmgr, zonemgr, 0xdeadbeef);
650 test_special_url_action(secmgr, zonemgr, URLACTION_SCRIPT_OVERRIDE_SAFETY);
651 test_special_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY);
653 test_activex(secmgr);
655 IInternetSecurityManager_Release(secmgr);
656 IInternetZoneManager_Release(zonemgr);
659 /* IE (or at least newer versions of it) seem to cache the keys in ZoneMap
660 * when urlmon.dll is loaded and it doesn't seem to update its cache, unless
661 * SetZoneMapping is used.
663 static void test_zone_domain_cache(void)
665 HRESULT hres;
666 DWORD res, zone;
667 IInternetSecurityManager *secmgr = NULL;
668 HKEY domains, domain;
670 static const WCHAR testing_domain_urlW[] = {'h','t','t','p',':','/','/','t','e','s','t','i','n','g','.',
671 'd','o','m','a','i','n','/',0};
673 res = RegOpenKeyA(HKEY_CURRENT_USER, szZoneMapDomainsKey, &domains);
674 ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
675 if(res != ERROR_SUCCESS)
676 return;
678 res = RegCreateKeyA(domains, "testing.domain", &domain);
679 ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
680 if(res != ERROR_SUCCESS) {
681 RegCloseKey(domains);
682 return;
685 zone = URLZONE_CUSTOM;
686 res = RegSetValueExA(domain, "http", 0, REG_DWORD, (BYTE*)&zone, sizeof(DWORD));
687 ok(res == ERROR_SUCCESS, "RegSetValueEx failed: %d\n", res);
689 RegCloseKey(domain);
691 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
692 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
694 zone = URLZONE_INVALID;
695 hres = IInternetSecurityManager_MapUrlToZone(secmgr, testing_domain_urlW, &zone, 0);
696 ok(hres == S_OK, "MapUrlToZone failed: %08x\n", hres);
697 todo_wine ok(zone == URLZONE_INTERNET, "Got %d, expected URLZONE_INTERNET\n", zone);
699 /* FIXME: Play nice with ZoneMaps that existed before the test is run. */
700 res = RegDeleteKeyA(domains, "testing.domain");
701 ok(res == ERROR_SUCCESS, "RegDeleteKey failed: %d\n", res);
703 RegCloseKey(domains);
704 IInternetSecurityManager_Release(secmgr);
707 typedef struct {
708 const char *domain;
709 const char *subdomain;
710 const char *scheme;
711 DWORD zone;
712 } zone_domain_mapping;
714 /* FIXME: Move these into SetZoneMapping tests when the day comes... */
715 static const zone_domain_mapping zone_domain_mappings[] = {
716 /* Implicitly means "*.yabadaba.do". */
717 {"yabadaba.do",NULL,"http",URLZONE_CUSTOM},
718 /* The '*' doesn't count as a wildcard, since it's not the first component of the subdomain. */
719 {"super.cool","testing.*","ftp",URLZONE_CUSTOM2},
720 /* The '*' counts since it's the first component of the subdomain. */
721 {"super.cool","*.testing","ftp",URLZONE_CUSTOM2},
722 /* All known scheme types apply to wildcard schemes. */
723 {"tests.test",NULL,"*",URLZONE_CUSTOM},
724 /* Due to a defect with how windows checks the mappings, unknown scheme types
725 * never seem to get mapped properly. */
726 {"tests.test",NULL,"zip",URLZONE_CUSTOM},
727 {"www.testing.com",NULL,"http",URLZONE_CUSTOM},
728 {"www.testing.com","testing","http",URLZONE_CUSTOM2},
729 {"org",NULL,"http",URLZONE_CUSTOM},
730 {"org","testing","http",URLZONE_CUSTOM2},
731 {"wine.testing",NULL,"*",URLZONE_CUSTOM2}
734 static BOOL register_zone_domains(void)
736 HKEY domains;
737 DWORD res, i;
739 /* Some Windows versions don't seem to have a "Domains" key in their HKLM. */
740 res = RegOpenKeyA(HKEY_LOCAL_MACHINE, szZoneMapDomainsKey, &domains);
741 ok(res == ERROR_SUCCESS || broken(res == ERROR_FILE_NOT_FOUND), "RegOpenKey failed: %d\n", res);
742 if(res == ERROR_SUCCESS) {
743 HKEY domain;
744 DWORD zone = URLZONE_CUSTOM;
746 res = RegCreateKeyA(domains, "local.machine", &domain);
747 if (res == ERROR_ACCESS_DENIED)
749 skip("need admin rights\n");
750 RegCloseKey(domains);
751 return FALSE;
753 ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
755 res = RegSetValueExA(domain, "http", 0, REG_DWORD, (BYTE*)&zone, sizeof(DWORD));
756 ok(res == ERROR_SUCCESS, "RegSetValueEx failed: %d\n", res);
758 RegCloseKey(domain);
759 RegCloseKey(domains);
762 res = RegOpenKeyA(HKEY_CURRENT_USER, szZoneMapDomainsKey, &domains);
763 ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
765 for(i = 0; i < ARRAY_SIZE(zone_domain_mappings); ++i) {
766 const zone_domain_mapping *test = zone_domain_mappings+i;
767 HKEY domain;
769 res = RegCreateKeyA(domains, test->domain, &domain);
770 ok(res == ERROR_SUCCESS, "RegCreateKey failed with %d on test %d\n", res, i);
772 /* Only set the value if there's no subdomain. */
773 if(!test->subdomain) {
774 res = RegSetValueExA(domain, test->scheme, 0, REG_DWORD, (BYTE*)&test->zone, sizeof(DWORD));
775 ok(res == ERROR_SUCCESS, "RegSetValueEx failed with %d on test %d\n", res, i);
776 } else {
777 HKEY subdomain;
779 res = RegCreateKeyA(domain, test->subdomain, &subdomain);
780 ok(res == ERROR_SUCCESS, "RegCreateKey failed with %d on test %d\n", res, i);
782 res = RegSetValueExA(subdomain, test->scheme, 0, REG_DWORD, (BYTE*)&test->zone, sizeof(DWORD));
783 ok(res == ERROR_SUCCESS, "RegSetValueEx failed with %d on test %d\n", res, i);
785 RegCloseKey(subdomain);
788 RegCloseKey(domain);
791 RegCloseKey(domains);
792 return TRUE;
795 static void unregister_zone_domains(void)
797 HKEY domains;
798 DWORD res, i;
800 res = RegOpenKeyA(HKEY_LOCAL_MACHINE, szZoneMapDomainsKey, &domains);
801 ok(res == ERROR_SUCCESS || broken(res == ERROR_FILE_NOT_FOUND), "RegOpenKey failed: %d\n", res);
802 if(res == ERROR_SUCCESS) {
803 RegDeleteKeyA(domains, "local.machine");
804 RegCloseKey(domains);
807 res = RegOpenKeyA(HKEY_CURRENT_USER, szZoneMapDomainsKey, &domains);
808 ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
810 for(i = 0; i < ARRAY_SIZE(zone_domain_mappings); ++i) {
811 const zone_domain_mapping *test = zone_domain_mappings+i;
813 /* FIXME: Uses the "cludge" approach to remove the test data from the registry!
814 * Although, if domain names are... unique, this shouldn't cause any harm
815 * to keys (if any) that existed before the tests.
817 if(test->subdomain) {
818 HKEY domain;
820 res = RegOpenKeyA(domains, test->domain, &domain);
821 if(res == ERROR_SUCCESS) {
822 RegDeleteKeyA(domain, test->subdomain);
823 RegCloseKey(domain);
826 RegDeleteKeyA(domains, test->domain);
829 RegCloseKey(domains);
832 static void run_child_process(void)
834 char cmdline[MAX_PATH];
835 char path[MAX_PATH];
836 char **argv;
837 PROCESS_INFORMATION pi;
838 STARTUPINFOA si = { 0 };
839 BOOL ret;
841 GetModuleFileNameA(NULL, path, MAX_PATH);
843 si.cb = sizeof(si);
844 winetest_get_mainargs(&argv);
845 sprintf(cmdline, "\"%s\" %s domain_tests", argv[0], argv[1]);
846 ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
847 ok(ret, "Failed to spawn child process: %u\n", GetLastError());
848 wait_child_process(pi.hProcess);
849 CloseHandle(pi.hThread);
850 CloseHandle(pi.hProcess);
853 typedef struct {
854 const WCHAR *url;
855 DWORD zone;
856 BOOL todo;
857 DWORD broken_zone;
858 } zone_mapping_test;
860 static const zone_mapping_test zone_mapping_tests[] = {
861 /* Tests for "yabadaba.do" zone mappings. */
862 {L"http://yabadaba.do/", URLZONE_CUSTOM},
863 {L"http://google.yabadaba.do/", URLZONE_CUSTOM},
864 {L"zip://yabadaba.do/", URLZONE_INTERNET},
865 /* Tests for "super.cool" zone mappings. */
866 {L"ftp://testing.google.super.cool/", URLZONE_INTERNET},
867 {L"ftp://testing.*.super.cool/", URLZONE_CUSTOM2},
868 {L"ftp://google.testing.super.cool/", URLZONE_CUSTOM2},
869 /* Tests for "tests.test" zone mappings. */
870 {L"http://tests.test/", URLZONE_CUSTOM},
871 {L"http://www.tests.test/", URLZONE_CUSTOM},
872 {L"ftp://tests.test/", URLZONE_CUSTOM},
873 {L"ftp://www.tests.test/", URLZONE_CUSTOM},
874 {L"test://www.tests.test/", URLZONE_INTERNET},
875 {L"test://tests.test/", URLZONE_INTERNET},
876 {L"zip://www.tests.test/", URLZONE_INTERNET},
877 {L"zip://tests.test/", URLZONE_INTERNET},
878 /* Tests for "www.testing.com" zone mappings. */
879 {L"http://google.www.testing.com/", URLZONE_INTERNET},
880 {L"http://www.testing.com/", URLZONE_CUSTOM, FALSE, URLZONE_INTERNET},
881 {L"http://testing.www.testing.com/", URLZONE_CUSTOM2, FALSE, URLZONE_INTERNET},
882 /* Tests for "org" zone mappings. */
883 {L"http://google.org/", URLZONE_INTERNET, FALSE, URLZONE_CUSTOM},
884 {L"http://org/", URLZONE_CUSTOM},
885 {L"http://testing.org/", URLZONE_CUSTOM2},
886 /* Tests for "wine.testing" mapping */
887 {L"*:wine.testing/test", URLZONE_CUSTOM2},
888 {L"http://wine.testing/testing", URLZONE_CUSTOM2}
891 static void test_zone_domain_mappings(void)
893 HRESULT hres;
894 DWORD i, res;
895 IInternetSecurityManager *secmgr = NULL;
896 HKEY domains;
897 DWORD zone = URLZONE_INVALID;
899 trace("testing zone domain mappings...\n");
901 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
902 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
904 res = RegOpenKeyA(HKEY_LOCAL_MACHINE, szZoneMapDomainsKey, &domains);
905 if(res == ERROR_SUCCESS) {
906 static const WCHAR local_machineW[] = {'h','t','t','p',':','/','/','t','e','s','t','.','l','o','c','a','l',
907 '.','m','a','c','h','i','n','e','/',0};
909 hres = IInternetSecurityManager_MapUrlToZone(secmgr, local_machineW, &zone, 0);
910 ok(hres == S_OK, "MapUrlToZone failed: %08x\n", hres);
911 ok(zone == URLZONE_CUSTOM, "Expected URLZONE_CUSTOM, but got %d\n", zone);
913 RegCloseKey(domains);
916 for(i = 0; i < ARRAY_SIZE(zone_mapping_tests); ++i) {
917 const zone_mapping_test *test = zone_mapping_tests+i;
918 zone = URLZONE_INVALID;
920 hres = IInternetSecurityManager_MapUrlToZone(secmgr, test->url, &zone, 0);
921 ok(hres == S_OK, "MapUrlToZone failed: %08x\n", hres);
922 todo_wine_if (test->todo)
923 ok(zone == test->zone || broken(test->broken_zone == zone),
924 "Expected %d, but got %d on test %d\n", test->zone, zone, i);
927 IInternetSecurityManager_Release(secmgr);
930 static void test_zone_domains(void)
932 if(is_ie_hardened()) {
933 skip("IE running in Enhanced Security Configuration\n");
934 return;
935 } else if(!pCreateUri) {
936 win_skip("Skipping zone domain tests, IE too old\n");
937 return;
940 trace("testing zone domains...\n");
942 test_zone_domain_cache();
944 if (!register_zone_domains()) return;
945 run_child_process();
946 unregister_zone_domains();
949 static void test_CoInternetCreateZoneManager(void)
951 IInternetZoneManager *zonemgr = NULL;
952 IUnknown *punk = NULL;
953 HRESULT hr;
955 trace("simple zone manager tests...\n");
957 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
958 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
959 if (FAILED(hr))
960 return;
962 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IUnknown, (void **) &punk);
963 ok(SUCCEEDED(hr), "got 0x%x with %p (expected Success)\n", hr, punk);
964 if (punk)
965 IUnknown_Release(punk);
967 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IInternetZoneManager, (void **) &punk);
968 ok(SUCCEEDED(hr), "got 0x%x with %p (expected Success)\n", hr, punk);
969 if (punk)
970 IUnknown_Release(punk);
973 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IInternetZoneManagerEx, (void **) &punk);
974 if (SUCCEEDED(hr)) {
975 IUnknown_Release(punk);
977 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IInternetZoneManagerEx2, (void **) &punk);
978 ok(hr == S_OK || broken(hr == E_NOINTERFACE /* some W2K3 */),
979 "got 0x%x (expected S_OK)\n", hr);
980 if (punk)
981 IUnknown_Release(punk);
982 else
983 win_skip("InternetZoneManagerEx2 not supported\n");
986 else
987 win_skip("InternetZoneManagerEx not supported\n");
989 hr = IInternetZoneManager_Release(zonemgr);
990 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
994 static void test_CreateZoneEnumerator(void)
996 IInternetZoneManager *zonemgr = NULL;
997 HRESULT hr;
998 DWORD dwEnum;
999 DWORD dwEnum2;
1000 DWORD dwCount;
1001 DWORD dwCount2;
1003 trace("testing zone enumerator...\n");
1005 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
1006 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
1007 if (FAILED(hr))
1008 return;
1010 dwEnum=0xdeadbeef;
1011 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, NULL, 0);
1012 ok((hr == E_INVALIDARG) && (dwEnum == 0xdeadbeef),
1013 "got 0x%x with 0x%x (expected E_INVALIDARG with 0xdeadbeef)\n", hr, dwEnum);
1015 dwCount=0xdeadbeef;
1016 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, NULL, &dwCount, 0);
1017 ok((hr == E_INVALIDARG) && (dwCount == 0xdeadbeef),
1018 "got 0x%x and 0x%x (expected E_INVALIDARG and 0xdeadbeef)\n", hr, dwCount);
1020 dwEnum=0xdeadbeef;
1021 dwCount=0xdeadbeef;
1022 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 0xffffffff);
1023 ok((hr == E_INVALIDARG) && (dwEnum == 0xdeadbeef) && (dwCount == 0xdeadbeef),
1024 "got 0x%x with 0x%x and 0x%x (expected E_INVALIDARG with 0xdeadbeef and 0xdeadbeef)\n",
1025 hr, dwEnum, dwCount);
1027 dwEnum=0xdeadbeef;
1028 dwCount=0xdeadbeef;
1029 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 1);
1030 ok((hr == E_INVALIDARG) && (dwEnum == 0xdeadbeef) && (dwCount == 0xdeadbeef),
1031 "got 0x%x with 0x%x and 0x%x (expected E_INVALIDARG with 0xdeadbeef and 0xdeadbeef)\n",
1032 hr, dwEnum, dwCount);
1034 dwEnum=0xdeadbeef;
1035 dwCount=0xdeadbeef;
1036 /* Normal use */
1037 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 0);
1038 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1040 if (SUCCEEDED(hr)) {
1041 dwEnum2=0xdeadbeef;
1042 dwCount2=0xdeadbeef;
1043 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum2, &dwCount2, 0);
1044 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1045 if (SUCCEEDED(hr)) {
1046 /* native urlmon has an incrementing counter for dwEnum */
1047 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum2);
1048 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1051 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum);
1052 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1054 /* Destroy the Enumerator twice is detected and handled in native urlmon */
1055 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum);
1056 ok((hr == E_INVALIDARG), "got 0x%x (expected E_INVALIDARG)\n", hr);
1059 /* ::Release succeed also, when a ::DestroyZoneEnumerator is missing */
1060 hr = IInternetZoneManager_Release(zonemgr);
1061 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1064 static void test_GetZoneActionPolicy(void)
1066 IInternetZoneManager *zonemgr = NULL;
1067 BYTE buf[32];
1068 HRESULT hres;
1069 DWORD action = URLACTION_CREDENTIALS_USE; /* Implemented on all IE versions */
1071 trace("testing GetZoneActionPolixy...\n");
1073 hres = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
1074 ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
1075 if(FAILED(hres))
1076 return;
1078 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, buf,
1079 sizeof(DWORD), URLZONEREG_DEFAULT);
1080 ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
1081 ok(*(DWORD*)buf == URLPOLICY_CREDENTIALS_SILENT_LOGON_OK ||
1082 *(DWORD*)buf == URLPOLICY_CREDENTIALS_MUST_PROMPT_USER ||
1083 *(DWORD*)buf == URLPOLICY_CREDENTIALS_CONDITIONAL_PROMPT ||
1084 *(DWORD*)buf == URLPOLICY_CREDENTIALS_ANONYMOUS_ONLY,
1085 "unexpected policy=%d\n", *(DWORD*)buf);
1087 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, NULL,
1088 sizeof(DWORD), URLZONEREG_DEFAULT);
1089 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
1091 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, buf,
1092 2, URLZONEREG_DEFAULT);
1093 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
1095 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
1096 sizeof(DWORD), URLZONEREG_DEFAULT);
1097 ok(hres == E_FAIL || broken(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
1098 "(0x%x) got 0x%x (expected E_FAIL)\n", action, hres);
1100 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, action, buf,
1101 sizeof(DWORD), URLZONEREG_DEFAULT);
1102 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
1104 IInternetZoneManager_Release(zonemgr);
1107 static void test_GetZoneAt(void)
1109 IInternetZoneManager *zonemgr = NULL;
1110 HRESULT hr;
1111 DWORD dwEnum;
1112 DWORD dwCount;
1113 DWORD dwZone;
1114 DWORD i;
1116 trace("testing GetZoneAt...\n");
1118 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
1119 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
1120 if (FAILED(hr))
1121 return;
1123 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 0);
1124 if (FAILED(hr))
1125 goto cleanup;
1127 if (0) {
1128 /* this crashes with native urlmon */
1129 IInternetZoneManager_GetZoneAt(zonemgr, dwEnum, 0, NULL);
1132 dwZone = 0xdeadbeef;
1133 hr = IInternetZoneManager_GetZoneAt(zonemgr, 0xdeadbeef, 0, &dwZone);
1134 ok(hr == E_INVALIDARG,
1135 "got 0x%x with 0x%x (expected E_INVALIDARG)\n", hr, dwZone);
1137 for (i = 0; i < dwCount; i++)
1139 dwZone = 0xdeadbeef;
1140 hr = IInternetZoneManager_GetZoneAt(zonemgr, dwEnum, i, &dwZone);
1141 ok(hr == S_OK, "#%d: got x%x with %d (expected S_OK)\n", i, hr, dwZone);
1144 dwZone = 0xdeadbeef;
1145 /* MSDN (index .. must be .. less than or equal to) is wrong */
1146 hr = IInternetZoneManager_GetZoneAt(zonemgr, dwEnum, dwCount, &dwZone);
1147 ok(hr == E_INVALIDARG,
1148 "got 0x%x with 0x%x (expected E_INVALIDARG)\n", hr, dwZone);
1150 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum);
1151 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1153 cleanup:
1154 hr = IInternetZoneManager_Release(zonemgr);
1155 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1158 static void test_GetZoneAttributes(void)
1160 IInternetZoneManager *zonemgr = NULL;
1161 CHAR buffer [sizeof(ZONEATTRIBUTES) + 32];
1162 ZONEATTRIBUTES* pZA = (ZONEATTRIBUTES*) buffer;
1163 HRESULT hr;
1164 DWORD i;
1166 trace("testing GetZoneAttributes...\n");
1168 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
1169 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
1170 if (FAILED(hr))
1171 return;
1173 /* native urlmon has Zone "0" up to Zone "4" since IE4 */
1174 for (i = 0; i < 5; i++) {
1175 memset(buffer, -1, sizeof(buffer));
1176 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, i, pZA);
1177 ok(hr == S_OK, "#%d: got 0x%x (expected S_OK)\n", i, hr);
1180 /* IE8 no longer set cbSize */
1181 memset(buffer, -1, sizeof(buffer));
1182 pZA->cbSize = 0;
1183 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, pZA);
1184 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1185 ok((pZA->cbSize == 0) || (pZA->cbSize == sizeof(ZONEATTRIBUTES)),
1186 "got cbSize = %d (expected 0)\n", pZA->cbSize);
1188 memset(buffer, -1, sizeof(buffer));
1189 pZA->cbSize = 64;
1190 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, pZA);
1191 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1192 ok((pZA->cbSize == 64) || (pZA->cbSize == sizeof(ZONEATTRIBUTES)),
1193 "got cbSize = %d (expected 64)\n", pZA->cbSize);
1195 memset(buffer, -1, sizeof(buffer));
1196 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, pZA);
1197 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1198 ok((pZA->cbSize == 0xffffffff) || (pZA->cbSize == sizeof(ZONEATTRIBUTES)),
1199 "got cbSize = 0x%x (expected 0xffffffff)\n", pZA->cbSize);
1201 /* IE8 up to IE10 don't fail on invalid zones */
1202 memset(buffer, -1, sizeof(buffer));
1203 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0xdeadbeef, pZA);
1204 ok(hr == S_OK || hr == E_FAIL || hr == E_POINTER,
1205 "got 0x%x (expected S_OK or E_FAIL)\n", hr);
1207 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, NULL);
1208 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1210 hr = IInternetZoneManager_Release(zonemgr);
1211 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1214 static void test_SetZoneAttributes(void)
1216 IInternetZoneManager *zonemgr = NULL;
1217 CHAR buffer [sizeof(ZONEATTRIBUTES) + 16];
1218 ZONEATTRIBUTES* pZA = (ZONEATTRIBUTES*) buffer;
1219 CHAR regpath[MAX_PATH];
1220 HKEY hkey;
1221 HRESULT hr;
1222 DWORD res;
1224 trace("testing SetZoneAttributes...\n");
1225 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
1226 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
1227 if (FAILED(hr))
1228 return;
1230 memset(buffer, -1, sizeof(buffer));
1231 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, URLZONE_LOCAL_MACHINE, pZA);
1232 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1234 sprintf(regpath, "%s\\Zones\\%d", szInternetSettingsKey, URLZONE_CUSTOM);
1235 res = RegCreateKeyA(HKEY_CURRENT_USER, regpath, &hkey);
1236 RegCloseKey(hkey);
1238 ok(res == ERROR_SUCCESS, "got %d (expected ERROR_SUCCESS)\n", res);
1239 if (res != ERROR_SUCCESS)
1240 goto cleanup;
1242 pZA->cbSize = sizeof(ZONEATTRIBUTES);
1243 hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, NULL);
1244 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1246 /* normal use */
1247 hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, pZA);
1248 if (hr == E_FAIL) {
1249 win_skip("SetZoneAttributes not supported: IE too old\n");
1250 goto cleanup;
1252 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1254 /* native urlmon ignores cbSize */
1255 pZA->cbSize = sizeof(ZONEATTRIBUTES) + sizeof(DWORD);
1256 hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, pZA);
1257 ok(hr == S_OK, "got 0x%x for sizeof(ZONEATTRIBUTES) + sizeof(DWORD) (expected S_OK)\n", hr);
1259 pZA->cbSize = sizeof(ZONEATTRIBUTES) - sizeof(DWORD);
1260 hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, pZA);
1261 ok(hr == S_OK, "got 0x%x for sizeof(ZONEATTRIBUTES) - sizeof(DWORD) (expected S_OK)\n", hr);
1263 pZA->cbSize = 0;
1264 hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, pZA);
1265 ok(hr == S_OK, "got 0x%x for size 0 (expected S_OK)\n", hr);
1267 /* The key for the zone must be present, when calling SetZoneAttributes */
1268 myRegDeleteTreeA(HKEY_CURRENT_USER, regpath);
1269 /* E_FAIL is returned from IE6 here, which is reasonable.
1270 All newer IE return S_OK without saving the zone attributes to the registry.
1271 This is a Windows bug, but we have to accept that as standard */
1272 hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, pZA);
1273 ok((hr == S_OK) || broken(hr == E_FAIL), "got 0x%x (expected S_OK)\n", hr);
1275 /* SetZoneAttributes did not create the directory */
1276 res = RegOpenKeyA(HKEY_CURRENT_USER, regpath, &hkey);
1277 ok((res == ERROR_FILE_NOT_FOUND) && (hkey == NULL),
1278 "got %u with %p (expected ERROR_FILE_NOT_FOUND with NULL)\n", res, hkey);
1280 if (hkey) RegCloseKey(hkey);
1282 cleanup:
1283 /* delete zone settings in the registry */
1284 myRegDeleteTreeA(HKEY_CURRENT_USER, regpath);
1286 hr = IInternetZoneManager_Release(zonemgr);
1287 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1291 static void test_InternetSecurityMarshalling(void)
1293 IInternetSecurityManager *secmgr = NULL;
1294 IUnknown *unk;
1295 IStream *stream;
1296 HRESULT hres;
1298 trace("testing marshalling...\n");
1300 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
1301 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
1302 if(FAILED(hres))
1303 return;
1305 hres = IInternetSecurityManager_QueryInterface(secmgr, &IID_IUnknown, (void**)&unk);
1306 ok(hres == S_OK, "QueryInterface returned: %08x\n", hres);
1308 hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1309 ok(hres == S_OK, "CreateStreamOnHGlobal returned: %08x\n", hres);
1311 hres = CoMarshalInterface(stream, &IID_IInternetSecurityManager, unk, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
1312 /* Not supported in W98 */
1313 ok(hres == S_OK || broken(hres == REGDB_E_IIDNOTREG),
1314 "CoMarshalInterface returned: %08x\n", hres);
1316 IStream_Release(stream);
1317 IUnknown_Release(unk);
1318 IInternetSecurityManager_Release(secmgr);
1321 static void test_InternetGetSecurityUrl(void)
1323 const WCHAR url5_out[] = {'h','t','t','p',':','w','w','w','.','z','o','n','e','3',
1324 '.','w','i','n','e','t','e','s','t',0};
1325 const WCHAR url7_out[] = {'f','t','p',':','z','o','n','e','3','.','w','i','n','e','t','e','s','t',0};
1327 const WCHAR *in[] = {url2, url3, url4, url5, url7, url8, url9, url10};
1328 const WCHAR *out_default[] = {url2, url3, url4, url5_out, url7_out, url8, url5_out, url10};
1329 const WCHAR *out_securl[] = {url2, url3, url4, url5, url7, url8, url9, url10};
1331 WCHAR *sec;
1332 DWORD i;
1333 HRESULT hres;
1335 trace("testing CoInternetGetSecurityUrl...\n");
1337 for(i = 0; i < ARRAY_SIZE(in); i++) {
1338 hres = pCoInternetGetSecurityUrl(in[i], &sec, PSU_DEFAULT, 0);
1339 ok(hres == S_OK, "(%d) CoInternetGetSecurityUrl returned: %08x\n", i, hres);
1340 if(hres == S_OK) {
1341 ok(!strcmp_w(sec, out_default[i]), "(%d) Got %s, expected %s\n",
1342 i, wine_dbgstr_w(sec), wine_dbgstr_w(out_default[i]));
1343 CoTaskMemFree(sec);
1346 hres = pCoInternetGetSecurityUrl(in[i], &sec, PSU_SECURITY_URL_ONLY, 0);
1347 ok(hres == S_OK, "(%d) CoInternetGetSecurityUrl returned: %08x\n", i, hres);
1348 if(hres == S_OK) {
1349 ok(!strcmp_w(sec, out_securl[i]), "(%d) Got %s, expected %s\n",
1350 i, wine_dbgstr_w(sec), wine_dbgstr_w(out_securl[i]));
1351 CoTaskMemFree(sec);
1355 SET_EXPECT(ParseUrl_SECURITY_URL_input2);
1356 SET_EXPECT(ParseUrl_SECURITY_URL_expected);
1357 SET_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
1359 hres = pCoInternetGetSecurityUrl(security_url2W, &sec, PSU_DEFAULT, 0);
1360 ok(hres == S_OK, "CoInternetGetSecurityUrl returned 0x%08x, expected S_OK\n", hres);
1362 CHECK_CALLED(ParseUrl_SECURITY_URL_input2);
1363 CHECK_CALLED(ParseUrl_SECURITY_URL_expected);
1364 CHECK_CALLED(ParseUrl_SECURITY_DOMAIN_expected);
1366 ok(!lstrcmpW(security_expectedW, sec), "Expected %s but got %s\n",
1367 wine_dbgstr_w(security_expectedW), wine_dbgstr_w(sec));
1368 CoTaskMemFree(sec);
1371 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
1372 REFIID riid, void **ppv)
1374 ok(0, "unexpected call\n");
1375 return E_NOINTERFACE;
1378 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
1380 return 2;
1383 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
1385 return 1;
1388 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
1389 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
1390 DWORD *pcchResult, DWORD dwReserved)
1392 const WCHAR *ret = NULL;
1394 ok(pwzResult != NULL, "pwzResult == NULL\n");
1395 ok(pcchResult != NULL, "pcchResult == NULL\n");
1396 ok(!dwParseFlags, "Expected 0, but got 0x%08x\n", dwParseFlags);
1398 switch(ParseAction) {
1399 case PARSE_SECURITY_URL:
1400 if(!strcmp_w(pwzUrl, security_urlW)) {
1401 CHECK_EXPECT(ParseUrl_SECURITY_URL_input);
1402 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1403 ret = security_expectedW;
1404 } else if(!strcmp_w(pwzUrl, security_url2W)) {
1405 CHECK_EXPECT(ParseUrl_SECURITY_URL_input2);
1406 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1407 ret = security_expectedW;
1408 } else if(!strcmp_w(pwzUrl, security_expectedW)) {
1409 CHECK_EXPECT(ParseUrl_SECURITY_URL_expected);
1410 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1411 ret = security_expectedW;
1412 } else if(!strcmp_w(pwzUrl, winetest_to_httpW)) {
1413 switch(++called_securl_http) {
1414 case 1:
1415 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1416 break;
1417 case 2:
1418 CHECK_EXPECT(ParseUrl_SECURITY_URL_http);
1419 ok(cchResult == lstrlenW(url9)+1, "Got %d\n", cchResult);
1420 break;
1421 default:
1422 todo_wine CHECK_EXPECT(ParseUrl_SECURITY_URL_http);
1424 ret = url9;
1425 } else
1426 ok(0, "Unexpected call, pwzUrl=%s\n", wine_dbgstr_w(pwzUrl));
1428 break;
1429 case PARSE_SECURITY_DOMAIN:
1431 CHECK_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
1433 ok(!strcmp_w(pwzUrl, security_expectedW), "Expected %s but got %s\n",
1434 wine_dbgstr_w(security_expectedW), wine_dbgstr_w(pwzUrl));
1435 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1436 ret = security_expectedW;
1437 break;
1438 default:
1439 ok(0, "Unexpected call, ParseAction=%d pwzUrl=%s\n", ParseAction,
1440 wine_dbgstr_w(pwzUrl));
1443 if(!ret)
1444 return E_FAIL;
1446 *pcchResult = lstrlenW(ret)+1;
1447 if(*pcchResult > cchResult)
1448 return S_FALSE;
1449 memcpy(pwzResult, ret, (*pcchResult)*sizeof(WCHAR));
1450 return S_OK;
1453 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
1454 LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
1455 LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
1457 ok(0, "unexpected call\n");
1458 return E_NOTIMPL;
1461 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
1462 LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
1464 ok(0, "unexpected call\n");
1465 return E_NOTIMPL;
1468 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
1469 LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
1470 DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
1472 ok(0, "unexpected call\n");
1473 return E_NOTIMPL;
1476 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
1477 InternetProtocolInfo_QueryInterface,
1478 InternetProtocolInfo_AddRef,
1479 InternetProtocolInfo_Release,
1480 InternetProtocolInfo_ParseUrl,
1481 InternetProtocolInfo_CombineUrl,
1482 InternetProtocolInfo_CompareUrl,
1483 InternetProtocolInfo_QueryInfo
1486 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
1488 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1490 if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
1491 *ppv = &protocol_info;
1492 return S_OK;
1495 ok(0, "unexpected call\n");
1496 return E_NOINTERFACE;
1499 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1501 return 2;
1504 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1506 return 1;
1509 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1510 REFIID riid, void **ppv)
1512 ok(0, "unexpected call\n");
1513 return E_NOTIMPL;
1516 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1518 ok(0, "unexpected call\n");
1519 return S_OK;
1522 static const IClassFactoryVtbl ClassFactoryVtbl = {
1523 ClassFactory_QueryInterface,
1524 ClassFactory_AddRef,
1525 ClassFactory_Release,
1526 ClassFactory_CreateInstance,
1527 ClassFactory_LockServer
1530 static IClassFactory protocol_cf = { &ClassFactoryVtbl };
1532 static void register_protocols(void)
1534 IInternetSession *session;
1535 HRESULT hres;
1537 hres = pCoInternetGetSession(0, &session, 0);
1538 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1539 if(FAILED(hres))
1540 return;
1542 hres = IInternetSession_RegisterNameSpace(session, &protocol_cf, &IID_NULL,
1543 winetestW, 0, NULL, 0);
1544 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1546 IInternetSession_Release(session);
1549 static void unregister_protocols(void) {
1550 IInternetSession *session;
1551 HRESULT hr;
1553 hr = pCoInternetGetSession(0, &session, 0);
1554 ok(hr == S_OK, "CoInternetGetSession failed: 0x%08x\n", hr);
1555 if(FAILED(hr))
1556 return;
1558 hr = IInternetSession_UnregisterNameSpace(session, &protocol_cf, winetestW);
1559 ok(hr == S_OK, "UnregisterNameSpace failed: 0x%08x\n", hr);
1561 IInternetSession_Release(session);
1564 static const struct {
1565 const WCHAR *uri;
1566 DWORD create_flags;
1567 const char *security_uri;
1568 HRESULT security_hres;
1569 const WCHAR *default_uri;
1570 HRESULT default_hres;
1571 BOOL todo;
1572 } sec_url_ex_tests[] = {
1573 {L"index.htm", Uri_CREATE_ALLOW_RELATIVE, "*:index.html", S_OK, L"*:index.htm", S_OK},
1574 {L"file://c:\\Index.htm", Uri_CREATE_FILE_USE_DOS_PATH, "file:///c:/Index.htm", S_OK, L"file:///c:/Index.htm", S_OK},
1575 {L"file:some%20file%2ejpg", 0, NULL, E_INVALIDARG, NULL, E_INVALIDARG},
1576 {L"file:some file.jpg", 0, NULL, E_INVALIDARG, NULL, E_INVALIDARG},
1577 {L"http://www.zone3.winetest/", 0, "http://www.zone3.winetest/", S_OK, L"http://www.zone3.winetest/", S_OK},
1578 {L"about:blank", 0, "about:blank", S_OK, L"about:blank", S_OK},
1579 {L"ftp://zone3.winetest/file.test", 0, "ftp://zone3.winetest/file.test", S_OK, L"ftp://zone3.winetest/file.test", S_OK},
1580 {L"test:123abc", 0, "test:123abc", S_OK, L"test:123abc", S_OK},
1581 {L"http:google.com/test.file", 0, "http:google.com/test.file", S_OK, L"http:google.com/test.file", S_OK},
1582 {L"ftp://test@ftp.winehq.org/", 0, "ftp://ftp.winehq.org/", S_OK, L"ftp://ftp.winehq.org/", S_OK},
1583 {L"test://google@ftp.winehq.org/", 0, "test://google@ftp.winehq.org/", S_OK, L"test://google@ftp.winehq.org/", S_OK}
1586 static void test_InternetGetSecurityUrlEx(void)
1588 HRESULT hr;
1589 DWORD i;
1590 IUri *uri = NULL, *result = NULL;
1592 trace("testing CoInternetGetSecurityUrlEx...\n");
1594 hr = pCoInternetGetSecurityUrlEx(NULL, NULL, PSU_DEFAULT, 0);
1595 ok(hr == E_INVALIDARG, "CoInternetGetSecurityUrlEx returned 0x%08x, expected E_INVALIDARG\n", hr);
1597 result = (void*) 0xdeadbeef;
1598 hr = pCoInternetGetSecurityUrlEx(NULL, &result, PSU_DEFAULT, 0);
1599 ok(hr == E_INVALIDARG, "CoInternetGetSecurityUrlEx returned 0x%08x, expected E_INVALIDARG\n", hr);
1600 ok(result == (void*) 0xdeadbeef, "'result' was %p\n", result);
1602 for(i = 0; i < ARRAY_SIZE(sec_url_ex_tests); ++i) {
1603 uri = NULL;
1605 hr = pCreateUri(sec_url_ex_tests[i].uri, sec_url_ex_tests[i].create_flags, 0, &uri);
1606 ok(hr == S_OK, "CreateUri returned 0x%08x on test %d\n", hr, i);
1607 if(hr == S_OK) {
1608 result = NULL;
1610 hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_DEFAULT, 0);
1611 todo_wine_if (sec_url_ex_tests[i].todo) {
1612 ok(hr == sec_url_ex_tests[i].default_hres,
1613 "CoInternetGetSecurityUrlEx returned 0x%08x, expected 0x%08x on test %d\n",
1614 hr, sec_url_ex_tests[i].default_hres, i);
1616 if(SUCCEEDED(hr)) {
1617 BSTR received;
1619 hr = IUri_GetDisplayUri(result, &received);
1620 ok(hr == S_OK, "GetDisplayUri returned 0x%08x on test %d\n", hr, i);
1621 if(hr == S_OK) {
1622 todo_wine_if (sec_url_ex_tests[i].todo) {
1623 ok(!lstrcmpW(sec_url_ex_tests[i].default_uri, received),
1624 "Expected %s but got %s on test %d\n",
1625 wine_dbgstr_w(sec_url_ex_tests[i].default_uri), wine_dbgstr_w(received), i);
1628 SysFreeString(received);
1630 if(result) IUri_Release(result);
1632 result = NULL;
1633 hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_SECURITY_URL_ONLY, 0);
1634 todo_wine_if (sec_url_ex_tests[i].todo) {
1635 ok(hr == sec_url_ex_tests[i].default_hres,
1636 "CoInternetGetSecurityUrlEx returned 0x%08x, expected 0x%08x on test %d\n",
1637 hr, sec_url_ex_tests[i].default_hres, i);
1639 if(SUCCEEDED(hr)) {
1640 BSTR received;
1642 hr = IUri_GetDisplayUri(result, &received);
1643 ok(hr == S_OK, "GetDisplayUri returned 0x%08x on test %d\n", hr, i);
1644 if(hr == S_OK) {
1645 todo_wine_if (sec_url_ex_tests[i].todo) {
1646 ok(!lstrcmpW(sec_url_ex_tests[i].default_uri, received),
1647 "Expected %s but got %s on test %d\n",
1648 wine_dbgstr_w(sec_url_ex_tests[i].default_uri), wine_dbgstr_w(received), i);
1651 SysFreeString(received);
1653 if(result) IUri_Release(result);
1656 if(uri) IUri_Release(uri);
1660 static void test_InternetGetSecurityUrlEx_Pluggable(void)
1662 HRESULT hr;
1663 IUri *uri = NULL, *result;
1665 trace("testing CoInternetGetSecurityUrlEx for pluggable protocols...\n");
1667 hr = pCreateUri(security_urlW, 0, 0, &uri);
1668 ok(hr == S_OK, "CreateUri returned 0x%08x\n", hr);
1669 if(hr == S_OK) {
1670 SET_EXPECT(ParseUrl_SECURITY_URL_input);
1671 SET_EXPECT(ParseUrl_SECURITY_URL_expected);
1672 SET_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
1674 hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_DEFAULT, 0);
1675 ok(hr == S_OK, "CoInternetGetSecurityUrlEx returned 0x%08x, expected S_OK\n", hr);
1677 CHECK_CALLED(ParseUrl_SECURITY_URL_input);
1678 CHECK_CALLED(ParseUrl_SECURITY_URL_expected);
1679 CHECK_CALLED(ParseUrl_SECURITY_DOMAIN_expected);
1681 if(hr == S_OK) {
1682 BSTR received = NULL;
1684 hr = IUri_GetAbsoluteUri(result, &received);
1685 ok(hr == S_OK, "GetAbsoluteUri returned 0x%08x\n", hr);
1686 if(hr == S_OK) {
1687 ok(!strcmp_w(security_expectedW, received), "Expected %s but got %s\n",
1688 wine_dbgstr_w(security_expectedW), wine_dbgstr_w(received));
1690 SysFreeString(received);
1692 if(result) IUri_Release(result);
1694 result = NULL;
1696 SET_EXPECT(ParseUrl_SECURITY_URL_input);
1697 SET_EXPECT(ParseUrl_SECURITY_URL_expected);
1699 hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_SECURITY_URL_ONLY, 0);
1700 ok(hr == S_OK, "CoInternetGetSecurityUrlEx returned 0x%08x, expected S_OK\n", hr);
1702 CHECK_CALLED(ParseUrl_SECURITY_URL_input);
1703 CHECK_CALLED(ParseUrl_SECURITY_URL_expected);
1705 if(hr == S_OK) {
1706 BSTR received = NULL;
1708 hr = IUri_GetAbsoluteUri(result, &received);
1709 ok(hr == S_OK, "GetAbsoluteUri returned 0x%08x\n", hr);
1710 if(hr == S_OK) {
1711 ok(!strcmp_w(security_expectedW, received), "Expected %s but got %s\n",
1712 wine_dbgstr_w(security_expectedW), wine_dbgstr_w(received));
1714 SysFreeString(received);
1716 if(result) IUri_Release(result);
1718 if(uri) IUri_Release(uri);
1721 static const BYTE secidex2_1[] = {'z','i','p',':','/','/','t','e','s','t','i','n','g','.','c','o','m','/',3,0,0,0};
1722 static const BYTE secidex2_2[] = {'z','i','p',':','t','e','s','t','i','n','g','.','c','o','m',3,0,0,0};
1723 static const BYTE secidex2_3[] = {'*',':','t','e','s','t','i','n','g','.','c','o','m',3,0,0,0};
1725 static const struct {
1726 const WCHAR *uri;
1727 DWORD create_flags;
1728 HRESULT map_hres;
1729 DWORD zone;
1730 BOOL map_todo;
1731 const BYTE *secid;
1732 DWORD secid_size;
1733 HRESULT secid_hres;
1734 BOOL secid_todo;
1735 } sec_mgr_ex2_tests[] = {
1736 {L"res://mshtml.dll/blank.htm", 0, S_OK, URLZONE_LOCAL_MACHINE, FALSE, secid1, sizeof(secid1), S_OK},
1737 {L"index.htm", Uri_CREATE_ALLOW_RELATIVE, 0, URLZONE_INTERNET, FALSE, secid2, sizeof(secid2), S_OK},
1738 {L"file://c:\\Index.html", 0, 0, URLZONE_LOCAL_MACHINE, FALSE, secid1, sizeof(secid1), S_OK},
1739 {L"http://www.zone3.winetest/", 0, 0, URLZONE_INTERNET, FALSE, secid5, sizeof(secid5), S_OK},
1740 {L"about:blank", 0, 0, URLZONE_INTERNET, FALSE, secid6, sizeof(secid6), S_OK},
1741 {L"ftp://zone3.winetest/file.test", 0, 0, URLZONE_INTERNET, FALSE, secid7, sizeof(secid7), S_OK},
1742 {L"/file/testing/test.test", Uri_CREATE_ALLOW_RELATIVE, 0, URLZONE_INTERNET, FALSE, NULL, 0, E_INVALIDARG},
1743 {L"zip://testing.com/", 0, 0, URLZONE_INTERNET, FALSE, secidex2_1, sizeof(secidex2_1), S_OK},
1744 {L"zip:testing.com", 0, 0, URLZONE_INTERNET, FALSE, secidex2_2, sizeof(secidex2_2), S_OK},
1745 {L"http:google.com", 0, S_OK, URLZONE_INVALID, FALSE, NULL, 0, E_INVALIDARG},
1746 {L"http:/google.com", 0, S_OK, URLZONE_INVALID, FALSE, NULL, 0, E_INVALIDARG},
1747 {L"*:/testing", 0, S_OK, URLZONE_INTERNET, FALSE, NULL, 0, E_INVALIDARG},
1748 {L"*://testing.com", 0, S_OK, URLZONE_INTERNET, FALSE, secidex2_3, sizeof(secidex2_3), S_OK}
1751 static void test_SecurityManagerEx2(void)
1753 HRESULT hres;
1754 DWORD i, zone;
1755 BYTE buf[512];
1756 DWORD buf_size = sizeof(buf);
1757 IInternetSecurityManager *sec_mgr;
1758 IInternetSecurityManagerEx2 *sec_mgr2;
1759 IUri *uri = NULL;
1761 static const WCHAR domainW[] = {'c','o','m','.','u','k',0};
1763 if(!pCreateUri) {
1764 win_skip("Skipping SecurityManagerEx2, IE is too old\n");
1765 return;
1768 trace("Testing SecurityManagerEx2...\n");
1770 hres = pCoInternetCreateSecurityManager(NULL, &sec_mgr, 0);
1771 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
1773 hres = IInternetSecurityManager_QueryInterface(sec_mgr, &IID_IInternetSecurityManagerEx2, (void**)&sec_mgr2);
1774 ok(hres == S_OK, "QueryInterface(IID_IInternetSecurityManagerEx2) failed: %08x\n", hres);
1776 zone = 0xdeadbeef;
1778 hres = IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2, NULL, &zone, 0, NULL, NULL);
1779 ok(hres == E_INVALIDARG, "MapUrlToZoneEx2 returned %08x, expected E_INVALIDARG\n", hres);
1780 ok(zone == URLZONE_INVALID, "zone was %d\n", zone);
1782 hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, NULL, buf, &buf_size, 0);
1783 ok(hres == E_INVALIDARG, "GetSecurityIdEx2 returned %08x, expected E_INVALIDARG\n", hres);
1784 ok(buf_size == sizeof(buf), "buf_size was %d\n", buf_size);
1786 hres = pCreateUri(url5, 0, 0, &uri);
1787 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
1789 hres = IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2, uri, NULL, 0, NULL, NULL);
1790 ok(hres == E_INVALIDARG, "MapToUrlZoneEx2 returned %08x, expected E_INVALIDARG\n", hres);
1792 buf_size = sizeof(buf);
1793 hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, NULL, &buf_size, 0);
1794 ok(hres == E_INVALIDARG || broken(hres == S_OK), "GetSecurityIdEx2 failed: %08x\n", hres);
1795 ok(buf_size == sizeof(buf), "bug_size was %d\n", buf_size);
1797 hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, buf, NULL, 0);
1798 ok(hres == E_INVALIDARG, "GetSecurityIdEx2 returned %08x, expected E_INVALIDARG\n", hres);
1800 IUri_Release(uri);
1802 for(i = 0; i < ARRAY_SIZE(sec_mgr_ex2_tests); ++i) {
1803 uri = NULL;
1804 zone = URLZONE_INVALID;
1806 hres = pCreateUri(sec_mgr_ex2_tests[i].uri, sec_mgr_ex2_tests[i].create_flags, 0, &uri);
1807 ok(hres == S_OK, "CreateUri returned %08x for '%s'\n", hres, wine_dbgstr_w(sec_mgr_ex2_tests[i].uri));
1809 hres = IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2, uri, &zone, 0, NULL, NULL);
1810 todo_wine_if (sec_mgr_ex2_tests[i].map_todo) {
1811 ok(hres == sec_mgr_ex2_tests[i].map_hres, "MapUrlToZoneEx2 returned %08x, expected %08x for '%s'\n",
1812 hres, sec_mgr_ex2_tests[i].map_hres, wine_dbgstr_w(sec_mgr_ex2_tests[i].uri));
1813 ok(zone == sec_mgr_ex2_tests[i].zone, "Expected zone %d, but got %d for '%s'\n", sec_mgr_ex2_tests[i].zone,
1814 zone, wine_dbgstr_w(sec_mgr_ex2_tests[i].uri));
1817 buf_size = sizeof(buf);
1818 memset(buf, 0xf0, buf_size);
1820 hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, buf, &buf_size, 0);
1821 todo_wine_if (sec_mgr_ex2_tests[i].secid_todo) {
1822 ok(hres == sec_mgr_ex2_tests[i].secid_hres, "GetSecurityIdEx2 returned %08x, expected %08x on test '%s'\n",
1823 hres, sec_mgr_ex2_tests[i].secid_hres, wine_dbgstr_w(sec_mgr_ex2_tests[i].uri));
1824 if(sec_mgr_ex2_tests[i].secid) {
1825 ok(buf_size == sec_mgr_ex2_tests[i].secid_size, "Got wrong security id size=%d, expected %d on test '%s'\n",
1826 buf_size, sec_mgr_ex2_tests[i].secid_size, wine_dbgstr_w(sec_mgr_ex2_tests[i].uri));
1827 ok(!memcmp(buf, sec_mgr_ex2_tests[i].secid, sec_mgr_ex2_tests[i].secid_size), "Got wrong security id on test '%s'\n",
1828 wine_dbgstr_w(sec_mgr_ex2_tests[i].uri));
1832 IUri_Release(uri);
1835 hres = pCreateUri(url15, 0, 0, &uri);
1836 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
1838 buf_size = sizeof(buf);
1839 memset(buf, 0xf0, buf_size);
1841 hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, buf, &buf_size, (DWORD_PTR)domainW);
1842 ok(hres == S_OK, "GetSecurityIdEx2 failed: %08x\n", hres);
1843 todo_wine ok(buf_size == sizeof(secid13), "buf_size was %d\n", buf_size);
1844 todo_wine ok(!memcmp(buf, secid13, sizeof(secid13)), "Got wrong secid\n");
1846 buf_size = sizeof(buf);
1847 memset(buf, 0xf0, buf_size);
1849 hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, buf, &buf_size, 0);
1850 ok(hres == S_OK, "GetSecurityIdEx2 failed: %08x\n", hres);
1851 ok(buf_size == sizeof(secid13_2), "buf_size was %d\n", buf_size);
1852 ok(!memcmp(buf, secid13_2, sizeof(secid13_2)), "Got wrong secid\n");
1854 IUri_Release(uri);
1856 IInternetSecurityManagerEx2_Release(sec_mgr2);
1857 IInternetSecurityManager_Release(sec_mgr);
1860 static void test_CoInternetIsFeatureZoneElevationEnabled(void)
1862 struct {
1863 const WCHAR *url_from;
1864 const WCHAR *url_to;
1865 DWORD flags;
1866 HRESULT hres;
1867 DWORD policy_flags;
1868 } testcases[] = {
1869 /* 0 */ { L"http://www.winehq.org", L"http://www.winehq.org", 0, S_FALSE, URLPOLICY_ALLOW },
1870 /* 1 */ { L"http://www.winehq.org", L"http://www.winehq.org", 0, S_OK, URLPOLICY_DISALLOW },
1871 /* 2 */ { L"http://www.winehq.org", L"http://www.codeweavers.com", 0, S_FALSE, URLPOLICY_ALLOW },
1872 /* 3 */ { L"http://www.winehq.org", L"http://www.codeweavers.com", 0, S_OK, URLPOLICY_DISALLOW },
1873 /* 4 */ { L"http://www.winehq.org", L"http://www.winehq.org", GET_FEATURE_FROM_PROCESS, S_FALSE, -1 },
1874 /* 5 */ { L"http://www.winehq.org", L"http://www.winehq.org/dir", GET_FEATURE_FROM_PROCESS, S_FALSE, -1 },
1875 /* 6 */ { L"http://www.winehq.org", L"http://www.codeweavers.com", GET_FEATURE_FROM_PROCESS, S_FALSE, -1 },
1876 /* 7 */ { L"http://www.winehq.org", L"ftp://winehq.org", GET_FEATURE_FROM_PROCESS, S_FALSE, -1 },
1877 /* 8 */ { L"http://www.winehq.org", L"ftp://winehq.org", GET_FEATURE_FROM_PROCESS|0x100, S_FALSE, URLPOLICY_ALLOW },
1878 /* 9 */ { L"http://www.winehq.org", L"ftp://winehq.org", GET_FEATURE_FROM_REGISTRY, S_FALSE, URLPOLICY_ALLOW },
1881 int i;
1882 HRESULT hres;
1884 if(!pCoInternetIsFeatureZoneElevationEnabled || !pCoInternetIsFeatureEnabled
1885 || !pCoInternetIsFeatureEnabledForUrl) {
1886 win_skip("Skipping CoInternetIsFeatureZoneElevationEnabled tests\n");
1887 return;
1891 hres = pCoInternetIsFeatureEnabled(FEATURE_ZONE_ELEVATION, GET_FEATURE_FROM_PROCESS);
1892 ok(SUCCEEDED(hres), "CoInternetIsFeatureEnabled returned %x\n", hres);
1894 trace("Testing CoInternetIsFeatureZoneElevationEnabled... (%x)\n", hres);
1896 for(i = 0; i < ARRAY_SIZE(testcases); i++) {
1897 if(hres==S_OK && testcases[i].flags == GET_FEATURE_FROM_PROCESS)
1898 testcases[i].policy_flags = URLPOLICY_ALLOW;
1901 /* IE10 does not seem to use passed ISecurityManager */
1902 SET_EXPECT(ProcessUrlAction);
1903 pCoInternetIsFeatureZoneElevationEnabled(url1, url1, &security_manager, 0);
1904 i = called_ProcessUrlAction;
1905 SET_CALLED(ProcessUrlAction);
1906 if(!i) {
1907 skip("CoInternetIsFeatureZoneElevationEnabled does not use passed ISecurityManager\n");
1908 return;
1911 for(i = 0; i < ARRAY_SIZE(testcases); i++) {
1912 if(testcases[i].policy_flags != -1) {
1913 ProcessUrlAction_policy = testcases[i].policy_flags;
1914 SET_EXPECT(ProcessUrlAction);
1916 hres = pCoInternetIsFeatureZoneElevationEnabled(testcases[i].url_from, testcases[i].url_to,
1917 &security_manager, testcases[i].flags);
1918 ok(hres == testcases[i].hres, "%d) CoInternetIsFeatureZoneElevationEnabled returned %x\n", i, hres);
1919 if(testcases[i].policy_flags != -1)
1920 CHECK_CALLED(ProcessUrlAction);
1922 if(testcases[i].policy_flags != -1)
1923 SET_EXPECT(ProcessUrlAction);
1924 hres = pCoInternetIsFeatureEnabledForUrl(FEATURE_ZONE_ELEVATION,
1925 testcases[i].flags, testcases[i].url_to, &security_manager);
1926 ok(hres == testcases[i].hres, "%d) CoInternetIsFeatureEnabledForUrl returned %x\n", i, hres);
1927 if(testcases[i].policy_flags != -1)
1928 CHECK_CALLED(ProcessUrlAction);
1932 START_TEST(sec_mgr)
1934 HMODULE hurlmon;
1935 int argc;
1936 char **argv;
1938 hurlmon = GetModuleHandleA("urlmon.dll");
1939 pCoInternetCreateSecurityManager = (void*) GetProcAddress(hurlmon, "CoInternetCreateSecurityManager");
1940 pCoInternetCreateZoneManager = (void*) GetProcAddress(hurlmon, "CoInternetCreateZoneManager");
1941 pCoInternetGetSecurityUrl = (void*) GetProcAddress(hurlmon, "CoInternetGetSecurityUrl");
1942 pCoInternetGetSecurityUrlEx = (void*) GetProcAddress(hurlmon, "CoInternetGetSecurityUrlEx");
1943 pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
1944 pCoInternetGetSession = (void*) GetProcAddress(hurlmon, "CoInternetGetSession");
1945 pCoInternetIsFeatureEnabled = (void*) GetProcAddress(hurlmon, "CoInternetIsFeatureEnabled");
1946 pCoInternetIsFeatureEnabledForUrl = (void*) GetProcAddress(hurlmon, "CoInternetIsFeatureEnabledForUrl");
1947 pCoInternetIsFeatureZoneElevationEnabled = (void*) GetProcAddress(hurlmon, "CoInternetIsFeatureZoneElevationEnabled");
1949 if (!pCoInternetCreateSecurityManager || !pCoInternetCreateZoneManager ||
1950 !pCoInternetGetSecurityUrl) {
1951 win_skip("Various CoInternet* functions not present in IE 4.0\n");
1952 return;
1955 argc = winetest_get_mainargs(&argv);
1956 if(argc > 2 && !strcmp(argv[2], "domain_tests")) {
1957 test_zone_domain_mappings();
1958 return;
1961 OleInitialize(NULL);
1962 register_protocols();
1964 test_InternetGetSecurityUrl();
1966 if(!pCoInternetGetSecurityUrlEx || !pCreateUri)
1967 win_skip("Skipping CoInternetGetSecurityUrlEx tests, IE too old\n");
1968 else {
1969 test_InternetGetSecurityUrlEx();
1970 test_InternetGetSecurityUrlEx_Pluggable();
1973 test_SecurityManager();
1974 test_SecurityManagerEx2();
1975 test_polices();
1976 test_zone_domains();
1977 test_CoInternetCreateZoneManager();
1978 test_CreateZoneEnumerator();
1979 test_GetZoneActionPolicy();
1980 test_GetZoneAt();
1981 test_GetZoneAttributes();
1982 test_SetZoneAttributes();
1983 test_InternetSecurityMarshalling();
1984 test_CoInternetIsFeatureZoneElevationEnabled();
1986 unregister_protocols();
1987 OleUninitialize();