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) {
20 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_good.zip";
22 EXPECT_EQ(creds.GetMethod(), AuthMethod::kOauth2);
24 int r = authenticate(
"", creds, treehub);
30 TEST(authenticate, good_cert_zip) {
32 boost::filesystem::path filepath = certs_dir /
"good.zip";
33 boost::filesystem::path capath = certs_dir /
"server.crt";
35 EXPECT_EQ(creds.GetMethod(), AuthMethod::kTls);
37 int r = authenticate(capath.string(), creds, treehub);
40 curlEasySetoptWrapper(curl_handle.get(), CURLOPT_VERBOSE, 1);
41 treehub.InjectIntoCurl(
"test.txt", curl_handle.get());
42 CURLcode rc = curl_easy_perform(curl_handle.get());
43 EXPECT_EQ(CURLE_OK, rc);
49 TEST(authenticate, good_cert_noauth_zip) {
51 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_noauth_good.zip";
52 boost::filesystem::path capath = certs_dir /
"server.crt";
54 EXPECT_EQ(creds.GetMethod(), AuthMethod::kNone);
56 int r = authenticate(capath.string(), creds, treehub);
59 curlEasySetoptWrapper(curl_handle.get(), CURLOPT_VERBOSE, 1);
60 treehub.InjectIntoCurl(
"test.txt", curl_handle.get());
61 CURLcode rc = curl_easy_perform(curl_handle.get());
63 EXPECT_EQ(CURLE_OK, rc);
66 TEST(authenticate, bad_cert_zip) {
70 boost::filesystem::path filepath = certs_dir /
"bad.zip";
72 EXPECT_EQ(creds.GetMethod(), AuthMethod::kTls);
74 int r = authenticate(
"", creds, treehub);
77 curlEasySetoptWrapper(curl_handle.get(), CURLOPT_VERBOSE, 1);
78 treehub.InjectIntoCurl(
"test.txt", curl_handle.get());
79 CURLcode rc = curl_easy_perform(curl_handle.get());
81 EXPECT_NE(CURLE_OK, rc);
85 TEST(authenticate, bad_zip) {
86 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_bad.zip";
93 TEST(authenticate, no_json_zip) {
94 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_no_json.zip";
99 TEST(authenticate, good_json) {
101 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_good.json";
108 TEST(authenticate, bad_json) {
109 boost::filesystem::path filepath =
"tests/sota_tools/auth_test_bad.json";
116 TEST(authenticate, invalid_file) {
117 boost::filesystem::path filepath =
"tests/sota_tools/auth_test.cc";
122 TEST(authenticate, offline_sign_creds) {
125 boost::filesystem::path auth_offline =
"tests/sota_tools/auth_test_good_offline.zip";
127 EXPECT_TRUE(creds_offline.CanSignOffline());
131 TEST(authenticate, online_sign_creds) {
133 boost::filesystem::path auth_online = certs_dir /
"good.zip";
135 EXPECT_FALSE(creds_online.CanSignOffline());
139 int main(
int argc,
char **argv) {
140 ::testing::InitGoogleTest(&argc, argv);
142 std::cerr <<
"Error: " << argv[0] <<
" requires the path to the directory with generated certificates.\n";
147 boost::process::child server_process(
"tests/sota_tools/authentication/tls_server.py",
"1443", certs_dir);
148 boost::process::child server_noauth_process(
"tests/sota_tools/authentication/tls_server.py",
"--noauth",
"2443",
154 TestUtils::waitForServer(
"https://localhost:2443/");
155 return RUN_ALL_TESTS();