| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chromeos/dbus/fake_auth_policy_client.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace chromeos { |
| 11 namespace { |
| 12 |
| 13 const char kCorrectMachineName[] = "machine_name"; |
| 14 const char kCorrectUserName[] = "user@realm.com"; |
| 15 |
| 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 |
| 34 |
| 35 // Tests parsing machine name. |
| 36 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) { |
| 37 TestDomainJoin("correct_length1", kCorrectUserName, authpolicy::ERROR_NONE); |
| 38 TestDomainJoin("", kCorrectUserName, authpolicy::ERROR_BAD_MACHINE_NAME); |
| 39 TestDomainJoin("too_long_machine_name ", kCorrectUserName, |
| 40 authpolicy::ERROR_MACHINE_NAME_TOO_LONG); |
| 41 TestDomainJoin("invalid:name", kCorrectUserName, |
| 42 authpolicy::ERROR_BAD_MACHINE_NAME); |
| 43 TestDomainJoin(">nvalidname", kCorrectUserName, |
| 44 authpolicy::ERROR_BAD_MACHINE_NAME); |
| 45 } |
| 46 |
| 47 // Tests parsing user name. |
| 48 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) { |
| 49 TestDomainJoin(kCorrectMachineName, "user@realm.com", authpolicy::ERROR_NONE); |
| 50 TestDomainJoin(kCorrectMachineName, "user", |
| 51 authpolicy::ERROR_PARSE_UPN_FAILED); |
| 52 TestDomainJoin(kCorrectMachineName, "", authpolicy::ERROR_PARSE_UPN_FAILED); |
| 53 TestDomainJoin(kCorrectMachineName, "user@", |
| 54 authpolicy::ERROR_PARSE_UPN_FAILED); |
| 55 TestDomainJoin(kCorrectMachineName, "@realm", |
| 56 authpolicy::ERROR_PARSE_UPN_FAILED); |
| 57 TestDomainJoin(kCorrectMachineName, "user@realm@com", |
| 58 authpolicy::ERROR_PARSE_UPN_FAILED); |
| 59 } |
| 60 |
| 61 } // namespace chromeos |
| OLD | NEW |