Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/dbus/fake_auth_policy_client.h" | 5 #include "chromeos/dbus/fake_auth_policy_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/run_loop.h" | |
| 8 #include "components/signin/core/account_id/account_id.h" | 10 #include "components/signin/core/account_id/account_id.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 12 |
| 11 namespace chromeos { | 13 namespace chromeos { |
| 12 namespace { | 14 namespace { |
| 13 | 15 |
| 14 const char kCorrectMachineName[] = "machine_name"; | 16 const char kCorrectMachineName[] = "machine_name"; |
| 15 const char kCorrectUserName[] = "user@realm.com"; | 17 const char kCorrectUserName[] = "user@realm.com"; |
| 16 | 18 |
| 17 } // namespace | 19 } // namespace |
| 18 | 20 |
| 19 // Tests parsing machine name. | 21 // Tests parsing machine name. |
| 20 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) { | 22 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) { |
| 23 base::MessageLoop loop; | |
|
hashimoto
2017/04/04 12:04:13
You can let a test fixture class own this loop and
Roman Sorokin (ftl)
2017/04/06 15:00:32
Done.
| |
| 21 FakeAuthPolicyClient client; | 24 FakeAuthPolicyClient client; |
| 22 client.set_started(true); | 25 client.set_started(true); |
| 23 client.JoinAdDomain("correct_length1", kCorrectUserName, /* password_fd */ -1, | 26 client.JoinAdDomain("correct_length1", kCorrectUserName, /* password_fd */ -1, |
| 24 base::Bind([](authpolicy::ErrorType error) { | 27 base::Bind([](authpolicy::ErrorType error) { |
| 25 EXPECT_EQ(authpolicy::ERROR_NONE, error); | 28 EXPECT_EQ(authpolicy::ERROR_NONE, error); |
| 26 })); | 29 })); |
| 27 client.JoinAdDomain("", kCorrectUserName, /* password_fd */ -1, | 30 client.JoinAdDomain("", kCorrectUserName, /* password_fd */ -1, |
| 28 base::Bind([](authpolicy::ErrorType error) { | 31 base::Bind([](authpolicy::ErrorType error) { |
| 29 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error); | 32 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error); |
| 30 })); | 33 })); |
| 31 client.JoinAdDomain( | 34 client.JoinAdDomain( |
| 32 "too_long_machine_name", kCorrectUserName, /* password_fd */ -1, | 35 "too_long_machine_name", kCorrectUserName, /* password_fd */ -1, |
| 33 base::Bind([](authpolicy::ErrorType error) { | 36 base::Bind([](authpolicy::ErrorType error) { |
| 34 EXPECT_EQ(authpolicy::ERROR_MACHINE_NAME_TOO_LONG, error); | 37 EXPECT_EQ(authpolicy::ERROR_MACHINE_NAME_TOO_LONG, error); |
| 35 })); | 38 })); |
| 36 client.JoinAdDomain("invalid:name", kCorrectUserName, /* password_fd */ -1, | 39 client.JoinAdDomain("invalid:name", kCorrectUserName, /* password_fd */ -1, |
| 37 base::Bind([](authpolicy::ErrorType error) { | 40 base::Bind([](authpolicy::ErrorType error) { |
| 38 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error); | 41 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error); |
| 39 })); | 42 })); |
| 40 client.JoinAdDomain(">nvalidname", kCorrectUserName, /* password_fd */ -1, | 43 client.JoinAdDomain(">nvalidname", kCorrectUserName, /* password_fd */ -1, |
| 41 base::Bind([](authpolicy::ErrorType error) { | 44 base::Bind([](authpolicy::ErrorType error) { |
| 42 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error); | 45 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error); |
| 43 })); | 46 })); |
| 47 | |
| 48 base::RunLoop().RunUntilIdle(); | |
| 44 } | 49 } |
| 45 | 50 |
| 46 // Tests parsing user name. | 51 // Tests parsing user name. |
| 47 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) { | 52 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) { |
| 53 base::MessageLoop loop; | |
| 48 FakeAuthPolicyClient client; | 54 FakeAuthPolicyClient client; |
| 49 client.set_started(true); | 55 client.set_started(true); |
| 50 client.JoinAdDomain(kCorrectMachineName, "user@realm.com", | 56 client.JoinAdDomain(kCorrectMachineName, "user@realm.com", |
| 51 /* password_fd */ -1, | 57 /* password_fd */ -1, |
| 52 base::Bind([](authpolicy::ErrorType error) { | 58 base::Bind([](authpolicy::ErrorType error) { |
| 53 EXPECT_EQ(authpolicy::ERROR_NONE, error); | 59 EXPECT_EQ(authpolicy::ERROR_NONE, error); |
| 54 })); | 60 })); |
| 55 client.JoinAdDomain(kCorrectMachineName, "user", /* password_fd */ -1, | 61 client.JoinAdDomain(kCorrectMachineName, "user", /* password_fd */ -1, |
| 56 base::Bind([](authpolicy::ErrorType error) { | 62 base::Bind([](authpolicy::ErrorType error) { |
| 57 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); | 63 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); |
| 58 })); | 64 })); |
| 59 client.JoinAdDomain(kCorrectMachineName, "", /* password_fd */ -1, | 65 client.JoinAdDomain(kCorrectMachineName, "", /* password_fd */ -1, |
| 60 base::Bind([](authpolicy::ErrorType error) { | 66 base::Bind([](authpolicy::ErrorType error) { |
| 61 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); | 67 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); |
| 62 })); | 68 })); |
| 63 client.JoinAdDomain(kCorrectMachineName, "user@", /* password_fd */ -1, | 69 client.JoinAdDomain(kCorrectMachineName, "user@", /* password_fd */ -1, |
| 64 base::Bind([](authpolicy::ErrorType error) { | 70 base::Bind([](authpolicy::ErrorType error) { |
| 65 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); | 71 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); |
| 66 })); | 72 })); |
| 67 client.JoinAdDomain(kCorrectMachineName, "@realm", /* password_fd */ -1, | 73 client.JoinAdDomain(kCorrectMachineName, "@realm", /* password_fd */ -1, |
| 68 base::Bind([](authpolicy::ErrorType error) { | 74 base::Bind([](authpolicy::ErrorType error) { |
| 69 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); | 75 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); |
| 70 })); | 76 })); |
| 71 client.JoinAdDomain(kCorrectMachineName, "user@realm@com", | 77 client.JoinAdDomain(kCorrectMachineName, "user@realm@com", |
| 72 /* password_fd */ -1, | 78 /* password_fd */ -1, |
| 73 base::Bind([](authpolicy::ErrorType error) { | 79 base::Bind([](authpolicy::ErrorType error) { |
| 74 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); | 80 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); |
| 75 })); | 81 })); |
| 82 | |
| 83 base::RunLoop().RunUntilIdle(); | |
| 76 } | 84 } |
| 77 | 85 |
| 78 // Tests calls to not started authpolicyd fails. | 86 // Tests calls to not started authpolicyd fails. |
| 79 TEST(FakeAuthPolicyClientTest, NotStartedAuthPolicyService) { | 87 TEST(FakeAuthPolicyClientTest, NotStartedAuthPolicyService) { |
| 88 base::MessageLoop loop; | |
| 80 FakeAuthPolicyClient client; | 89 FakeAuthPolicyClient client; |
| 81 client.JoinAdDomain(kCorrectMachineName, kCorrectUserName, | 90 client.JoinAdDomain(kCorrectMachineName, kCorrectUserName, |
| 82 /* password_fd */ -1, | 91 /* password_fd */ -1, |
| 83 base::Bind([](authpolicy::ErrorType error) { | 92 base::Bind([](authpolicy::ErrorType error) { |
| 84 EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error); | 93 EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error); |
| 85 })); | 94 })); |
| 86 client.AuthenticateUser( | 95 client.AuthenticateUser( |
| 87 kCorrectUserName, /* password_fd */ -1, | 96 kCorrectUserName, /* password_fd */ -1, |
| 88 base::Bind([](authpolicy::ErrorType error, | 97 base::Bind([](authpolicy::ErrorType error, |
| 89 const authpolicy::ActiveDirectoryAccountData&) { | 98 const authpolicy::ActiveDirectoryAccountData&) { |
| 90 EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error); | 99 EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error); |
| 91 })); | 100 })); |
| 92 client.RefreshDevicePolicy( | 101 client.RefreshDevicePolicy( |
| 93 base::Bind([](bool success) { EXPECT_FALSE(success); })); | 102 base::Bind([](bool success) { EXPECT_FALSE(success); })); |
| 94 client.RefreshUserPolicy( | 103 client.RefreshUserPolicy( |
| 95 AccountId::FromUserEmail(kCorrectUserName), | 104 AccountId::FromUserEmail(kCorrectUserName), |
| 96 base::Bind([](bool success) { EXPECT_FALSE(success); })); | 105 base::Bind([](bool success) { EXPECT_FALSE(success); })); |
| 106 | |
| 107 base::RunLoop().RunUntilIdle(); | |
| 97 } | 108 } |
| 98 | 109 |
| 99 } // namespace chromeos | 110 } // namespace chromeos |
| OLD | NEW |