Chromium Code Reviews| 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 TEST(FakeAuthPolicyClientTest, JoinAdDomain_BadMachineName) { | |
|
achuithb
2017/01/27 01:02:15
add a comment
Roman Sorokin (ftl)
2017/01/27 09:48:17
Done.
| |
| 36 TestDomainJoin("correct_length1", kCorrectUserName, authpolicy::ERROR_NONE); | |
| 37 TestDomainJoin("", kCorrectUserName, authpolicy::ERROR_BAD_MACHINE_NAME); | |
| 38 TestDomainJoin("too_long_machine_name ", kCorrectUserName, | |
| 39 authpolicy::ERROR_MACHINE_NAME_TOO_LONG); | |
| 40 TestDomainJoin("invalid:name", kCorrectUserName, | |
| 41 authpolicy::ERROR_BAD_MACHINE_NAME); | |
| 42 TestDomainJoin(">nvalidname", kCorrectUserName, | |
| 43 authpolicy::ERROR_BAD_MACHINE_NAME); | |
| 44 } | |
| 45 | |
| 46 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) { | |
|
achuithb
2017/01/27 01:02:15
add a comment
Roman Sorokin (ftl)
2017/01/27 09:48:17
Done.
| |
| 47 TestDomainJoin(kCorrectMachineName, "user@realm.com", authpolicy::ERROR_NONE); | |
| 48 TestDomainJoin(kCorrectMachineName, "user", | |
| 49 authpolicy::ERROR_PARSE_UPN_FAILED); | |
| 50 TestDomainJoin(kCorrectMachineName, "", authpolicy::ERROR_PARSE_UPN_FAILED); | |
| 51 TestDomainJoin(kCorrectMachineName, "user@", | |
| 52 authpolicy::ERROR_PARSE_UPN_FAILED); | |
| 53 TestDomainJoin(kCorrectMachineName, "@realm", | |
| 54 authpolicy::ERROR_PARSE_UPN_FAILED); | |
| 55 TestDomainJoin(kCorrectMachineName, "user@realm@com", | |
| 56 authpolicy::ERROR_PARSE_UPN_FAILED); | |
| 57 } | |
| 58 | |
| 59 } // namespace chromeos | |
| OLD | NEW |