2007-10-24 17:17:36 +02:00
|
|
|
/*
|
|
|
|
* Credentials User Interface Tests
|
|
|
|
*
|
|
|
|
* Copyright 2007 Robert Shearman for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wincred.h"
|
2015-08-14 15:00:23 +02:00
|
|
|
#include "sspi.h"
|
2007-10-24 17:17:36 +02:00
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2015-08-14 15:00:23 +02:00
|
|
|
static SECURITY_STATUS (SEC_ENTRY *pSspiEncodeAuthIdentityAsStrings)
|
|
|
|
(PSEC_WINNT_AUTH_IDENTITY_OPAQUE,PCWSTR*,PCWSTR*,PCWSTR*);
|
|
|
|
static void (SEC_ENTRY *pSspiFreeAuthIdentity)
|
|
|
|
(PSEC_WINNT_AUTH_IDENTITY_OPAQUE);
|
|
|
|
static ULONG (SEC_ENTRY *pSspiPromptForCredentialsW)
|
|
|
|
(PCWSTR,void*,ULONG,PCWSTR,PSEC_WINNT_AUTH_IDENTITY_OPAQUE,PSEC_WINNT_AUTH_IDENTITY_OPAQUE*,int*,ULONG);
|
|
|
|
|
2007-10-24 17:17:36 +02:00
|
|
|
static void test_CredUIPromptForCredentials(void)
|
|
|
|
{
|
2020-10-08 23:27:59 +02:00
|
|
|
static const WCHAR wszServerName[] = L"WineTest";
|
2007-10-24 17:17:36 +02:00
|
|
|
DWORD ret;
|
|
|
|
WCHAR username[256];
|
|
|
|
WCHAR password[256];
|
|
|
|
CREDUI_INFOW credui_info;
|
|
|
|
BOOL save = FALSE;
|
|
|
|
|
|
|
|
credui_info.cbSize = sizeof(credui_info);
|
|
|
|
credui_info.hwndParent = NULL;
|
|
|
|
credui_info.pszMessageText = NULL;
|
|
|
|
credui_info.hbmBanner = NULL;
|
|
|
|
|
|
|
|
ret = CredUIConfirmCredentialsW(NULL, TRUE);
|
2007-11-27 13:32:39 +01:00
|
|
|
ok(ret == ERROR_INVALID_PARAMETER /* 2003 + */ || ret == ERROR_NOT_FOUND /* XP */,
|
|
|
|
"CredUIConfirmCredentials should have returned ERROR_INVALID_PARAMETER or ERROR_NOT_FOUND instead of %d\n", ret);
|
2007-10-24 17:17:36 +02:00
|
|
|
|
|
|
|
ret = CredUIConfirmCredentialsW(wszServerName, TRUE);
|
|
|
|
ok(ret == ERROR_NOT_FOUND, "CredUIConfirmCredentials should have returned ERROR_NOT_FOUND instead of %d\n", ret);
|
|
|
|
|
|
|
|
username[0] = '\0';
|
|
|
|
password[0] = '\0';
|
|
|
|
ret = CredUIPromptForCredentialsW(NULL, NULL, NULL, 0, username,
|
2018-06-06 00:38:26 +02:00
|
|
|
ARRAY_SIZE(username),
|
|
|
|
password, ARRAY_SIZE(password),
|
2007-10-24 17:17:36 +02:00
|
|
|
NULL, CREDUI_FLAGS_ALWAYS_SHOW_UI);
|
|
|
|
ok(ret == ERROR_INVALID_FLAGS, "CredUIPromptForCredentials should have returned ERROR_INVALID_FLAGS instead of %d\n", ret);
|
|
|
|
|
|
|
|
ret = CredUIPromptForCredentialsW(NULL, NULL, NULL, 0, username,
|
2018-06-06 00:38:26 +02:00
|
|
|
ARRAY_SIZE(username),
|
|
|
|
password, ARRAY_SIZE(password),
|
2007-10-24 17:17:36 +02:00
|
|
|
NULL, CREDUI_FLAGS_ALWAYS_SHOW_UI | CREDUI_FLAGS_GENERIC_CREDENTIALS);
|
|
|
|
ok(ret == ERROR_INVALID_PARAMETER, "CredUIPromptForCredentials should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
|
|
|
|
|
|
|
|
ret = CredUIPromptForCredentialsW(NULL, wszServerName, NULL, 0, username,
|
2018-06-06 00:38:26 +02:00
|
|
|
ARRAY_SIZE(username),
|
|
|
|
password, ARRAY_SIZE(password),
|
2007-10-24 17:17:36 +02:00
|
|
|
NULL, CREDUI_FLAGS_SHOW_SAVE_CHECK_BOX);
|
2015-11-17 05:21:40 +01:00
|
|
|
ok(ret == ERROR_INVALID_PARAMETER, "CredUIPromptForCredentials should have returned ERROR_INVALID_PARAMETER instead of %d\n", ret);
|
2007-10-24 17:17:36 +02:00
|
|
|
|
|
|
|
if (winetest_interactive)
|
|
|
|
{
|
|
|
|
ret = CredUIPromptForCredentialsW(NULL, wszServerName, NULL, 0, username,
|
2018-06-06 00:38:26 +02:00
|
|
|
ARRAY_SIZE(username),
|
|
|
|
password, ARRAY_SIZE(password),
|
2007-10-24 17:17:36 +02:00
|
|
|
&save, CREDUI_FLAGS_EXPECT_CONFIRMATION);
|
|
|
|
ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
|
|
|
|
if (ret == ERROR_SUCCESS)
|
2011-02-05 01:05:09 +01:00
|
|
|
{
|
2007-10-24 17:17:36 +02:00
|
|
|
ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
|
2011-02-05 01:05:09 +01:00
|
|
|
ok(ret == ERROR_SUCCESS, "CredUIConfirmCredentials failed with error %d\n", ret);
|
|
|
|
}
|
2007-10-24 17:17:36 +02:00
|
|
|
|
2020-10-08 23:27:59 +02:00
|
|
|
credui_info.pszCaptionText = L"CREDUI_FLAGS_EXPECT_CONFIRMATION";
|
2018-06-06 00:38:26 +02:00
|
|
|
ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, ERROR_ACCESS_DENIED,
|
|
|
|
username, ARRAY_SIZE(username),
|
|
|
|
password, ARRAY_SIZE(password),
|
2007-10-24 17:17:36 +02:00
|
|
|
&save, CREDUI_FLAGS_EXPECT_CONFIRMATION);
|
|
|
|
ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
|
|
|
|
if (ret == ERROR_SUCCESS)
|
2011-02-05 01:05:09 +01:00
|
|
|
{
|
2007-10-24 17:17:36 +02:00
|
|
|
ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
|
2011-02-05 01:05:09 +01:00
|
|
|
ok(ret == ERROR_SUCCESS, "CredUIConfirmCredentials failed with error %d\n", ret);
|
|
|
|
}
|
2007-10-24 17:17:36 +02:00
|
|
|
|
2020-10-08 23:27:59 +02:00
|
|
|
credui_info.pszCaptionText = L"CREDUI_FLAGS_INCORRECT_PASSWORD|CREDUI_FLAGS_EXPECT_CONFIRMATION";
|
2007-10-24 17:17:36 +02:00
|
|
|
ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, 0,
|
2018-06-06 00:38:26 +02:00
|
|
|
username, ARRAY_SIZE(username),
|
|
|
|
password, ARRAY_SIZE(password),
|
2007-10-24 17:17:36 +02:00
|
|
|
NULL, CREDUI_FLAGS_INCORRECT_PASSWORD|CREDUI_FLAGS_EXPECT_CONFIRMATION);
|
|
|
|
ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
|
|
|
|
if (ret == ERROR_SUCCESS)
|
2011-02-05 01:05:09 +01:00
|
|
|
{
|
2007-10-24 17:17:36 +02:00
|
|
|
ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
|
2011-02-05 01:05:09 +01:00
|
|
|
ok(ret == ERROR_SUCCESS, "CredUIConfirmCredentials failed with error %d\n", ret);
|
|
|
|
}
|
|
|
|
|
2007-10-24 17:17:36 +02:00
|
|
|
|
|
|
|
save = TRUE;
|
2020-10-08 23:27:59 +02:00
|
|
|
credui_info.pszCaptionText = L"CREDUI_FLAGS_DO_NOT_PERSIST|CREDUI_FLAGS_EXPECT_CONFIRMATION";
|
2007-10-24 17:17:36 +02:00
|
|
|
ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, 0,
|
2018-06-06 00:38:26 +02:00
|
|
|
username, ARRAY_SIZE(username),
|
|
|
|
password, ARRAY_SIZE(password),
|
2007-10-24 17:17:36 +02:00
|
|
|
&save, CREDUI_FLAGS_DO_NOT_PERSIST|CREDUI_FLAGS_EXPECT_CONFIRMATION);
|
|
|
|
ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
|
|
|
|
ok(save, "save flag should have been untouched\n");
|
|
|
|
|
|
|
|
save = FALSE;
|
2020-10-08 23:27:59 +02:00
|
|
|
credui_info.pszCaptionText = L"CREDUI_FLAGS_PERSIST|CREDUI_FLAGS_EXPECT_CONFIRMATION";
|
2007-10-24 17:17:36 +02:00
|
|
|
ret = CredUIPromptForCredentialsW(&credui_info, wszServerName, NULL, 0,
|
2018-06-06 00:38:26 +02:00
|
|
|
username, ARRAY_SIZE(username),
|
|
|
|
password, ARRAY_SIZE(password),
|
2007-10-24 17:17:36 +02:00
|
|
|
&save, CREDUI_FLAGS_PERSIST|CREDUI_FLAGS_EXPECT_CONFIRMATION);
|
|
|
|
ok(ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "CredUIPromptForCredentials failed with error %d\n", ret);
|
|
|
|
ok(!save, "save flag should have been untouched\n");
|
|
|
|
if (ret == ERROR_SUCCESS)
|
2011-02-05 01:05:09 +01:00
|
|
|
{
|
2007-10-24 17:17:36 +02:00
|
|
|
ret = CredUIConfirmCredentialsW(wszServerName, FALSE);
|
2011-02-05 01:05:09 +01:00
|
|
|
ok(ret == ERROR_SUCCESS, "CredUIConfirmCredentials failed with error %d\n", ret);
|
|
|
|
}
|
|
|
|
|
2007-10-24 17:17:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-14 15:00:23 +02:00
|
|
|
static void test_SspiPromptForCredentials(void)
|
|
|
|
{
|
|
|
|
ULONG ret;
|
|
|
|
SECURITY_STATUS status;
|
|
|
|
CREDUI_INFOW info;
|
|
|
|
PSEC_WINNT_AUTH_IDENTITY_OPAQUE id;
|
|
|
|
const WCHAR *username, *domain, *creds;
|
|
|
|
int save;
|
|
|
|
|
|
|
|
if (!pSspiPromptForCredentialsW || !pSspiFreeAuthIdentity)
|
|
|
|
{
|
|
|
|
win_skip( "SspiPromptForCredentialsW is missing\n" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
info.cbSize = sizeof(info);
|
|
|
|
info.hwndParent = NULL;
|
2020-10-08 23:27:59 +02:00
|
|
|
info.pszMessageText = L"SspiTest";
|
|
|
|
info.pszCaptionText = L"basic";
|
2015-08-14 15:00:23 +02:00
|
|
|
info.hbmBanner = NULL;
|
2020-10-08 23:27:59 +02:00
|
|
|
ret = pSspiPromptForCredentialsW( NULL, &info, 0, L"basic", NULL, &id, &save, 0 );
|
2015-08-14 15:00:23 +02:00
|
|
|
ok( ret == ERROR_INVALID_PARAMETER, "got %u\n", ret );
|
|
|
|
|
2020-10-08 23:27:59 +02:00
|
|
|
ret = pSspiPromptForCredentialsW( L"SspiTest", &info, 0, NULL, NULL, &id, &save, 0 );
|
2015-08-14 15:00:23 +02:00
|
|
|
ok( ret == ERROR_NO_SUCH_PACKAGE, "got %u\n", ret );
|
|
|
|
|
|
|
|
if (winetest_interactive)
|
|
|
|
{
|
|
|
|
id = NULL;
|
|
|
|
save = -1;
|
2020-10-08 23:27:59 +02:00
|
|
|
ret = pSspiPromptForCredentialsW( L"SspiTest", &info, 0, L"basic", NULL, &id, &save, 0 );
|
2015-08-14 15:00:23 +02:00
|
|
|
ok( ret == ERROR_SUCCESS || ret == ERROR_CANCELLED, "got %u\n", ret );
|
|
|
|
if (ret == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ok( id != NULL, "id not set\n" );
|
|
|
|
ok( save == TRUE || save == FALSE, "got %d\n", save );
|
|
|
|
|
|
|
|
username = creds = NULL;
|
|
|
|
domain = (const WCHAR *)0xdeadbeef;
|
|
|
|
status = pSspiEncodeAuthIdentityAsStrings( id, &username, &domain, &creds );
|
|
|
|
ok( status == SEC_E_OK, "got %u\n", status );
|
|
|
|
ok( username != NULL, "username not set\n" );
|
|
|
|
ok( domain == NULL, "domain not set\n" );
|
|
|
|
ok( creds != NULL, "creds not set\n" );
|
|
|
|
pSspiFreeAuthIdentity( id );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-24 17:17:36 +02:00
|
|
|
START_TEST(credui)
|
|
|
|
{
|
2015-08-14 15:00:23 +02:00
|
|
|
HMODULE hcredui = GetModuleHandleA( "credui.dll" ), hsecur32 = LoadLibraryA( "secur32.dll" );
|
|
|
|
|
|
|
|
if (hcredui)
|
|
|
|
pSspiPromptForCredentialsW = (void *)GetProcAddress( hcredui, "SspiPromptForCredentialsW" );
|
|
|
|
if (hsecur32)
|
|
|
|
{
|
|
|
|
pSspiEncodeAuthIdentityAsStrings = (void *)GetProcAddress( hsecur32, "SspiEncodeAuthIdentityAsStrings" );
|
|
|
|
pSspiFreeAuthIdentity = (void *)GetProcAddress( hsecur32, "SspiFreeAuthIdentity" );
|
|
|
|
}
|
|
|
|
|
2007-10-24 17:17:36 +02:00
|
|
|
test_CredUIPromptForCredentials();
|
2015-08-14 15:00:23 +02:00
|
|
|
test_SspiPromptForCredentials();
|
|
|
|
|
|
|
|
FreeLibrary( hsecur32 );
|
2007-10-24 17:17:36 +02:00
|
|
|
}
|