Commit 812664fa authored by Roman Sorokin's avatar Roman Sorokin Committed by Commit Bot

AuthPolicyClient: Add WaitForServiceToBeAvailable method

BUG=chromium:843177
TEST=FakeAuthPolicyClientTest.WaitForServiceToBeAvailableCalled
TBR=alemate@chromium.org,pmarko@chromium.org

Change-Id: I83004c7a4910d96dd9b71849326dd2c92186692a
Reviewed-on: https://chromium-review.googlesource.com/1060053
Commit-Queue: Roman Sorokin <rsorokin@chromium.org>
Reviewed-by: default avatarRyo Hashimoto <hashimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565619}
parent 40c20642
...@@ -71,7 +71,7 @@ constexpr char kCloseButtonId[] = "closeButton"; ...@@ -71,7 +71,7 @@ constexpr char kCloseButtonId[] = "closeButton";
class TestAuthPolicyClient : public FakeAuthPolicyClient { class TestAuthPolicyClient : public FakeAuthPolicyClient {
public: public:
TestAuthPolicyClient() { FakeAuthPolicyClient::set_started(true); } TestAuthPolicyClient() { FakeAuthPolicyClient::SetStarted(true); }
void AuthenticateUser(const authpolicy::AuthenticateUserRequest& request, void AuthenticateUser(const authpolicy::AuthenticateUserRequest& request,
int password_fd, int password_fd,
......
...@@ -69,6 +69,12 @@ class TestAuthPolicyClient : public chromeos::AuthPolicyClient { ...@@ -69,6 +69,12 @@ class TestAuthPolicyClient : public chromeos::AuthPolicyClient {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
void WaitForServiceToBeAvailable(
dbus::ObjectProxy::WaitForServiceToBeAvailableCallback callback)
override {
NOTIMPLEMENTED();
}
void SetRefreshUserPolicyCallbackError(authpolicy::ErrorType error) { void SetRefreshUserPolicyCallbackError(authpolicy::ErrorType error) {
refresh_user_policy_callback_error_ = error; refresh_user_policy_callback_error_ = error;
} }
......
...@@ -159,6 +159,12 @@ class AuthPolicyClientImpl : public AuthPolicyClient { ...@@ -159,6 +159,12 @@ class AuthPolicyClientImpl : public AuthPolicyClient {
std::move(on_connected_callback)); std::move(on_connected_callback));
} }
void WaitForServiceToBeAvailable(
dbus::ObjectProxy::WaitForServiceToBeAvailableCallback callback)
override {
proxy_->WaitForServiceToBeAvailable(std::move(callback));
}
protected: protected:
void Init(dbus::Bus* bus) override { void Init(dbus::Bus* bus) override {
bus_ = bus; bus_ = bus;
......
...@@ -87,6 +87,9 @@ class CHROMEOS_EXPORT AuthPolicyClient : public DBusClient { ...@@ -87,6 +87,9 @@ class CHROMEOS_EXPORT AuthPolicyClient : public DBusClient {
dbus::ObjectProxy::SignalCallback signal_callback, dbus::ObjectProxy::SignalCallback signal_callback,
dbus::ObjectProxy::OnConnectedCallback on_connected_callback) = 0; dbus::ObjectProxy::OnConnectedCallback on_connected_callback) = 0;
virtual void WaitForServiceToBeAvailable(
dbus::ObjectProxy::WaitForServiceToBeAvailableCallback callback) = 0;
protected: protected:
// Create() should be used instead. // Create() should be used instead.
AuthPolicyClient(); AuthPolicyClient();
......
...@@ -260,6 +260,27 @@ void FakeAuthPolicyClient::ConnectToSignal( ...@@ -260,6 +260,27 @@ void FakeAuthPolicyClient::ConnectToSignal(
dbus_operation_delay_); dbus_operation_delay_);
} }
void FakeAuthPolicyClient::WaitForServiceToBeAvailable(
dbus::ObjectProxy::WaitForServiceToBeAvailableCallback callback) {
if (started_) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(std::move(callback), true /* service_is_available */));
return;
}
wait_for_service_to_be_available_callbacks_.push_back(std::move(callback));
}
void FakeAuthPolicyClient::SetStarted(bool started) {
started_ = started;
if (started_) {
std::vector<WaitForServiceToBeAvailableCallback> callbacks;
callbacks.swap(wait_for_service_to_be_available_callbacks_);
for (size_t i = 0; i < callbacks.size(); ++i)
std::move(callbacks[i]).Run(true /* service_is_available*/);
}
}
void FakeAuthPolicyClient::OnDevicePolicyRetrieved( void FakeAuthPolicyClient::OnDevicePolicyRetrieved(
RefreshPolicyCallback callback, RefreshPolicyCallback callback,
SessionManagerClient::RetrievePolicyResponseType response_type, SessionManagerClient::RetrievePolicyResponseType response_type,
......
...@@ -65,10 +65,14 @@ class CHROMEOS_EXPORT FakeAuthPolicyClient : public AuthPolicyClient { ...@@ -65,10 +65,14 @@ class CHROMEOS_EXPORT FakeAuthPolicyClient : public AuthPolicyClient {
dbus::ObjectProxy::SignalCallback signal_callback, dbus::ObjectProxy::SignalCallback signal_callback,
dbus::ObjectProxy::OnConnectedCallback on_connected_callback) override; dbus::ObjectProxy::OnConnectedCallback on_connected_callback) override;
void WaitForServiceToBeAvailable(
dbus::ObjectProxy::WaitForServiceToBeAvailableCallback callback) override;
// Mark service as started. It's getting started by the // Mark service as started. It's getting started by the
// UpstartClient::StartAuthPolicyService on the Active Directory managed // UpstartClient::StartAuthPolicyService on the Active Directory managed
// devices. // devices. If |started| is true, it triggers calling
void set_started(bool started) { started_ = started; } // |wait_for_service_to_be_available_callbacks_|.
void SetStarted(bool started);
bool started() const { return started_; } bool started() const { return started_; }
...@@ -133,6 +137,9 @@ class CHROMEOS_EXPORT FakeAuthPolicyClient : public AuthPolicyClient { ...@@ -133,6 +137,9 @@ class CHROMEOS_EXPORT FakeAuthPolicyClient : public AuthPolicyClient {
base::TimeDelta::FromMilliseconds(100); base::TimeDelta::FromMilliseconds(100);
enterprise_management::ChromeDeviceSettingsProto device_policy_; enterprise_management::ChromeDeviceSettingsProto device_policy_;
std::vector<WaitForServiceToBeAvailableCallback>
wait_for_service_to_be_available_callbacks_;
base::WeakPtrFactory<FakeAuthPolicyClient> weak_factory_{this}; base::WeakPtrFactory<FakeAuthPolicyClient> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(FakeAuthPolicyClient); DISALLOW_COPY_AND_ASSIGN(FakeAuthPolicyClient);
......
...@@ -89,6 +89,19 @@ class FakeAuthPolicyClientTest : public ::testing::Test { ...@@ -89,6 +89,19 @@ class FakeAuthPolicyClientTest : public ::testing::Test {
std::string())); std::string()));
} }
void WaitForServiceToBeAvailable() {
authpolicy_client()->WaitForServiceToBeAvailable(base::BindOnce(
&FakeAuthPolicyClientTest::OnWaitForServiceToBeAvailableCalled,
base::Unretained(this)));
}
void OnWaitForServiceToBeAvailableCalled(bool is_service_available) {
EXPECT_TRUE(is_service_available);
service_is_available_called_num_++;
}
int service_is_available_called_num_ = 0;
private: private:
FakeAuthPolicyClient* auth_policy_client_ptr_; // not owned. FakeAuthPolicyClient* auth_policy_client_ptr_; // not owned.
FakeSessionManagerClient* session_manager_client_ptr_; // not owned. FakeSessionManagerClient* session_manager_client_ptr_; // not owned.
...@@ -99,7 +112,7 @@ class FakeAuthPolicyClientTest : public ::testing::Test { ...@@ -99,7 +112,7 @@ class FakeAuthPolicyClientTest : public ::testing::Test {
// Tests parsing machine name. // Tests parsing machine name.
TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) { TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) {
authpolicy_client()->set_started(true); authpolicy_client()->SetStarted(true);
JoinAdDomain("correct_length1", kCorrectUserName, JoinAdDomain("correct_length1", kCorrectUserName,
base::BindOnce( base::BindOnce(
[](authpolicy::ErrorType error, const std::string& domain) { [](authpolicy::ErrorType error, const std::string& domain) {
...@@ -139,7 +152,7 @@ TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) { ...@@ -139,7 +152,7 @@ TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) {
// Tests join to a different machine domain. // Tests join to a different machine domain.
TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_MachineDomain) { TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_MachineDomain) {
authpolicy_client()->set_started(true); authpolicy_client()->SetStarted(true);
JoinAdDomainWithMachineDomain(kCorrectMachineName, kMachineDomain, JoinAdDomainWithMachineDomain(kCorrectMachineName, kMachineDomain,
kCorrectUserName, kCorrectUserName,
base::BindOnce([](authpolicy::ErrorType error, base::BindOnce([](authpolicy::ErrorType error,
...@@ -163,7 +176,7 @@ TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_MachineDomain) { ...@@ -163,7 +176,7 @@ TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_MachineDomain) {
// Tests parsing user name. // Tests parsing user name.
TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) { TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) {
authpolicy_client()->set_started(true); authpolicy_client()->SetStarted(true);
JoinAdDomain(kCorrectMachineName, kCorrectUserName, JoinAdDomain(kCorrectMachineName, kCorrectUserName,
base::BindOnce( base::BindOnce(
[](authpolicy::ErrorType error, const std::string& domain) { [](authpolicy::ErrorType error, const std::string& domain) {
...@@ -209,7 +222,7 @@ TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) { ...@@ -209,7 +222,7 @@ TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) {
// Tests that fake server does not support legacy encryption types. // Tests that fake server does not support legacy encryption types.
TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_NotSupportedEncType) { TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_NotSupportedEncType) {
authpolicy_client()->set_started(true); authpolicy_client()->SetStarted(true);
base::RunLoop loop; base::RunLoop loop;
authpolicy::JoinDomainRequest request; authpolicy::JoinDomainRequest request;
request.set_machine_name(kCorrectMachineName); request.set_machine_name(kCorrectMachineName);
...@@ -232,7 +245,7 @@ TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_NotSupportedEncType) { ...@@ -232,7 +245,7 @@ TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_NotSupportedEncType) {
// Test AuthenticateUser. // Test AuthenticateUser.
TEST_F(FakeAuthPolicyClientTest, AuthenticateUser_ByAccountId) { TEST_F(FakeAuthPolicyClientTest, AuthenticateUser_ByAccountId) {
authpolicy_client()->set_started(true); authpolicy_client()->SetStarted(true);
LockDeviceActiveDirectory(); LockDeviceActiveDirectory();
// Check that account_id do not change. // Check that account_id do not change.
AuthenticateUser( AuthenticateUser(
...@@ -279,7 +292,7 @@ TEST_F(FakeAuthPolicyClientTest, NotStartedAuthPolicyService) { ...@@ -279,7 +292,7 @@ TEST_F(FakeAuthPolicyClientTest, NotStartedAuthPolicyService) {
// Tests RefreshDevicePolicy. On a not locked device it should cache policy. On // Tests RefreshDevicePolicy. On a not locked device it should cache policy. On
// a locked device it should send policy to session_manager. // a locked device it should send policy to session_manager.
TEST_F(FakeAuthPolicyClientTest, NotLockedDeviceCachesPolicy) { TEST_F(FakeAuthPolicyClientTest, NotLockedDeviceCachesPolicy) {
authpolicy_client()->set_started(true); authpolicy_client()->SetStarted(true);
authpolicy_client()->RefreshDevicePolicy( authpolicy_client()->RefreshDevicePolicy(
base::BindOnce([](authpolicy::ErrorType error) { base::BindOnce([](authpolicy::ErrorType error) {
EXPECT_EQ(authpolicy::ERROR_DEVICE_POLICY_CACHED_BUT_NOT_SENT, error); EXPECT_EQ(authpolicy::ERROR_DEVICE_POLICY_CACHED_BUT_NOT_SENT, error);
...@@ -297,7 +310,7 @@ TEST_F(FakeAuthPolicyClientTest, NotLockedDeviceCachesPolicy) { ...@@ -297,7 +310,7 @@ TEST_F(FakeAuthPolicyClientTest, NotLockedDeviceCachesPolicy) {
// Tests that RefreshDevicePolicy stores device policy in the session manager. // Tests that RefreshDevicePolicy stores device policy in the session manager.
TEST_F(FakeAuthPolicyClientTest, RefreshDevicePolicyStoresPolicy) { TEST_F(FakeAuthPolicyClientTest, RefreshDevicePolicyStoresPolicy) {
authpolicy_client()->set_started(true); authpolicy_client()->SetStarted(true);
LockDeviceActiveDirectory(); LockDeviceActiveDirectory();
{ {
...@@ -335,4 +348,17 @@ TEST_F(FakeAuthPolicyClientTest, RefreshDevicePolicyStoresPolicy) { ...@@ -335,4 +348,17 @@ TEST_F(FakeAuthPolicyClientTest, RefreshDevicePolicyStoresPolicy) {
} }
} }
TEST_F(FakeAuthPolicyClientTest, WaitForServiceToBeAvailableCalled) {
WaitForServiceToBeAvailable();
WaitForServiceToBeAvailable();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, service_is_available_called_num_);
authpolicy_client()->SetStarted(true);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(2, service_is_available_called_num_);
WaitForServiceToBeAvailable();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(3, service_is_available_called_num_);
}
} // namespace chromeos } // namespace chromeos
...@@ -20,7 +20,7 @@ void FakeUpstartClient::Init(dbus::Bus* bus) {} ...@@ -20,7 +20,7 @@ void FakeUpstartClient::Init(dbus::Bus* bus) {}
void FakeUpstartClient::StartAuthPolicyService() { void FakeUpstartClient::StartAuthPolicyService() {
static_cast<FakeAuthPolicyClient*>( static_cast<FakeAuthPolicyClient*>(
DBusThreadManager::Get()->GetAuthPolicyClient()) DBusThreadManager::Get()->GetAuthPolicyClient())
->set_started(true); ->SetStarted(true);
} }
void FakeUpstartClient::RestartAuthPolicyService() { void FakeUpstartClient::RestartAuthPolicyService() {
...@@ -28,7 +28,7 @@ void FakeUpstartClient::RestartAuthPolicyService() { ...@@ -28,7 +28,7 @@ void FakeUpstartClient::RestartAuthPolicyService() {
DBusThreadManager::Get()->GetAuthPolicyClient()); DBusThreadManager::Get()->GetAuthPolicyClient());
DLOG_IF(WARNING, !authpolicy_client->started()) DLOG_IF(WARNING, !authpolicy_client->started())
<< "Trying to restart authpolicyd which is not started"; << "Trying to restart authpolicyd which is not started";
authpolicy_client->set_started(true); authpolicy_client->SetStarted(true);
} }
void FakeUpstartClient::StartMediaAnalytics( void FakeUpstartClient::StartMediaAnalytics(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment