[URLMON] Sync with Wine Staging 3.3. CORE-14434
[reactos.git] / modules / rostests / winetests / urlmon / sec_mgr.c
1 /*
2 * Copyright 2005-2006 Jacek Caban for CodeWeavers
3 * Copyright 2009-2011 Detlef Riekenberg
4 * Copyright 2011 Thomas Mullaly for CodeWeavers
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #define WIN32_NO_STATUS
22 #define _INC_WINDOWS
23 #define COM_NO_WINDOWS_H
24
25 #define COBJMACROS
26 #define CONST_VTABLE
27 #define NONAMELESSUNION
28
29 /* needed for IInternetZoneManagerEx2 */
30 #undef _WIN32_IE
31 #define _WIN32_IE 0x0700
32
33 #include <wine/test.h>
34 //#include <stdarg.h>
35 //#include <stddef.h>
36 #include <stdio.h>
37
38 //#include "windef.h"
39 //#include "winbase.h"
40 #include <winreg.h>
41 #include <winnls.h>
42 #include <ole2.h>
43 //#include "urlmon.h"
44
45 //#include "initguid.h"
46
47 #define URLZONE_CUSTOM URLZONE_USER_MIN+1
48 #define URLZONE_CUSTOM2 URLZONE_CUSTOM+1
49
50 #define DEFINE_EXPECT(func) \
51 static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
52
53 #define SET_EXPECT(func) \
54 expect_ ## func = TRUE
55
56 #define CHECK_EXPECT(func) \
57 do { \
58 ok(expect_ ##func, "unexpected call " #func "\n"); \
59 expect_ ## func = FALSE; \
60 called_ ## func = TRUE; \
61 }while(0)
62
63 #define CHECK_EXPECT2(func) \
64 do { \
65 ok(expect_ ##func, "unexpected call " #func "\n"); \
66 called_ ## func = TRUE; \
67 }while(0)
68
69 #define CHECK_CALLED(func) \
70 do { \
71 ok(called_ ## func, "expected " #func "\n"); \
72 expect_ ## func = called_ ## func = FALSE; \
73 }while(0)
74
75 #define SET_CALLED(func) \
76 do { \
77 expect_ ## func = called_ ## func = FALSE; \
78 }while(0)
79
80 DEFINE_EXPECT(ParseUrl_SECURITY_URL_input);
81 DEFINE_EXPECT(ParseUrl_SECURITY_URL_input2);
82 DEFINE_EXPECT(ParseUrl_SECURITY_URL_expected);
83 DEFINE_EXPECT(ParseUrl_SECURITY_URL_http);
84 DEFINE_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
85 DEFINE_EXPECT(ProcessUrlAction);
86
87 static HRESULT (WINAPI *pCoInternetCreateSecurityManager)(IServiceProvider *, IInternetSecurityManager**, DWORD);
88 static HRESULT (WINAPI *pCoInternetCreateZoneManager)(IServiceProvider *, IInternetZoneManager**, DWORD);
89 static HRESULT (WINAPI *pCoInternetGetSecurityUrl)(LPCWSTR, LPWSTR*, PSUACTION, DWORD);
90 static HRESULT (WINAPI *pCoInternetGetSecurityUrlEx)(IUri*, IUri**, PSUACTION, DWORD_PTR);
91 static HRESULT (WINAPI *pCreateUri)(LPCWSTR, DWORD, DWORD_PTR, IUri**);
92 static HRESULT (WINAPI *pCoInternetGetSession)(DWORD, IInternetSession**, DWORD);
93 static HRESULT (WINAPI *pCoInternetIsFeatureEnabled)(INTERNETFEATURELIST, DWORD);
94 static HRESULT (WINAPI *pCoInternetIsFeatureEnabledForUrl)(INTERNETFEATURELIST, DWORD, LPCWSTR, IInternetSecurityManager*);
95 static HRESULT (WINAPI *pCoInternetIsFeatureZoneElevationEnabled)(LPCWSTR, LPCWSTR, IInternetSecurityManager*, DWORD);
96
97 static const WCHAR url1[] = {'r','e','s',':','/','/','m','s','h','t','m','l','.','d','l','l',
98 '/','b','l','a','n','k','.','h','t','m',0};
99 static const WCHAR url2[] = {'i','n','d','e','x','.','h','t','m',0};
100 static const WCHAR url3[] = {'f','i','l','e',':','/','/','c',':','\\','I','n','d','e','x','.','h','t','m',0};
101 static const WCHAR url4[] = {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e',
102 '%','2','e','j','p','g',0};
103 static const WCHAR url5[] = {'h','t','t','p',':','/','/','w','w','w','.','z','o','n','e','3',
104 '.','w','i','n','e','t','e','s','t',0};
105 static const WCHAR url6[] = {'a','b','o','u','t',':','b','l','a','n','k',0};
106 static const WCHAR url7[] = {'f','t','p',':','/','/','z','o','n','e','3',
107 '.','w','i','n','e','t','e','s','t','/','f','i','l','e','.','t','e','s','t',0};
108 static const WCHAR url8[] = {'t','e','s','t',':','1','2','3','a','b','c',0};
109 static const WCHAR url9[] = {'h','t','t','p',':','/','/','w','w','w','.','z','o','n','e','3',
110 '.','w','i','n','e','t','e','s','t', '/','s','i','t','e','/','a','b','o','u','t',0};
111 static const WCHAR url10[] = {'f','i','l','e',':','/','/','s','o','m','e','%','2','0','f','i','l','e',
112 '.','j','p','g',0};
113 static const WCHAR url11[] = {'f','i','l','e',':','/','/','c',':','/','I','n','d','e','x','.','h','t','m',0};
114 static const WCHAR url12[] = {'f','i','l','e',':','/','/','/','c',':','/','I','n','d','e','x','.','h','t','m',0};
115 static const WCHAR url13[] = {'h','t','t','p',':','g','o','o','g','l','e','.','c','o','m',0};
116 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};
117 static const WCHAR url15[] = {'h','t','t','p',':','/','/','g','o','o','g','l','e','.','c','o','m','.','u','k',0};
118 static const WCHAR url16[] = {'f','i','l','e',':','/','/','/','c',':',0};
119 static const WCHAR url17[] = {'f','i','l','e',':','/','/','/','c',':','c','\\',0};
120 static const WCHAR url18[] = {'c',':','\\','t','e','s','t','.','h','t','m',0};
121
122 static const WCHAR winetestW[] = {'w','i','n','e','t','e','s','t',0};
123 static const WCHAR security_urlW[] = {'w','i','n','e','t','e','s','t',':','t','e','s','t','i','n','g',0};
124 static const WCHAR security_url2W[] = {'w','i','n','e','t','e','s','t',':','t','e','s','t','i','n','g','2',0};
125 static const WCHAR security_expectedW[] = {'w','i','n','e','t','e','s','t',':','z','i','p',0};
126 static const WCHAR winetest_to_httpW[] = {'w','i','n','e','t','e','s','t',':','h',0};
127
128 static const char *szZoneMapDomainsKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Domains";
129 static const char *szInternetSettingsKey = "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings";
130
131 static const BYTE secid1[] = {'f','i','l','e',':',0,0,0,0};
132 static const BYTE secid2[] = {'*',':','i','n','d','e','x','.','h','t','m',3,0,0,0};
133 static const BYTE secid5[] = {'h','t','t','p',':','w','w','w','.','z','o','n','e','3',
134 '.','w','i','n','e','t','e','s','t',3,0,0,0};
135 static const BYTE secid6[] = {'a','b','o','u','t',':','b','l','a','n','k',3,0,0,0};
136 static const BYTE secid7[] = {'f','t','p',':','z','o','n','e','3',
137 '.','w','i','n','e','t','e','s','t',3,0,0,0};
138 static const BYTE secid10[] =
139 {'f','i','l','e',':','s','o','m','e','%','2','0','f','i','l','e','.','j','p','g',3,0,0,0};
140 static const BYTE secid14[] =
141 {'z','i','p',':','t','e','s','t','i','n','g','.','c','o','m','/','t','e','s','t','i','n','g',3,0,0,0};
142 static const BYTE secid10_2[] =
143 {'f','i','l','e',':','s','o','m','e',' ','f','i','l','e','.','j','p','g',3,0,0,0};
144 static const BYTE secid13[] = {'h','t','t','p',':','c','o','m','.','u','k',3,0,0,0};
145 static const BYTE secid13_2[] = {'h','t','t','p',':','g','o','o','g','l','e','.','c','o','m','.','u','k',3,0,0,0};
146
147 static const GUID CLSID_TestActiveX =
148 {0x178fc163,0xf585,0x4e24,{0x9c,0x13,0x4b,0xb7,0xfa,0xf8,0x06,0x46}};
149
150 /* Defined as extern in urlmon.idl, but not exported by uuid.lib */
151 const GUID GUID_CUSTOM_CONFIRMOBJECTSAFETY =
152 {0x10200490,0xfa38,0x11d0,{0xac,0x0e,0x00,0xa0,0xc9,0xf,0xff,0xc0}};
153
154 static int called_securl_http;
155 static DWORD ProcessUrlAction_policy;
156
157 static struct secmgr_test {
158 LPCWSTR url;
159 DWORD zone;
160 HRESULT zone_hres;
161 DWORD secid_size;
162 const BYTE *secid;
163 HRESULT secid_hres;
164 } secmgr_tests[] = {
165 {url1, 0, S_OK, sizeof(secid1), secid1, S_OK},
166 {url2, 100, 0x80041001, 0, NULL, E_INVALIDARG},
167 {url3, 0, S_OK, sizeof(secid1), secid1, S_OK},
168 {url5, 3, S_OK, sizeof(secid5), secid5, S_OK},
169 {url6, 3, S_OK, sizeof(secid6), secid6, S_OK},
170 {url7, 3, S_OK, sizeof(secid7), secid7, S_OK},
171 {url11,0, S_OK, sizeof(secid1), secid1, S_OK},
172 {url12,0, S_OK, sizeof(secid1), secid1, S_OK},
173 {url16,0, S_OK, sizeof(secid1), secid1, S_OK},
174 {url17,0, S_OK, sizeof(secid1), secid1, S_OK},
175 {url18,0, S_OK, sizeof(secid1), secid1, S_OK}
176 };
177
178 static int strcmp_w(const WCHAR *str1, const WCHAR *str2)
179 {
180 DWORD len1 = lstrlenW(str1);
181 DWORD len2 = lstrlenW(str2);
182
183 if(len1!=len2) return 1;
184 return memcmp(str1, str2, len1*sizeof(WCHAR));
185 }
186
187 static inline void heap_free(void *mem)
188 {
189 HeapFree(GetProcessHeap(), 0, mem);
190 }
191
192 static inline LPWSTR a2w(LPCSTR str)
193 {
194 LPWSTR ret = NULL;
195
196 if(str) {
197 DWORD len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
198 ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
199 MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
200 }
201
202 return ret;
203 }
204
205 static inline DWORD strcmp_aw(LPCSTR strA, LPCWSTR strB) {
206 LPWSTR strAW = a2w(strA);
207 DWORD ret = lstrcmpW(strAW, strB);
208 heap_free(strAW);
209 return ret;
210 }
211
212
213 /* Based on RegDeleteTreeW from dlls/advapi32/registry.c */
214 static LONG myRegDeleteTreeA(HKEY hKey, LPCSTR lpszSubKey)
215 {
216 LONG ret;
217 DWORD dwMaxSubkeyLen, dwMaxValueLen;
218 DWORD dwMaxLen, dwSize;
219 CHAR szNameBuf[MAX_PATH], *lpszName = szNameBuf;
220 HKEY hSubKey = hKey;
221
222 if(lpszSubKey)
223 {
224 ret = RegOpenKeyExA(hKey, lpszSubKey, 0, KEY_READ, &hSubKey);
225 if (ret) return ret;
226 }
227
228 /* Get highest length for keys, values */
229 ret = RegQueryInfoKeyA(hSubKey, NULL, NULL, NULL, NULL,
230 &dwMaxSubkeyLen, NULL, NULL, &dwMaxValueLen, NULL, NULL, NULL);
231 if (ret) goto cleanup;
232
233 dwMaxSubkeyLen++;
234 dwMaxValueLen++;
235 dwMaxLen = max(dwMaxSubkeyLen, dwMaxValueLen);
236 if (dwMaxLen > sizeof(szNameBuf)/sizeof(CHAR))
237 {
238 /* Name too big: alloc a buffer for it */
239 if (!(lpszName = HeapAlloc( GetProcessHeap(), 0, dwMaxLen*sizeof(CHAR))))
240 {
241 ret = ERROR_NOT_ENOUGH_MEMORY;
242 goto cleanup;
243 }
244 }
245
246 /* Recursively delete all the subkeys */
247 while (TRUE)
248 {
249 dwSize = dwMaxLen;
250 if (RegEnumKeyExA(hSubKey, 0, lpszName, &dwSize, NULL,
251 NULL, NULL, NULL)) break;
252
253 ret = myRegDeleteTreeA(hSubKey, lpszName);
254 if (ret) goto cleanup;
255 }
256
257 if (lpszSubKey)
258 ret = RegDeleteKeyA(hKey, lpszSubKey);
259 else
260 while (TRUE)
261 {
262 dwSize = dwMaxLen;
263 if (RegEnumValueA(hKey, 0, lpszName, &dwSize,
264 NULL, NULL, NULL, NULL)) break;
265
266 ret = RegDeleteValueA(hKey, lpszName);
267 if (ret) goto cleanup;
268 }
269
270 cleanup:
271 /* Free buffer if allocated */
272 if (lpszName != szNameBuf)
273 heap_free(lpszName);
274 if(lpszSubKey)
275 RegCloseKey(hSubKey);
276 return ret;
277 }
278
279 static HRESULT WINAPI SecurityManager_QueryInterface(IInternetSecurityManager* This,
280 REFIID riid, void **ppvObject)
281 {
282 ok(0, "unexpected call\n");
283 return E_NOTIMPL;
284 }
285
286 static ULONG WINAPI SecurityManager_AddRef(IInternetSecurityManager* This)
287 {
288 return 2;
289 }
290
291 static ULONG WINAPI SecurityManager_Release(IInternetSecurityManager* This)
292 {
293 return 1;
294 }
295
296 static HRESULT WINAPI SecurityManager_SetSecuritySite(IInternetSecurityManager* This,
297 IInternetSecurityMgrSite *pSite)
298 {
299 ok(0, "unexpected call\n");
300 return E_NOTIMPL;
301 }
302
303 static HRESULT WINAPI SecurityManager_GetSecuritySite(IInternetSecurityManager* This,
304 IInternetSecurityMgrSite **ppSite)
305 {
306 ok(0, "unexpected call\n");
307 return E_NOTIMPL;
308 }
309
310 static HRESULT WINAPI SecurityManager_MapUrlToZone(IInternetSecurityManager* This,
311 LPCWSTR pwszUrl, DWORD *pdwZone, DWORD dwFlags)
312 {
313 ok(0, "unexpected call\n");
314 return E_NOTIMPL;
315 }
316
317 static HRESULT WINAPI SecurityManager_GetSecurityId(IInternetSecurityManager* This,
318 LPCWSTR pwszUrl, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
319 {
320 ok(0, "unexpected call\n");
321 return E_NOTIMPL;
322 }
323
324 static HRESULT WINAPI SecurityManager_ProcessUrlAction(IInternetSecurityManager* This,
325 LPCWSTR pwszUrl, DWORD dwAction, BYTE *pPolicy, DWORD cbPolicy,
326 BYTE *pContext, DWORD cbContext, DWORD dwFlags, DWORD dwReserved)
327 {
328 CHECK_EXPECT(ProcessUrlAction);
329 ok(dwAction == URLACTION_FEATURE_ZONE_ELEVATION, "dwAction = %x\n", dwAction);
330 ok(cbPolicy == sizeof(DWORD), "cbPolicy = %d\n", cbPolicy);
331 ok(!pContext, "pContext != NULL\n");
332 ok(dwFlags == PUAF_NOUI, "dwFlags = %x\n", dwFlags);
333 ok(dwReserved == 0, "dwReserved = %x\n", dwReserved);
334
335 *pPolicy = ProcessUrlAction_policy;
336 return ProcessUrlAction_policy==URLPOLICY_ALLOW ? S_OK : S_FALSE;
337 }
338
339 static HRESULT WINAPI SecurityManager_QueryCustomPolicy(IInternetSecurityManager* This,
340 LPCWSTR pwszUrl, REFGUID guidKey, BYTE **ppPolicy, DWORD *pcbPolicy,
341 BYTE *pContext, DWORD cbContext, DWORD dwReserved)
342 {
343 ok(0, "unexpected call\n");
344 return E_NOTIMPL;
345 }
346
347 static HRESULT WINAPI SecurityManager_SetZoneMapping(IInternetSecurityManager* This,
348 DWORD dwZone, LPCWSTR lpszPattern, DWORD dwFlags)
349 {
350 ok(0, "unexpected call\n");
351 return E_NOTIMPL;
352 }
353
354 static HRESULT WINAPI SecurityManager_GetZoneMappings(IInternetSecurityManager* This,
355 DWORD dwZone, IEnumString **ppenumString, DWORD dwFlags)
356 {
357 ok(0, "unexpected call\n");
358 return E_NOTIMPL;
359 }
360
361 static const IInternetSecurityManagerVtbl SecurityManagerVtbl = {
362 SecurityManager_QueryInterface,
363 SecurityManager_AddRef,
364 SecurityManager_Release,
365 SecurityManager_SetSecuritySite,
366 SecurityManager_GetSecuritySite,
367 SecurityManager_MapUrlToZone,
368 SecurityManager_GetSecurityId,
369 SecurityManager_ProcessUrlAction,
370 SecurityManager_QueryCustomPolicy,
371 SecurityManager_SetZoneMapping,
372 SecurityManager_GetZoneMappings
373 };
374
375 static IInternetSecurityManager security_manager = { &SecurityManagerVtbl };
376
377 static void test_SecurityManager(void)
378 {
379 int i;
380 IInternetSecurityManager *secmgr = NULL;
381 BYTE buf[512];
382 DWORD zone, size, policy;
383 HRESULT hres;
384
385 if(!pCoInternetCreateSecurityManager) {
386 return;
387 }
388
389 trace("Testing security manager...\n");
390
391 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
392 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
393 if(FAILED(hres))
394 return;
395
396 for(i=0; i < sizeof(secmgr_tests)/sizeof(secmgr_tests[0]); i++) {
397 zone = 100;
398 hres = IInternetSecurityManager_MapUrlToZone(secmgr, secmgr_tests[i].url,
399 &zone, 0);
400 ok(hres == secmgr_tests[i].zone_hres /* IE <=6 */
401 || (FAILED(secmgr_tests[i].zone_hres) && hres == E_INVALIDARG), /* IE7 */
402 "[%d] MapUrlToZone failed: %08x, expected %08x\n",
403 i, hres, secmgr_tests[i].zone_hres);
404 if(SUCCEEDED(hres))
405 ok(zone == secmgr_tests[i].zone, "[%d] zone=%d, expected %d\n", i, zone,
406 secmgr_tests[i].zone);
407 else
408 ok(zone == secmgr_tests[i].zone || zone == -1, "[%d] zone=%d\n", i, zone);
409
410 size = sizeof(buf);
411 memset(buf, 0xf0, sizeof(buf));
412 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[i].url,
413 buf, &size, 0);
414 ok(hres == secmgr_tests[i].secid_hres,
415 "[%d] GetSecurityId failed: %08x, expected %08x\n",
416 i, hres, secmgr_tests[i].secid_hres);
417 if(secmgr_tests[i].secid) {
418 ok(size == secmgr_tests[i].secid_size, "[%d] size=%d, expected %d\n",
419 i, size, secmgr_tests[i].secid_size);
420 ok(!memcmp(buf, secmgr_tests[i].secid, size), "[%d] wrong secid\n", i);
421 }
422 }
423
424 zone = 100;
425 hres = IInternetSecurityManager_MapUrlToZone(secmgr, url10, &zone, 0);
426 ok(hres == S_OK, "MapUrlToZone failed: %08x, expected S_OK\n", hres);
427 ok(zone == 3, "zone=%d, expected 3\n", zone);
428
429 /* win2k3 translates %20 into a space */
430 size = sizeof(buf);
431 memset(buf, 0xf0, sizeof(buf));
432 hres = IInternetSecurityManager_GetSecurityId(secmgr, url10, buf, &size, 0);
433 ok(hres == S_OK, "GetSecurityId failed: %08x, expected S_OK\n", hres);
434 ok(size == sizeof(secid10) ||
435 size == sizeof(secid10_2), /* win2k3 */
436 "size=%d\n", size);
437 ok(!memcmp(buf, secid10, sizeof(secid10)) ||
438 !memcmp(buf, secid10_2, sizeof(secid10_2)), /* win2k3 */
439 "wrong secid\n");
440
441 zone = 100;
442 hres = IInternetSecurityManager_MapUrlToZone(secmgr, url13, &zone, 0);
443 ok(hres == S_OK, "MapUrlToZone failed: %08x\n", hres);
444 ok(zone == URLZONE_INVALID || broken(zone == URLZONE_INTERNET), "zone=%d\n", zone);
445
446 size = sizeof(buf);
447 memset(buf, 0xf0, sizeof(buf));
448 hres = IInternetSecurityManager_GetSecurityId(secmgr, url13, buf, &size, 0);
449 ok(hres == E_INVALIDARG || broken(hres == S_OK), "GetSecurityId failed: %08x\n", hres);
450
451 zone = 100;
452 hres = IInternetSecurityManager_MapUrlToZone(secmgr, url14, &zone, 0);
453 ok(hres == S_OK, "MapUrlToZone failed: %08x, expected S_OK\n", hres);
454 ok(zone == URLZONE_INTERNET, "zone=%d\n", zone);
455
456 size = sizeof(buf);
457 memset(buf, 0xf0, sizeof(buf));
458 hres = IInternetSecurityManager_GetSecurityId(secmgr, url14, buf, &size, 0);
459 ok(hres == S_OK, "GetSecurityId failed: %08x, expected S_OK\n", hres);
460 ok(size == sizeof(secid14), "size=%d\n", size);
461 ok(!memcmp(buf, secid14, size), "wrong secid\n");
462
463 zone = 100;
464 hres = IInternetSecurityManager_MapUrlToZone(secmgr, NULL, &zone, 0);
465 ok(hres == E_INVALIDARG, "MapUrlToZone failed: %08x, expected E_INVALIDARG\n", hres);
466 ok(zone == 100 || zone == -1, "zone=%d\n", zone);
467
468 size = sizeof(buf);
469 hres = IInternetSecurityManager_GetSecurityId(secmgr, NULL, buf, &size, 0);
470 ok(hres == E_INVALIDARG,
471 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
472 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
473 NULL, &size, 0);
474 ok(hres == E_INVALIDARG,
475 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
476 hres = IInternetSecurityManager_GetSecurityId(secmgr, secmgr_tests[1].url,
477 buf, NULL, 0);
478 ok(hres == E_INVALIDARG,
479 "GetSecurityId failed: %08x, expected E_INVALIDARG\n", hres);
480
481 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, NULL, URLACTION_SCRIPT_RUN, (BYTE*)&policy,
482 sizeof(WCHAR), NULL, 0, 0, 0);
483 ok(hres == E_INVALIDARG, "ProcessUrlAction failed: %08x, expected E_INVALIDARG\n", hres);
484
485 IInternetSecurityManager_Release(secmgr);
486 }
487
488 /* Check if Internet Explorer is configured to run in "Enhanced Security Configuration" (aka hardened mode) */
489 /* Note: this code is duplicated in dlls/mshtml/tests/mshtml_test.h and dlls/urlmon/tests/sec_mgr.c */
490 static BOOL is_ie_hardened(void)
491 {
492 HKEY zone_map;
493 DWORD ie_harden, type, size;
494
495 ie_harden = 0;
496 if(RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap",
497 0, KEY_QUERY_VALUE, &zone_map) == ERROR_SUCCESS) {
498 size = sizeof(DWORD);
499 if (RegQueryValueExA(zone_map, "IEHarden", NULL, &type, (LPBYTE) &ie_harden, &size) != ERROR_SUCCESS ||
500 type != REG_DWORD) {
501 ie_harden = 0;
502 }
503 RegCloseKey(zone_map);
504 }
505
506 return ie_harden != 0;
507 }
508
509 static void test_url_action(IInternetSecurityManager *secmgr, IInternetZoneManager *zonemgr, DWORD action)
510 {
511 DWORD res, size, policy, reg_policy;
512 char buf[10];
513 HKEY hkey;
514 HRESULT hres;
515
516 /* FIXME: HKEY_CURRENT_USER is most of the time the default but this can be changed on a system.
517 * The test should be changed to cope with that, if need be.
518 */
519 res = RegOpenKeyA(HKEY_CURRENT_USER,
520 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3", &hkey);
521 ok(res == ERROR_SUCCESS, "Could not open zone key\n");
522 if(res != ERROR_SUCCESS)
523 return;
524
525 wsprintfA(buf, "%X", action);
526 size = sizeof(DWORD);
527 res = RegQueryValueExA(hkey, buf, NULL, NULL, (BYTE*)&reg_policy, &size);
528 RegCloseKey(hkey);
529
530 /* Try settings from HKEY_LOCAL_MACHINE. */
531 if(res != ERROR_SUCCESS || size != sizeof(DWORD)) {
532 res = RegOpenKeyA(HKEY_LOCAL_MACHINE,
533 "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3", &hkey);
534 ok(res == ERROR_SUCCESS, "Could not open zone key\n");
535
536 size = sizeof(DWORD);
537 res = RegQueryValueExA(hkey, buf, NULL, NULL, (BYTE*)&reg_policy, &size);
538 RegCloseKey(hkey);
539 }
540
541 if(res != ERROR_SUCCESS || size != sizeof(DWORD)) {
542 policy = 0xdeadbeef;
543 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
544 sizeof(WCHAR), NULL, 0, 0, 0);
545 ok(hres == E_FAIL || broken(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
546 "(0x%x) got 0x%x (expected E_FAIL)\n", action, hres);
547 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
548
549 policy = 0xdeadbeef;
550 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
551 sizeof(DWORD), URLZONEREG_DEFAULT);
552 ok(hres == E_FAIL || broken(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
553 "(0x%x) got 0x%x (expected E_FAIL)\n", action, hres);
554 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
555 return;
556 }
557
558 policy = 0xdeadbeef;
559 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
560 sizeof(DWORD), URLZONEREG_DEFAULT);
561 ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
562 ok(policy == reg_policy, "(%x) policy=%x, expected %x\n", action, policy, reg_policy);
563
564 if(policy != URLPOLICY_QUERY) {
565 if(winetest_interactive || ! is_ie_hardened()) {
566 BOOL expect_parse_call = !called_securl_http;
567
568 policy = 0xdeadbeef;
569 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
570 sizeof(WCHAR), NULL, 0, 0, 0);
571 if(reg_policy == URLPOLICY_DISALLOW)
572 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
573 else
574 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
575 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
576
577 policy = 0xdeadbeef;
578 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
579 2, NULL, 0, 0, 0);
580 if(reg_policy == URLPOLICY_DISALLOW)
581 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
582 else
583 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
584 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
585
586 policy = 0xdeadbeef;
587 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
588 sizeof(DWORD), NULL, 0, 0, 0);
589 if(reg_policy == URLPOLICY_DISALLOW)
590 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
591 else
592 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
593 ok(policy == reg_policy, "(%x) policy=%x\n", action, policy);
594
595 policy = 0xdeadbeef;
596 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url9, action, (BYTE*)&policy,
597 sizeof(WCHAR), (BYTE*)0xdeadbeef, 16, 0, 0);
598 if(reg_policy == URLPOLICY_DISALLOW)
599 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
600 else
601 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
602 ok(policy == 0xdeadbeef, "(%x) policy=%x\n", action, policy);
603
604 policy = 0xdeadbeef;
605 if(expect_parse_call)
606 SET_EXPECT(ParseUrl_SECURITY_URL_http);
607 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, winetest_to_httpW, action, (BYTE*)&policy,
608 sizeof(DWORD), NULL, 0, 0, 0);
609 if(expect_parse_call)
610 CHECK_CALLED(ParseUrl_SECURITY_URL_http);
611 if(reg_policy == URLPOLICY_DISALLOW)
612 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
613 else
614 ok(hres == S_OK, "ProcessUrlAction(%x) failed: %08x\n", action, hres);
615 ok(policy == reg_policy, "(%x) policy=%x\n", action, policy);
616 }else {
617 skip("IE running in Enhanced Security Configuration\n");
618 }
619 }
620 }
621
622 static void test_special_url_action(IInternetSecurityManager *secmgr, IInternetZoneManager *zonemgr, DWORD action)
623 {
624 DWORD policy;
625 HRESULT hres;
626
627 policy = 0xdeadbeef;
628 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, (BYTE*)&policy,
629 sizeof(DWORD), URLZONEREG_DEFAULT);
630 ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
631 ok(policy == URLPOLICY_DISALLOW, "(%x) policy=%x, expected URLPOLICY_DISALLOW\n", action, policy);
632
633 policy = 0xdeadbeef;
634 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, action, (BYTE*)&policy,
635 sizeof(WCHAR), NULL, 0, 0, 0);
636 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
637
638 policy = 0xdeadbeef;
639 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, action, (BYTE*)&policy,
640 sizeof(DWORD), NULL, 0, 0, 0);
641 ok(hres == S_FALSE, "ProcessUrlAction(%x) failed: %08x, expected S_FALSE\n", action, hres);
642 ok(policy == URLPOLICY_DISALLOW, "policy = %x\n", policy);
643 }
644
645 static void test_activex(IInternetSecurityManager *secmgr)
646 {
647 DWORD policy, policy_size;
648 struct CONFIRMSAFETY cs;
649 BYTE *ppolicy;
650 HRESULT hres;
651
652 policy = 0xdeadbeef;
653 hres = IInternetSecurityManager_ProcessUrlAction(secmgr, url1, URLACTION_ACTIVEX_RUN, (BYTE*)&policy,
654 sizeof(DWORD), (BYTE*)&CLSID_TestActiveX, sizeof(CLSID), 0, 0);
655 ok(hres == S_OK, "ProcessUrlAction(URLACTION_ACTIVEX_RUN) failed: %08x\n", hres);
656 ok(policy == URLPOLICY_ALLOW || policy == URLPOLICY_DISALLOW, "policy = %x\n", policy);
657
658 cs.clsid = CLSID_TestActiveX;
659 cs.pUnk = (IUnknown*)0xdeadbeef;
660 cs.dwFlags = 0;
661 hres = IInternetSecurityManager_QueryCustomPolicy(secmgr, url1, &GUID_CUSTOM_CONFIRMOBJECTSAFETY,
662 &ppolicy, &policy_size, (BYTE*)&cs, sizeof(cs), 0);
663 ok(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND), "QueryCusromPolicy failed: %08x\n", hres);
664 }
665
666 static void test_polices(void)
667 {
668 IInternetZoneManager *zonemgr = NULL;
669 IInternetSecurityManager *secmgr = NULL;
670 HRESULT hres;
671
672 trace("testing polices...\n");
673
674 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
675 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
676 hres = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
677 ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
678
679 test_url_action(secmgr, zonemgr, URLACTION_SCRIPT_RUN);
680 test_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_RUN);
681 test_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_OVERRIDE_OBJECT_SAFETY);
682 test_url_action(secmgr, zonemgr, URLACTION_CHANNEL_SOFTDIST_PERMISSIONS);
683 test_url_action(secmgr, zonemgr, 0xdeadbeef);
684
685 test_special_url_action(secmgr, zonemgr, URLACTION_SCRIPT_OVERRIDE_SAFETY);
686 test_special_url_action(secmgr, zonemgr, URLACTION_ACTIVEX_OVERRIDE_SCRIPT_SAFETY);
687
688 test_activex(secmgr);
689
690 IInternetSecurityManager_Release(secmgr);
691 IInternetZoneManager_Release(zonemgr);
692 }
693
694 /* IE (or at least newer versions of it) seem to cache the keys in ZoneMap
695 * when urlmon.dll is loaded and it doesn't seem to update its cache, unless
696 * SetZoneMapping is used.
697 */
698 static void test_zone_domain_cache(void)
699 {
700 HRESULT hres;
701 DWORD res, zone;
702 IInternetSecurityManager *secmgr = NULL;
703 HKEY domains, domain;
704
705 static const WCHAR testing_domain_urlW[] = {'h','t','t','p',':','/','/','t','e','s','t','i','n','g','.',
706 'd','o','m','a','i','n','/',0};
707
708 res = RegOpenKeyA(HKEY_CURRENT_USER, szZoneMapDomainsKey, &domains);
709 ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
710 if(res != ERROR_SUCCESS)
711 return;
712
713 res = RegCreateKeyA(domains, "testing.domain", &domain);
714 ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
715 if(res != ERROR_SUCCESS) {
716 RegCloseKey(domains);
717 return;
718 }
719
720 zone = URLZONE_CUSTOM;
721 res = RegSetValueExA(domain, "http", 0, REG_DWORD, (BYTE*)&zone, sizeof(DWORD));
722 ok(res == ERROR_SUCCESS, "RegSetValueEx failed: %d\n", res);
723
724 RegCloseKey(domain);
725
726 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
727 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
728
729 zone = URLZONE_INVALID;
730 hres = IInternetSecurityManager_MapUrlToZone(secmgr, testing_domain_urlW, &zone, 0);
731 ok(hres == S_OK, "MapUrlToZone failed: %08x\n", hres);
732 todo_wine ok(zone == URLZONE_INTERNET, "Got %d, expected URLZONE_INTERNET\n", zone);
733
734 /* FIXME: Play nice with ZoneMaps that existed before the test is run. */
735 res = RegDeleteKeyA(domains, "testing.domain");
736 ok(res == ERROR_SUCCESS, "RegDeleteKey failed: %d\n", res);
737
738 RegCloseKey(domains);
739 IInternetSecurityManager_Release(secmgr);
740 }
741
742 typedef struct {
743 const char *domain;
744 const char *subdomain;
745 const char *scheme;
746 DWORD zone;
747 } zone_domain_mapping;
748
749 /* FIXME: Move these into SetZoneMapping tests when the day comes... */
750 static const zone_domain_mapping zone_domain_mappings[] = {
751 /* Implicitly means "*.yabadaba.do". */
752 {"yabadaba.do",NULL,"http",URLZONE_CUSTOM},
753 /* The '*' doesn't count as a wildcard, since it's not the first component of the subdomain. */
754 {"super.cool","testing.*","ftp",URLZONE_CUSTOM2},
755 /* The '*' counts since it's the first component of the subdomain. */
756 {"super.cool","*.testing","ftp",URLZONE_CUSTOM2},
757 /* All known scheme types apply to wildcard schemes. */
758 {"tests.test",NULL,"*",URLZONE_CUSTOM},
759 /* Due to a defect with how windows checks the mappings, unknown scheme types
760 * never seem to get mapped properly. */
761 {"tests.test",NULL,"zip",URLZONE_CUSTOM},
762 {"www.testing.com",NULL,"http",URLZONE_CUSTOM},
763 {"www.testing.com","testing","http",URLZONE_CUSTOM2},
764 {"org",NULL,"http",URLZONE_CUSTOM},
765 {"org","testing","http",URLZONE_CUSTOM2},
766 {"wine.testing",NULL,"*",URLZONE_CUSTOM2}
767 };
768
769 static BOOL register_zone_domains(void)
770 {
771 HKEY domains;
772 DWORD res, i;
773
774 /* Some Windows versions don't seem to have a "Domains" key in their HKLM. */
775 res = RegOpenKeyA(HKEY_LOCAL_MACHINE, szZoneMapDomainsKey, &domains);
776 ok(res == ERROR_SUCCESS || broken(res == ERROR_FILE_NOT_FOUND), "RegOpenKey failed: %d\n", res);
777 if(res == ERROR_SUCCESS) {
778 HKEY domain;
779 DWORD zone = URLZONE_CUSTOM;
780
781 res = RegCreateKeyA(domains, "local.machine", &domain);
782 if (res == ERROR_ACCESS_DENIED)
783 {
784 skip("need admin rights\n");
785 RegCloseKey(domains);
786 return FALSE;
787 }
788 ok(res == ERROR_SUCCESS, "RegCreateKey failed: %d\n", res);
789
790 res = RegSetValueExA(domain, "http", 0, REG_DWORD, (BYTE*)&zone, sizeof(DWORD));
791 ok(res == ERROR_SUCCESS, "RegSetValueEx failed: %d\n", res);
792
793 RegCloseKey(domain);
794 RegCloseKey(domains);
795 }
796
797 res = RegOpenKeyA(HKEY_CURRENT_USER, szZoneMapDomainsKey, &domains);
798 ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
799
800 for(i = 0; i < sizeof(zone_domain_mappings)/sizeof(zone_domain_mappings[0]); ++i) {
801 const zone_domain_mapping *test = zone_domain_mappings+i;
802 HKEY domain;
803
804 res = RegCreateKeyA(domains, test->domain, &domain);
805 ok(res == ERROR_SUCCESS, "RegCreateKey failed with %d on test %d\n", res, i);
806
807 /* Only set the value if there's no subdomain. */
808 if(!test->subdomain) {
809 res = RegSetValueExA(domain, test->scheme, 0, REG_DWORD, (BYTE*)&test->zone, sizeof(DWORD));
810 ok(res == ERROR_SUCCESS, "RegSetValueEx failed with %d on test %d\n", res, i);
811 } else {
812 HKEY subdomain;
813
814 res = RegCreateKeyA(domain, test->subdomain, &subdomain);
815 ok(res == ERROR_SUCCESS, "RegCreateKey failed with %d on test %d\n", res, i);
816
817 res = RegSetValueExA(subdomain, test->scheme, 0, REG_DWORD, (BYTE*)&test->zone, sizeof(DWORD));
818 ok(res == ERROR_SUCCESS, "RegSetValueEx failed with %d on test %d\n", res, i);
819
820 RegCloseKey(subdomain);
821 }
822
823 RegCloseKey(domain);
824 }
825
826 RegCloseKey(domains);
827 return TRUE;
828 }
829
830 static void unregister_zone_domains(void)
831 {
832 HKEY domains;
833 DWORD res, i;
834
835 res = RegOpenKeyA(HKEY_LOCAL_MACHINE, szZoneMapDomainsKey, &domains);
836 ok(res == ERROR_SUCCESS || broken(res == ERROR_FILE_NOT_FOUND), "RegOpenKey failed: %d\n", res);
837 if(res == ERROR_SUCCESS) {
838 RegDeleteKeyA(domains, "local.machine");
839 RegCloseKey(domains);
840 }
841
842 res = RegOpenKeyA(HKEY_CURRENT_USER, szZoneMapDomainsKey, &domains);
843 ok(res == ERROR_SUCCESS, "RegOpenKey failed: %d\n", res);
844
845 for(i = 0; i < sizeof(zone_domain_mappings)/sizeof(zone_domain_mappings[0]); ++i) {
846 const zone_domain_mapping *test = zone_domain_mappings+i;
847
848 /* FIXME: Uses the "cludge" approach to remove the test data from the registry!
849 * Although, if domain names are... unique, this shouldn't cause any harm
850 * to keys (if any) that existed before the tests.
851 */
852 if(test->subdomain) {
853 HKEY domain;
854
855 res = RegOpenKeyA(domains, test->domain, &domain);
856 if(res == ERROR_SUCCESS) {
857 RegDeleteKeyA(domain, test->subdomain);
858 RegCloseKey(domain);
859 }
860 }
861 RegDeleteKeyA(domains, test->domain);
862 }
863
864 RegCloseKey(domains);
865 }
866
867 static void run_child_process(void)
868 {
869 char cmdline[MAX_PATH];
870 char path[MAX_PATH];
871 char **argv;
872 PROCESS_INFORMATION pi;
873 STARTUPINFOA si = { 0 };
874 BOOL ret;
875
876 GetModuleFileNameA(NULL, path, MAX_PATH);
877
878 si.cb = sizeof(si);
879 winetest_get_mainargs(&argv);
880 sprintf(cmdline, "\"%s\" %s domain_tests", argv[0], argv[1]);
881 ret = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
882 ok(ret, "Failed to spawn child process: %u\n", GetLastError());
883 winetest_wait_child_process(pi.hProcess);
884 CloseHandle(pi.hThread);
885 CloseHandle(pi.hProcess);
886 }
887
888 typedef struct {
889 const char *url;
890 DWORD zone;
891 BOOL todo;
892 DWORD broken_zone;
893 } zone_mapping_test;
894
895 static const zone_mapping_test zone_mapping_tests[] = {
896 /* Tests for "yabadaba.do" zone mappings. */
897 {"http://yabadaba.do/",URLZONE_CUSTOM},
898 {"http://google.yabadaba.do/",URLZONE_CUSTOM},
899 {"zip://yabadaba.do/",URLZONE_INTERNET},
900 /* Tests for "super.cool" zone mappings. */
901 {"ftp://testing.google.super.cool/",URLZONE_INTERNET},
902 {"ftp://testing.*.super.cool/",URLZONE_CUSTOM2},
903 {"ftp://google.testing.super.cool/",URLZONE_CUSTOM2},
904 /* Tests for "tests.test" zone mappings. */
905 {"http://tests.test/",URLZONE_CUSTOM},
906 {"http://www.tests.test/",URLZONE_CUSTOM},
907 {"ftp://tests.test/",URLZONE_CUSTOM},
908 {"ftp://www.tests.test/",URLZONE_CUSTOM},
909 {"test://www.tests.test/",URLZONE_INTERNET},
910 {"test://tests.test/",URLZONE_INTERNET},
911 {"zip://www.tests.test/",URLZONE_INTERNET},
912 {"zip://tests.test/",URLZONE_INTERNET},
913 /* Tests for "www.testing.com" zone mappings. */
914 {"http://google.www.testing.com/",URLZONE_INTERNET},
915 {"http://www.testing.com/",URLZONE_CUSTOM,FALSE,URLZONE_INTERNET},
916 {"http://testing.www.testing.com/",URLZONE_CUSTOM2,FALSE,URLZONE_INTERNET},
917 /* Tests for "org" zone mappings. */
918 {"http://google.org/",URLZONE_INTERNET,FALSE,URLZONE_CUSTOM},
919 {"http://org/",URLZONE_CUSTOM},
920 {"http://testing.org/",URLZONE_CUSTOM2},
921 /* Tests for "wine.testing" mapping */
922 {"*:wine.testing/test",URLZONE_CUSTOM2},
923 {"http://wine.testing/testing",URLZONE_CUSTOM2}
924 };
925
926 static void test_zone_domain_mappings(void)
927 {
928 HRESULT hres;
929 DWORD i, res;
930 IInternetSecurityManager *secmgr = NULL;
931 HKEY domains;
932 DWORD zone = URLZONE_INVALID;
933
934 trace("testing zone domain mappings...\n");
935
936 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
937 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
938
939 res = RegOpenKeyA(HKEY_LOCAL_MACHINE, szZoneMapDomainsKey, &domains);
940 if(res == ERROR_SUCCESS) {
941 static const WCHAR local_machineW[] = {'h','t','t','p',':','/','/','t','e','s','t','.','l','o','c','a','l',
942 '.','m','a','c','h','i','n','e','/',0};
943
944 hres = IInternetSecurityManager_MapUrlToZone(secmgr, local_machineW, &zone, 0);
945 ok(hres == S_OK, "MapUrlToZone failed: %08x\n", hres);
946 ok(zone == URLZONE_CUSTOM, "Expected URLZONE_CUSTOM, but got %d\n", zone);
947
948 RegCloseKey(domains);
949 }
950
951 for(i = 0; i < sizeof(zone_mapping_tests)/sizeof(zone_mapping_tests[0]); ++i) {
952 const zone_mapping_test *test = zone_mapping_tests+i;
953 LPWSTR urlW = a2w(test->url);
954 zone = URLZONE_INVALID;
955
956 hres = IInternetSecurityManager_MapUrlToZone(secmgr, urlW, &zone, 0);
957 ok(hres == S_OK, "MapUrlToZone failed: %08x\n", hres);
958 todo_wine_if (test->todo)
959 ok(zone == test->zone || broken(test->broken_zone == zone),
960 "Expected %d, but got %d on test %d\n", test->zone, zone, i);
961
962 heap_free(urlW);
963 }
964
965 IInternetSecurityManager_Release(secmgr);
966 }
967
968 static void test_zone_domains(void)
969 {
970 if(is_ie_hardened()) {
971 skip("IE running in Enhanced Security Configuration\n");
972 return;
973 } else if(!pCreateUri) {
974 win_skip("Skipping zone domain tests, IE too old\n");
975 return;
976 }
977
978 trace("testing zone domains...\n");
979
980 test_zone_domain_cache();
981
982 if (!register_zone_domains()) return;
983 run_child_process();
984 unregister_zone_domains();
985 }
986
987 static void test_CoInternetCreateZoneManager(void)
988 {
989 IInternetZoneManager *zonemgr = NULL;
990 IUnknown *punk = NULL;
991 HRESULT hr;
992
993 trace("simple zone manager tests...\n");
994
995 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
996 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
997 if (FAILED(hr))
998 return;
999
1000 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IUnknown, (void **) &punk);
1001 ok(SUCCEEDED(hr), "got 0x%x with %p (expected Success)\n", hr, punk);
1002 if (punk)
1003 IUnknown_Release(punk);
1004
1005 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IInternetZoneManager, (void **) &punk);
1006 ok(SUCCEEDED(hr), "got 0x%x with %p (expected Success)\n", hr, punk);
1007 if (punk)
1008 IUnknown_Release(punk);
1009
1010
1011 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IInternetZoneManagerEx, (void **) &punk);
1012 if (SUCCEEDED(hr)) {
1013 IUnknown_Release(punk);
1014
1015 hr = IInternetZoneManager_QueryInterface(zonemgr, &IID_IInternetZoneManagerEx2, (void **) &punk);
1016 ok(hr == S_OK || broken(hr == E_NOINTERFACE /* some W2K3 */),
1017 "got 0x%x (expected S_OK)\n", hr);
1018 if (punk)
1019 IUnknown_Release(punk);
1020 else
1021 win_skip("InternetZoneManagerEx2 not supported\n");
1022
1023 }
1024 else
1025 win_skip("InternetZoneManagerEx not supported\n");
1026
1027 hr = IInternetZoneManager_Release(zonemgr);
1028 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1029
1030 }
1031
1032 static void test_CreateZoneEnumerator(void)
1033 {
1034 IInternetZoneManager *zonemgr = NULL;
1035 HRESULT hr;
1036 DWORD dwEnum;
1037 DWORD dwEnum2;
1038 DWORD dwCount;
1039 DWORD dwCount2;
1040
1041 trace("testing zone enumerator...\n");
1042
1043 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
1044 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
1045 if (FAILED(hr))
1046 return;
1047
1048 dwEnum=0xdeadbeef;
1049 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, NULL, 0);
1050 ok((hr == E_INVALIDARG) && (dwEnum == 0xdeadbeef),
1051 "got 0x%x with 0x%x (expected E_INVALIDARG with 0xdeadbeef)\n", hr, dwEnum);
1052
1053 dwCount=0xdeadbeef;
1054 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, NULL, &dwCount, 0);
1055 ok((hr == E_INVALIDARG) && (dwCount == 0xdeadbeef),
1056 "got 0x%x and 0x%x (expected E_INVALIDARG and 0xdeadbeef)\n", hr, dwCount);
1057
1058 dwEnum=0xdeadbeef;
1059 dwCount=0xdeadbeef;
1060 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 0xffffffff);
1061 ok((hr == E_INVALIDARG) && (dwEnum == 0xdeadbeef) && (dwCount == 0xdeadbeef),
1062 "got 0x%x with 0x%x and 0x%x (expected E_INVALIDARG with 0xdeadbeef and 0xdeadbeef)\n",
1063 hr, dwEnum, dwCount);
1064
1065 dwEnum=0xdeadbeef;
1066 dwCount=0xdeadbeef;
1067 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 1);
1068 ok((hr == E_INVALIDARG) && (dwEnum == 0xdeadbeef) && (dwCount == 0xdeadbeef),
1069 "got 0x%x with 0x%x and 0x%x (expected E_INVALIDARG with 0xdeadbeef and 0xdeadbeef)\n",
1070 hr, dwEnum, dwCount);
1071
1072 dwEnum=0xdeadbeef;
1073 dwCount=0xdeadbeef;
1074 /* Normal use */
1075 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 0);
1076 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1077
1078 if (SUCCEEDED(hr)) {
1079 dwEnum2=0xdeadbeef;
1080 dwCount2=0xdeadbeef;
1081 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum2, &dwCount2, 0);
1082 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1083 if (SUCCEEDED(hr)) {
1084 /* native urlmon has an incrementing counter for dwEnum */
1085 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum2);
1086 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1087 }
1088
1089 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum);
1090 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1091
1092 /* Destroy the Enumerator twice is detected and handled in native urlmon */
1093 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum);
1094 ok((hr == E_INVALIDARG), "got 0x%x (expected E_INVALIDARG)\n", hr);
1095 }
1096
1097 /* ::Release succeed also, when a ::DestroyZoneEnumerator is missing */
1098 hr = IInternetZoneManager_Release(zonemgr);
1099 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1100 }
1101
1102 static void test_GetZoneActionPolicy(void)
1103 {
1104 IInternetZoneManager *zonemgr = NULL;
1105 BYTE buf[32];
1106 HRESULT hres;
1107 DWORD action = URLACTION_CREDENTIALS_USE; /* Implemented on all IE versions */
1108
1109 trace("testing GetZoneActionPolixy...\n");
1110
1111 hres = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
1112 ok(hres == S_OK, "CoInternetCreateZoneManager failed: %08x\n", hres);
1113 if(FAILED(hres))
1114 return;
1115
1116 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, buf,
1117 sizeof(DWORD), URLZONEREG_DEFAULT);
1118 ok(hres == S_OK, "GetZoneActionPolicy failed: %08x\n", hres);
1119 ok(*(DWORD*)buf == URLPOLICY_CREDENTIALS_SILENT_LOGON_OK ||
1120 *(DWORD*)buf == URLPOLICY_CREDENTIALS_MUST_PROMPT_USER ||
1121 *(DWORD*)buf == URLPOLICY_CREDENTIALS_CONDITIONAL_PROMPT ||
1122 *(DWORD*)buf == URLPOLICY_CREDENTIALS_ANONYMOUS_ONLY,
1123 "unexpected policy=%d\n", *(DWORD*)buf);
1124
1125 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, NULL,
1126 sizeof(DWORD), URLZONEREG_DEFAULT);
1127 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
1128
1129 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, action, buf,
1130 2, URLZONEREG_DEFAULT);
1131 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
1132
1133 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 3, 0x1fff, buf,
1134 sizeof(DWORD), URLZONEREG_DEFAULT);
1135 ok(hres == E_FAIL || broken(hres == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)),
1136 "(0x%x) got 0x%x (expected E_FAIL)\n", action, hres);
1137
1138 hres = IInternetZoneManager_GetZoneActionPolicy(zonemgr, 13, action, buf,
1139 sizeof(DWORD), URLZONEREG_DEFAULT);
1140 ok(hres == E_INVALIDARG, "GetZoneActionPolicy failed: %08x, expected E_INVALIDARG\n", hres);
1141
1142 IInternetZoneManager_Release(zonemgr);
1143 }
1144
1145 static void test_GetZoneAt(void)
1146 {
1147 IInternetZoneManager *zonemgr = NULL;
1148 HRESULT hr;
1149 DWORD dwEnum;
1150 DWORD dwCount;
1151 DWORD dwZone;
1152 DWORD i;
1153
1154 trace("testing GetZoneAt...\n");
1155
1156 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
1157 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
1158 if (FAILED(hr))
1159 return;
1160
1161 hr = IInternetZoneManager_CreateZoneEnumerator(zonemgr, &dwEnum, &dwCount, 0);
1162 if (FAILED(hr))
1163 goto cleanup;
1164
1165 if (0) {
1166 /* this crashes with native urlmon */
1167 IInternetZoneManager_GetZoneAt(zonemgr, dwEnum, 0, NULL);
1168 }
1169
1170 dwZone = 0xdeadbeef;
1171 hr = IInternetZoneManager_GetZoneAt(zonemgr, 0xdeadbeef, 0, &dwZone);
1172 ok(hr == E_INVALIDARG,
1173 "got 0x%x with 0x%x (expected E_INVALIDARG)\n", hr, dwZone);
1174
1175 for (i = 0; i < dwCount; i++)
1176 {
1177 dwZone = 0xdeadbeef;
1178 hr = IInternetZoneManager_GetZoneAt(zonemgr, dwEnum, i, &dwZone);
1179 ok(hr == S_OK, "#%d: got x%x with %d (expected S_OK)\n", i, hr, dwZone);
1180 }
1181
1182 dwZone = 0xdeadbeef;
1183 /* MSDN (index .. must be .. less than or equal to) is wrong */
1184 hr = IInternetZoneManager_GetZoneAt(zonemgr, dwEnum, dwCount, &dwZone);
1185 ok(hr == E_INVALIDARG,
1186 "got 0x%x with 0x%x (expected E_INVALIDARG)\n", hr, dwZone);
1187
1188 hr = IInternetZoneManager_DestroyZoneEnumerator(zonemgr, dwEnum);
1189 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1190
1191 cleanup:
1192 hr = IInternetZoneManager_Release(zonemgr);
1193 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1194 }
1195
1196 static void test_GetZoneAttributes(void)
1197 {
1198 IInternetZoneManager *zonemgr = NULL;
1199 CHAR buffer [sizeof(ZONEATTRIBUTES) + 32];
1200 ZONEATTRIBUTES* pZA = (ZONEATTRIBUTES*) buffer;
1201 HRESULT hr;
1202 DWORD i;
1203
1204 trace("testing GetZoneAttributes...\n");
1205
1206 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
1207 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
1208 if (FAILED(hr))
1209 return;
1210
1211 /* native urlmon has Zone "0" up to Zone "4" since IE4 */
1212 for (i = 0; i < 5; i++) {
1213 memset(buffer, -1, sizeof(buffer));
1214 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, i, pZA);
1215 ok(hr == S_OK, "#%d: got 0x%x (expected S_OK)\n", i, hr);
1216 }
1217
1218 /* IE8 no longer set cbSize */
1219 memset(buffer, -1, sizeof(buffer));
1220 pZA->cbSize = 0;
1221 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, pZA);
1222 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1223 ok((pZA->cbSize == 0) || (pZA->cbSize == sizeof(ZONEATTRIBUTES)),
1224 "got cbSize = %d (expected 0)\n", pZA->cbSize);
1225
1226 memset(buffer, -1, sizeof(buffer));
1227 pZA->cbSize = 64;
1228 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, pZA);
1229 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1230 ok((pZA->cbSize == 64) || (pZA->cbSize == sizeof(ZONEATTRIBUTES)),
1231 "got cbSize = %d (expected 64)\n", pZA->cbSize);
1232
1233 memset(buffer, -1, sizeof(buffer));
1234 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, pZA);
1235 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1236 ok((pZA->cbSize == 0xffffffff) || (pZA->cbSize == sizeof(ZONEATTRIBUTES)),
1237 "got cbSize = 0x%x (expected 0xffffffff)\n", pZA->cbSize);
1238
1239 /* IE8 up to IE10 don't fail on invalid zones */
1240 memset(buffer, -1, sizeof(buffer));
1241 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0xdeadbeef, pZA);
1242 ok(hr == S_OK || hr == E_FAIL || hr == E_POINTER,
1243 "got 0x%x (expected S_OK or E_FAIL)\n", hr);
1244
1245 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, 0, NULL);
1246 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1247
1248 hr = IInternetZoneManager_Release(zonemgr);
1249 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1250 }
1251
1252 static void test_SetZoneAttributes(void)
1253 {
1254 IInternetZoneManager *zonemgr = NULL;
1255 CHAR buffer [sizeof(ZONEATTRIBUTES) + 16];
1256 ZONEATTRIBUTES* pZA = (ZONEATTRIBUTES*) buffer;
1257 CHAR regpath[MAX_PATH];
1258 HKEY hkey;
1259 HRESULT hr;
1260 DWORD res;
1261
1262 trace("testing SetZoneAttributes...\n");
1263 hr = pCoInternetCreateZoneManager(NULL, &zonemgr, 0);
1264 ok(hr == S_OK, "CoInternetCreateZoneManager result: 0x%x\n", hr);
1265 if (FAILED(hr))
1266 return;
1267
1268 memset(buffer, -1, sizeof(buffer));
1269 hr = IInternetZoneManager_GetZoneAttributes(zonemgr, URLZONE_LOCAL_MACHINE, pZA);
1270 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1271
1272 sprintf(regpath, "%s\\Zones\\%d", szInternetSettingsKey, URLZONE_CUSTOM);
1273 res = RegCreateKeyA(HKEY_CURRENT_USER, regpath, &hkey);
1274 RegCloseKey(hkey);
1275
1276 ok(res == ERROR_SUCCESS, "got %d (expected ERROR_SUCCESS)\n", res);
1277 if (res != ERROR_SUCCESS)
1278 goto cleanup;
1279
1280 pZA->cbSize = sizeof(ZONEATTRIBUTES);
1281 hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, NULL);
1282 ok(hr == E_INVALIDARG, "got 0x%x (expected E_INVALIDARG)\n", hr);
1283
1284 /* normal use */
1285 hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, pZA);
1286 if (hr == E_FAIL) {
1287 win_skip("SetZoneAttributes not supported: IE too old\n");
1288 goto cleanup;
1289 }
1290 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1291
1292 /* native urlmon ignores cbSize */
1293 pZA->cbSize = sizeof(ZONEATTRIBUTES) + sizeof(DWORD);
1294 hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, pZA);
1295 ok(hr == S_OK, "got 0x%x for sizeof(ZONEATTRIBUTES) + sizeof(DWORD) (expected S_OK)\n", hr);
1296
1297 pZA->cbSize = sizeof(ZONEATTRIBUTES) - sizeof(DWORD);
1298 hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, pZA);
1299 ok(hr == S_OK, "got 0x%x for sizeof(ZONEATTRIBUTES) - sizeof(DWORD) (expected S_OK)\n", hr);
1300
1301 pZA->cbSize = 0;
1302 hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, pZA);
1303 ok(hr == S_OK, "got 0x%x for size 0 (expected S_OK)\n", hr);
1304
1305 /* The key for the zone must be present, when calling SetZoneAttributes */
1306 myRegDeleteTreeA(HKEY_CURRENT_USER, regpath);
1307 /* E_FAIL is returned from IE6 here, which is reasonable.
1308 All newer IE return S_OK without saving the zone attributes to the registry.
1309 This is a Windows bug, but we have to accept that as standard */
1310 hr = IInternetZoneManager_SetZoneAttributes(zonemgr, URLZONE_CUSTOM, pZA);
1311 ok((hr == S_OK) || broken(hr == E_FAIL), "got 0x%x (expected S_OK)\n", hr);
1312
1313 /* SetZoneAttributes did not create the directory */
1314 res = RegOpenKeyA(HKEY_CURRENT_USER, regpath, &hkey);
1315 ok((res == ERROR_FILE_NOT_FOUND) && (hkey == NULL),
1316 "got %u with %p (expected ERROR_FILE_NOT_FOUND with NULL)\n", res, hkey);
1317
1318 if (hkey) RegCloseKey(hkey);
1319
1320 cleanup:
1321 /* delete zone settings in the registry */
1322 myRegDeleteTreeA(HKEY_CURRENT_USER, regpath);
1323
1324 hr = IInternetZoneManager_Release(zonemgr);
1325 ok(hr == S_OK, "got 0x%x (expected S_OK)\n", hr);
1326 }
1327
1328
1329 static void test_InternetSecurityMarshalling(void)
1330 {
1331 IInternetSecurityManager *secmgr = NULL;
1332 IUnknown *unk;
1333 IStream *stream;
1334 HRESULT hres;
1335
1336 trace("testing marshalling...\n");
1337
1338 hres = pCoInternetCreateSecurityManager(NULL, &secmgr, 0);
1339 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
1340 if(FAILED(hres))
1341 return;
1342
1343 hres = IInternetSecurityManager_QueryInterface(secmgr, &IID_IUnknown, (void**)&unk);
1344 ok(hres == S_OK, "QueryInterface returned: %08x\n", hres);
1345
1346 hres = CreateStreamOnHGlobal(NULL, TRUE, &stream);
1347 ok(hres == S_OK, "CreateStreamOnHGlobal returned: %08x\n", hres);
1348
1349 hres = CoMarshalInterface(stream, &IID_IInternetSecurityManager, unk, MSHCTX_INPROC, NULL, MSHLFLAGS_NORMAL);
1350 /* Not supported in W98 */
1351 ok(hres == S_OK || broken(hres == REGDB_E_IIDNOTREG),
1352 "CoMarshalInterface returned: %08x\n", hres);
1353
1354 IStream_Release(stream);
1355 IUnknown_Release(unk);
1356 IInternetSecurityManager_Release(secmgr);
1357 }
1358
1359 static void test_InternetGetSecurityUrl(void)
1360 {
1361 const WCHAR url5_out[] = {'h','t','t','p',':','w','w','w','.','z','o','n','e','3',
1362 '.','w','i','n','e','t','e','s','t',0};
1363 const WCHAR url7_out[] = {'f','t','p',':','z','o','n','e','3','.','w','i','n','e','t','e','s','t',0};
1364
1365 const WCHAR *in[] = {url2, url3, url4, url5, url7, url8, url9, url10};
1366 const WCHAR *out_default[] = {url2, url3, url4, url5_out, url7_out, url8, url5_out, url10};
1367 const WCHAR *out_securl[] = {url2, url3, url4, url5, url7, url8, url9, url10};
1368
1369 WCHAR *sec;
1370 DWORD i;
1371 HRESULT hres;
1372
1373 trace("testing CoInternetGetSecurityUrl...\n");
1374
1375 for(i=0; i<sizeof(in)/sizeof(WCHAR*); i++) {
1376 hres = pCoInternetGetSecurityUrl(in[i], &sec, PSU_DEFAULT, 0);
1377 ok(hres == S_OK, "(%d) CoInternetGetSecurityUrl returned: %08x\n", i, hres);
1378 if(hres == S_OK) {
1379 ok(!strcmp_w(sec, out_default[i]), "(%d) Got %s, expected %s\n",
1380 i, wine_dbgstr_w(sec), wine_dbgstr_w(out_default[i]));
1381 CoTaskMemFree(sec);
1382 }
1383
1384 hres = pCoInternetGetSecurityUrl(in[i], &sec, PSU_SECURITY_URL_ONLY, 0);
1385 ok(hres == S_OK, "(%d) CoInternetGetSecurityUrl returned: %08x\n", i, hres);
1386 if(hres == S_OK) {
1387 ok(!strcmp_w(sec, out_securl[i]), "(%d) Got %s, expected %s\n",
1388 i, wine_dbgstr_w(sec), wine_dbgstr_w(out_securl[i]));
1389 CoTaskMemFree(sec);
1390 }
1391 }
1392
1393 SET_EXPECT(ParseUrl_SECURITY_URL_input2);
1394 SET_EXPECT(ParseUrl_SECURITY_URL_expected);
1395 SET_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
1396
1397 hres = pCoInternetGetSecurityUrl(security_url2W, &sec, PSU_DEFAULT, 0);
1398 ok(hres == S_OK, "CoInternetGetSecurityUrl returned 0x%08x, expected S_OK\n", hres);
1399
1400 CHECK_CALLED(ParseUrl_SECURITY_URL_input2);
1401 CHECK_CALLED(ParseUrl_SECURITY_URL_expected);
1402 CHECK_CALLED(ParseUrl_SECURITY_DOMAIN_expected);
1403
1404 ok(!lstrcmpW(security_expectedW, sec), "Expected %s but got %s\n",
1405 wine_dbgstr_w(security_expectedW), wine_dbgstr_w(sec));
1406 CoTaskMemFree(sec);
1407 }
1408
1409 static HRESULT WINAPI InternetProtocolInfo_QueryInterface(IInternetProtocolInfo *iface,
1410 REFIID riid, void **ppv)
1411 {
1412 ok(0, "unexpected call\n");
1413 return E_NOINTERFACE;
1414 }
1415
1416 static ULONG WINAPI InternetProtocolInfo_AddRef(IInternetProtocolInfo *iface)
1417 {
1418 return 2;
1419 }
1420
1421 static ULONG WINAPI InternetProtocolInfo_Release(IInternetProtocolInfo *iface)
1422 {
1423 return 1;
1424 }
1425
1426 static HRESULT WINAPI InternetProtocolInfo_ParseUrl(IInternetProtocolInfo *iface, LPCWSTR pwzUrl,
1427 PARSEACTION ParseAction, DWORD dwParseFlags, LPWSTR pwzResult, DWORD cchResult,
1428 DWORD *pcchResult, DWORD dwReserved)
1429 {
1430 const WCHAR *ret = NULL;
1431
1432 ok(pwzResult != NULL, "pwzResult == NULL\n");
1433 ok(pcchResult != NULL, "pcchResult == NULL\n");
1434 ok(!dwParseFlags, "Expected 0, but got 0x%08x\n", dwParseFlags);
1435
1436 switch(ParseAction) {
1437 case PARSE_SECURITY_URL:
1438 if(!strcmp_w(pwzUrl, security_urlW)) {
1439 CHECK_EXPECT(ParseUrl_SECURITY_URL_input);
1440 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1441 ret = security_expectedW;
1442 } else if(!strcmp_w(pwzUrl, security_url2W)) {
1443 CHECK_EXPECT(ParseUrl_SECURITY_URL_input2);
1444 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1445 ret = security_expectedW;
1446 } else if(!strcmp_w(pwzUrl, security_expectedW)) {
1447 CHECK_EXPECT(ParseUrl_SECURITY_URL_expected);
1448 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1449 ret = security_expectedW;
1450 } else if(!strcmp_w(pwzUrl, winetest_to_httpW)) {
1451 switch(++called_securl_http) {
1452 case 1:
1453 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1454 break;
1455 case 2:
1456 CHECK_EXPECT(ParseUrl_SECURITY_URL_http);
1457 ok(cchResult == lstrlenW(url9)+1, "Got %d\n", cchResult);
1458 break;
1459 default:
1460 todo_wine CHECK_EXPECT(ParseUrl_SECURITY_URL_http);
1461 }
1462 ret = url9;
1463 } else
1464 ok(0, "Unexpected call, pwzUrl=%s\n", wine_dbgstr_w(pwzUrl));
1465
1466 break;
1467 case PARSE_SECURITY_DOMAIN:
1468
1469 CHECK_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
1470
1471 ok(!strcmp_w(pwzUrl, security_expectedW), "Expected %s but got %s\n",
1472 wine_dbgstr_w(security_expectedW), wine_dbgstr_w(pwzUrl));
1473 ok(cchResult == lstrlenW(pwzUrl)+1, "Got %d\n", cchResult);
1474 ret = security_expectedW;
1475 break;
1476 default:
1477 ok(0, "Unexpected call, ParseAction=%d pwzUrl=%s\n", ParseAction,
1478 wine_dbgstr_w(pwzUrl));
1479 }
1480
1481 if(!ret)
1482 return E_FAIL;
1483
1484 *pcchResult = lstrlenW(ret)+1;
1485 if(*pcchResult > cchResult)
1486 return S_FALSE;
1487 memcpy(pwzResult, ret, (*pcchResult)*sizeof(WCHAR));
1488 return S_OK;
1489 }
1490
1491 static HRESULT WINAPI InternetProtocolInfo_CombineUrl(IInternetProtocolInfo *iface,
1492 LPCWSTR pwzBaseUrl, LPCWSTR pwzRelativeUrl, DWORD dwCombineFlags,
1493 LPWSTR pwzResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
1494 {
1495 ok(0, "unexpected call\n");
1496 return E_NOTIMPL;
1497 }
1498
1499 static HRESULT WINAPI InternetProtocolInfo_CompareUrl(IInternetProtocolInfo *iface,
1500 LPCWSTR pwzUrl1, LPCWSTR pwzUrl2, DWORD dwCompareFlags)
1501 {
1502 ok(0, "unexpected call\n");
1503 return E_NOTIMPL;
1504 }
1505
1506 static HRESULT WINAPI InternetProtocolInfo_QueryInfo(IInternetProtocolInfo *iface,
1507 LPCWSTR pwzUrl, QUERYOPTION OueryOption, DWORD dwQueryFlags, LPVOID pBuffer,
1508 DWORD cbBuffer, DWORD *pcbBuf, DWORD dwReserved)
1509 {
1510 ok(0, "unexpected call\n");
1511 return E_NOTIMPL;
1512 }
1513
1514 static const IInternetProtocolInfoVtbl InternetProtocolInfoVtbl = {
1515 InternetProtocolInfo_QueryInterface,
1516 InternetProtocolInfo_AddRef,
1517 InternetProtocolInfo_Release,
1518 InternetProtocolInfo_ParseUrl,
1519 InternetProtocolInfo_CombineUrl,
1520 InternetProtocolInfo_CompareUrl,
1521 InternetProtocolInfo_QueryInfo
1522 };
1523
1524 static IInternetProtocolInfo protocol_info = { &InternetProtocolInfoVtbl };
1525
1526 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
1527 {
1528 if(IsEqualGUID(&IID_IInternetProtocolInfo, riid)) {
1529 *ppv = &protocol_info;
1530 return S_OK;
1531 }
1532
1533 ok(0, "unexpected call\n");
1534 return E_NOINTERFACE;
1535 }
1536
1537 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1538 {
1539 return 2;
1540 }
1541
1542 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1543 {
1544 return 1;
1545 }
1546
1547 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *pOuter,
1548 REFIID riid, void **ppv)
1549 {
1550 ok(0, "unexpected call\n");
1551 return E_NOTIMPL;
1552 }
1553
1554 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
1555 {
1556 ok(0, "unexpected call\n");
1557 return S_OK;
1558 }
1559
1560 static const IClassFactoryVtbl ClassFactoryVtbl = {
1561 ClassFactory_QueryInterface,
1562 ClassFactory_AddRef,
1563 ClassFactory_Release,
1564 ClassFactory_CreateInstance,
1565 ClassFactory_LockServer
1566 };
1567
1568 static IClassFactory protocol_cf = { &ClassFactoryVtbl };
1569
1570 static void register_protocols(void)
1571 {
1572 IInternetSession *session;
1573 HRESULT hres;
1574
1575 hres = pCoInternetGetSession(0, &session, 0);
1576 ok(hres == S_OK, "CoInternetGetSession failed: %08x\n", hres);
1577 if(FAILED(hres))
1578 return;
1579
1580 hres = IInternetSession_RegisterNameSpace(session, &protocol_cf, &IID_NULL,
1581 winetestW, 0, NULL, 0);
1582 ok(hres == S_OK, "RegisterNameSpace failed: %08x\n", hres);
1583
1584 IInternetSession_Release(session);
1585 }
1586
1587 static void unregister_protocols(void) {
1588 IInternetSession *session;
1589 HRESULT hr;
1590
1591 hr = pCoInternetGetSession(0, &session, 0);
1592 ok(hr == S_OK, "CoInternetGetSession failed: 0x%08x\n", hr);
1593 if(FAILED(hr))
1594 return;
1595
1596 hr = IInternetSession_UnregisterNameSpace(session, &protocol_cf, winetestW);
1597 ok(hr == S_OK, "UnregisterNameSpace failed: 0x%08x\n", hr);
1598
1599 IInternetSession_Release(session);
1600 }
1601
1602 static const struct {
1603 const char *uri;
1604 DWORD create_flags;
1605 const char *security_uri;
1606 HRESULT security_hres;
1607 const char *default_uri;
1608 HRESULT default_hres;
1609 BOOL todo;
1610 } sec_url_ex_tests[] = {
1611 {"index.htm",Uri_CREATE_ALLOW_RELATIVE,"*:index.html",S_OK,"*:index.htm",S_OK},
1612 {"file://c:\\Index.htm",Uri_CREATE_FILE_USE_DOS_PATH,"file:///c:/Index.htm",S_OK,"file:///c:/Index.htm",S_OK},
1613 {"file:some%20file%2ejpg",0,NULL,E_INVALIDARG,NULL,E_INVALIDARG},
1614 {"file:some file.jpg",0,NULL,E_INVALIDARG,NULL,E_INVALIDARG},
1615 {"http://www.zone3.winetest/",0,"http://www.zone3.winetest/",S_OK,"http://www.zone3.winetest/",S_OK},
1616 {"about:blank",0,"about:blank",S_OK,"about:blank",S_OK},
1617 {"ftp://zone3.winetest/file.test",0,"ftp://zone3.winetest/file.test",S_OK,"ftp://zone3.winetest/file.test",S_OK},
1618 {"test:123abc",0,"test:123abc",S_OK,"test:123abc",S_OK},
1619 {"http:google.com/test.file",0,"http:google.com/test.file",S_OK,"http:google.com/test.file",S_OK},
1620 {"ftp://test@ftp.winehq.org/",0,"ftp://ftp.winehq.org/",S_OK,"ftp://ftp.winehq.org/",S_OK},
1621 {"test://google@ftp.winehq.org/",0,"test://google@ftp.winehq.org/",S_OK,"test://google@ftp.winehq.org/",S_OK}
1622 };
1623
1624 static void test_InternetGetSecurityUrlEx(void)
1625 {
1626 HRESULT hr;
1627 DWORD i;
1628 IUri *uri = NULL, *result = NULL;
1629
1630 trace("testing CoInternetGetSecurityUrlEx...\n");
1631
1632 hr = pCoInternetGetSecurityUrlEx(NULL, NULL, PSU_DEFAULT, 0);
1633 ok(hr == E_INVALIDARG, "CoInternetGetSecurityUrlEx returned 0x%08x, expected E_INVALIDARG\n", hr);
1634
1635 result = (void*) 0xdeadbeef;
1636 hr = pCoInternetGetSecurityUrlEx(NULL, &result, PSU_DEFAULT, 0);
1637 ok(hr == E_INVALIDARG, "CoInternetGetSecurityUrlEx returned 0x%08x, expected E_INVALIDARG\n", hr);
1638 ok(result == (void*) 0xdeadbeef, "'result' was %p\n", result);
1639
1640 for(i = 0; i < sizeof(sec_url_ex_tests)/sizeof(sec_url_ex_tests[0]); ++i) {
1641 LPWSTR uriW = a2w(sec_url_ex_tests[i].uri);
1642 uri = NULL;
1643
1644 hr = pCreateUri(uriW, sec_url_ex_tests[i].create_flags, 0, &uri);
1645 ok(hr == S_OK, "CreateUri returned 0x%08x on test %d\n", hr, i);
1646 if(hr == S_OK) {
1647 result = NULL;
1648
1649 hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_DEFAULT, 0);
1650 todo_wine_if (sec_url_ex_tests[i].todo) {
1651 ok(hr == sec_url_ex_tests[i].default_hres,
1652 "CoInternetGetSecurityUrlEx returned 0x%08x, expected 0x%08x on test %d\n",
1653 hr, sec_url_ex_tests[i].default_hres, i);
1654 }
1655 if(SUCCEEDED(hr)) {
1656 BSTR received;
1657
1658 hr = IUri_GetDisplayUri(result, &received);
1659 ok(hr == S_OK, "GetDisplayUri returned 0x%08x on test %d\n", hr, i);
1660 if(hr == S_OK) {
1661 todo_wine_if (sec_url_ex_tests[i].todo) {
1662 ok(!strcmp_aw(sec_url_ex_tests[i].default_uri, received),
1663 "Expected %s but got %s on test %d\n", sec_url_ex_tests[i].default_uri,
1664 wine_dbgstr_w(received), i);
1665 }
1666 }
1667 SysFreeString(received);
1668 }
1669 if(result) IUri_Release(result);
1670
1671 result = NULL;
1672 hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_SECURITY_URL_ONLY, 0);
1673 todo_wine_if (sec_url_ex_tests[i].todo) {
1674 ok(hr == sec_url_ex_tests[i].default_hres,
1675 "CoInternetGetSecurityUrlEx returned 0x%08x, expected 0x%08x on test %d\n",
1676 hr, sec_url_ex_tests[i].default_hres, i);
1677 }
1678 if(SUCCEEDED(hr)) {
1679 BSTR received;
1680
1681 hr = IUri_GetDisplayUri(result, &received);
1682 ok(hr == S_OK, "GetDisplayUri returned 0x%08x on test %d\n", hr, i);
1683 if(hr == S_OK) {
1684 todo_wine_if (sec_url_ex_tests[i].todo) {
1685 ok(!strcmp_aw(sec_url_ex_tests[i].default_uri, received),
1686 "Expected %s but got %s on test %d\n", sec_url_ex_tests[i].default_uri,
1687 wine_dbgstr_w(received), i);
1688 }
1689 }
1690 SysFreeString(received);
1691 }
1692 if(result) IUri_Release(result);
1693 }
1694
1695 if(uri) IUri_Release(uri);
1696 heap_free(uriW);
1697 }
1698 }
1699
1700 static void test_InternetGetSecurityUrlEx_Pluggable(void)
1701 {
1702 HRESULT hr;
1703 IUri *uri = NULL, *result;
1704
1705 trace("testing CoInternetGetSecurityUrlEx for pluggable protocols...\n");
1706
1707 hr = pCreateUri(security_urlW, 0, 0, &uri);
1708 ok(hr == S_OK, "CreateUri returned 0x%08x\n", hr);
1709 if(hr == S_OK) {
1710 SET_EXPECT(ParseUrl_SECURITY_URL_input);
1711 SET_EXPECT(ParseUrl_SECURITY_URL_expected);
1712 SET_EXPECT(ParseUrl_SECURITY_DOMAIN_expected);
1713
1714 hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_DEFAULT, 0);
1715 ok(hr == S_OK, "CoInternetGetSecurityUrlEx returned 0x%08x, expected S_OK\n", hr);
1716
1717 CHECK_CALLED(ParseUrl_SECURITY_URL_input);
1718 CHECK_CALLED(ParseUrl_SECURITY_URL_expected);
1719 CHECK_CALLED(ParseUrl_SECURITY_DOMAIN_expected);
1720
1721 if(hr == S_OK) {
1722 BSTR received = NULL;
1723
1724 hr = IUri_GetAbsoluteUri(result, &received);
1725 ok(hr == S_OK, "GetAbsoluteUri returned 0x%08x\n", hr);
1726 if(hr == S_OK) {
1727 ok(!strcmp_w(security_expectedW, received), "Expected %s but got %s\n",
1728 wine_dbgstr_w(security_expectedW), wine_dbgstr_w(received));
1729 }
1730 SysFreeString(received);
1731 }
1732 if(result) IUri_Release(result);
1733
1734 result = NULL;
1735
1736 SET_EXPECT(ParseUrl_SECURITY_URL_input);
1737 SET_EXPECT(ParseUrl_SECURITY_URL_expected);
1738
1739 hr = pCoInternetGetSecurityUrlEx(uri, &result, PSU_SECURITY_URL_ONLY, 0);
1740 ok(hr == S_OK, "CoInternetGetSecurityUrlEx returned 0x%08x, expected S_OK\n", hr);
1741
1742 CHECK_CALLED(ParseUrl_SECURITY_URL_input);
1743 CHECK_CALLED(ParseUrl_SECURITY_URL_expected);
1744
1745 if(hr == S_OK) {
1746 BSTR received = NULL;
1747
1748 hr = IUri_GetAbsoluteUri(result, &received);
1749 ok(hr == S_OK, "GetAbsoluteUri returned 0x%08x\n", hr);
1750 if(hr == S_OK) {
1751 ok(!strcmp_w(security_expectedW, received), "Expected %s but got %s\n",
1752 wine_dbgstr_w(security_expectedW), wine_dbgstr_w(received));
1753 }
1754 SysFreeString(received);
1755 }
1756 if(result) IUri_Release(result);
1757 }
1758 if(uri) IUri_Release(uri);
1759 }
1760
1761 static const BYTE secidex2_1[] = {'z','i','p',':','/','/','t','e','s','t','i','n','g','.','c','o','m','/',3,0,0,0};
1762 static const BYTE secidex2_2[] = {'z','i','p',':','t','e','s','t','i','n','g','.','c','o','m',3,0,0,0};
1763 static const BYTE secidex2_3[] = {'*',':','t','e','s','t','i','n','g','.','c','o','m',3,0,0,0};
1764
1765 static const struct {
1766 const char *uri;
1767 DWORD create_flags;
1768 HRESULT map_hres;
1769 DWORD zone;
1770 BOOL map_todo;
1771 const BYTE *secid;
1772 DWORD secid_size;
1773 HRESULT secid_hres;
1774 BOOL secid_todo;
1775 } sec_mgr_ex2_tests[] = {
1776 {"res://mshtml.dll/blank.htm",0,S_OK,URLZONE_LOCAL_MACHINE,FALSE,secid1,sizeof(secid1),S_OK},
1777 {"index.htm",Uri_CREATE_ALLOW_RELATIVE,0,URLZONE_INTERNET,FALSE,secid2,sizeof(secid2),S_OK},
1778 {"file://c:\\Index.html",0,0,URLZONE_LOCAL_MACHINE,FALSE,secid1,sizeof(secid1),S_OK},
1779 {"http://www.zone3.winetest/",0,0,URLZONE_INTERNET,FALSE,secid5,sizeof(secid5),S_OK},
1780 {"about:blank",0,0,URLZONE_INTERNET,FALSE,secid6,sizeof(secid6),S_OK},
1781 {"ftp://zone3.winetest/file.test",0,0,URLZONE_INTERNET,FALSE,secid7,sizeof(secid7),S_OK},
1782 {"/file/testing/test.test",Uri_CREATE_ALLOW_RELATIVE,0,URLZONE_INTERNET,FALSE,NULL,0,E_INVALIDARG},
1783 {"zip://testing.com/",0,0,URLZONE_INTERNET,FALSE,secidex2_1,sizeof(secidex2_1),S_OK},
1784 {"zip:testing.com",0,0,URLZONE_INTERNET,FALSE,secidex2_2,sizeof(secidex2_2),S_OK},
1785 {"http:google.com",0,S_OK,URLZONE_INVALID,FALSE,NULL,0,E_INVALIDARG},
1786 {"http:/google.com",0,S_OK,URLZONE_INVALID,FALSE,NULL,0,E_INVALIDARG},
1787 {"*:/testing",0,S_OK,URLZONE_INTERNET,FALSE,NULL,0,E_INVALIDARG},
1788 {"*://testing.com",0,S_OK,URLZONE_INTERNET,FALSE,secidex2_3,sizeof(secidex2_3),S_OK}
1789 };
1790
1791 static void test_SecurityManagerEx2(void)
1792 {
1793 HRESULT hres;
1794 DWORD i, zone;
1795 BYTE buf[512];
1796 DWORD buf_size = sizeof(buf);
1797 IInternetSecurityManager *sec_mgr;
1798 IInternetSecurityManagerEx2 *sec_mgr2;
1799 IUri *uri = NULL;
1800
1801 static const WCHAR domainW[] = {'c','o','m','.','u','k',0};
1802
1803 if(!pCreateUri) {
1804 win_skip("Skipping SecurityManagerEx2, IE is too old\n");
1805 return;
1806 }
1807
1808 trace("Testing SecurityManagerEx2...\n");
1809
1810 hres = pCoInternetCreateSecurityManager(NULL, &sec_mgr, 0);
1811 ok(hres == S_OK, "CoInternetCreateSecurityManager failed: %08x\n", hres);
1812
1813 hres = IInternetSecurityManager_QueryInterface(sec_mgr, &IID_IInternetSecurityManagerEx2, (void**)&sec_mgr2);
1814 ok(hres == S_OK, "QueryInterface(IID_IInternetSecurityManagerEx2) failed: %08x\n", hres);
1815
1816 zone = 0xdeadbeef;
1817
1818 hres = IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2, NULL, &zone, 0, NULL, NULL);
1819 ok(hres == E_INVALIDARG, "MapUrlToZoneEx2 returned %08x, expected E_INVALIDARG\n", hres);
1820 ok(zone == URLZONE_INVALID, "zone was %d\n", zone);
1821
1822 hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, NULL, buf, &buf_size, 0);
1823 ok(hres == E_INVALIDARG, "GetSecurityIdEx2 returned %08x, expected E_INVALIDARG\n", hres);
1824 ok(buf_size == sizeof(buf), "buf_size was %d\n", buf_size);
1825
1826 hres = pCreateUri(url5, 0, 0, &uri);
1827 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
1828
1829 hres = IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2, uri, NULL, 0, NULL, NULL);
1830 ok(hres == E_INVALIDARG, "MapToUrlZoneEx2 returned %08x, expected E_INVALIDARG\n", hres);
1831
1832 buf_size = sizeof(buf);
1833 hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, NULL, &buf_size, 0);
1834 ok(hres == E_INVALIDARG || broken(hres == S_OK), "GetSecurityIdEx2 failed: %08x\n", hres);
1835 ok(buf_size == sizeof(buf), "bug_size was %d\n", buf_size);
1836
1837 hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, buf, NULL, 0);
1838 ok(hres == E_INVALIDARG, "GetSecurityIdEx2 returned %08x, expected E_INVALIDARG\n", hres);
1839
1840 IUri_Release(uri);
1841
1842 for(i = 0; i < sizeof(sec_mgr_ex2_tests)/sizeof(sec_mgr_ex2_tests[0]); ++i) {
1843 LPWSTR uriW = a2w(sec_mgr_ex2_tests[i].uri);
1844
1845 uri = NULL;
1846 zone = URLZONE_INVALID;
1847
1848 hres = pCreateUri(uriW, sec_mgr_ex2_tests[i].create_flags, 0, &uri);
1849 ok(hres == S_OK, "CreateUri returned %08x for '%s'\n", hres, sec_mgr_ex2_tests[i].uri);
1850
1851 hres = IInternetSecurityManagerEx2_MapUrlToZoneEx2(sec_mgr2, uri, &zone, 0, NULL, NULL);
1852 todo_wine_if (sec_mgr_ex2_tests[i].map_todo) {
1853 ok(hres == sec_mgr_ex2_tests[i].map_hres, "MapUrlToZoneEx2 returned %08x, expected %08x for '%s'\n",
1854 hres, sec_mgr_ex2_tests[i].map_hres, sec_mgr_ex2_tests[i].uri);
1855 ok(zone == sec_mgr_ex2_tests[i].zone, "Expected zone %d, but got %d for '%s'\n", sec_mgr_ex2_tests[i].zone,
1856 zone, sec_mgr_ex2_tests[i].uri);
1857 }
1858
1859 buf_size = sizeof(buf);
1860 memset(buf, 0xf0, buf_size);
1861
1862 hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, buf, &buf_size, 0);
1863 todo_wine_if (sec_mgr_ex2_tests[i].secid_todo) {
1864 ok(hres == sec_mgr_ex2_tests[i].secid_hres, "GetSecurityIdEx2 returned %08x, expected %08x on test '%s'\n",
1865 hres, sec_mgr_ex2_tests[i].secid_hres, sec_mgr_ex2_tests[i].uri);
1866 if(sec_mgr_ex2_tests[i].secid) {
1867 ok(buf_size == sec_mgr_ex2_tests[i].secid_size, "Got wrong security id size=%d, expected %d on test '%s'\n",
1868 buf_size, sec_mgr_ex2_tests[i].secid_size, sec_mgr_ex2_tests[i].uri);
1869 ok(!memcmp(buf, sec_mgr_ex2_tests[i].secid, sec_mgr_ex2_tests[i].secid_size), "Got wrong security id on test '%s'\n",
1870 sec_mgr_ex2_tests[i].uri);
1871 }
1872 }
1873
1874 heap_free(uriW);
1875 IUri_Release(uri);
1876 }
1877
1878 hres = pCreateUri(url15, 0, 0, &uri);
1879 ok(hres == S_OK, "CreateUri failed: %08x\n", hres);
1880
1881 buf_size = sizeof(buf);
1882 memset(buf, 0xf0, buf_size);
1883
1884 hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, buf, &buf_size, (DWORD_PTR)domainW);
1885 ok(hres == S_OK, "GetSecurityIdEx2 failed: %08x\n", hres);
1886 todo_wine ok(buf_size == sizeof(secid13), "buf_size was %d\n", buf_size);
1887 todo_wine ok(!memcmp(buf, secid13, sizeof(secid13)), "Got wrong secid\n");
1888
1889 buf_size = sizeof(buf);
1890 memset(buf, 0xf0, buf_size);
1891
1892 hres = IInternetSecurityManagerEx2_GetSecurityIdEx2(sec_mgr2, uri, buf, &buf_size, 0);
1893 ok(hres == S_OK, "GetSecurityIdEx2 failed: %08x\n", hres);
1894 ok(buf_size == sizeof(secid13_2), "buf_size was %d\n", buf_size);
1895 ok(!memcmp(buf, secid13_2, sizeof(secid13_2)), "Got wrong secid\n");
1896
1897 IUri_Release(uri);
1898
1899 IInternetSecurityManagerEx2_Release(sec_mgr2);
1900 IInternetSecurityManager_Release(sec_mgr);
1901 }
1902
1903 static void test_CoInternetIsFeatureZoneElevationEnabled(void)
1904 {
1905 struct {
1906 const char *url_from;
1907 const char *url_to;
1908 DWORD flags;
1909 HRESULT hres;
1910 DWORD policy_flags;
1911 } testcases[] = {
1912 /* 0 */ { "http://www.winehq.org", "http://www.winehq.org", 0, S_FALSE, URLPOLICY_ALLOW },
1913 /* 1 */ { "http://www.winehq.org", "http://www.winehq.org", 0, S_OK, URLPOLICY_DISALLOW },
1914 /* 2 */ { "http://www.winehq.org", "http://www.codeweavers.com", 0, S_FALSE, URLPOLICY_ALLOW },
1915 /* 3 */ { "http://www.winehq.org", "http://www.codeweavers.com", 0, S_OK, URLPOLICY_DISALLOW },
1916 /* 4 */ { "http://www.winehq.org", "http://www.winehq.org", GET_FEATURE_FROM_PROCESS, S_FALSE, -1 },
1917 /* 5 */ { "http://www.winehq.org", "http://www.winehq.org/dir", GET_FEATURE_FROM_PROCESS, S_FALSE, -1 },
1918 /* 6 */ { "http://www.winehq.org", "http://www.codeweavers.com", GET_FEATURE_FROM_PROCESS, S_FALSE, -1 },
1919 /* 7 */ { "http://www.winehq.org", "ftp://winehq.org", GET_FEATURE_FROM_PROCESS, S_FALSE, -1 },
1920 /* 8 */ { "http://www.winehq.org", "ftp://winehq.org", GET_FEATURE_FROM_PROCESS|0x100, S_FALSE, URLPOLICY_ALLOW },
1921 /* 9 */ { "http://www.winehq.org", "ftp://winehq.org", GET_FEATURE_FROM_REGISTRY, S_FALSE, URLPOLICY_ALLOW },
1922 };
1923
1924 WCHAR *url_from, *url_to;
1925 int i;
1926 HRESULT hres;
1927
1928 if(!pCoInternetIsFeatureZoneElevationEnabled || !pCoInternetIsFeatureEnabled
1929 || !pCoInternetIsFeatureEnabledForUrl) {
1930 win_skip("Skipping CoInternetIsFeatureZoneElevationEnabled tests\n");
1931 return;
1932 }
1933
1934
1935 hres = pCoInternetIsFeatureEnabled(FEATURE_ZONE_ELEVATION, GET_FEATURE_FROM_PROCESS);
1936 ok(SUCCEEDED(hres), "CoInternetIsFeatureEnabled returned %x\n", hres);
1937
1938 trace("Testing CoInternetIsFeatureZoneElevationEnabled... (%x)\n", hres);
1939
1940 for(i=0; i<sizeof(testcases)/sizeof(testcases[0]); i++) {
1941 if(hres==S_OK && testcases[i].flags == GET_FEATURE_FROM_PROCESS)
1942 testcases[i].policy_flags = URLPOLICY_ALLOW;
1943 }
1944
1945 /* IE10 does not seem to use passed ISecurityManager */
1946 SET_EXPECT(ProcessUrlAction);
1947 pCoInternetIsFeatureZoneElevationEnabled(url1, url1, &security_manager, 0);
1948 i = called_ProcessUrlAction;
1949 SET_CALLED(ProcessUrlAction);
1950 if(!i) {
1951 skip("CoInternetIsFeatureZoneElevationEnabled does not use passed ISecurityManager\n");
1952 return;
1953 }
1954
1955 for(i=0; i<sizeof(testcases)/sizeof(testcases[0]); i++) {
1956 url_from = a2w(testcases[i].url_from);
1957 url_to = a2w(testcases[i].url_to);
1958
1959 if(testcases[i].policy_flags != -1) {
1960 ProcessUrlAction_policy = testcases[i].policy_flags;
1961 SET_EXPECT(ProcessUrlAction);
1962 }
1963 hres = pCoInternetIsFeatureZoneElevationEnabled(url_from, url_to,
1964 &security_manager, testcases[i].flags);
1965 ok(hres == testcases[i].hres, "%d) CoInternetIsFeatureZoneElevationEnabled returned %x\n", i, hres);
1966 if(testcases[i].policy_flags != -1)
1967 CHECK_CALLED(ProcessUrlAction);
1968
1969 if(testcases[i].policy_flags != -1)
1970 SET_EXPECT(ProcessUrlAction);
1971 hres = pCoInternetIsFeatureEnabledForUrl(FEATURE_ZONE_ELEVATION,
1972 testcases[i].flags, url_to, &security_manager);
1973 ok(hres == testcases[i].hres, "%d) CoInternetIsFeatureEnabledForUrl returned %x\n", i, hres);
1974 if(testcases[i].policy_flags != -1)
1975 CHECK_CALLED(ProcessUrlAction);
1976
1977 heap_free(url_from);
1978 heap_free(url_to);
1979 }
1980 }
1981
1982 START_TEST(sec_mgr)
1983 {
1984 HMODULE hurlmon;
1985 int argc;
1986 char **argv;
1987
1988 hurlmon = GetModuleHandleA("urlmon.dll");
1989 pCoInternetCreateSecurityManager = (void*) GetProcAddress(hurlmon, "CoInternetCreateSecurityManager");
1990 pCoInternetCreateZoneManager = (void*) GetProcAddress(hurlmon, "CoInternetCreateZoneManager");
1991 pCoInternetGetSecurityUrl = (void*) GetProcAddress(hurlmon, "CoInternetGetSecurityUrl");
1992 pCoInternetGetSecurityUrlEx = (void*) GetProcAddress(hurlmon, "CoInternetGetSecurityUrlEx");
1993 pCreateUri = (void*) GetProcAddress(hurlmon, "CreateUri");
1994 pCoInternetGetSession = (void*) GetProcAddress(hurlmon, "CoInternetGetSession");
1995 pCoInternetIsFeatureEnabled = (void*) GetProcAddress(hurlmon, "CoInternetIsFeatureEnabled");
1996 pCoInternetIsFeatureEnabledForUrl = (void*) GetProcAddress(hurlmon, "CoInternetIsFeatureEnabledForUrl");
1997 pCoInternetIsFeatureZoneElevationEnabled = (void*) GetProcAddress(hurlmon, "CoInternetIsFeatureZoneElevationEnabled");
1998
1999 if (!pCoInternetCreateSecurityManager || !pCoInternetCreateZoneManager ||
2000 !pCoInternetGetSecurityUrl) {
2001 win_skip("Various CoInternet* functions not present in IE 4.0\n");
2002 return;
2003 }
2004
2005 argc = winetest_get_mainargs(&argv);
2006 if(argc > 2 && !strcmp(argv[2], "domain_tests")) {
2007 test_zone_domain_mappings();
2008 return;
2009 }
2010
2011 OleInitialize(NULL);
2012 register_protocols();
2013
2014 test_InternetGetSecurityUrl();
2015
2016 if(!pCoInternetGetSecurityUrlEx || !pCreateUri)
2017 win_skip("Skipping CoInternetGetSecurityUrlEx tests, IE too old\n");
2018 else {
2019 test_InternetGetSecurityUrlEx();
2020 test_InternetGetSecurityUrlEx_Pluggable();
2021 }
2022
2023 test_SecurityManager();
2024 test_SecurityManagerEx2();
2025 test_polices();
2026 test_zone_domains();
2027 test_CoInternetCreateZoneManager();
2028 test_CreateZoneEnumerator();
2029 test_GetZoneActionPolicy();
2030 test_GetZoneAt();
2031 test_GetZoneAttributes();
2032 test_SetZoneAttributes();
2033 test_InternetSecurityMarshalling();
2034 test_CoInternetIsFeatureZoneElevationEnabled();
2035
2036 unregister_protocols();
2037 OleUninitialize();
2038 }