Aktualizr
C++ SOTA Client
All Classes Namespaces Files Functions Variables Enumerations Enumerator Pages
cert_provider_test.h
1 #ifndef CERT_PROVIDER_TEST_H_
2 #define CERT_PROVIDER_TEST_H_
3 
4 #include <set>
5 #include <unordered_map>
6 
7 #include "test_utils.h"
8 
9 class DeviceCredGenerator : public Process {
10  public:
11  DeviceCredGenerator(const std::string& exe_path) : Process(exe_path) {}
12 
13  class ArgSet {
14  private:
15  class Param {
16  public:
17  Param(const std::string& key, ArgSet* arg_set) : key_(key), arg_set_(arg_set) {}
18  Param& operator=(const std::string& val) {
19  arg_set_->arg_map_[key_] = val;
20  return *this;
21  }
22 
23  void clear() { arg_set_->arg_map_.erase(key_); }
24 
25  private:
26  const std::string key_;
27  ArgSet* arg_set_;
28  };
29 
30  class Option {
31  public:
32  Option(const std::string& key, ArgSet* arg_set) : key_(key), arg_set_(arg_set) {}
33  void set() { arg_set_->arg_set_.insert(key_); }
34  void clear() { arg_set_->arg_set_.erase(key_); }
35 
36  private:
37  const std::string key_;
38  ArgSet* arg_set_;
39  };
40 
41  public:
42  Param fleetCA{"--fleet-ca", this};
43  Param fleetCAKey{"--fleet-ca-key", this};
44  Param localDir{"--local", this};
45  Param directoryPrefix{"--directory", this};
46  Param configFile{"--config", this};
47  Param validityDays{"--days", this};
48  Param countryCode{"--certificate-c", this};
49  Param state{"--certificate-st", this};
50  Param organization{"--certificate-o", this};
51  Param commonName{"--certificate-cn", this};
52  Param rsaBits{"--bits", this};
53  Param credentialFile{"--credentials", this};
54 
55  Option provideRootCA{"--root-ca", this};
56  Option provideServerURL{"--server-url", this};
57 
58  public:
59  operator std::vector<std::string>() const {
60  std::vector<std::string> res_vect;
61 
62  for (auto val_pair : arg_map_) {
63  res_vect.push_back(val_pair.first);
64  res_vect.push_back(val_pair.second);
65  }
66 
67  for (auto key : arg_set_) {
68  res_vect.push_back(key);
69  }
70 
71  return res_vect;
72  }
73 
74  private:
75  std::unordered_map<std::string, std::string> arg_map_;
76  std::set<std::string> arg_set_;
77  };
78 
79  struct OutputPath {
80  OutputPath(const std::string& root_dir, const std::string& prefix = "/var/sota/import",
81  const std::string& private_key_file = "pkey.pem", const std::string& cert_file = "client.pem")
82  : directory{prefix},
83  privateKeyFile{private_key_file},
84  certFile{cert_file},
85  serverRootCA{"root.crt"},
86  gtwURLFile{"gateway.url"},
87  rootDir{root_dir},
88  privateKeyFileFullPath{(rootDir / directory / privateKeyFile)},
89  certFileFullPath{rootDir / directory / certFile},
90  serverRootCAFullPath{rootDir / directory / serverRootCA},
91  gtwURLFileFullPath{rootDir / directory / gtwURLFile} {}
92 
93  const std::string directory;
94  const std::string privateKeyFile;
95  const std::string certFile;
96  const std::string serverRootCA;
97  const std::string gtwURLFile;
98 
99  const boost::filesystem::path rootDir;
100  const boost::filesystem::path privateKeyFileFullPath;
101  const boost::filesystem::path certFileFullPath;
102  const boost::filesystem::path serverRootCAFullPath;
103  const boost::filesystem::path gtwURLFileFullPath;
104  };
105 };
106 
107 #endif // CERT_PROVIDER_TEST_H_
DeviceCredGenerator::OutputPath
Definition: cert_provider_test.h:79
DeviceCredGenerator
Definition: cert_provider_test.h:9
Process
Definition: test_utils.h:19
DeviceCredGenerator::ArgSet
Definition: cert_provider_test.h:13