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

Unified Diff: chromeos/dbus/fake_auth_policy_client.cc

Issue 2794493002: Add AuthPolicyLoginHelper (Closed)
Patch Set: Fix test + Update on Lutz's comments Created 3 years, 8 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
Index: chromeos/dbus/fake_auth_policy_client.cc
diff --git a/chromeos/dbus/fake_auth_policy_client.cc b/chromeos/dbus/fake_auth_policy_client.cc
index 0231e29fb2f6ccd1d6e9b67db672ce2d6b676710..3df84c65642d44fb69203394ffcdc6ad7144996d 100644
--- a/chromeos/dbus/fake_auth_policy_client.cc
+++ b/chromeos/dbus/fake_auth_policy_client.cc
@@ -13,6 +13,7 @@
#include "base/strings/string_split.h"
#include "base/task_scheduler/post_task.h"
#include "base/threading/platform_thread.h"
+#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
#include "chromeos/chromeos_paths.h"
#include "chromeos/cryptohome/cryptohome_parameters.h"
@@ -29,8 +30,8 @@ namespace {
const size_t kMaxMachineNameLength = 15;
const char kInvalidMachineNameCharacters[] = "\\/:*?\"<>|";
-// Delay policy fetch to be more realistic.
-constexpr int kPolicyFetchDelaySeconds = 5;
+// Delay operations to be more realistic.
+constexpr int kOperationDelaySeconds = 3;
// Drop stub policy file of |policy_type| at |policy_path| containing
// |serialized_payload|.
@@ -38,7 +39,7 @@ bool WritePolicyFile(const base::FilePath& policy_path,
const std::string& serialized_payload,
const std::string& policy_type) {
base::PlatformThread::Sleep(
- base::TimeDelta::FromSeconds(kPolicyFetchDelaySeconds));
+ base::TimeDelta::FromSeconds(kOperationDelaySeconds));
em::PolicyData data;
data.set_policy_value(serialized_payload);
@@ -62,6 +63,11 @@ bool WritePolicyFile(const base::FilePath& policy_path,
return bytes_written == static_cast<int>(serialized_response.size());
}
+void PostDelayedClosure(const base::Closure& closure) {
+ base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
+ FROM_HERE, closure, base::TimeDelta::FromSeconds(kOperationDelaySeconds));
+}
+
} // namespace
namespace chromeos {
@@ -76,46 +82,41 @@ void FakeAuthPolicyClient::JoinAdDomain(const std::string& machine_name,
const std::string& user_principal_name,
int password_fd,
const JoinCallback& callback) {
+ authpolicy::ErrorType error = authpolicy::ERROR_NONE;
if (!started_) {
LOG(ERROR) << "authpolicyd not started";
- callback.Run(authpolicy::ERROR_DBUS_FAILURE);
- return;
+ error = authpolicy::ERROR_DBUS_FAILURE;
+ } else if (machine_name.size() > kMaxMachineNameLength) {
+ error = authpolicy::ERROR_MACHINE_NAME_TOO_LONG;
+ } else if (machine_name.empty() ||
+ machine_name.find_first_of(kInvalidMachineNameCharacters) !=
+ std::string::npos) {
+ error = authpolicy::ERROR_BAD_MACHINE_NAME;
+ } else {
+ std::vector<std::string> parts = base::SplitString(
+ user_principal_name, "@", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
+ if (parts.size() != 2 || parts[0].empty() || parts[1].empty()) {
+ error = authpolicy::ERROR_PARSE_UPN_FAILED;
+ }
}
- if (machine_name.size() > kMaxMachineNameLength) {
- callback.Run(authpolicy::ERROR_MACHINE_NAME_TOO_LONG);
- return;
- }
-
- if (machine_name.empty() ||
- machine_name.find_first_of(kInvalidMachineNameCharacters) !=
- std::string::npos) {
- callback.Run(authpolicy::ERROR_BAD_MACHINE_NAME);
- return;
- }
-
- std::vector<std::string> parts = base::SplitString(
- user_principal_name, "@", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
- if (parts.size() != 2 || parts[0].empty() || parts[1].empty()) {
- callback.Run(authpolicy::ERROR_PARSE_UPN_FAILED);
- return;
- }
-
- callback.Run(authpolicy::ERROR_NONE);
+ PostDelayedClosure(base::Bind(callback, error));
}
void FakeAuthPolicyClient::AuthenticateUser(
const std::string& user_principal_name,
int password_fd,
const AuthCallback& callback) {
+ authpolicy::ErrorType error = authpolicy::ERROR_NONE;
authpolicy::ActiveDirectoryAccountData account_data;
if (!started_) {
LOG(ERROR) << "authpolicyd not started";
- callback.Run(authpolicy::ERROR_DBUS_FAILURE, account_data);
- return;
+ error = authpolicy::ERROR_DBUS_FAILURE;
+ } else {
+ if (auth_error_ == authpolicy::ERROR_NONE)
+ account_data.set_account_id(base::MD5String(user_principal_name));
+ error = auth_error_;
}
- if (auth_error_ == authpolicy::ERROR_NONE)
- account_data.set_account_id(base::MD5String(user_principal_name));
- callback.Run(auth_error_, account_data);
+ PostDelayedClosure(base::Bind(callback, error, account_data));
}
void FakeAuthPolicyClient::RefreshDevicePolicy(

Powered by Google App Engine
This is Rietveld 408576698