2 * Credentials User Interface Tests
4 * Copyright 2007 Robert Shearman for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/test.h"
30 static SECURITY_STATUS (SEC_ENTRY
*pSspiEncodeAuthIdentityAsStrings
)
31 (PSEC_WINNT_AUTH_IDENTITY_OPAQUE
,PCWSTR
*,PCWSTR
*,PCWSTR
*);
32 static void (SEC_ENTRY
*pSspiFreeAuthIdentity
)
33 (PSEC_WINNT_AUTH_IDENTITY_OPAQUE
);
34 static ULONG (SEC_ENTRY
*pSspiPromptForCredentialsW
)
35 (PCWSTR
,void*,ULONG
,PCWSTR
,PSEC_WINNT_AUTH_IDENTITY_OPAQUE
,PSEC_WINNT_AUTH_IDENTITY_OPAQUE
*,int*,ULONG
);
37 static void test_CredUIPromptForCredentials(void)
39 static const WCHAR wszServerName
[] = {'W','i','n','e','T','e','s','t',0};
43 CREDUI_INFOW credui_info
;
46 credui_info
.cbSize
= sizeof(credui_info
);
47 credui_info
.hwndParent
= NULL
;
48 credui_info
.pszMessageText
= NULL
;
49 credui_info
.hbmBanner
= NULL
;
51 ret
= CredUIConfirmCredentialsW(NULL
, TRUE
);
52 ok(ret
== ERROR_INVALID_PARAMETER
/* 2003 + */ || ret
== ERROR_NOT_FOUND
/* XP */,
53 "CredUIConfirmCredentials should have returned ERROR_INVALID_PARAMETER or ERROR_NOT_FOUND instead of %d\n", ret
);
55 ret
= CredUIConfirmCredentialsW(wszServerName
, TRUE
);
56 ok(ret
== ERROR_NOT_FOUND
, "CredUIConfirmCredentials should have returned ERROR_NOT_FOUND instead of %d\n", ret
);
60 ret
= CredUIPromptForCredentialsW(NULL
, NULL
, NULL
, 0, username
,
61 sizeof(username
)/sizeof(username
[0]),
62 password
, sizeof(password
)/sizeof(password
[0]),
63 NULL
, CREDUI_FLAGS_ALWAYS_SHOW_UI
);
64 ok(ret
== ERROR_INVALID_FLAGS
, "CredUIPromptForCredentials should have returned ERROR_INVALID_FLAGS instead of %d\n", ret
);
66 ret
= CredUIPromptForCredentialsW(NULL
, NULL
, NULL
, 0, username
,
67 sizeof(username
)/sizeof(username
[0]),
68 password
, sizeof(password
)/sizeof(password
[0]),
69 NULL
, CREDUI_FLAGS_ALWAYS_SHOW_UI
| CREDUI_FLAGS_GENERIC_CREDENTIALS
);
70 ok(ret
== ERROR_INVALID_PARAMETER
, "CredUIPromptForCredentials should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
72 ret
= CredUIPromptForCredentialsW(NULL
, wszServerName
, NULL
, 0, username
,
73 sizeof(username
)/sizeof(username
[0]),
74 password
, sizeof(password
)/sizeof(password
[0]),
75 NULL
, CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX
);
76 ok(ret
== ERROR_INVALID_PARAMETER
, "CredUIPromptForCredentials should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret
);
78 if (winetest_interactive
)
80 static const WCHAR wszCaption1
[] = {'C','R','E','D','U','I','_','F','L','A','G','S','_','E','X','P','E','C','T','_','C','O','N','F','I','R','M','A','T','I','O','N',0};
81 static const WCHAR wszCaption2
[] = {'C','R','E','D','U','I','_','F','L','A','G','S','_','I','N','C','O','R','R','E','C','T','_','P','A','S','S','W','O','R','D','|',
82 'C','R','E','D','U','I','_','F','L','A','G','S','_','E','X','P','E','C','T','_','C','O','N','F','I','R','M','A','T','I','O','N',0};
83 static const WCHAR wszCaption3
[] = {'C','R','E','D','U','I','_','F','L','A','G','S','_','D','O','_','N','O','T','_','P','E','R','S','I','S','T','|',
84 'C','R','E','D','U','I','_','F','L','A','G','S','_','E','X','P','E','C','T','_','C','O','N','F','I','R','M','A','T','I','O','N',0};
85 static const WCHAR wszCaption4
[] = {'C','R','E','D','U','I','_','F','L','A','G','S','_','P','E','R','S','I','S','T','|',
86 'C','R','E','D','U','I','_','F','L','A','G','S','_','E','X','P','E','C','T','_','C','O','N','F','I','R','M','A','T','I','O','N',0};
88 ret
= CredUIPromptForCredentialsW(NULL
, wszServerName
, NULL
, 0, username
,
89 sizeof(username
)/sizeof(username
[0]),
90 password
, sizeof(password
)/sizeof(password
[0]),
91 &save
, CREDUI_FLAGS_EXPECT_CONFIRMATION
);
92 ok(ret
== ERROR_SUCCESS
|| ret
== ERROR_CANCELLED
, "CredUIPromptForCredentials failed with error %d\n", ret
);
93 if (ret
== ERROR_SUCCESS
)
95 ret
= CredUIConfirmCredentialsW(wszServerName
, FALSE
);
96 ok(ret
== ERROR_SUCCESS
, "CredUIConfirmCredentials failed with error %d\n", ret
);
99 credui_info
.pszCaptionText
= wszCaption1
;
100 ret
= CredUIPromptForCredentialsW(&credui_info
, wszServerName
, NULL
,
102 username
, sizeof(username
)/sizeof(username
[0]),
103 password
, sizeof(password
)/sizeof(password
[0]),
104 &save
, CREDUI_FLAGS_EXPECT_CONFIRMATION
);
105 ok(ret
== ERROR_SUCCESS
|| ret
== ERROR_CANCELLED
, "CredUIPromptForCredentials failed with error %d\n", ret
);
106 if (ret
== ERROR_SUCCESS
)
108 ret
= CredUIConfirmCredentialsW(wszServerName
, FALSE
);
109 ok(ret
== ERROR_SUCCESS
, "CredUIConfirmCredentials failed with error %d\n", ret
);
112 credui_info
.pszCaptionText
= wszCaption2
;
113 ret
= CredUIPromptForCredentialsW(&credui_info
, wszServerName
, NULL
, 0,
114 username
, sizeof(username
)/sizeof(username
[0]),
115 password
, sizeof(password
)/sizeof(password
[0]),
116 NULL
, CREDUI_FLAGS_INCORRECT_PASSWORD
|CREDUI_FLAGS_EXPECT_CONFIRMATION
);
117 ok(ret
== ERROR_SUCCESS
|| ret
== ERROR_CANCELLED
, "CredUIPromptForCredentials failed with error %d\n", ret
);
118 if (ret
== ERROR_SUCCESS
)
120 ret
= CredUIConfirmCredentialsW(wszServerName
, FALSE
);
121 ok(ret
== ERROR_SUCCESS
, "CredUIConfirmCredentials failed with error %d\n", ret
);
126 credui_info
.pszCaptionText
= wszCaption3
;
127 ret
= CredUIPromptForCredentialsW(&credui_info
, wszServerName
, NULL
, 0,
128 username
, sizeof(username
)/sizeof(username
[0]),
129 password
, sizeof(password
)/sizeof(password
[0]),
130 &save
, CREDUI_FLAGS_DO_NOT_PERSIST
|CREDUI_FLAGS_EXPECT_CONFIRMATION
);
131 ok(ret
== ERROR_SUCCESS
|| ret
== ERROR_CANCELLED
, "CredUIPromptForCredentials failed with error %d\n", ret
);
132 ok(save
, "save flag should have been untouched\n");
135 credui_info
.pszCaptionText
= wszCaption4
;
136 ret
= CredUIPromptForCredentialsW(&credui_info
, wszServerName
, NULL
, 0,
137 username
, sizeof(username
)/sizeof(username
[0]),
138 password
, sizeof(password
)/sizeof(password
[0]),
139 &save
, CREDUI_FLAGS_PERSIST
|CREDUI_FLAGS_EXPECT_CONFIRMATION
);
140 ok(ret
== ERROR_SUCCESS
|| ret
== ERROR_CANCELLED
, "CredUIPromptForCredentials failed with error %d\n", ret
);
141 ok(!save
, "save flag should have been untouched\n");
142 if (ret
== ERROR_SUCCESS
)
144 ret
= CredUIConfirmCredentialsW(wszServerName
, FALSE
);
145 ok(ret
== ERROR_SUCCESS
, "CredUIConfirmCredentials failed with error %d\n", ret
);
151 static void test_SspiPromptForCredentials(void)
153 static const WCHAR targetW
[] = {'S','s','p','i','T','e','s','t',0};
154 static const WCHAR basicW
[] = {'b','a','s','i','c',0};
156 SECURITY_STATUS status
;
158 PSEC_WINNT_AUTH_IDENTITY_OPAQUE id
;
159 const WCHAR
*username
, *domain
, *creds
;
162 if (!pSspiPromptForCredentialsW
|| !pSspiFreeAuthIdentity
)
164 win_skip( "SspiPromptForCredentialsW is missing\n" );
168 info
.cbSize
= sizeof(info
);
169 info
.hwndParent
= NULL
;
170 info
.pszMessageText
= targetW
;
171 info
.pszCaptionText
= basicW
;
172 info
.hbmBanner
= NULL
;
173 ret
= pSspiPromptForCredentialsW( NULL
, &info
, 0, basicW
, NULL
, &id
, &save
, 0 );
174 ok( ret
== ERROR_INVALID_PARAMETER
, "got %u\n", ret
);
176 ret
= pSspiPromptForCredentialsW( targetW
, &info
, 0, NULL
, NULL
, &id
, &save
, 0 );
177 ok( ret
== ERROR_NO_SUCH_PACKAGE
, "got %u\n", ret
);
179 if (winetest_interactive
)
183 ret
= pSspiPromptForCredentialsW( targetW
, &info
, 0, basicW
, NULL
, &id
, &save
, 0 );
184 ok( ret
== ERROR_SUCCESS
|| ret
== ERROR_CANCELLED
, "got %u\n", ret
);
185 if (ret
== ERROR_SUCCESS
)
187 ok( id
!= NULL
, "id not set\n" );
188 ok( save
== TRUE
|| save
== FALSE
, "got %d\n", save
);
190 username
= creds
= NULL
;
191 domain
= (const WCHAR
*)0xdeadbeef;
192 status
= pSspiEncodeAuthIdentityAsStrings( id
, &username
, &domain
, &creds
);
193 ok( status
== SEC_E_OK
, "got %u\n", status
);
194 ok( username
!= NULL
, "username not set\n" );
195 ok( domain
== NULL
, "domain not set\n" );
196 ok( creds
!= NULL
, "creds not set\n" );
197 pSspiFreeAuthIdentity( id
);
204 HMODULE hcredui
= GetModuleHandleA( "credui.dll" ), hsecur32
= LoadLibraryA( "secur32.dll" );
207 pSspiPromptForCredentialsW
= (void *)GetProcAddress( hcredui
, "SspiPromptForCredentialsW" );
210 pSspiEncodeAuthIdentityAsStrings
= (void *)GetProcAddress( hsecur32
, "SspiEncodeAuthIdentityAsStrings" );
211 pSspiFreeAuthIdentity
= (void *)GetProcAddress( hsecur32
, "SspiFreeAuthIdentity" );
214 test_CredUIPromptForCredentials();
215 test_SspiPromptForCredentials();
217 FreeLibrary( hsecur32
);