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

Side by Side Diff: chromeos/dbus/fake_auth_policy_client_unittest.cc

Issue 2673813003: Emulate StartAuthPolicyService from FakeUpstartClient (Closed)
Patch Set: rebase Created 3 years, 10 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 | « chromeos/dbus/fake_auth_policy_client.cc ('k') | chromeos/dbus/fake_upstart_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "chromeos/dbus/fake_auth_policy_client.h" 5 #include "chromeos/dbus/fake_auth_policy_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "components/signin/core/account_id/account_id.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 10
10 namespace chromeos { 11 namespace chromeos {
11 namespace { 12 namespace {
12 13
13 const char kCorrectMachineName[] = "machine_name"; 14 const char kCorrectMachineName[] = "machine_name";
14 const char kCorrectUserName[] = "user@realm.com"; 15 const char kCorrectUserName[] = "user@realm.com";
15 16
16 void JoinAdCallback(const std::string& machine_name,
17 const std::string& user_principal_name,
18 authpolicy::ErrorType expected,
19 authpolicy::ErrorType actual) {
20 EXPECT_EQ(expected, actual) << "with machine name: " << machine_name
21 << ", and user name: " << user_principal_name;
22 }
23
24 void TestDomainJoin(const std::string& machine_name,
25 const std::string& user_principal_name,
26 authpolicy::ErrorType expected) {
27 FakeAuthPolicyClient client;
28 client.JoinAdDomain(
29 machine_name, user_principal_name, /* password_fd */ -1,
30 base::Bind(&JoinAdCallback, machine_name, user_principal_name, expected));
31 }
32
33 } // namespace 17 } // namespace
34 18
35 // Tests parsing machine name. 19 // Tests parsing machine name.
36 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) { 20 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) {
37 TestDomainJoin("correct_length1", kCorrectUserName, authpolicy::ERROR_NONE); 21 FakeAuthPolicyClient client;
38 TestDomainJoin("", kCorrectUserName, authpolicy::ERROR_BAD_MACHINE_NAME); 22 client.set_started(true);
39 TestDomainJoin("too_long_machine_name ", kCorrectUserName, 23 client.JoinAdDomain("correct_length1", kCorrectUserName, /* password_fd */ -1,
40 authpolicy::ERROR_MACHINE_NAME_TOO_LONG); 24 base::Bind([](authpolicy::ErrorType error) {
41 TestDomainJoin("invalid:name", kCorrectUserName, 25 EXPECT_EQ(authpolicy::ERROR_NONE, error);
42 authpolicy::ERROR_BAD_MACHINE_NAME); 26 }));
43 TestDomainJoin(">nvalidname", kCorrectUserName, 27 client.JoinAdDomain("", kCorrectUserName, /* password_fd */ -1,
44 authpolicy::ERROR_BAD_MACHINE_NAME); 28 base::Bind([](authpolicy::ErrorType error) {
29 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error);
30 }));
31 client.JoinAdDomain(
32 "too_long_machine_name", kCorrectUserName, /* password_fd */ -1,
33 base::Bind([](authpolicy::ErrorType error) {
34 EXPECT_EQ(authpolicy::ERROR_MACHINE_NAME_TOO_LONG, error);
35 }));
36 client.JoinAdDomain("invalid:name", kCorrectUserName, /* password_fd */ -1,
37 base::Bind([](authpolicy::ErrorType error) {
38 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error);
39 }));
40 client.JoinAdDomain(">nvalidname", kCorrectUserName, /* password_fd */ -1,
41 base::Bind([](authpolicy::ErrorType error) {
42 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error);
43 }));
45 } 44 }
46 45
47 // Tests parsing user name. 46 // Tests parsing user name.
48 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) { 47 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) {
49 TestDomainJoin(kCorrectMachineName, "user@realm.com", authpolicy::ERROR_NONE); 48 FakeAuthPolicyClient client;
50 TestDomainJoin(kCorrectMachineName, "user", 49 client.set_started(true);
51 authpolicy::ERROR_PARSE_UPN_FAILED); 50 client.JoinAdDomain(kCorrectMachineName, "user@realm.com",
52 TestDomainJoin(kCorrectMachineName, "", authpolicy::ERROR_PARSE_UPN_FAILED); 51 /* password_fd */ -1,
53 TestDomainJoin(kCorrectMachineName, "user@", 52 base::Bind([](authpolicy::ErrorType error) {
54 authpolicy::ERROR_PARSE_UPN_FAILED); 53 EXPECT_EQ(authpolicy::ERROR_NONE, error);
55 TestDomainJoin(kCorrectMachineName, "@realm", 54 }));
56 authpolicy::ERROR_PARSE_UPN_FAILED); 55 client.JoinAdDomain(kCorrectMachineName, "user", /* password_fd */ -1,
57 TestDomainJoin(kCorrectMachineName, "user@realm@com", 56 base::Bind([](authpolicy::ErrorType error) {
58 authpolicy::ERROR_PARSE_UPN_FAILED); 57 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error);
58 }));
59 client.JoinAdDomain(kCorrectMachineName, "", /* password_fd */ -1,
60 base::Bind([](authpolicy::ErrorType error) {
61 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error);
62 }));
63 client.JoinAdDomain(kCorrectMachineName, "user@", /* password_fd */ -1,
64 base::Bind([](authpolicy::ErrorType error) {
65 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error);
66 }));
67 client.JoinAdDomain(kCorrectMachineName, "@realm", /* password_fd */ -1,
68 base::Bind([](authpolicy::ErrorType error) {
69 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error);
70 }));
71 client.JoinAdDomain(kCorrectMachineName, "user@realm@com",
72 /* password_fd */ -1,
73 base::Bind([](authpolicy::ErrorType error) {
74 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error);
75 }));
76 }
77
78 // Tests calls to not started authpolicyd fails.
79 TEST(FakeAuthPolicyClientTest, NotStartedAuthPolicyService) {
80 FakeAuthPolicyClient client;
81 client.JoinAdDomain(kCorrectMachineName, kCorrectUserName,
82 /* password_fd */ -1,
83 base::Bind([](authpolicy::ErrorType error) {
84 EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error);
85 }));
86 client.AuthenticateUser(
87 kCorrectUserName, /* password_fd */ -1,
88 base::Bind([](authpolicy::ErrorType error,
89 const authpolicy::ActiveDirectoryAccountData&) {
90 EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error);
91 }));
92 client.RefreshDevicePolicy(
93 base::Bind([](bool success) { EXPECT_EQ(false, success); }));
94 client.RefreshUserPolicy(
95 AccountId::FromUserEmail(kCorrectUserName),
96 base::Bind([](bool success) { EXPECT_EQ(false, success); }));
59 } 97 }
60 98
61 } // namespace chromeos 99 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_auth_policy_client.cc ('k') | chromeos/dbus/fake_upstart_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698