2 * Subject Interface Package tests
4 * Copyright 2006 Paul Vriens
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/test.h"
31 static void test_AddRemoveProvider(void)
34 SIP_ADD_NEWPROVIDER newprov;
35 GUID actionid = { 0xdeadbe, 0xefde, 0xadbe, { 0xef,0xde,0xad,0xbe,0xef,0xde,0xad,0xbe }};
36 static WCHAR dummydll[] = {'d','e','a','d','b','e','e','f','.','d','l','l',0 };
37 static WCHAR dummyfunction[] = {'d','u','m','m','y','f','u','n','c','t','i','o','n',0 };
40 SetLastError(0xdeadbeef);
41 ret = CryptSIPRemoveProvider(NULL);
42 ok (!ret, "Expected CryptSIPRemoveProvider to fail.\n");
43 ok (GetLastError() == ERROR_INVALID_PARAMETER,
44 "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
46 /* nonexistent provider should result in a registry error */
47 SetLastError(0xdeadbeef);
48 ret = CryptSIPRemoveProvider(&actionid);
49 ok (!ret, "Expected CryptSIPRemoveProvider to fail.\n");
50 ok (GetLastError() == ERROR_FILE_NOT_FOUND,
51 "Expected ERROR_FILE_NOT_FOUND, got %ld.\n", GetLastError());
53 /* Everything OK, pwszIsFunctionName and pwszIsFunctionNameFmt2 are left NULL
56 memset(&newprov, 0, sizeof(SIP_ADD_NEWPROVIDER));
57 newprov.cbStruct = sizeof(SIP_ADD_NEWPROVIDER);
58 newprov.pgSubject = &actionid;
59 newprov.pwszDLLFileName = dummydll;
60 newprov.pwszGetFuncName = dummyfunction;
61 newprov.pwszPutFuncName = dummyfunction;
62 newprov.pwszCreateFuncName = dummyfunction;
63 newprov.pwszVerifyFuncName = dummyfunction;
64 newprov.pwszRemoveFuncName = dummyfunction;
65 SetLastError(0xdeadbeef);
66 ret = CryptSIPAddProvider(&newprov);
67 ok ( ret, "CryptSIPAddProvider should have succeeded\n");
68 ok ( GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n",
71 /* Dummy provider will be deleted, but the function still fails because
72 * pwszIsFunctionName and pwszIsFunctionNameFmt2 are not present in the
75 SetLastError(0xdeadbeef);
76 ret = CryptSIPRemoveProvider(&actionid);
77 ok (!ret, "Expected CryptSIPRemoveProvider to fail.\n");
78 ok (GetLastError() == ERROR_FILE_NOT_FOUND,
79 "Expected ERROR_FILE_NOT_FOUND, got %ld.\n", GetLastError());
82 memset(&newprov, 0, sizeof(SIP_ADD_NEWPROVIDER));
83 newprov.cbStruct = sizeof(SIP_ADD_NEWPROVIDER);
84 newprov.pgSubject = &actionid;
85 newprov.pwszDLLFileName = dummydll;
86 newprov.pwszGetFuncName = dummyfunction;
87 newprov.pwszPutFuncName = dummyfunction;
88 newprov.pwszCreateFuncName = dummyfunction;
89 newprov.pwszVerifyFuncName = dummyfunction;
90 newprov.pwszRemoveFuncName = dummyfunction;
91 newprov.pwszIsFunctionNameFmt2 = dummyfunction;
92 newprov.pwszIsFunctionName = dummyfunction;
93 SetLastError(0xdeadbeef);
94 ret = CryptSIPAddProvider(&newprov);
95 ok ( ret, "CryptSIPAddProvider should have succeeded\n");
96 ok ( GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n",
99 /* Dummy provider should be deleted */
100 SetLastError(0xdeadbeef);
101 ret = CryptSIPRemoveProvider(&actionid);
102 ok ( ret, "CryptSIPRemoveProvider should have succeeded\n");
103 ok ( GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n",
107 static void test_SIPLoad(void)
111 static GUID dummySubject = { 0xdeadbeef, 0xdead, 0xbeef, { 0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef }};
112 static GUID unknown = { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
113 SIP_DISPATCH_INFO sdi;
116 SetLastError(0xdeadbeef);
117 ret = CryptSIPLoad(NULL, 0, NULL);
118 ok ( !ret, "Expected CryptSIPLoad to fail\n");
120 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
121 "Expected ERROR_INVALID_PARAMETER, got 0x%08lx\n", GetLastError());
123 /* Only pSipDispatch NULL */
124 SetLastError(0xdeadbeef);
125 ret = CryptSIPLoad(&subject, 0, NULL);
126 ok ( !ret, "Expected CryptSIPLoad to fail\n");
128 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
129 "Expected ERROR_INVALID_PARAMETER, got 0x%08lx\n", GetLastError());
131 /* No NULLs, but nonexistent pgSubject */
132 SetLastError(0xdeadbeef);
133 memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
134 sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
135 ret = CryptSIPLoad(&dummySubject, 0, &sdi);
136 ok ( !ret, "Expected CryptSIPLoad to fail\n");
138 ok ( GetLastError() == TRUST_E_SUBJECT_FORM_UNKNOWN,
139 "Expected TRUST_E_SUBJECT_FORM_UNKNOWN, got 0x%08lx\n", GetLastError());
141 /* cbSize not initialized */
142 SetLastError(0xdeadbeef);
143 memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
144 ret = CryptSIPLoad(&dummySubject, 0, &sdi);
145 ok ( !ret, "Expected CryptSIPLoad to fail\n");
147 ok ( GetLastError() == TRUST_E_SUBJECT_FORM_UNKNOWN,
148 "Expected TRUST_E_SUBJECT_FORM_UNKNOWN, got 0x%08lx\n", GetLastError());
150 /* cbSize not initialized, but valid subject (named unknown but registered by wintrust) */
151 SetLastError(0xdeadbeef);
152 memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
153 ret = CryptSIPLoad(&unknown, 0, &sdi);
156 ok ( ret, "Expected CryptSIPLoad to succeed\n");
157 ok ( GetLastError() == ERROR_PROC_NOT_FOUND,
158 "Expected ERROR_PROC_NOT_FOUND, got 0x%08lx\n", GetLastError());
162 SetLastError(0xdeadbeef);
163 memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
164 sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
165 ret = CryptSIPLoad(&unknown, 0, &sdi);
167 ok ( ret, "Expected CryptSIPLoad to succeed\n");
168 ok ( GetLastError() == 0xdeadbeef,
169 "Expected 0xdeadbeef, got 0x%08lx\n", GetLastError());
171 /* Reserved parameter not 0 */
172 SetLastError(0xdeadbeef);
173 memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
174 sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
175 ret = CryptSIPLoad(&unknown, 1, &sdi);
176 ok ( !ret, "Expected CryptSIPLoad to fail\n");
178 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
179 "Expected ERROR_INVALID_PARAMETER, got 0x%08lx\n", GetLastError());
184 test_AddRemoveProvider();