1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_SOCKET_SSL_TEST_UTIL_H_
#define NET_SOCKET_SSL_TEST_UTIL_H_
#include "build/build_config.h"
#include <string>
#include "base/file_path.h"
#include "base/process_util.h"
// TODO(dkegel): share this between net/base and
// chrome/browser without putting it in net.lib
namespace net {
// This object bounds the lifetime of an external python-based HTTP/HTTPS/FTP
// server that can provide various responses useful for testing.
// A few basic convenience methods are provided, but no
// URL handling methods (those belong at a higher layer, e.g. in
// url_request_unittest.h).
class TestServerLauncher {
public:
TestServerLauncher();
virtual ~TestServerLauncher();
enum Protocol {
ProtoHTTP, ProtoFTP
};
// Load the test root cert, if it hasn't been loaded yet.
bool LoadTestRootCert();
// Start src/net/tools/testserver/testserver.py and
// ask it to serve the given protocol.
// If protocol is HTTP, and cert_path is not empty, serves HTTPS.
// file_root_url specifies the root url on the server that documents will be
// served out of. This is /files/ by default.
// Returns true on success, false if files not found or root cert
// not trusted.
bool Start(Protocol protocol,
const std::string& host_name, int port,
const FilePath& document_root,
const FilePath& cert_path,
const std::wstring& file_root_url);
// Stop the server started by Start().
bool Stop();
// If you access the server's Kill url, it will exit by itself
// without a call to Stop().
// WaitToFinish is handy in that case.
// It returns true if the server exited cleanly.
bool WaitToFinish(int milliseconds);
// Paths to a good, an expired, and an invalid server certificate
// (use as arguments to Start()).
FilePath GetOKCertPath();
FilePath GetExpiredCertPath();
FilePath GetDocumentRootPath() { return document_root_dir_; }
// Issuer name of the root cert that should be trusted for the test to work.
static const wchar_t kCertIssuerName[];
// Hostname to use for test server
static const char kHostName[];
// Different hostname to use for test server (that still resolves to same IP)
static const char kMismatchedHostName[];
// Port to use for test server
static const int kOKHTTPSPort;
// Port to use for bad test server
static const int kBadHTTPSPort;
private:
// Wait a while for the server to start, return whether
// we were able to make a connection to it.
bool WaitToStart(const std::string& host_name, int port);
// Append to PYTHONPATH so Python can find pyftpdlib and tlslite.
void SetPythonPath();
// Path to our test root certificate.
FilePath GetRootCertPath();
// Returns false if our test root certificate is not trusted.
bool CheckCATrusted();
FilePath document_root_dir_;
FilePath cert_dir_;
FilePath python_runtime_;
base::ProcessHandle process_handle_;
#if defined(OS_LINUX)
struct PrivateCERTCertificate;
PrivateCERTCertificate *cert_;
#endif
DISALLOW_COPY_AND_ASSIGN(TestServerLauncher);
};
}
#endif // NET_SOCKET_SSL_TEST_UTIL_H_
|