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

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

Issue 2794493002: Add AuthPolicyLoginHelper (Closed)
Patch Set: Update after review Created 3 years, 8 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.h » ('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 "base/message_loop/message_loop.h"
9 #include "base/run_loop.h"
8 #include "components/signin/core/account_id/account_id.h" 10 #include "components/signin/core/account_id/account_id.h"
9 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
10 12
11 namespace chromeos { 13 namespace chromeos {
12 namespace { 14 namespace {
13 15
14 const char kCorrectMachineName[] = "machine_name"; 16 const char kCorrectMachineName[] = "machine_name";
15 const char kCorrectUserName[] = "user@realm.com"; 17 const char kCorrectUserName[] = "user@realm.com";
16 18
17 } // namespace 19 } // namespace
18 20
21 class FakeAuthPolicyClientTest : public ::testing::Test {
22 public:
23 FakeAuthPolicyClientTest(){};
24
25 protected:
26 FakeAuthPolicyClient* authpolicy_client() { return &client_; }
27
28 private:
29 FakeAuthPolicyClient client_;
30 base::MessageLoop loop_;
31
32 DISALLOW_COPY_AND_ASSIGN(FakeAuthPolicyClientTest);
33 };
34
19 // Tests parsing machine name. 35 // Tests parsing machine name.
20 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) { 36 TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) {
21 FakeAuthPolicyClient client; 37 authpolicy_client()->set_started(true);
22 client.set_started(true); 38 authpolicy_client()->JoinAdDomain("correct_length1", kCorrectUserName,
23 client.JoinAdDomain("correct_length1", kCorrectUserName, /* password_fd */ -1, 39 /* password_fd */ -1,
24 base::Bind([](authpolicy::ErrorType error) { 40 base::Bind([](authpolicy::ErrorType error) {
25 EXPECT_EQ(authpolicy::ERROR_NONE, error); 41 EXPECT_EQ(authpolicy::ERROR_NONE, error);
26 })); 42 }));
27 client.JoinAdDomain("", kCorrectUserName, /* password_fd */ -1, 43 authpolicy_client()->JoinAdDomain(
28 base::Bind([](authpolicy::ErrorType error) { 44 "", kCorrectUserName, /* password_fd */ -1,
29 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error); 45 base::Bind([](authpolicy::ErrorType error) {
30 })); 46 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error);
31 client.JoinAdDomain( 47 }));
48 authpolicy_client()->JoinAdDomain(
32 "too_long_machine_name", kCorrectUserName, /* password_fd */ -1, 49 "too_long_machine_name", kCorrectUserName, /* password_fd */ -1,
33 base::Bind([](authpolicy::ErrorType error) { 50 base::Bind([](authpolicy::ErrorType error) {
34 EXPECT_EQ(authpolicy::ERROR_MACHINE_NAME_TOO_LONG, error); 51 EXPECT_EQ(authpolicy::ERROR_MACHINE_NAME_TOO_LONG, error);
35 })); 52 }));
36 client.JoinAdDomain("invalid:name", kCorrectUserName, /* password_fd */ -1, 53 authpolicy_client()->JoinAdDomain(
37 base::Bind([](authpolicy::ErrorType error) { 54 "invalid:name", kCorrectUserName, /* password_fd */ -1,
38 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error); 55 base::Bind([](authpolicy::ErrorType error) {
39 })); 56 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error);
40 client.JoinAdDomain(">nvalidname", kCorrectUserName, /* password_fd */ -1, 57 }));
41 base::Bind([](authpolicy::ErrorType error) { 58 authpolicy_client()->JoinAdDomain(
42 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error); 59 ">nvalidname", kCorrectUserName, /* password_fd */ -1,
43 })); 60 base::Bind([](authpolicy::ErrorType error) {
61 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error);
62 }));
63
64 base::RunLoop().RunUntilIdle();
44 } 65 }
45 66
46 // Tests parsing user name. 67 // Tests parsing user name.
47 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) { 68 TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) {
48 FakeAuthPolicyClient client; 69 authpolicy_client()->set_started(true);
49 client.set_started(true); 70 authpolicy_client()->JoinAdDomain(kCorrectMachineName, "user@realm.com",
50 client.JoinAdDomain(kCorrectMachineName, "user@realm.com", 71 /* password_fd */ -1,
51 /* password_fd */ -1, 72 base::Bind([](authpolicy::ErrorType error) {
52 base::Bind([](authpolicy::ErrorType error) { 73 EXPECT_EQ(authpolicy::ERROR_NONE, error);
53 EXPECT_EQ(authpolicy::ERROR_NONE, error); 74 }));
54 })); 75 authpolicy_client()->JoinAdDomain(
55 client.JoinAdDomain(kCorrectMachineName, "user", /* password_fd */ -1, 76 kCorrectMachineName, "user", /* password_fd */ -1,
56 base::Bind([](authpolicy::ErrorType error) { 77 base::Bind([](authpolicy::ErrorType error) {
57 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); 78 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error);
58 })); 79 }));
59 client.JoinAdDomain(kCorrectMachineName, "", /* password_fd */ -1, 80 authpolicy_client()->JoinAdDomain(
60 base::Bind([](authpolicy::ErrorType error) { 81 kCorrectMachineName, "", /* password_fd */ -1,
61 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); 82 base::Bind([](authpolicy::ErrorType error) {
62 })); 83 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error);
63 client.JoinAdDomain(kCorrectMachineName, "user@", /* password_fd */ -1, 84 }));
64 base::Bind([](authpolicy::ErrorType error) { 85 authpolicy_client()->JoinAdDomain(
65 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); 86 kCorrectMachineName, "user@", /* password_fd */ -1,
66 })); 87 base::Bind([](authpolicy::ErrorType error) {
67 client.JoinAdDomain(kCorrectMachineName, "@realm", /* password_fd */ -1, 88 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error);
68 base::Bind([](authpolicy::ErrorType error) { 89 }));
69 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); 90 authpolicy_client()->JoinAdDomain(
70 })); 91 kCorrectMachineName, "@realm", /* password_fd */ -1,
71 client.JoinAdDomain(kCorrectMachineName, "user@realm@com", 92 base::Bind([](authpolicy::ErrorType error) {
72 /* password_fd */ -1, 93 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error);
73 base::Bind([](authpolicy::ErrorType error) { 94 }));
74 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); 95 authpolicy_client()->JoinAdDomain(
75 })); 96 kCorrectMachineName, "user@realm@com",
97 /* password_fd */ -1, base::Bind([](authpolicy::ErrorType error) {
98 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error);
99 }));
100
101 base::RunLoop().RunUntilIdle();
76 } 102 }
77 103
78 // Tests calls to not started authpolicyd fails. 104 // Tests calls to not started authpolicyd fails.
79 TEST(FakeAuthPolicyClientTest, NotStartedAuthPolicyService) { 105 TEST_F(FakeAuthPolicyClientTest, NotStartedAuthPolicyService) {
80 FakeAuthPolicyClient client; 106 authpolicy_client()->JoinAdDomain(
81 client.JoinAdDomain(kCorrectMachineName, kCorrectUserName, 107 kCorrectMachineName, kCorrectUserName,
82 /* password_fd */ -1, 108 /* password_fd */ -1, base::Bind([](authpolicy::ErrorType error) {
83 base::Bind([](authpolicy::ErrorType error) { 109 EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error);
84 EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error); 110 }));
85 })); 111 authpolicy_client()->AuthenticateUser(
86 client.AuthenticateUser(
87 kCorrectUserName, /* password_fd */ -1, 112 kCorrectUserName, /* password_fd */ -1,
88 base::Bind([](authpolicy::ErrorType error, 113 base::Bind([](authpolicy::ErrorType error,
89 const authpolicy::ActiveDirectoryAccountData&) { 114 const authpolicy::ActiveDirectoryAccountData&) {
90 EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error); 115 EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error);
91 })); 116 }));
92 client.RefreshDevicePolicy( 117 authpolicy_client()->RefreshDevicePolicy(
93 base::Bind([](bool success) { EXPECT_FALSE(success); })); 118 base::Bind([](bool success) { EXPECT_FALSE(success); }));
94 client.RefreshUserPolicy( 119 authpolicy_client()->RefreshUserPolicy(
95 AccountId::FromUserEmail(kCorrectUserName), 120 AccountId::FromUserEmail(kCorrectUserName),
96 base::Bind([](bool success) { EXPECT_FALSE(success); })); 121 base::Bind([](bool success) { EXPECT_FALSE(success); }));
122
123 base::RunLoop().RunUntilIdle();
97 } 124 }
98 125
99 } // namespace chromeos 126 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_auth_policy_client.cc ('k') | chromeos/dbus/fake_upstart_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698