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 |
| 21 class FakeAuthPolicyClientTest : public ::testing::Test { | |
| 22 protected: | |
| 23 FakeAuthPolicyClient client; | |
|
xiyuan
2017/04/07 15:04:24
client -> client_
And I would prefer to put this
Roman Sorokin (ftl)
2017/04/10 16:09:00
Done.
| |
| 24 | |
| 25 private: | |
| 26 base::MessageLoop loop; | |
|
xiyuan
2017/04/07 15:04:24
loop -> loop_
Roman Sorokin (ftl)
2017/04/10 16:09:00
Done.
| |
| 27 }; | |
|
xiyuan
2017/04/07 15:04:24
nit: DISALLOW_COPY_AND_ASSIGN
Roman Sorokin (ftl)
2017/04/10 16:09:00
Done.
| |
| 28 | |
| 19 // Tests parsing machine name. | 29 // Tests parsing machine name. |
| 20 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) { | 30 TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_ParseMachineName) { |
| 21 FakeAuthPolicyClient client; | |
| 22 client.set_started(true); | 31 client.set_started(true); |
| 23 client.JoinAdDomain("correct_length1", kCorrectUserName, /* password_fd */ -1, | 32 client.JoinAdDomain("correct_length1", kCorrectUserName, /* password_fd */ -1, |
| 24 base::Bind([](authpolicy::ErrorType error) { | 33 base::Bind([](authpolicy::ErrorType error) { |
| 25 EXPECT_EQ(authpolicy::ERROR_NONE, error); | 34 EXPECT_EQ(authpolicy::ERROR_NONE, error); |
| 26 })); | 35 })); |
| 27 client.JoinAdDomain("", kCorrectUserName, /* password_fd */ -1, | 36 client.JoinAdDomain("", kCorrectUserName, /* password_fd */ -1, |
| 28 base::Bind([](authpolicy::ErrorType error) { | 37 base::Bind([](authpolicy::ErrorType error) { |
| 29 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error); | 38 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error); |
| 30 })); | 39 })); |
| 31 client.JoinAdDomain( | 40 client.JoinAdDomain( |
| 32 "too_long_machine_name", kCorrectUserName, /* password_fd */ -1, | 41 "too_long_machine_name", kCorrectUserName, /* password_fd */ -1, |
| 33 base::Bind([](authpolicy::ErrorType error) { | 42 base::Bind([](authpolicy::ErrorType error) { |
| 34 EXPECT_EQ(authpolicy::ERROR_MACHINE_NAME_TOO_LONG, error); | 43 EXPECT_EQ(authpolicy::ERROR_MACHINE_NAME_TOO_LONG, error); |
| 35 })); | 44 })); |
| 36 client.JoinAdDomain("invalid:name", kCorrectUserName, /* password_fd */ -1, | 45 client.JoinAdDomain("invalid:name", kCorrectUserName, /* password_fd */ -1, |
| 37 base::Bind([](authpolicy::ErrorType error) { | 46 base::Bind([](authpolicy::ErrorType error) { |
| 38 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error); | 47 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error); |
| 39 })); | 48 })); |
| 40 client.JoinAdDomain(">nvalidname", kCorrectUserName, /* password_fd */ -1, | 49 client.JoinAdDomain(">nvalidname", kCorrectUserName, /* password_fd */ -1, |
| 41 base::Bind([](authpolicy::ErrorType error) { | 50 base::Bind([](authpolicy::ErrorType error) { |
| 42 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error); | 51 EXPECT_EQ(authpolicy::ERROR_BAD_MACHINE_NAME, error); |
| 43 })); | 52 })); |
| 53 | |
| 54 base::RunLoop().RunUntilIdle(); | |
| 44 } | 55 } |
| 45 | 56 |
| 46 // Tests parsing user name. | 57 // Tests parsing user name. |
| 47 TEST(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) { | 58 TEST_F(FakeAuthPolicyClientTest, JoinAdDomain_ParseUPN) { |
| 48 FakeAuthPolicyClient client; | |
| 49 client.set_started(true); | 59 client.set_started(true); |
| 50 client.JoinAdDomain(kCorrectMachineName, "user@realm.com", | 60 client.JoinAdDomain(kCorrectMachineName, "user@realm.com", |
| 51 /* password_fd */ -1, | 61 /* password_fd */ -1, |
| 52 base::Bind([](authpolicy::ErrorType error) { | 62 base::Bind([](authpolicy::ErrorType error) { |
| 53 EXPECT_EQ(authpolicy::ERROR_NONE, error); | 63 EXPECT_EQ(authpolicy::ERROR_NONE, error); |
| 54 })); | 64 })); |
| 55 client.JoinAdDomain(kCorrectMachineName, "user", /* password_fd */ -1, | 65 client.JoinAdDomain(kCorrectMachineName, "user", /* password_fd */ -1, |
| 56 base::Bind([](authpolicy::ErrorType error) { | 66 base::Bind([](authpolicy::ErrorType error) { |
| 57 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); | 67 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); |
| 58 })); | 68 })); |
| 59 client.JoinAdDomain(kCorrectMachineName, "", /* password_fd */ -1, | 69 client.JoinAdDomain(kCorrectMachineName, "", /* password_fd */ -1, |
| 60 base::Bind([](authpolicy::ErrorType error) { | 70 base::Bind([](authpolicy::ErrorType error) { |
| 61 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); | 71 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); |
| 62 })); | 72 })); |
| 63 client.JoinAdDomain(kCorrectMachineName, "user@", /* password_fd */ -1, | 73 client.JoinAdDomain(kCorrectMachineName, "user@", /* password_fd */ -1, |
| 64 base::Bind([](authpolicy::ErrorType error) { | 74 base::Bind([](authpolicy::ErrorType error) { |
| 65 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); | 75 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); |
| 66 })); | 76 })); |
| 67 client.JoinAdDomain(kCorrectMachineName, "@realm", /* password_fd */ -1, | 77 client.JoinAdDomain(kCorrectMachineName, "@realm", /* password_fd */ -1, |
| 68 base::Bind([](authpolicy::ErrorType error) { | 78 base::Bind([](authpolicy::ErrorType error) { |
| 69 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); | 79 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); |
| 70 })); | 80 })); |
| 71 client.JoinAdDomain(kCorrectMachineName, "user@realm@com", | 81 client.JoinAdDomain(kCorrectMachineName, "user@realm@com", |
| 72 /* password_fd */ -1, | 82 /* password_fd */ -1, |
| 73 base::Bind([](authpolicy::ErrorType error) { | 83 base::Bind([](authpolicy::ErrorType error) { |
| 74 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); | 84 EXPECT_EQ(authpolicy::ERROR_PARSE_UPN_FAILED, error); |
| 75 })); | 85 })); |
| 86 | |
| 87 base::RunLoop().RunUntilIdle(); | |
| 76 } | 88 } |
| 77 | 89 |
| 78 // Tests calls to not started authpolicyd fails. | 90 // Tests calls to not started authpolicyd fails. |
| 79 TEST(FakeAuthPolicyClientTest, NotStartedAuthPolicyService) { | 91 TEST_F(FakeAuthPolicyClientTest, NotStartedAuthPolicyService) { |
| 80 FakeAuthPolicyClient client; | |
| 81 client.JoinAdDomain(kCorrectMachineName, kCorrectUserName, | 92 client.JoinAdDomain(kCorrectMachineName, kCorrectUserName, |
| 82 /* password_fd */ -1, | 93 /* password_fd */ -1, |
| 83 base::Bind([](authpolicy::ErrorType error) { | 94 base::Bind([](authpolicy::ErrorType error) { |
| 84 EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error); | 95 EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error); |
| 85 })); | 96 })); |
| 86 client.AuthenticateUser( | 97 client.AuthenticateUser( |
| 87 kCorrectUserName, /* password_fd */ -1, | 98 kCorrectUserName, /* password_fd */ -1, |
| 88 base::Bind([](authpolicy::ErrorType error, | 99 base::Bind([](authpolicy::ErrorType error, |
| 89 const authpolicy::ActiveDirectoryAccountData&) { | 100 const authpolicy::ActiveDirectoryAccountData&) { |
| 90 EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error); | 101 EXPECT_EQ(authpolicy::ERROR_DBUS_FAILURE, error); |
| 91 })); | 102 })); |
| 92 client.RefreshDevicePolicy( | 103 client.RefreshDevicePolicy( |
| 93 base::Bind([](bool success) { EXPECT_FALSE(success); })); | 104 base::Bind([](bool success) { EXPECT_FALSE(success); })); |
| 94 client.RefreshUserPolicy( | 105 client.RefreshUserPolicy( |
| 95 AccountId::FromUserEmail(kCorrectUserName), | 106 AccountId::FromUserEmail(kCorrectUserName), |
| 96 base::Bind([](bool success) { EXPECT_FALSE(success); })); | 107 base::Bind([](bool success) { EXPECT_FALSE(success); })); |
| 108 | |
| 109 base::RunLoop().RunUntilIdle(); | |
| 97 } | 110 } |
| 98 | 111 |
| 99 } // namespace chromeos | 112 } // namespace chromeos |
| OLD | NEW |