OLD | NEW |
1 // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 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 | 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "chromeos/process_mock.h" | 7 #include "chromeos/process_mock.h" |
8 #include "chromeos/syslog_logging.h" | 8 #include "chromeos/syslog_logging.h" |
9 #include "chromeos/test_helpers.h" | 9 #include "chromeos/test_helpers.h" |
10 #include "gflags/gflags.h" | 10 #include "gflags/gflags.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 class IpsecManagerTest : public ::testing::Test { | 26 class IpsecManagerTest : public ::testing::Test { |
27 public: | 27 public: |
28 void SetUp() { | 28 void SetUp() { |
29 file_util::GetCurrentDirectory(&test_path_); | 29 file_util::GetCurrentDirectory(&test_path_); |
30 test_path_ = test_path_.Append("test"); | 30 test_path_ = test_path_.Append("test"); |
31 file_util::Delete(test_path_, true); | 31 file_util::Delete(test_path_, true); |
32 file_util::CreateDirectory(test_path_); | 32 file_util::CreateDirectory(test_path_); |
33 stateful_container_ = test_path_.Append("etc"); | 33 stateful_container_ = test_path_.Append("etc"); |
34 file_util::CreateDirectory(stateful_container_); | 34 file_util::CreateDirectory(stateful_container_); |
35 remote_ = "1.2.3.4"; | 35 remote_ = "vpnserver"; |
36 ServiceManager::temp_path_ = new FilePath(test_path_); | 36 ServiceManager::temp_path_ = new FilePath(test_path_); |
37 psk_file_ = test_path_.Append("psk").value(); | 37 psk_file_ = test_path_.Append("psk").value(); |
38 server_ca_file_ = test_path_.Append("server.ca").value(); | 38 server_ca_file_ = test_path_.Append("server.ca").value(); |
39 client_key_file_ = test_path_.Append("client.key").value(); | 39 client_key_file_ = test_path_.Append("client.key").value(); |
40 client_cert_file_ = test_path_.Append("client.cert").value(); | 40 client_cert_file_ = test_path_.Append("client.cert").value(); |
41 ipsec_run_path_ = test_path_.Append("run").value(); | 41 ipsec_run_path_ = test_path_.Append("run").value(); |
42 ipsec_up_file_ = FilePath(ipsec_run_path_).Append("up").value(); | 42 ipsec_up_file_ = FilePath(ipsec_run_path_).Append("up").value(); |
43 WriteFile(psk_file_, "secret"); | 43 WriteFile(psk_file_, "secret"); |
44 WriteFile(server_ca_file_, ""); | 44 WriteFile(server_ca_file_, ""); |
45 WriteFile(client_key_file_, ""); | 45 WriteFile(client_key_file_, ""); |
46 WriteFile(client_cert_file_, ""); | 46 WriteFile(client_cert_file_, ""); |
47 chromeos::ClearLog(); | 47 chromeos::ClearLog(); |
48 starter_ = new ProcessMock; | 48 starter_ = new ProcessMock; |
49 ipsec_.starter_.reset(starter_); | 49 ipsec_.starter_.reset(starter_); |
50 ipsec_.stateful_container_ = stateful_container_.value(); | 50 ipsec_.stateful_container_ = stateful_container_.value(); |
51 ipsec_.ipsec_group_ = getgid(); | 51 ipsec_.ipsec_group_ = getgid(); |
52 ipsec_.ipsec_run_path_ = ipsec_run_path_; | 52 ipsec_.ipsec_run_path_ = ipsec_run_path_; |
53 ipsec_.ipsec_up_file_ = ipsec_up_file_; | 53 ipsec_.ipsec_up_file_ = ipsec_up_file_; |
54 ipsec_.force_local_address_ = "5.6.7.8"; | 54 ipsec_.force_local_address_ = "5.6.7.8"; |
| 55 ipsec_.force_remote_address_ = "1.2.3.4"; |
55 } | 56 } |
56 | 57 |
57 void SetStartStarterExpectations(bool already_running); | 58 void SetStartStarterExpectations(bool already_running); |
58 | 59 |
59 protected: | 60 protected: |
60 void WriteFile(const std::string& file_path, const char* contents) { | 61 void WriteFile(const std::string& file_path, const char* contents) { |
61 if (file_util::WriteFile(FilePath(file_path), contents, | 62 if (file_util::WriteFile(FilePath(file_path), contents, |
62 strlen(contents)) < 0) { | 63 strlen(contents)) < 0) { |
63 LOG(ERROR) << "Unable to create " << file_path; | 64 LOG(ERROR) << "Unable to create " << file_path; |
64 } | 65 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 DoInitialize(1, true); | 177 DoInitialize(1, true); |
177 } | 178 } |
178 | 179 |
179 protected: | 180 protected: |
180 void CheckStarter(const std::string& actual); | 181 void CheckStarter(const std::string& actual); |
181 }; | 182 }; |
182 | 183 |
183 TEST_F(IpsecManagerTestIkeV1Psk, Initialize) { | 184 TEST_F(IpsecManagerTestIkeV1Psk, Initialize) { |
184 } | 185 } |
185 | 186 |
186 TEST_F(IpsecManagerTestIkeV1Psk, GetLocalAddressForRemote) { | 187 TEST_F(IpsecManagerTestIkeV1Psk, GetAddressesFromRemoteHost) { |
187 ipsec_.force_local_address_ = NULL; | 188 ipsec_.force_local_address_ = NULL; |
188 std::string local_address; | 189 std::string local_address; |
189 EXPECT_TRUE(ipsec_.GetLocalAddressForRemote("127.0.0.1", &local_address)); | 190 std::string remote_address; |
| 191 EXPECT_TRUE(ipsec_.GetAddressesFromRemoteHost("localhost", |
| 192 &remote_address, |
| 193 &local_address)); |
190 EXPECT_EQ("127.0.0.1", local_address); | 194 EXPECT_EQ("127.0.0.1", local_address); |
| 195 EXPECT_EQ("127.0.0.1", remote_address); |
191 } | 196 } |
192 | 197 |
193 TEST_F(IpsecManagerTestIkeV1Psk, FormatPsk) { | 198 TEST_F(IpsecManagerTestIkeV1Psk, FormatPsk) { |
194 FilePath input(test_path_.Append("psk")); | 199 FilePath input(test_path_.Append("psk")); |
195 const char psk[] = "pAssword\n"; | 200 const char psk[] = "pAssword\n"; |
196 file_util::WriteFile(input, psk, strlen(psk)); | 201 file_util::WriteFile(input, psk, strlen(psk)); |
197 FilePath output; | 202 FilePath output; |
198 std::string formatted; | 203 std::string formatted; |
199 EXPECT_TRUE(ipsec_.FormatPsk(input, &formatted)); | 204 EXPECT_TRUE(ipsec_.FormatPsk(input, &formatted)); |
200 EXPECT_EQ("5.6.7.8 1.2.3.4 : PSK \"pAssword\"\n", formatted); | 205 EXPECT_EQ("5.6.7.8 1.2.3.4 : PSK \"pAssword\"\n", formatted); |
(...skipping 22 matching lines...) Expand all Loading... |
223 "\tnat_traversal=yes\n" | 228 "\tnat_traversal=yes\n" |
224 "conn managed\n" | 229 "conn managed\n" |
225 "\tike=3des-sha1-modp1024\n" | 230 "\tike=3des-sha1-modp1024\n" |
226 "\tkeyexchange=ikev1\n" | 231 "\tkeyexchange=ikev1\n" |
227 "\tauthby=psk\n" | 232 "\tauthby=psk\n" |
228 "\tpfs=no\n" | 233 "\tpfs=no\n" |
229 "\trekey=no\n" | 234 "\trekey=no\n" |
230 "\tleft=%defaultroute\n" | 235 "\tleft=%defaultroute\n" |
231 "\tleftprotoport=17/1701\n" | 236 "\tleftprotoport=17/1701\n" |
232 "\tleftupdown=/usr/libexec/l2tpipsec_vpn/pluto_updown\n" | 237 "\tleftupdown=/usr/libexec/l2tpipsec_vpn/pluto_updown\n" |
233 "\tright=1.2.3.4\n" | 238 "\tright=vpnserver\n" |
234 "\trightprotoport=17/1701\n" | 239 "\trightprotoport=17/1701\n" |
235 "\ttype=transport\n" | 240 "\ttype=transport\n" |
236 "\tauto=start\n"; | 241 "\tauto=start\n"; |
237 EXPECT_EQ(kExpected, actual); | 242 EXPECT_EQ(kExpected, actual); |
238 } | 243 } |
239 | 244 |
240 TEST_F(IpsecManagerTestIkeV1Psk, FormatStarterConfigFile) { | 245 TEST_F(IpsecManagerTestIkeV1Psk, FormatStarterConfigFile) { |
241 CheckStarter(ipsec_.FormatStarterConfigFile()); | 246 CheckStarter(ipsec_.FormatStarterConfigFile()); |
242 } | 247 } |
243 | 248 |
(...skipping 24 matching lines...) Expand all Loading... |
268 | 273 |
269 TEST_F(IpsecManagerTestIkeV1Certs, Initialize) { | 274 TEST_F(IpsecManagerTestIkeV1Certs, Initialize) { |
270 DoInitialize(1, false); | 275 DoInitialize(1, false); |
271 } | 276 } |
272 | 277 |
273 | 278 |
274 int main(int argc, char** argv) { | 279 int main(int argc, char** argv) { |
275 SetUpTests(&argc, argv, true); | 280 SetUpTests(&argc, argv, true); |
276 return RUN_ALL_TESTS(); | 281 return RUN_ALL_TESTS(); |
277 } | 282 } |
OLD | NEW |