17 #ifndef __PROCESS_SSL_TEST_HPP__
18 #define __PROCESS_SSL_TEST_HPP__
23 #include <openssl/rsa.h>
24 #include <openssl/bio.h>
25 #include <openssl/x509.h>
26 #include <openssl/x509v3.h>
41 #endif // USE_SSL_SOCKET
57 #endif // USE_SSL_SOCKET
62 #ifndef USE_SSL_SOCKET
72 static void TearDownTestCase()
75 set_environment_variables({});
90 Path certificate_path()
106 Path scrap_certificate_path()
115 static void set_environment_variables(
116 const std::map<std::string, std::string>&
environment)
137 const std::string&
name,
const std::string& value, environment) {
142 process::network::openssl::reinitialize();
152 void generate_keys_and_certs() {
161 auto cleanup = [&private_key, &certificate, &scrap_key, &scrap_certificate](
163 if (private_key.
isSome()) { EVP_PKEY_free(private_key.
get()); }
164 if (certificate.isSome()) { X509_free(certificate.get()); }
165 if (scrap_key.isSome()) { EVP_PKEY_free(scrap_key.get()); }
166 if (scrap_certificate.
isSome()) { X509_free(scrap_certificate.
get()); }
170 if (abort_message.isSome()) {
171 ABORT(abort_message.get());
176 private_key = process::network::openssl::generate_private_rsa_key();
178 cleanup(
"Could not generate private key: " + private_key.
error());
186 cleanup(
"Could not determine hostname of libprocess: " +
191 certificate = process::network::openssl::generate_x509(
200 if (certificate.isError()) {
201 cleanup(
"Could not generate certificate: " + certificate.error());
206 process::network::openssl::write_key_file(private_key.
get(), key_path());
209 cleanup(
"Could not write private key to disk: " + key_write.
error());
214 process::network::openssl::write_certificate_file(
218 if (certificate_write.
isError()) {
219 cleanup(
"Could not write certificate to disk: " +
220 certificate_write.
error());
224 scrap_key = process::network::openssl::generate_private_rsa_key();
225 if (scrap_key.isError()) {
226 cleanup(
"Could not generate a scrap private key: " + scrap_key.error());
230 key_write = process::network::openssl::write_key_file(
235 cleanup(
"Could not write scrap key to disk: " + key_write.
error());
239 scrap_certificate = process::network::openssl::generate_x509(
243 if (scrap_certificate.
isError()) {
244 cleanup(
"Could not generate a scrap certificate: " +
245 scrap_certificate.
error());
249 certificate_write = process::network::openssl::write_certificate_file(
250 scrap_certificate.
get(),
251 scrap_certificate_path());
253 if (certificate_write.
isError()) {
254 cleanup(
"Could not write scrap certificate to disk: " +
255 certificate_write.
error());
273 public ::testing::WithParamInterface<const char*>
276 SSLTest() : data(
"Hello World!") {}
281 generate_keys_and_certs();
293 const std::map<std::string, std::string>&
environment)
295 set_environment_variables(environment);
299 process::network::internal::SocketImpl::Kind::SSL);
340 const std::map<std::string, std::string>& environment,
350 const std::vector<std::string> argv = {
352 "--use_ssl=" +
stringify(use_ssl_socket),
359 return Error(
"Could not establish build directory path");
365 std::map<std::string, std::string> full_environment(environment);
378 static constexpr
size_t BACKLOG = 5;
380 const std::string data;
383 #endif // USE_SSL_SOCKET
385 #endif // __PROCESS_SSL_TEST_HPP__
Try< Subprocess > subprocess(const std::string &path, std::vector< std::string > argv, const Subprocess::IO &in=Subprocess::FD(STDIN_FILENO), const Subprocess::IO &out=Subprocess::FD(STDOUT_FILENO), const Subprocess::IO &err=Subprocess::FD(STDERR_FILENO), const flags::FlagsBase *flags=nullptr, const Option< std::map< std::string, std::string >> &environment=None(), const Option< lambda::function< pid_t(const lambda::function< int()> &)>> &clone=None(), const std::vector< Subprocess::ParentHook > &parent_hooks={}, const std::vector< Subprocess::ChildHook > &child_hooks={})
Forks a subprocess and execs the specified 'path' with the specified 'argv', redirecting stdin...
Definition: errorbase.hpp:35
#define ABORT(...)
Definition: abort.hpp:40
Result< std::string > realpath(const std::string &path)
Definition: realpath.hpp:24
Try< Address > address(int_fd s)
Returns the Address with the assigned ip and assigned port.
Definition: network.hpp:79
static Result< T > error(const std::string &message)
Definition: result.hpp:53
process::Future< bool > cleanup(const std::string &hierarchy)
static Try< Socket > create(int_fd s, SocketImpl::Kind kind=SocketImpl::DEFAULT_KIND())
Returns an instance of a Socket using the specified kind of implementation.
Definition: socket.hpp:257
std::string getcwd()
Definition: getcwd.hpp:23
Try< Nothing > listen(int backlog)
Definition: socket.hpp:341
Try< std::string > getHostname(const IP &ip)
Definition: net.hpp:45
std::string join(const std::string &path1, const std::string &path2, const char _separator=os::PATH_SEPARATOR)
Definition: path.hpp:56
void setenv(const std::string &key, const std::string &value, bool overwrite=true)
Definition: os.hpp:157
#define STDERR_FILENO
Definition: windows.hpp:161
void unsetenv(const std::string &key)
Definition: os.hpp:167
Definition: result.hpp:40
constexpr char BACKLOG[]
Definition: statistics.hpp:29
process::Future< uint64_t > listen(const std::string &hierarchy, const std::string &cgroup, const std::string &control, const Option< std::string > &args=Option< std::string >::none())
Environment * environment
static IO FD(int_fd fd, IO::FDType type=IO::DUPLICATED)
Represents a POSIX or Windows file system path and offers common path manipulations.
Definition: path.hpp:145
uint16_t port
Definition: address.hpp:135
#define foreachpair(KEY, VALUE, ELEMS)
Definition: foreach.hpp:51
const T & get() const
Definition: result.hpp:115
Try< std::string > hostname()
Definition: net.hpp:154
static Try error(const E &e)
Definition: try.hpp:42
Definition: address.hpp:52
Try< AddressType > bind(const AddressType &address)
Definition: socket.hpp:336
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
bool isError() const
Definition: try.hpp:71
network::inet::Address address()
Returns the socket address associated with this instance of the library.
virtual void SetUp()
Definition: utils.hpp:35
bool isSome() const
Definition: result.hpp:111
bool isError() const
Definition: result.hpp:113
Try< Nothing > create(const std::string &hierarchy, const std::string &cgroup, bool recursive=false)
Try< Nothing > bind(int_fd s, const Address &address)
Definition: network.hpp:46
std::string stringify(int flags)
net::IP ip
Definition: address.hpp:134
Try< AddressType > address() const
Definition: socket.hpp:321
const T & get() const
Definition: try.hpp:73
constexpr const char * name
Definition: shell.hpp:41