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

Side by Side Diff: chrome/browser/chromeos/login/enterprise_enrollment_browsertest.cc

Issue 2716383002: Add Active Directory enterprise enrollment/domain join tests (Closed)
Patch Set: Created 3 years, 9 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 | « chrome/browser/chromeos/login/enrollment/enrollment_screen.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/macros.h" 5 #include "base/macros.h"
6 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h" 6 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h"
7 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper. h" 7 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper. h"
8 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_ impl.h" 8 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_ impl.h"
9 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_ mock.h" 9 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_ mock.h"
10 #include "chrome/browser/chromeos/login/login_manager_test.h" 10 #include "chrome/browser/chromeos/login/login_manager_test.h"
11 #include "chrome/browser/chromeos/login/startup_utils.h" 11 #include "chrome/browser/chromeos/login/startup_utils.h"
12 #include "chrome/browser/chromeos/login/test/js_checker.h" 12 #include "chrome/browser/chromeos/login/test/js_checker.h"
13 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h" 13 #include "chrome/browser/chromeos/login/test/oobe_screen_waiter.h"
14 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 14 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
15 #include "chrome/browser/chromeos/login/wizard_controller.h" 15 #include "chrome/browser/chromeos/login/wizard_controller.h"
16 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" 16 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h"
17 #include "chromeos/dbus/dbus_thread_manager.h"
18 #include "chromeos/dbus/upstart_client.h"
17 #include "content/public/test/test_utils.h" 19 #include "content/public/test/test_utils.h"
18 20
19 using testing::_; 21 using testing::_;
20 using testing::Invoke; 22 using testing::Invoke;
21 using testing::InvokeWithoutArgs; 23 using testing::InvokeWithoutArgs;
22 24
23 namespace chromeos { 25 namespace chromeos {
24 26
27 namespace {
28
29 const char ad_machine_name_input[] =
achuithb 2017/02/27 16:03:47 Shouldn't this be kAdMachineNameInput? Same for re
Roman Sorokin (ftl) 2017/02/27 16:20:48 yeah, my bad.
30 "document.querySelector('#oauth-enroll-ad-join-ui /deep/ "
31 "#machineNameInput')";
32 const char ad_username_input[] =
33 "document.querySelector('#oauth-enroll-ad-join-ui /deep/ #userInput')";
34 const char ad_password_input[] =
35 "document.querySelector('#oauth-enroll-ad-join-ui /deep/ #passwordInput')";
36 const char ad_test_realm[] = "ad_test_realm.com";
37 const char ad_test_user[] = "ad_test_user@ad_test_realm.com";
38
39 } // namespace
40
25 class EnterpriseEnrollmentTest : public LoginManagerTest { 41 class EnterpriseEnrollmentTest : public LoginManagerTest {
26 public: 42 public:
27 EnterpriseEnrollmentTest() 43 EnterpriseEnrollmentTest()
28 : LoginManagerTest(true /*should_launch_browser*/) { 44 : LoginManagerTest(true /*should_launch_browser*/) {
29 enrollment_setup_functions_.clear(); 45 enrollment_setup_functions_.clear();
30 46
31 EnterpriseEnrollmentHelper::SetupEnrollmentHelperMock([]( 47 EnterpriseEnrollmentHelper::SetupEnrollmentHelperMock([](
32 EnterpriseEnrollmentHelper::EnrollmentStatusConsumer* status_consumer, 48 EnterpriseEnrollmentHelper::EnrollmentStatusConsumer* status_consumer,
33 const policy::EnrollmentConfig& enrollment_config, 49 const policy::EnrollmentConfig& enrollment_config,
34 const std::string& enrolling_user_domain) { 50 const std::string& enrolling_user_domain) {
35 51
36 auto* mock = new EnterpriseEnrollmentHelperMock(status_consumer); 52 auto* mock = new EnterpriseEnrollmentHelperMock(status_consumer);
37 for (OnSetupEnrollmentHelper fn : enrollment_setup_functions_) 53 for (OnSetupEnrollmentHelper fn : enrollment_setup_functions_)
38 fn(mock); 54 fn(mock);
39 return (EnterpriseEnrollmentHelper*)mock; 55 return (EnterpriseEnrollmentHelper*)mock;
40 }); 56 });
41 } 57 }
42 58
43 using OnSetupEnrollmentHelper = 59 using OnSetupEnrollmentHelper =
44 void (*)(EnterpriseEnrollmentHelperMock* mock); 60 std::function<void(EnterpriseEnrollmentHelperMock*)>;
45 61
46 // The given function will be executed when the next enrollment helper is 62 // The given function will be executed when the next enrollment helper is
47 // created. 63 // created.
48 void AddEnrollmentSetupFunction(OnSetupEnrollmentHelper on_setup) { 64 void AddEnrollmentSetupFunction(OnSetupEnrollmentHelper on_setup) {
49 enrollment_setup_functions_.push_back(on_setup); 65 enrollment_setup_functions_.push_back(on_setup);
50 } 66 }
51 67
52 // Set up expectations for enrollment credentials. 68 // Set up expectations for enrollment credentials.
53 void ExpectEnrollmentCredentials() { 69 void ExpectEnrollmentCredentials() {
54 AddEnrollmentSetupFunction([]( 70 AddEnrollmentSetupFunction([](
(...skipping 13 matching lines...) Expand all
68 "$('oauth-enrollment').authenticator_.dispatchEvent(" 84 "$('oauth-enrollment').authenticator_.dispatchEvent("
69 "new CustomEvent('authCompleted'," 85 "new CustomEvent('authCompleted',"
70 "{" 86 "{"
71 "detail: {" 87 "detail: {"
72 "email: 'testuser@test.com'," 88 "email: 'testuser@test.com',"
73 "authCode: 'test_auth_code'" 89 "authCode: 'test_auth_code'"
74 "}" 90 "}"
75 "}));"); 91 "}));");
76 } 92 }
77 93
94 void SubmitActiveDirectoryCredentials(const std::string& machine_name,
achuithb 2017/02/27 16:03:47 Function comment.
Roman Sorokin (ftl) 2017/02/27 16:20:49 Done.
95 const std::string& username,
96 const std::string& password) {
97 EXPECT_TRUE(IsStepDisplayed("ad-join"));
98 js_checker().ExpectFalse(std::string(ad_machine_name_input) + ".hidden");
99 js_checker().ExpectFalse(std::string(ad_username_input) + ".hidden");
100 js_checker().ExpectFalse(std::string(ad_password_input) + ".hidden");
101 const std::string set_machine_name =
102 std::string(ad_machine_name_input) + ".value = '" + machine_name + "'";
103 const std::string set_username =
104 std::string(ad_username_input) + ".value = '" + username + "'";
105 const std::string set_password =
106 std::string(ad_password_input) + ".value = '" + password + "'";
107 js_checker().ExecuteAsync(set_machine_name);
108 js_checker().ExecuteAsync(set_username);
109 js_checker().ExecuteAsync(set_password);
110 js_checker().Evaluate(
111 "document.querySelector('#oauth-enroll-ad-join-ui /deep/ "
112 "#button').fire('tap')");
113 ExecutePendingJavaScript();
114 }
115
78 void DisableAttributePromptUpdate() { 116 void DisableAttributePromptUpdate() {
79 AddEnrollmentSetupFunction( 117 AddEnrollmentSetupFunction(
80 [](EnterpriseEnrollmentHelperMock* enrollment_helper) { 118 [](EnterpriseEnrollmentHelperMock* enrollment_helper) {
81 EXPECT_CALL(*enrollment_helper, GetDeviceAttributeUpdatePermission()) 119 EXPECT_CALL(*enrollment_helper, GetDeviceAttributeUpdatePermission())
82 .WillOnce(InvokeWithoutArgs([enrollment_helper]() { 120 .WillOnce(InvokeWithoutArgs([enrollment_helper]() {
83 enrollment_helper->status_consumer() 121 enrollment_helper->status_consumer()
84 ->OnDeviceAttributeUpdatePermission(false); 122 ->OnDeviceAttributeUpdatePermission(false);
85 })); 123 }));
86 }); 124 });
87 } 125 }
88 126
89 // Forces an attribute prompt to display. 127 // Forces an attribute prompt to display.
90 void ExpectAttributePromptUpdate() { 128 void ExpectAttributePromptUpdate() {
91 AddEnrollmentSetupFunction( 129 AddEnrollmentSetupFunction(
92 [](EnterpriseEnrollmentHelperMock* enrollment_helper) { 130 [](EnterpriseEnrollmentHelperMock* enrollment_helper) {
93 // Causes the attribute-prompt flow to activate. 131 // Causes the attribute-prompt flow to activate.
94 ON_CALL(*enrollment_helper, GetDeviceAttributeUpdatePermission()) 132 ON_CALL(*enrollment_helper, GetDeviceAttributeUpdatePermission())
95 .WillByDefault(InvokeWithoutArgs([enrollment_helper]() { 133 .WillByDefault(InvokeWithoutArgs([enrollment_helper]() {
96 enrollment_helper->status_consumer() 134 enrollment_helper->status_consumer()
97 ->OnDeviceAttributeUpdatePermission(true); 135 ->OnDeviceAttributeUpdatePermission(true);
98 })); 136 }));
99 137
100 // Ensures we receive the updates attributes. 138 // Ensures we receive the updates attributes.
101 EXPECT_CALL(*enrollment_helper, 139 EXPECT_CALL(*enrollment_helper,
102 UpdateDeviceAttributes("asset_id", "location")); 140 UpdateDeviceAttributes("asset_id", "location"));
103 }); 141 });
104 } 142 }
105 143
144 void SetupActiveDirectoryJoin() {
achuithb 2017/02/27 16:03:47 Function comment
Roman Sorokin (ftl) 2017/02/27 16:20:49 Done.
145 AddEnrollmentSetupFunction([this](
146 EnterpriseEnrollmentHelperMock* enrollment_helper) {
147 // Causes the attribute-prompt flow to activate.
148 EXPECT_CALL(*enrollment_helper, EnrollUsingAuthCode("test_auth_code", _))
149 .WillOnce(InvokeWithoutArgs([this]() {
150 this->enrollment_screen()->JoinDomain(
151 base::BindOnce([](const std::string& realm) {
152 EXPECT_EQ(ad_test_realm, realm);
153 }));
154 }));
155 });
156 }
157
106 // Fills out the UI with device attribute information and submits it. 158 // Fills out the UI with device attribute information and submits it.
107 void SubmitAttributePromptUpdate() { 159 void SubmitAttributePromptUpdate() {
108 // Fill out the attribute prompt info and submit it. 160 // Fill out the attribute prompt info and submit it.
109 js_checker().ExecuteAsync("$('oauth-enroll-asset-id').value = 'asset_id'"); 161 js_checker().ExecuteAsync("$('oauth-enroll-asset-id').value = 'asset_id'");
110 js_checker().ExecuteAsync("$('oauth-enroll-location').value = 'location'"); 162 js_checker().ExecuteAsync("$('oauth-enroll-location').value = 'location'");
111 js_checker().Evaluate( 163 js_checker().Evaluate(
112 "$('oauth-enroll-attribute-prompt-card').fire('submit')"); 164 "$('oauth-enroll-attribute-prompt-card').fire('submit')");
113 } 165 }
114 166
115 // Completes the enrollment process. 167 // Completes the enrollment process.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 EXPECT_TRUE(IsStepDisplayed("attribute-prompt")); 274 EXPECT_TRUE(IsStepDisplayed("attribute-prompt"));
223 EXPECT_FALSE(IsStepDisplayed("success")); 275 EXPECT_FALSE(IsStepDisplayed("success"));
224 EXPECT_FALSE(IsStepDisplayed("error")); 276 EXPECT_FALSE(IsStepDisplayed("error"));
225 277
226 SubmitAttributePromptUpdate(); 278 SubmitAttributePromptUpdate();
227 279
228 // We have to remove the enrollment_helper before the dtor gets called. 280 // We have to remove the enrollment_helper before the dtor gets called.
229 enrollment_screen()->enrollment_helper_.reset(); 281 enrollment_screen()->enrollment_helper_.reset();
230 } 282 }
231 283
284 // Shows the enrollment screen and mocks the enrollment helper to show Active
285 // Directory domain join screen. Verifies the domain join screen is displayed.
286 // Submits Active Directory credentials. Verifies that the AuthpolicyClient
287 // calls us back with the correct realm.
288 IN_PROC_BROWSER_TEST_F(EnterpriseEnrollmentTest,
289 TestActiveDirectoryEnrollment_Success) {
290 ShowEnrollmentScreen();
291 DisableAttributePromptUpdate();
292 SetupActiveDirectoryJoin();
293 SubmitEnrollmentCredentials();
294 chromeos::DBusThreadManager::Get()
295 ->GetUpstartClient()
296 ->StartAuthPolicyService();
297 SubmitActiveDirectoryCredentials("machine_name", ad_test_user, "password");
achuithb 2017/02/27 16:03:47 Some more newlines in this test would help readabi
Roman Sorokin (ftl) 2017/02/27 16:20:49 Done.
298 EXPECT_FALSE(IsStepDisplayed("ad-join"));
299 CompleteEnrollment();
300 // Verify that the success page is displayed.
301 EXPECT_TRUE(IsStepDisplayed("success"));
302 EXPECT_FALSE(IsStepDisplayed("error"));
303
304 // We have to remove the enrollment_helper before the dtor gets called.
305 enrollment_screen()->enrollment_helper_.reset();
306 }
307
308 // Shows the enrollment screen and mocks the enrollment helper to show Active
309 // Directory domain join screen. Verifies the domain join screen is displayed.
310 // Submits Active Directory different incorrect credentials. Verifies that the
311 // correct error is displayed.
312 IN_PROC_BROWSER_TEST_F(EnterpriseEnrollmentTest,
313 TestActiveDirectoryEnrollment_UIErrors) {
314 ShowEnrollmentScreen();
315 SetupActiveDirectoryJoin();
316 SubmitEnrollmentCredentials();
317 chromeos::DBusThreadManager::Get()
318 ->GetUpstartClient()
319 ->StartAuthPolicyService();
320
321 // Checking error in case of empty password. Whether password is not empty
322 // being checked in the UI. Machine name length is checked after that in the
323 // authpolicyd.
324 SubmitActiveDirectoryCredentials("too_long_machine_name", ad_test_user, "");
325 EXPECT_TRUE(IsStepDisplayed("ad-join"));
326 js_checker().ExpectFalse(std::string(ad_machine_name_input) + ".isInvalid");
327 js_checker().ExpectFalse(std::string(ad_username_input) + ".isInvalid");
328 js_checker().ExpectTrue(std::string(ad_password_input) + ".isInvalid");
329
330 // Checking error in case of too long machine name.
331 SubmitActiveDirectoryCredentials("too_long_machine_name", ad_test_user,
332 "password");
333 EXPECT_TRUE(IsStepDisplayed("ad-join"));
334 js_checker().ExpectTrue(std::string(ad_machine_name_input) + ".isInvalid");
335 js_checker().ExpectFalse(std::string(ad_username_input) + ".isInvalid");
336 js_checker().ExpectFalse(std::string(ad_password_input) + ".isInvalid");
337
338 // Checking error in case of bad username (without realm).
339 SubmitActiveDirectoryCredentials("machine_name", "ad_test_user", "password");
340 EXPECT_TRUE(IsStepDisplayed("ad-join"));
341 js_checker().ExpectFalse(std::string(ad_machine_name_input) + ".isInvalid");
342 js_checker().ExpectTrue(std::string(ad_username_input) + ".isInvalid");
343 js_checker().ExpectFalse(std::string(ad_password_input) + ".isInvalid");
344
345 // We have to remove the enrollment_helper before the dtor gets called.
346 enrollment_screen()->enrollment_helper_.reset();
347 }
348
232 } // namespace chromeos 349 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/enrollment/enrollment_screen.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698