Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chromeos/process_mock.h" | |
| 6 #include "chromeos/test_helpers.h" | |
| 7 #include "gflags/gflags.h" | |
| 8 #include "gtest/gtest.h" | |
| 9 #include "vpn-manager/l2tp_manager.h" | |
|
petkov
2011/03/04 18:42:56
add blank line
kmixter1
2011/03/05 02:48:59
Done.
| |
| 10 | |
| 11 DECLARE_string(password); | |
| 12 DECLARE_string(pppd_plugin); | |
| 13 DECLARE_string(user); | |
| 14 | |
| 15 using ::chromeos::ProcessMock; | |
| 16 using ::testing::_; | |
| 17 using ::testing::InSequence; | |
| 18 using ::testing::Return; | |
| 19 | |
| 20 class L2tpManagerTest : public ::testing::Test { | |
| 21 public: | |
| 22 void SetUp() { | |
| 23 test_path_ = FilePath("test"); | |
| 24 ServiceManager::temp_path_ = test_path_; | |
| 25 file_util::Delete(test_path_, true); | |
| 26 file_util::CreateDirectory(test_path_); | |
| 27 remote_ = "1.2.3.4"; | |
| 28 control_path_ = test_path_.Append("control"); | |
| 29 pppd_config_path_ = test_path_.Append("pppd.config"); | |
| 30 l2tpd_ = new ProcessMock; | |
| 31 l2tp_.l2tpd_.reset(l2tpd_); | |
| 32 l2tp_.l2tpd_control_path_ = control_path_; | |
| 33 FLAGS_pppd_plugin = ""; | |
| 34 FLAGS_user = "me"; | |
| 35 EXPECT_TRUE(l2tp_.Initialize(remote_)); | |
| 36 } | |
| 37 | |
| 38 protected: | |
| 39 std::string remote_; | |
| 40 FilePath test_path_; | |
| 41 FilePath control_path_; | |
| 42 FilePath pppd_config_path_; | |
| 43 L2tpManager l2tp_; | |
| 44 ProcessMock* l2tpd_; | |
| 45 }; | |
| 46 | |
| 47 TEST_F(L2tpManagerTest, FormatL2tpdConfiguration) { | |
| 48 static const char kBaseExpected[] = | |
| 49 "[lac managed]\n" | |
| 50 "lns = 1.2.3.4\n" | |
| 51 "require chap = yes\n" | |
| 52 "refuse pap = yes\n" | |
| 53 "require authentication = yes\n" | |
| 54 "name = me\n" | |
| 55 "ppp debug = yes\n" | |
| 56 "pppoptfile = test/pppd.config\n" | |
| 57 "length bit = yes\n"; | |
| 58 EXPECT_EQ(kBaseExpected, | |
| 59 l2tp_.FormatL2tpdConfiguration(pppd_config_path_.value())); | |
| 60 } | |
| 61 | |
| 62 TEST_F(L2tpManagerTest, FormatPppdConfiguration) { | |
| 63 const char kBaseExpected[] = | |
| 64 "ipcp-accept-local\n" | |
| 65 "ipcp-accept-remote\n" | |
| 66 "refuse-eap\n" | |
| 67 "noccp\n" | |
| 68 "noauth\n" | |
| 69 "crtscts\n" | |
| 70 "idle 1800\n" | |
| 71 "mtu 1410\n" | |
| 72 "mru 1410\n" | |
| 73 "nodefaultroute\n" | |
| 74 "debug\n" | |
| 75 "lock\n" | |
| 76 "connect-delay 5000\n"; | |
| 77 std::string expected(kBaseExpected); | |
| 78 EXPECT_EQ(expected, l2tp_.FormatPppdConfiguration()); | |
| 79 FLAGS_pppd_plugin = "myplugin"; | |
| 80 expected.append("plugin myplugin\n"); | |
| 81 EXPECT_EQ(expected, l2tp_.FormatPppdConfiguration()); | |
| 82 } | |
| 83 | |
| 84 TEST_F(L2tpManagerTest, Initiate) { | |
| 85 FLAGS_user = "me"; | |
| 86 FLAGS_password = "password"; | |
| 87 EXPECT_TRUE(l2tp_.Initiate()); | |
| 88 ExpectFileEquals("c managed me password\n", control_path_.value().c_str()); | |
| 89 FLAGS_pppd_plugin = "set"; | |
| 90 EXPECT_TRUE(l2tp_.Initiate()); | |
| 91 ExpectFileEquals("c managed\n", control_path_.value().c_str()); | |
| 92 } | |
| 93 | |
| 94 TEST_F(L2tpManagerTest, Terminate) { | |
| 95 EXPECT_TRUE(l2tp_.Terminate()); | |
| 96 ExpectFileEquals("d managed\n", control_path_.value().c_str()); | |
| 97 } | |
| 98 | |
| 99 TEST_F(L2tpManagerTest, Start) { | |
| 100 InSequence unused; | |
| 101 const int kMockFd = 567; | |
| 102 | |
| 103 EXPECT_CALL(*l2tpd_, Reset(0)); | |
| 104 EXPECT_CALL(*l2tpd_, AddArg(L2TPD)); | |
| 105 EXPECT_CALL(*l2tpd_, AddArg("-c")); | |
| 106 EXPECT_CALL(*l2tpd_, AddArg("test/l2tpd.conf")); | |
| 107 EXPECT_CALL(*l2tpd_, AddArg("-C")); | |
| 108 EXPECT_CALL(*l2tpd_, AddArg("test/l2tpd.control")); | |
| 109 EXPECT_CALL(*l2tpd_, AddArg("-D")); | |
| 110 EXPECT_CALL(*l2tpd_, RedirectUsingPipe(STDERR_FILENO, false)); | |
| 111 EXPECT_CALL(*l2tpd_, Start()); | |
| 112 EXPECT_CALL(*l2tpd_, GetPipe(STDERR_FILENO)).WillOnce(Return(kMockFd)); | |
| 113 | |
| 114 EXPECT_TRUE(l2tp_.Start()); | |
| 115 EXPECT_EQ(kMockFd, l2tp_.output_fd()); | |
| 116 } | |
| 117 | |
| 118 int main(int argc, char** argv) { | |
| 119 SetUpTests(&argc, argv, true); | |
| 120 return RUN_ALL_TESTS(); | |
| 121 } | |
| OLD | NEW |