Chromium Code Reviews| Index: chromeos/dbus/fake_auth_policy_client_unittest.cc |
| diff --git a/chromeos/dbus/fake_auth_policy_client_unittest.cc b/chromeos/dbus/fake_auth_policy_client_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1ace1aac54c09ebc008f7aad6b805e8bdfe0c6ce |
| --- /dev/null |
| +++ b/chromeos/dbus/fake_auth_policy_client_unittest.cc |
| @@ -0,0 +1,59 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chromeos/dbus/fake_auth_policy_client.h" |
| + |
| +#include "base/bind.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace chromeos { |
| +namespace { |
| + |
| +const char kCorrectMachineName[] = "machine_name"; |
| +const char kCorrectUserName[] = "user@realm.com"; |
| + |
| +void JoinAdCallback(const std::string& machine_name, |
| + const std::string& user_principal_name, |
| + authpolicy::ErrorType expected, |
| + authpolicy::ErrorType actual) { |
| + EXPECT_EQ(expected, actual) << "with machine name: " << machine_name |
| + << ", and user name: " << user_principal_name; |
| +} |
| + |
| +void TestDomainJoin(const std::string& machine_name, |
| + const std::string& user_principal_name, |
| + authpolicy::ErrorType expected) { |
| + FakeAuthPolicyClient client; |
| + client.JoinAdDomain( |
| + machine_name, user_principal_name, /* password_fd */ -1, |
| + base::Bind(&JoinAdCallback, machine_name, user_principal_name, expected)); |
| +} |
| + |
| +} // namespace |
| + |
| +TEST(FakeAuthPolicyClientTest, JoinAdDomain_BadMachineName) { |
|
achuithb
2017/01/27 01:02:15
add a comment
Roman Sorokin (ftl)
2017/01/27 09:48:17
Done.
|
| + TestDomainJoin("correct_length1", kCorrectUserName, authpolicy::ERROR_NONE); |
| + TestDomainJoin("", kCorrectUserName, authpolicy::ERROR_BAD_MACHINE_NAME); |
| + TestDomainJoin("too_long_machine_name ", kCorrectUserName, |
| + authpolicy::ERROR_MACHINE_NAME_TOO_LONG); |
| + TestDomainJoin("invalid:name", kCorrectUserName, |
| + authpolicy::ERROR_BAD_MACHINE_NAME); |
| + TestDomainJoin(">nvalidname", kCorrectUserName, |
| + authpolicy::ERROR_BAD_MACHINE_NAME); |
| +} |
| + |
| +TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) { |
|
achuithb
2017/01/27 01:02:15
add a comment
Roman Sorokin (ftl)
2017/01/27 09:48:17
Done.
|
| + TestDomainJoin(kCorrectMachineName, "user@realm.com", authpolicy::ERROR_NONE); |
| + TestDomainJoin(kCorrectMachineName, "user", |
| + authpolicy::ERROR_PARSE_UPN_FAILED); |
| + TestDomainJoin(kCorrectMachineName, "", authpolicy::ERROR_PARSE_UPN_FAILED); |
| + TestDomainJoin(kCorrectMachineName, "user@", |
| + authpolicy::ERROR_PARSE_UPN_FAILED); |
| + TestDomainJoin(kCorrectMachineName, "@realm", |
| + authpolicy::ERROR_PARSE_UPN_FAILED); |
| + TestDomainJoin(kCorrectMachineName, "user@realm@com", |
| + authpolicy::ERROR_PARSE_UPN_FAILED); |
| +} |
| + |
| +} // namespace chromeos |