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