1 #include <gtest/gtest.h>
6 #include <boost/process.hpp>
8 #include "authenticate.h"
9 #include "server_credentials.h"
10 #include "test_utils.h"
11 #include "treehub_server.h"
12 #include "utilities/utils.h"
14 boost::filesystem::path certs_dir;
18 TEST(authenticate, good_zip) {
21 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_good.zip";
23 EXPECT_EQ(creds.GetMethod(), AuthMethod::kOauth2);
25 int r = authenticate(
"", creds, treehub);
31 TEST(authenticate, good_cert_zip) {
33 boost::filesystem::path filepath = certs_dir /
"good.zip";
34 boost::filesystem::path capath = certs_dir /
"server.crt";
36 EXPECT_EQ(creds.GetMethod(), AuthMethod::kTls);
38 int r = authenticate(capath.string(), creds, treehub);
41 curlEasySetoptWrapper(curl_handle.get(), CURLOPT_VERBOSE, 1);
42 treehub.InjectIntoCurl(
"test.txt", curl_handle.get());
43 CURLcode rc = curl_easy_perform(curl_handle.get());
44 EXPECT_EQ(CURLE_OK, rc);
50 TEST(authenticate, good_cert_noauth_zip) {
52 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_noauth_good.zip";
53 boost::filesystem::path capath = certs_dir /
"server.crt";
55 EXPECT_EQ(creds.GetMethod(), AuthMethod::kNone);
57 int r = authenticate(capath.string(), creds, treehub);
60 curlEasySetoptWrapper(curl_handle.get(), CURLOPT_VERBOSE, 1);
61 treehub.InjectIntoCurl(
"test.txt", curl_handle.get());
62 CURLcode rc = curl_easy_perform(curl_handle.get());
64 EXPECT_EQ(CURLE_OK, rc);
67 TEST(authenticate, bad_cert_zip) {
71 boost::filesystem::path filepath = certs_dir /
"bad.zip";
73 EXPECT_EQ(creds.GetMethod(), AuthMethod::kTls);
75 int r = authenticate(
"", creds, treehub);
78 curlEasySetoptWrapper(curl_handle.get(), CURLOPT_VERBOSE, 1);
79 treehub.InjectIntoCurl(
"test.txt", curl_handle.get());
80 CURLcode rc = curl_easy_perform(curl_handle.get());
82 EXPECT_NE(CURLE_OK, rc);
86 TEST(authenticate, bad_zip) {
87 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_bad.zip";
94 TEST(authenticate, no_json_zip) {
95 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_no_json.zip";
100 TEST(authenticate, good_json) {
105 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_good.json";
111 TEST(authenticate, good_json_v2) {
114 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_good_v2.json";
123 TEST(authenticate, bad_json) {
124 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_bad.json";
131 TEST(authenticate, invalid_file) {
132 boost::filesystem::path filepath =
"tests/sota_tools/auth_test.cc";
137 TEST(authenticate, offline_sign_creds) {
140 boost::filesystem::path auth_offline =
"tests/sota_tools/auth_test_good_offline.zip";
142 EXPECT_TRUE(creds_offline.CanSignOffline());
146 TEST(authenticate, online_sign_creds) {
148 boost::filesystem::path auth_online = certs_dir /
"good.zip";
150 EXPECT_FALSE(creds_online.CanSignOffline());
154 int main(
int argc,
char **argv) {
155 ::testing::InitGoogleTest(&argc, argv);
157 std::cerr <<
"Error: " << argv[0] <<
" requires the path to the directory with generated certificates.\n";
162 boost::process::child server_process(
"tests/sota_tools/authentication/tls_server.py",
"1443", certs_dir);
163 boost::process::child server_noauth_process(
"tests/sota_tools/authentication/tls_server.py",
"--noauth",
"2443",
169 TestUtils::waitForServer(
"https://localhost:2443/");
170 return RUN_ALL_TESTS();