blob: 4dad5c0da6b2fc0148957c33636198d9c3df8499 [file] [log] [blame]
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento0dc02012021-11-23 22:55:03 -05002/*
Davide Pesaventoeec07f52022-03-09 14:20:08 -05003 * Copyright (c) 2017-2022, Regents of the University of California.
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -07004 *
5 * This file is part of ndncert, a certificate management system based on NDN.
6 *
7 * ndncert is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License along with
16 * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ndncert authors and contributors.
19 */
20
Davide Pesavento0dc02012021-11-23 22:55:03 -050021#include "detail/ndncert-common.hpp"
22
Davide Pesavento829aff62022-05-15 20:30:34 -040023#include "tests/boost-test.hpp"
Davide Pesavento0dc02012021-11-23 22:55:03 -050024
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070025#include <boost/filesystem.hpp>
26#include <fstream>
27#include <stdlib.h>
28
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040029namespace ndncert::tests {
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070030
31class GlobalConfiguration
32{
33public:
34 GlobalConfiguration()
35 {
36 const char* envHome = ::getenv("HOME");
37 if (envHome)
38 m_home = envHome;
39
Davide Pesavento829aff62022-05-15 20:30:34 -040040 auto testHome = boost::filesystem::path(UNIT_TESTS_TMPDIR) / "test-home";
Davide Pesavento0dc02012021-11-23 22:55:03 -050041 if (::setenv("HOME", testHome.c_str(), 1) != 0)
42 NDN_THROW(std::runtime_error("setenv() failed"));
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070043
Davide Pesavento0dc02012021-11-23 22:55:03 -050044 boost::filesystem::create_directories(testHome);
45
46 std::ofstream clientConf((testHome / ".ndn" / "client.conf").c_str());
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070047 clientConf << "pib=pib-sqlite3" << std::endl
48 << "tpm=tpm-file" << std::endl;
49 }
50
Davide Pesavento0dc02012021-11-23 22:55:03 -050051 ~GlobalConfiguration() noexcept
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070052 {
Davide Pesavento0dc02012021-11-23 22:55:03 -050053 if (m_home.empty())
54 ::unsetenv("HOME");
55 else
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070056 ::setenv("HOME", m_home.data(), 1);
57 }
58
59private:
60 std::string m_home;
61};
62
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070063BOOST_TEST_GLOBAL_CONFIGURATION(GlobalConfiguration);
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070064
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040065} // namespace ndncert::tests