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