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

Unified Diff: chromeos/dbus/fake_auth_policy_client_unittest.cc

Issue 2673813003: Emulate StartAuthPolicyService from FakeUpstartClient (Closed)
Patch Set: rebase Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/dbus/fake_auth_policy_client.cc ('k') | chromeos/dbus/fake_upstart_client.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
index a8b6b79a7c0cfe4ebcfc33dd59201796a69490da..4cd560868ab427002a4ebe2f3bb9fac0b9ed09d1 100644
--- a/chromeos/dbus/fake_auth_policy_client_unittest.cc
+++ b/chromeos/dbus/fake_auth_policy_client_unittest.cc
@@ -5,6 +5,7 @@
#include "chromeos/dbus/fake_auth_policy_client.h"
#include "base/bind.h"
+#include "components/signin/core/account_id/account_id.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
@@ -13,49 +14,86 @@ 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
// Tests parsing machine name.
TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) {
- 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);
+ FakeAuthPolicyClient client;
+ client.set_started(true);
+ client.JoinAdDomain("correct_length1", kCorrectUserName, /* password_fd */ -1,
+ base::Bind([](authpolicy::ErrorType error) {
+ EXPECT_EQ(authpolicy::ERROR_NONE, error);
+ }));
+ client.JoinAdDomain("", kCorrectUserName, /* password_fd */ -1,
+ base::Bind([](authpolicy::ErrorType error) {
+ EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error);
+ }));
+ client.JoinAdDomain(
+ "too_long_machine_name", kCorrectUserName, /* password_fd */ -1,
+ base::Bind([](authpolicy::ErrorType error) {
+ EXPECT_EQ(authpolicy::ERROR_MACHINE_NAME_TOO_LONG, error);
+ }));
+ client.JoinAdDomain("invalid:name", kCorrectUserName, /* password_fd */ -1,
+ base::Bind([](authpolicy::ErrorType error) {
+ EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error);
+ }));
+ client.JoinAdDomain(">nvalidname", kCorrectUserName, /* password_fd */ -1,
+ base::Bind([](authpolicy::ErrorType error) {
+ EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error);
+ }));
}
// Tests parsing user name.
TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) {
- 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);
+ FakeAuthPolicyClient client;
+ client.set_started(true);
+ client.JoinAdDomain(kCorrectMachineName, "user@realm.com",
+ /* password_fd */ -1,
+ base::Bind([](authpolicy::ErrorType error) {
+ EXPECT_EQ(authpolicy::ERROR_NONE, error);
+ }));
+ client.JoinAdDomain(kCorrectMachineName, "user", /* password_fd */ -1,
+ base::Bind([](authpolicy::ErrorType error) {
+ EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error);
+ }));
+ client.JoinAdDomain(kCorrectMachineName, "", /* password_fd */ -1,
+ base::Bind([](authpolicy::ErrorType error) {
+ EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error);
+ }));
+ client.JoinAdDomain(kCorrectMachineName, "user@", /* password_fd */ -1,
+ base::Bind([](authpolicy::ErrorType error) {
+ EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error);
+ }));
+ client.JoinAdDomain(kCorrectMachineName, "@realm", /* password_fd */ -1,
+ base::Bind([](authpolicy::ErrorType error) {
+ EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error);
+ }));
+ client.JoinAdDomain(kCorrectMachineName, "user@realm@com",
+ /* password_fd */ -1,
+ base::Bind([](authpolicy::ErrorType error) {
+ EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error);
+ }));
+}
+
+// Tests calls to not started authpolicyd fails.
+TEST(FakeAuthPolicyClientTest, NotStartedAuthPolicyService) {
+ FakeAuthPolicyClient client;
+ client.JoinAdDomain(kCorrectMachineName, kCorrectUserName,
+ /* password_fd */ -1,
+ base::Bind([](authpolicy::ErrorType error) {
+ EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error);
+ }));
+ client.AuthenticateUser(
+ kCorrectUserName, /* password_fd */ -1,
+ base::Bind([](authpolicy::ErrorType error,
+ const authpolicy::ActiveDirectoryAccountData&) {
+ EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error);
+ }));
+ client.RefreshDevicePolicy(
+ base::Bind([](bool success) { EXPECT_EQ(false, success); }));
+ client.RefreshUserPolicy(
+ AccountId::FromUserEmail(kCorrectUserName),
+ base::Bind([](bool success) { EXPECT_EQ(false, success); }));
}
} // namespace chromeos
« no previous file with comments | « chromeos/dbus/fake_auth_policy_client.cc ('k') | chromeos/dbus/fake_upstart_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698