Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: goopdate/cred_dialog_unittest.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « goopdate/cred_dialog.cc ('k') | goopdate/current_state.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2009 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 // ========================================================================
15
16 #include "omaha/base/constants.h"
17 #include "omaha/base/omaha_version.h"
18 #include "omaha/base/scoped_impersonation.h"
19 #include "omaha/goopdate/cred_dialog.h"
20 #include "omaha/testing/unit_test.h"
21
22 namespace omaha {
23
24 class CredentialDialogTest : public testing::Test {
25 protected:
26 explicit CredentialDialogTest(bool is_machine)
27 : is_machine_(is_machine) {}
28
29 virtual void SetUp() {
30 }
31
32 virtual void TearDown() {
33 }
34
35 virtual bool ShouldRunTest() {
36 if (IsEnvironmentVariableSet(_T("OMAHA_TEST_UI"))) {
37 return true;
38 } else {
39 std::wcout << _T("\tThis test did not run because 'OMAHA_TEST_UI' is ")
40 _T("not set in the environment.") << std::endl;
41 return false;
42 }
43 }
44
45 virtual void TestComObject(LPCTSTR server, LPCTSTR caption) {
46 REFCLSID clsid = is_machine_ ? __uuidof(CredentialDialogMachineClass)
47 : __uuidof(CredentialDialogUserClass);
48 CComPtr<ICredentialDialog> dialog;
49 EXPECT_SUCCEEDED(dialog.CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER));
50 if (dialog) {
51 CComBSTR server_bs(server);
52 CComBSTR caption_bs(caption);
53 CComBSTR user;
54 CComBSTR pass;
55 EXPECT_SUCCEEDED(dialog->QueryUserForCredentials(0,
56 server_bs,
57 caption_bs,
58 &user,
59 &pass));
60 }
61 }
62
63 virtual void TestAuto(LPCTSTR server, LPCTSTR caption) {
64 CString user;
65 CString pass;
66 EXPECT_SUCCEEDED(LaunchCredentialDialog(is_machine_,
67 NULL,
68 CString(server),
69 CString(caption),
70 &user,
71 &pass));
72 }
73
74 // TestAutoImpersonating() assumes that omaha_unittest.exe is being executed
75 // as LocalSystem; it will fail otherwise.
76 virtual void TestAutoImpersonating(LPCTSTR server, LPCTSTR caption) {
77 EXPECT_SUCCEEDED(InitializeClientSecurity());
78
79 // Manually load the COM proxy into the process before we start; it will
80 // assert on DLL load if we load it while impersonating. (PSMachine should
81 // always be loaded already in a production environment; this is just an
82 // artifact of the unit test environment.)
83 CPath proxy_path(goopdate_utils::BuildInstallDirectory(
84 is_machine_, omaha::GetVersionString()));
85 EXPECT_TRUE(proxy_path.Append(kPSFileNameMachine));
86 scoped_library psmachine_load(::LoadLibrary(proxy_path));
87 EXPECT_TRUE(!!psmachine_load);
88
89 scoped_handle logged_on_user_token(
90 goopdate_utils::GetImpersonationTokenForMachineProcess(is_machine_));
91 EXPECT_TRUE(valid(logged_on_user_token));
92 if (valid(logged_on_user_token)) {
93 scoped_impersonation impersonate_user(get(logged_on_user_token));
94 HRESULT hr = HRESULT_FROM_WIN32(impersonate_user.result());
95 EXPECT_SUCCEEDED(hr);
96 if (SUCCEEDED(hr)) {
97 TestAuto(server, caption);
98 }
99 }
100 }
101
102 const bool is_machine_;
103
104 private:
105 DISALLOW_IMPLICIT_CONSTRUCTORS(CredentialDialogTest);
106 };
107
108 class CredentialDialogMachineTest : public CredentialDialogTest {
109 protected:
110 CredentialDialogMachineTest() : CredentialDialogTest(true) {}
111 };
112
113 class CredentialDialogUserTest : public CredentialDialogTest {
114 protected:
115 CredentialDialogUserTest() : CredentialDialogTest(false) {}
116 };
117
118 TEST_F(CredentialDialogUserTest, COM) {
119 if (ShouldRunTest()) {
120 TestComObject(_T("test-u-com-server"), _T("test-u-com-caption"));
121 }
122 }
123
124 TEST_F(CredentialDialogUserTest, Auto) {
125 if (ShouldRunTest()) {
126 TestAuto(_T("test-u-auto-server"), _T("test-u-auto-caption"));
127 }
128 }
129
130 TEST_F(CredentialDialogMachineTest, COM) {
131 if (ShouldRunTest()) {
132 TestComObject(_T("test-m-com-server"), _T("test-m-com-caption"));
133 }
134 }
135
136 TEST_F(CredentialDialogMachineTest, Auto) {
137 if (ShouldRunTest()) {
138 TestAuto(_T("test-m-auto-server"), _T("test-m-auto-caption"));
139 }
140 }
141
142 TEST_F(CredentialDialogMachineTest, Impersonating) {
143 bool is_system = false;
144 EXPECT_SUCCEEDED(IsSystemProcess(&is_system));
145 if (!is_system) {
146 std::wcout << _T("\tThis test is only meaningful when the unit test is ")
147 _T("run as the SYSTEM account.") << std::endl;
148 } else {
149 TestAutoImpersonating(_T("test-m-imp-server"), _T("test-m-imp-caption"));
150 }
151 }
152
153 } // end namespace omaha
154
OLDNEW
« no previous file with comments | « goopdate/cred_dialog.cc ('k') | goopdate/current_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698