Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 void JoinAdCallback(const std::string& machine_name, |
| 17 const std::string& user_principal_name, | 18 const std::string& user_principal_name, |
| 18 authpolicy::ErrorType expected, | 19 authpolicy::ErrorType expected, |
| 19 authpolicy::ErrorType actual) { | 20 authpolicy::ErrorType actual) { |
| 20 EXPECT_EQ(expected, actual) << "with machine name: " << machine_name | 21 EXPECT_EQ(expected, actual) << "with machine name: " << machine_name |
| 21 << ", and user name: " << user_principal_name; | 22 << ", and user name: " << user_principal_name; |
| 22 } | 23 } |
| 23 | 24 |
| 25 void AuthenticateUserCallback(const std::string& user_principal_name, | |
| 26 authpolicy::ErrorType expected, | |
| 27 authpolicy::ErrorType actual, | |
| 28 const std::string& obj_guid) { | |
| 29 EXPECT_EQ(expected, actual) << "with user name: " << user_principal_name; | |
| 30 } | |
| 31 | |
| 32 void RefreshDevicePolicyCallback(bool expected, bool actual) { | |
| 33 EXPECT_EQ(expected, actual); | |
| 34 } | |
| 35 | |
| 36 void RefreshUserPolicyCallback(const std::string& user_principal_name, | |
| 37 bool expected, | |
| 38 bool actual) { | |
| 39 EXPECT_EQ(expected, actual) << "with user name: " << user_principal_name; | |
| 40 } | |
| 41 | |
| 24 void TestDomainJoin(const std::string& machine_name, | 42 void TestDomainJoin(const std::string& machine_name, |
| 25 const std::string& user_principal_name, | 43 const std::string& user_principal_name, |
| 26 authpolicy::ErrorType expected) { | 44 authpolicy::ErrorType expected) { |
| 27 FakeAuthPolicyClient client; | 45 FakeAuthPolicyClient client; |
| 46 client.Start(); | |
| 28 client.JoinAdDomain( | 47 client.JoinAdDomain( |
| 29 machine_name, user_principal_name, /* password_fd */ -1, | 48 machine_name, user_principal_name, /* password_fd */ -1, |
| 30 base::Bind(&JoinAdCallback, machine_name, user_principal_name, expected)); | 49 base::Bind(&JoinAdCallback, machine_name, user_principal_name, expected)); |
| 31 } | 50 } |
| 32 | 51 |
| 33 } // namespace | 52 } // namespace |
| 34 | 53 |
| 35 // Tests parsing machine name. | 54 // Tests parsing machine name. |
| 36 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) { | 55 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) { |
| 37 TestDomainJoin("correct_length1", kCorrectUserName, authpolicy::ERROR_NONE); | 56 TestDomainJoin("correct_length1", kCorrectUserName, authpolicy::ERROR_NONE); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 51 authpolicy::ERROR_PARSE_UPN_FAILED); | 70 authpolicy::ERROR_PARSE_UPN_FAILED); |
| 52 TestDomainJoin(kCorrectMachineName, "", authpolicy::ERROR_PARSE_UPN_FAILED); | 71 TestDomainJoin(kCorrectMachineName, "", authpolicy::ERROR_PARSE_UPN_FAILED); |
| 53 TestDomainJoin(kCorrectMachineName, "user@", | 72 TestDomainJoin(kCorrectMachineName, "user@", |
| 54 authpolicy::ERROR_PARSE_UPN_FAILED); | 73 authpolicy::ERROR_PARSE_UPN_FAILED); |
| 55 TestDomainJoin(kCorrectMachineName, "@realm", | 74 TestDomainJoin(kCorrectMachineName, "@realm", |
| 56 authpolicy::ERROR_PARSE_UPN_FAILED); | 75 authpolicy::ERROR_PARSE_UPN_FAILED); |
| 57 TestDomainJoin(kCorrectMachineName, "user@realm@com", | 76 TestDomainJoin(kCorrectMachineName, "user@realm@com", |
| 58 authpolicy::ERROR_PARSE_UPN_FAILED); | 77 authpolicy::ERROR_PARSE_UPN_FAILED); |
| 59 } | 78 } |
| 60 | 79 |
| 80 // Tests calls to not started authpolicyd fails. | |
| 81 TEST(FakeAuthPolicyClientTest, NotStartedAuthPolicyService) { | |
| 82 FakeAuthPolicyClient client; | |
| 83 client.JoinAdDomain( | |
| 84 kCorrectMachineName, kCorrectUserName, /* password_fd */ -1, | |
| 85 base::Bind(&JoinAdCallback, kCorrectMachineName, kCorrectUserName, | |
|
hashimoto
2017/02/06 04:15:49
How about using lambdas?
Instead of base::Bind(&J
Roman Sorokin (ftl)
2017/02/06 10:30:40
Thanks for the hint! Changed for the all calls.
| |
| 86 authpolicy::ERROR_DBUS_FAILURE)); | |
| 87 client.AuthenticateUser( | |
| 88 kCorrectUserName, /* password_fd */ -1, | |
| 89 base::Bind(&AuthenticateUserCallback, kCorrectUserName, | |
| 90 authpolicy::ERROR_DBUS_FAILURE)); | |
| 91 client.RefreshDevicePolicy(base::Bind(&RefreshDevicePolicyCallback, false)); | |
| 92 client.RefreshUserPolicy( | |
| 93 AccountId::FromUserEmail(kCorrectUserName), | |
| 94 base::Bind(&RefreshUserPolicyCallback, kCorrectUserName, false)); | |
| 95 } | |
| 96 | |
| 61 } // namespace chromeos | 97 } // namespace chromeos |
| OLD | NEW |